Skip to content

Don't let a stale job persist overwrite a completed scan - #20

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-9b78
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-9b78

Conversation

@cursor

@cursor cursor Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

persist_job snapshotted job state at schedule time and wrote it asynchronously. A slower in-flight write of a running snapshot could finish after the terminal persist, leaving status=running on disk. On reload, ScanJob.from_dict then marked the finished scan as failed ("Scan interrupted by server restart"), dropping the completed result.

Trigger: a scan emits enough events to trigger a periodic persist, then completes while that write is still in the thread pool (JSON dump + fsync). Last writer wins with the stale snapshot.

Fix: snapshot at write time and serialize snapshot+write per job so the latest in-memory state always wins. If the job was deleted mid-write, drop the durable record so it is not resurrected.

Validation: test_jobs_sse.py::TestPersistDoesNotClobberTerminalState (overlapping persist keeps completed; delete during persist does not resurrect). python3 -m pytest test_jobs_sse.py — 27 passed.

Open in Web View Automation 

persist_job snapshotted ScanJob.to_dict() at schedule time and wrote it
asynchronously. A slower in-flight write of a 'running' snapshot could
finish after the terminal persist, leaving status=running on disk.
Reload then marked the finished scan as failed ('interrupted by server
restart'). Snapshot at write time and serialise per job so the latest
state always wins; drop the file if the job was deleted mid-write.

Co-authored-by: dmitryflynn <dmitryflynn@users.noreply.github.com>
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