Skip to content

fix: atomically persist subtitle job state#5

Open
z2z23n0 wants to merge 1 commit into
OpenMOSS:mainfrom
z2z23n0:fix/atomically-persist-job-state
Open

fix: atomically persist subtitle job state#5
z2z23n0 wants to merge 1 commit into
OpenMOSS:mainfrom
z2z23n0:fix/atomically-persist-job-state

Conversation

@z2z23n0

@z2z23n0 z2z23n0 commented Jul 10, 2026

Copy link
Copy Markdown

Problem

job.json was written directly with Path.write_text, which truncates the existing file before the replacement JSON is complete. An interrupted write can therefore leave invalid JSON, and the next startup silently skips that job.

Fix

  • Write the complete payload to a unique temporary file in the job directory.
  • Atomically replace job.json with os.replace only after the temporary write succeeds.
  • Clean up temporary files on success and failure.
  • Add regression coverage for interrupted writes, same-directory replacement, and restart loading with an orphan temporary file.

Tests

  • python -m pytest -q tests/test_job_persistence.py (3 passed)
  • python -m pytest -q (30 passed)

@z2z23n0 z2z23n0 marked this pull request as ready for review July 10, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant