Repository navigation
fix(taskq): stop fencing a user stop on the generation it read - #17161
Conversation
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. What this change shipsInventory (3 items) — 3 justifiedIntent: when a user presses Stop on a sub-agent that has not started yet, the stop should actually cancel it, so the parent session is not left stuck behind it with a 409. This is a FIX (#17158, plus a parametrized test the description says fails on base).
[FIRST-PRINCIPLES-REVIEWED] fe5c1cd Description read[DESCRIPTION-READ] f83f1f9418e08d40f451eeb1763713a78665ad156deb3d82f13cd10191076178 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check whether Suggestions
[DESIGN-REVIEWED] fe5c1cd Description read[DESCRIPTION-READ] c48a4721df83b843db7913194d1dd0210c1b9829cfb61456214b305902ee7299 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
cfef4ea to
b52a2cb
Compare
|
|
|
CI note for cfef4ea: both reds were inherited, not caused by this diff. Coverage Gate flagged |
b52a2cb to
3534b29
Compare
|
taskq_cancel_queued read the row, then cancelled under that read's generation. A claim, requeue or wake that bumps the generation while the row stays unstarted made the store refuse the cancel as stale_result, and the stop was dropped. A retry_wait row left that way is outside the boot reconciler's ACTIVE set and stays in the parent's queued count, so the attached-children guard never clears. The generation fence added nothing the in-transaction only_from test does not already guarantee: a row that reached starting/running is still refused and left to the live reap. Drop the generation argument and keep only_from. Closes #17158
3534b29 to
fe5c1cd
Compare
|
CI note for fe5c1cd: Backend Tests (Windows) (2) failed in |
iamwhatever
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean, security checklist all-NO, AI reviewers green. Category: taskq_cancel_queued drops the generation fence on a user stop so a row whose generation moved while still unstarted (admitted / retry_wait) is cancelled instead of refused as stale_result; only_from still limits the cancel to unstarted rows; one-line root-cause fix plus integration test. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/taskq.md.
Problem / Motivation
Goal: A user Stop on a sub-agent row that has not started still cancels it when a concurrent write moved only the row's generation, so the parent is never left blocked behind a row nobody will settle.
taskq_cancel_queuedreads the row and then cancels it under the generation it read. If a claim (queued -> admitted), a requeue or a wake (intoretry_wait) bumps the generation in between, the row is still unstarted butTaskStore.cancelrefuses withstale_result. The stop is then dropped. Aretry_waitrow left behind this way is outside the boot reconciler'sACTIVEset and is still counted bycount_pending. The parent's attached-children guard (/continue->409 slot_subagents_running) therefore stays wedged across restarts. Full mechanism with file:line evidence is in #17158.Why it matters
The user pressed Stop and was shown a stop, but the session stays blocked with a 409 that names no task. Restarting does not help. Recovering needs a manual edit of the task database.
Not a goal
TaskStore.cancel's generation fence oronly_fromsemantics.retry_wait/CLAIMABLErows.What changed (motivation → approach → change)
retry_waitrow keeps the parent attached forever.taskq_cancel_queuedtakes aNonefrom the conditional cancel to mean "the drain started it" even when only the generation moved and the row is still unstarted. Nothing retries the cancel for a store-only row._repost_unlanded_cancelcovers window entries only.taskq_cancel_queued(src/kiro_crew/subagent_manager/admission/taskq_bridge.py) no longer passesgeneration=rec.generationtoTaskStore.cancel; it keepsonly_from=unstarted. The store re-testsonly_frominside the cancel's own transaction, so a row that reachedstarting/runningis still never cancelled under its executor, while a row whose generation alone moved (a claim, requeue or wake) is still unstarted and now cancels.docs/system-specs/modules/taskq.md(caller table + test list) is updated in the same commit.Backwards compatibility
Compatible: the function's contract (params on cancel,
Noneotherwise) and its refusal of a started row are unchanged. It only cancels in one more case, a row that is still unstarted at a newer generation, which is the stop the user asked for.Removes nothing: no path, record, key or validator is removed or tightened. A stop that used to be dropped now lands.
Tests
test/test_taskq_admission_integration.py::test_a_stop_whose_generation_moved_under_an_unstarted_row_still_cancels[queued|retry_wait]: forces a realclaiminsidetaskq_cancel_queued's read, so the generation moves before the cancel. It asserts the row endscancelled, the params come back, and nostale_resultrefusal was recorded. Mutation check: restoringgeneration=rec.generation(the pre-fix code) turns both cases red.test_a_queued_row_the_drain_started_is_not_cancelled_under_the_spawnstill passes, so a row that went live is still left to the reap.Manual verification
N/A. Unit coverage is sufficient: the race is forced deterministically against the real store and real admission.
python3 scripts/local-gate.pypassed (backend related: 776 passed; frontend related: 10147 passed).Related Issues
Closes #17158
Pattern harvest
Rule candidate: review-prompt
Pattern: "a read-then-conditional-write caller fences on more than its decision needs; when the in-transaction state predicate (
only_from) already guarantees safety, an added generation fence only turns harmless concurrent bumps into dropped operations"Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement