Repository navigation
fix(work-ledger): drain a person steer so a cancel cannot orphan it - #36658
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the steer path now goes through the same [DESIGN-REVIEWED] 7734f95 Description read[DESCRIPTION-READ] c972a6da5eb13e39f3c89cfa7e3412bf02449fa68ee25eaf6a3e292254e8d7ca 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The steer path now uses the existing drain helper. A grep found 4 snapshot-then-record sequences in the handlers: the 3 siblings were already drained, and this PR covers the last one. What this change shipsInventory (2 items) — 2 justifiedIntent: make sure a person's steer on a work item is either fully recorded or fully undone, even if the gateway shuts down mid-write. FIX.
[FIRST-PRINCIPLES-REVIEWED] 7734f95 Description read[DESCRIPTION-READ] 0ad959167ad3c2e33510a51491679fb2cfab6c249b841b98575a6f428c85327f That sha256 names the PR description this verdict read. 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: |
`record_person_steer_result` commits the `steer` event (`apply_person_steer`) and then appends its `work/recorded` crew-log entry, undoing the event when the append does not land -- but it ran that commit-then-record sequence bare, inside the board lock. A cancellation (gateway shutdown) landing between the commit and the append left the steer event in the cache with no crew-log entry and no undo, so the Board and sidebar showed an answered steer that the next `work_ledger_rebuild` silently dropped, and callers reported `not_recorded` while the cache said otherwise. Wrap the commit-and-record block in a nested coroutine and drive it through `_drain_before_cancelling`, the same way the worker-report route and the conductor write path already do: once the event commits, the append (or the restore) finishes before the cancellation is re-raised. Pre-commit reads and refusals are unchanged.
d3b3858 to
7734f95
Compare
Code change approver recommendation: ApproveWhy: the decider estimates a 6% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. Moves the steer path's commit-then-record block into a nested coroutine awaited through _drain_before_cancelling, matching the worker-report, conductor and remote-ingest write paths. The moved body only changed indentation. The drain runs while the board lock is held, and the return codes and pre-commit refusals are unchanged. The new test pauses the write after the commit, cancels it, and asserts the cancellation still reaches the caller and the steer's crew-log entry was written; on main the cancel would land while the write is paused and that assertion would fail. The test's patch of _board_header through the routes module reaches the worker module because that module copies patches to every holder of the name. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving. On this head, the review confirmed that the commit-then-record block of record_person_steer_result now runs inside the existing _drain_before_cancelling helper, still under the board lock. Every early return keeps its code and its audit entry. The new test was also run against the merge-base version of work_ledger_worker.py: it fails there with the steer event committed and no crew-log entry, and it passes with this fix. One thing done well: the fix reuses the same drain shape the worker-report route already uses, and the test parks the write on an event in the exact window between commit and append, with no sleep.
- Optional:
test/test_crew_mode_person_steer_ledger.py:151awaits the cancelled task with no bound. A bounded wait such asawait_until(task, what=...), like the sibling drain tests use, would make a future hang fail by name. - Optional: a sibling case where
on_work_recordedreturns False under the same cancel would cover the "fully undone" branch. - Optional: #36833 adds a trace call in the same block. Whichever PR lands second should move that call inside
_commit_and_record, before its final return.
…36658) `record_person_steer_result` commits the `steer` event (`apply_person_steer`) and then appends its `work/recorded` crew-log entry, undoing the event when the append does not land -- but it ran that commit-then-record sequence bare, inside the board lock. A cancellation (gateway shutdown) landing between the commit and the append left the steer event in the cache with no crew-log entry and no undo, so the Board and sidebar showed an answered steer that the next `work_ledger_rebuild` silently dropped, and callers reported `not_recorded` while the cache said otherwise. Wrap the commit-and-record block in a nested coroutine and drive it through `_drain_before_cancelling`, the same way the worker-report route and the conductor write path already do: once the event commits, the append (or the restore) finishes before the cancellation is re-raised. Pre-commit reads and refusals are unchanged. (cherry picked from commit 7009e5c)
…36658) `record_person_steer_result` commits the `steer` event (`apply_person_steer`) and then appends its `work/recorded` crew-log entry, undoing the event when the append does not land -- but it ran that commit-then-record sequence bare, inside the board lock. A cancellation (gateway shutdown) landing between the commit and the append left the steer event in the cache with no crew-log entry and no undo, so the Board and sidebar showed an answered steer that the next `work_ledger_rebuild` silently dropped, and callers reported `not_recorded` while the cache said otherwise. Wrap the commit-and-record block in a nested coroutine and drive it through `_drain_before_cancelling`, the same way the worker-report route and the conductor write path already do: once the event commits, the append (or the restore) finishes before the cancellation is re-raised. Pre-commit reads and refusals are unchanged. (cherry picked from commit 7009e5c)
Problem / Motivation
Goal: A person's steer on a work item is either fully recorded or fully undone, even when the gateway shuts down mid-write.
record_person_steer_result(work_ledger_worker.py) commits thesteerevent withapply_person_steer, then appends itswork/recordedcrew-log entry, and undoes the event when the append does not land. It ran that commit-then-record sequence bare. A cancellation (gateway shutdown) landing between the commit and the append left the steer event in the cache with no crew-log entry and no undo.Why it matters
The Board and sidebar then show an answered steer that was never recorded. The next
work_ledger_rebuildsilently drops it, so the person's instruction to the worker vanishes, and the caller that gotnot_recorded(or nothing) disagrees with what the cache showed.Not a goal
What changed (motivation → approach → change)
Root cause: the steer path is the one commit-then-record sequence not driven through
_drain_before_cancelling, the helper the worker-report route, the conductor write path and remote ingest already use. Fix: move the snapshot, commit, crew-log append, undo-on-miss and mark-recorded block into a nested_commit_and_recordcoroutine and await it through_drain_before_cancelling. Once the event commits, the append (or the restore) finishes before the cancellation is re-raised. The pre-commit reads and refusals above it are unchanged, and the block's body is moved, not rewritten.No spec change: the drain contract is already the documented behavior of the other write paths; this brings the steer path under it.
Backwards compatibility
Compatible: the same inputs give the same results and codes; only a cancellation mid-write now finishes the append-or-restore before it propagates.
Removes nothing: no field, code or route changes.
Tests
test/test_crew_mode_person_steer_ledger.py:test_a_cancellation_after_the_commit_still_records_the_steer: parks the write afterapply_person_steercommits (on the_board_headerawait), cancels it there, and asserts the cancellation still reaches the caller, the one steer event is present, and its crew-logsteerentry was appended.Proof: PROVEN test/test_crew_mode_person_steer_ledger.py::test_a_cancellation_after_the_commit_still_records_the_steer (head 7734f95)
Manual verification
N/A — unit coverage sufficient; the cancellation window is driven deterministically in the test, which a manual shutdown cannot hit reliably.
Related Issues
N/A — found by a crewmate's scout of the work-ledger handlers and proven on main; no tracking issue.
Sibling sweep
Swept:
git grep -n "_refuse_unrecorded(\|_mark_recorded,\|on_work_recorded" -- src/kiro_crew/dashboard— every commit-then-record sequence in the handlers, checked for a_drain_before_cancellingaround it.Pattern harvest
Rule candidate: review-prompt
Pattern: a cache commit followed by an awaited durable append with an undo-on-miss, run outside a cancellation drain. Any commit-then-record pair must run inside
_drain_before_cancellingso a cancel cannot land between the two halves.Checklist
Contribution License Agreement
Contributed under the project's Apache-2.0 license.