Skip to content

fix(work-ledger): drain a person steer so a cancel cannot orphan it - #36658

Merged
RohanK6 merged 1 commit into
mainfrom
crew/conductor/wl-steer-drain
Nov 13, 2026
Merged

RohanK6 merged 1 commit into
mainfrom
crew/conductor/wl-steer-drain

Conversation

@RohanK6

@RohanK6 RohanK6 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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 the steer event with apply_person_steer, then appends its work/recorded crew-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_rebuild silently drops it, so the person's instruction to the worker vanishes, and the caller that got not_recorded (or nothing) disagrees with what the cache showed.

Not a goal

  • Does not change the steer's validation, refusals, or what it records.
  • Does not touch the other commit-then-record paths: they already run drained (see the sibling sweep).

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_record coroutine 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 after apply_person_steer commits (on the _board_header await), cancels it there, and asserts the cancellation still reaches the caller, the one steer event is present, and its crew-log steer entry 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_cancelling around it.

  • Sibling: src/kiro_crew/dashboard/handlers/work_ledger_worker.py:record_person_steer_result -- changed here
  • Sibling: src/kiro_crew/dashboard/handlers/work_ledger_worker.py:_commit_and_record (the worker-report route) -- not affected -- already drained
  • Sibling: src/kiro_crew/dashboard/handlers/work_ledger_conductor.py:_under_board -- not affected -- the conductor write path is already drained
  • Sibling: src/kiro_crew/dashboard/handlers/remote_ingest.py:_file_one -- not affected -- remote ingest is already drained

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_cancelling so a cancel cannot land between the two halves.

Checklist

  • At most two commits (one), Conventional Commits title
  • Existing tests pass and new tests added
  • Self-review completed; follows project style
  • Documentation updated (N/A — no documented contract changed)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@RohanK6
RohanK6 requested review from a team and KiroCrewCaptain as code owners November 13, 2026 14:27
@RohanK6
RohanK6 requested a review from mbriones98 November 13, 2026 14:27
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 7734f9546081f2994cf77f66768b09a78a26215d touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 7734f9546081f2994cf77f66768b09a78a26215d — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the steer path now goes through the same _drain_before_cancelling transaction as the worker-report, conductor and remote-ingest write paths, and the change removes nothing.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 7734f9546081f2994cf77f66768b09a78a26215d — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 ships

Inventory (2 items) — 2 justified

Intent: 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.

  1. A shutdown cancellation that lands after the steer commits now waits for the crew-log append or the undo to finish before it propagates. Done by reusing _drain_before_cancelling (work_ledger_recording.py:195). — justified
  2. A new test parks the write right after the commit, cancels it, and asserts that both the steer event and its crew-log entry exist. — justified

[FIRST-PRINCIPLES-REVIEWED] 7734f95

Description read

[DESCRIPTION-READ] 0ad959167ad3c2e33510a51491679fb2cfab6c249b841b98575a6f428c85327f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 7734f9546081f2994cf77f66768b09a78a26215d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 7734f95

Verdict parsed from the review's SHA-scoped output markers for commit 7734f9546081f2994cf77f66768b09a78a26215d.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 7734f9546081f2994cf77f66768b09a78a26215d false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 7734f9546081f2994cf77f66768b09a78a26215d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7734f95

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 7734f9546081f2994cf77f66768b09a78a26215d false-positive: <reason, 20 to 500 characters>

`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.
@RohanK6
RohanK6 force-pushed the crew/conductor/wl-steer-drain branch from d3b3858 to 7734f95 Compare November 13, 2026 16:21
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: 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 7734f95460 · 140 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Nov 13, 2026
@RohanK6
RohanK6 enabled auto-merge (squash) November 13, 2026 20:43

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:151 awaits the cancelled task with no bound. A bounded wait such as await_until(task, what=...), like the sibling drain tests use, would make a future hang fail by name.
  • Optional: a sibling case where on_work_recorded returns 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.

@RohanK6
RohanK6 merged commit 7009e5c into main Nov 13, 2026
209 of 219 checks passed
@RohanK6
RohanK6 deleted the crew/conductor/wl-steer-drain branch November 13, 2026 21:03
buluoray pushed a commit that referenced this pull request Nov 15, 2026
…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)
buluoray pushed a commit that referenced this pull request Nov 15, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants