Skip to content

Don't mark a cancelled scan as completed - #27

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

Don't mark a cancelled scan as completed#27
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-818a

Conversation

@cursor

@cursor cursor Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

Cancelling a scan near the end of a run could persist the job as completed instead of cancelled.

Trigger: user hits Cancel after the engine has returned (or after JobCancelled was swallowed by a post-scan except Exception: pass) but before the local agent finalized the job. The worker then assigned job.status = "completed" unconditionally, so the cancel was overwritten. The UI showed a finished scan the operator had already cancelled.

Root cause

api/agents/local_agent.py finalized with a direct job.status = "completed" instead of try_set_terminal. That races with cancel_job(), which does use the atomic helper. The JobCancelled handler also refused to revert once status was already completed.

Separately, src/engine.py swallowed JobCancelled in trailing except Exception: pass blocks (reasoning / architecture / triage emits), so a cancel during those hooks let run_scan return normally and hit the buggy complete path.

Fix

  • Commit completed status only via try_set_terminal. If cancel already won, leave the job cancelled.
  • Re-raise JobCancelled from the post-scan fail-soft handlers so cancel still unwinds the engine.

Validation

python3 -m pytest test_local_agent_cancel.py test_jobmanager_concurrency.py test_jobs_sse.py test_agent_architecture.py -q — 67 passed.

Open in Web View Automation 

The local agent assigned status=completed after the engine returned, even when
cancel_job had already won try_set_terminal. Combined with JobCancelled being
swallowed by post-scan except Exception: pass, a user cancel near the end of a
scan was persisted as a finished result.

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