Don't mark a cancelled scan as completed - #27
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
JobCancelledwas swallowed by a post-scanexcept Exception: pass) but before the local agent finalized the job. The worker then assignedjob.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.pyfinalized with a directjob.status = "completed"instead oftry_set_terminal. That races withcancel_job(), which does use the atomic helper. The JobCancelled handler also refused to revert once status was alreadycompleted.Separately,
src/engine.pyswallowedJobCancelledin trailingexcept Exception: passblocks (reasoning / architecture / triage emits), so a cancel during those hooks letrun_scanreturn normally and hit the buggy complete path.Fix
try_set_terminal. If cancel already won, leave the job cancelled.JobCancelledfrom 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.