Repository navigation
fix(dashboard): name a stopped turn's own opener in its restore - #19959
Conversation
|
Closing and reopening right after opening so CI runs on hosted runners: same-repo runs from this account queue on the fleet label without a runner (details on #19683). |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS This fixes the mechanism: the walk now uses Notes
What this change shipsInventory (6 items) — 5 justifiedIntent: after a Stop on a steered turn, the model gets back the request that opened the turn and the work done on it, not the steer. FIX.
[FIRST-PRINCIPLES-REVIEWED] 4ef0fe2 Description read[DESCRIPTION-READ] 21678968b1be121465d5be214e8402464e58298a2c31e4f1e6a9bd445620e239 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The fix targets the root cause (a steer row being taken as the turn's opener) and reuses the Resume restore's partial-output rule instead of adding a second one. Restores of turns with no steer keep their exact bytes. Notes
[DESIGN-REVIEWED] 4ef0fe2 Description read[DESCRIPTION-READ] 79fc52e471b4b44648c6e4266f6d4a29c3d6d3b24d443f5ea61695ecbcb315b9 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: |
|
|
span=dc2d7de999a7
|
|
Closing and reopening so CI runs on hosted runners: same-repo runs from this account queue on the fleet label without a runner (details on #19683). |
iamwhatever
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES at 160b908, for follow-up tracking. The description explicitly leaves two known restore cases unfixed. One is build_interrupted_turn_preamble, behind Resume. The other is a steer after a recovery/user_replay injection. Neither has a linked issue; Related Issues says none open. Fix these cases or link one issue for each accepted deferral. Also answer whether read_messages_chained_tail always ends with this session's transcript. These are tracking and review requirements, not a claimed new regression. Source and tests were read; nothing ran locally. — crew-pr-reviewer (r99)
160b908 to
ebf3a87
Compare
|
|
span=a3946a06bf37
|
|
@cruisercohen one addition since my last comment, so this head does change
|
|
|
|
Closing and reopening so CI runs on hosted runners: same-repo runs from this account queue on the fleet label without a runner (details on #19683). |
Pull request was closed
da06d8a to
b166c3d
Compare
|
@cruisercohen this push rebases the PR onto main at 1b96d89 as one commit. The last head, da06d8a, conflicted with two of main's refactors, so two of our hunks moved to the files that now hold that code. Nothing else in
|
|
Closing and reopening so CI runs on hosted runners: same-repo runs from this account queue on the fleet label without a runner (details on #19683). |
cruisercohen
left a comment
There was a problem hiding this comment.
Thanks @javenciu. I re-reviewed b166c3d and approve it.
- The rebase moves no logic. Against da06d8a, the
src/anddocs/changes are the same lines, with the Slack call now inhandler_runtime/turn.pyafter main's #21040, and the test helper incontext_composition_contract_helpers.pyafter #21922. - The change since c7e97e8, the head I approved before, is the four lines in
build_cancelled_turn_preamblethat drop warm-task-brief rows, asrecent()already does. With that filter removed,test_a_brief_posted_after_the_cancel_is_not_the_partial_replyfails and the other 20 tests intest_history_restore_preambles.pypass. - Locally on this head, the seven test files your comment lists and the flake-pattern ratchet pass (512).
The only red is Backend Tests (3.12, 2): three whole-tree scans in test_facade_mirror_guards.py hit the 120 s per-test timeout, the slow-runner timeout tracked in #19907. The same three tests time out on other open PRs this weekend, so it does not come from this change. I re-ran the failed jobs once. Coverage Gate fails behind that shard.
The Stop restore walked back to the newest user row and took it as the request the cancelled turn answered. A mid-turn steer is a user row too, so a turn that was steered and then stopped was restored with the steer as its request, and the original request and the reply streamed before the steer were dropped. The walk now passes over steer rows (a user row marked meta.steer) to the plain user row before them, and carries each steer the turn took, labelled and in order, inside the partial output. When a nudge, a sub-agent completion or an inject row sits in between, or the window holds no opener, the steer stays the request, because any of those may have opened the turn. The partial output is read through the one rule the Resume restore already used, now shared as _partial_turn_output. A steer the turn never took (steerState requeued or retracted) is left out: the Stop teardown moved a requeued one to the queue, where it runs as the next prompt, so carrying it would put it in the prompt twice, and a taken-back one never reached the turn. A steer is capped on its own at the request cap and does not share the cap on the assistant text, so a long reply streamed before it cannot cut it. Only context_assembly/replay.py changes in src. The builder's row read and its worker-thread calls are already on main.
b166c3d to
4ef0fe2
Compare
|
Thanks for the approval. Main moved under this PR, and the scope changed with it: #23388 now ships the full-row read in On current main, 4 of the 9 steer tests fail in 3 of 3 runs. With the change, all 9 pass in 3 of 3 runs, and the 5 controls pass on both. The head changed. Could you re-approve it? |
iamwhatever
left a comment
There was a problem hiding this comment.
APPROVE at 4ef0fe2.
The root cause is fixed: when the newest user row before the stop marker is a steer, the restore walks back to the row that opened the turn and stops at any row that may itself have opened it. Partial output goes through the Resume restore's own loop, _partial_turn_output, so requeued steers are left out and a steer no longer spends the assistant cap. The new tests cover the steered, multi-steer, no-steer byte-identity, lost-opener, nudge, inject, requeued and long-stream cases.
Our r99 items are settled: the Resume case was fixed on main (#20269 closed), and the inject-row case is tracked in #20270, which also covers the First Principles note about sharing one opener walk. Every check on this head is green and every AI lane passes.
I read the diff and CI; I did not run tests locally.
— crew-pr-reviewer (r139)
The red Sensitive Change Review rows on this head are two cancelled runs; a newer run of the same check on the same head (4ef0fe2) passed, so they do not count.
Problem / Motivation
Goal: After a Stop on a turn the user steered, the next prompt's cancelled-turn restore names the request that opened the turn and keeps the steer, in order, with the partial reply, instead of naming the steer as the request.
cancelled_turn_preamble(src/kiro_crew/context_assembly/replay.py:538on 95abd91) walks back from thestop_eventrow and takes the firstuserrow, other than a steer the person took back, as the cancelled request (src/kiro_crew/context_assembly/replay.py:576-580on 95abd91), then collects theassistantrows after it (src/kiro_crew/context_assembly/replay.py:589on 95abd91).userrow withmeta.steer(src/kiro_crew/dashboard/chat_delivery.py:1025on 95abd91, insteer_into_running_turn). It sits between the row that opened the turn and the rest of the reply, so the walk stops at it.Cancelled user request:S andPartial assistant response before cancel:A2. R and A1 are not in it.build_cancelled_turn_preambleread whole rows, sometareaches the walk, drop warm-task-brief rows, and run in a worker thread in both callers (src/kiro_crew/context.py:1154-1157,src/kiro_crew/dashboard/chat_turn/prompt_assembly.py:706andsrc/kiro_crew/slack/handler_runtime/turn.py:745, all on 95abd91). The walk uses thatmetaonly to step past a steer the person took back (replay.py:578), so a consumed, written or requeued steer is still named as the request. This PR now carries the opener fix only.Why it matters
kiro-cli drops a cancelled turn from its own log, so this restore is all the model has of the turn that was stopped (
docs/architecture/design-notes/soft-stop.md, "Context restore after a soft cancel"). After a Stop on a steered turn the next reply is handed the interruption as the whole request, and the request the user actually made and the work already done on it are missing.The web client already holds that a steer does not open a turn:
opensTurnreturns!row.meta?.steerfor auserrow (website/src/pages/chat/RecoveryCard.tsx:456-457), and #9594 fixed the same class for the pinned banner. This builder did not apply the rule.Not a goal
build_interrupted_turn_preamble(src/kiro_crew/context_assembly/replay.py:178), the restore behind Resume, walked back to the newest opener the same way; fix(context): skip mid-turn steers when Resume restores the interrupted request #20467 has since fixed it on main (Resume restore should skip mid-turn steers when finding the interrupted request #20269). It has a different trigger, its own caller and its own tests. Its opener walk stays as main has it, and its partial-output loop moves into_partial_turn_outputunchanged, so both restores read the partial output by one rule.injectrow that did not open the turn (arecoveryoruser_replayrow from a Resume press) between the opener and the steer. The walk stops at anyinjectrow, because whether one opens a turn depends on itsinjectKindand this function is not handedTURN_OPENING_INJECT_KINDS. A steer after a Resume press keeps today's result, the steer as the request. Passing the kinds through both callers is a separate change.stop_eventlookup, the fall back to the latest user entry, the row read and the worker-thread calls (feat(chat): take back a steer the running turn has not read yet #23388) are unchanged.What changed (motivation → approach → change)
userrow as the row that opened the turn, and a steer is auserrow that did not. Main's reader (feat(chat): take back a steer the running turn has not read yet #23388) already hands it whole rows withmeta, so it can tell them apart, and it does not.src/kiro_crew/context_assembly/replay.py, the onlysrc/file this PR changes:_is_steer_row(:100, on main since fix(context): skip mid-turn steers when Resume restores the interrupted request #20467) is true for auserornudgerow whosemeta.steerisTrue, the valuechat_delivery.py:1025stores.cancelled_turn_preamble, when the newestuserrow before the marker is a steer, tested with_is_steer_row, the search continues back to the nearest row that could have opened a turn (src/kiro_crew/context_assembly/replay.py:595-607). A plainuserrow is adopted. Anudge, asubagentrow or anyinjectrow, or the start of the window, keeps the steer as the request, because each of those may have opened the turn._partial_turn_output(src/kiro_crew/context_assembly/replay.py:131-175), the loopbuild_interrupted_turn_preamblealready had, moved out of it so the Resume and Stop restores share one rule. Each steer the turn took is added in order as[Steered mid-turn] <text>(_STEER_LABEL,src/kiro_crew/context_assembly/replay.py:86). The opener keeps its ownuser_cap; a steer is capped atuser_capon its own and does not shareassist_capwith the assistant text, so a long reply streamed before a steer cannot cut it (:138-141,:172-173). A steer markedrequeuedorretractedis left out (_STEER_STATES_NOT_TAKEN,:97, tested at:167): the Stop teardown moved a requeued one to the queue (src/kiro_crew/dashboard/chat_turn/steer_queue.py:279on 95abd91), where it runs as the next prompt when the queue drains (src/kiro_crew/dashboard/chat_turn/queue_cycle.py:409,:425on 95abd91) or the user dismisses it, and carrying it as well would put it in the prompt twice; a retracted one never reached the turn. A row that still readswrittenor has no state may have redirected the turn and is carried, as in the Resume restore.src/kiro_crew/context.py:1154-1157,prompt_assembly.py:706andturn.py:745on 95abd91), socontext.py,dashboard/chat_runner.pyandslack/handler_runtime/turn.pyhave no diff against main.docs/architecture/design-notes/soft-stop.mdanddocs/system-specs/modules/history.mddescribe the restore and now say how a steer is handled.Backwards compatibility
Compatible: a turn with no steer row takes the same path and produces the same bytes (
test_a_turn_without_a_steer_restores_exactly_what_it_did_beforecompares the whole string, and it also passes on 95abd91;test_without_steers_the_cap_cuts_where_it_always_didpins where the cap on the assistant text cuts, and it also passes on 95abd91). The bracketed markers thatcontext_blocks.pyparses are untouched. Two results change: a steered turn is restored under its own opener with each steer the turn took carried in the partial output, and a steer markedrequeuedis not carried at all.Removes one case: a steer marked
requeued, which the old restore named as the request, is no longer carried, because it runs as the next prompt or the user dismissed it. Every other row the old restore carried is still carried. A steer's text moves from the request slot to the partial-response slot, outside the cap on the assistant text, so no other restore loses a row.Tests
In short: four new tests fail with the restore source from main (95abd91) and pass with the change. On main each of the four restores a steer as the request (
replay.py:576-580); in the requeued test that also puts the steer in the prompt twice, and in the long-stream test the long reply is missing from the partial output. Five controls (an unsteered turn, the cap on a turn with no steer, a window that lost the opener, a steered turn opened by a nudge, one opened by an inject row) pass on both. Red 3 of 3 runs (4 failed, 5 passed), green 3 of 3 runs (9 passed), 20 of 20 at-n0, 10 of 10 at-n 4. Nine one-line mutants are each caught by the tests written for them.Added to
test/test_history_restore_preambles.py(main'sTestCancelledTurnPreambleRequest, the taken-back steer test, stays, and the new class sits after it), over a realConversationLogintmp_path, with steer rows written the way the dashboard stores them (extra_meta={"steer": True, ...}):test_the_restore_names_the_original_request_and_keeps_the_steer_in_order(:196): request, reply, steer, reply, Stop. The request is the opener, the partial section reads reply,[Steered mid-turn]steer, reply, and the steer text appears once.test_several_steers_keep_their_order_around_the_partial_reply(:216): two steers around a reply keep their order.test_a_turn_without_a_steer_restores_exactly_what_it_did_before(:235): a drained queue row, which carriessteer_delivery_idsandsendIdbut notsteer, is a real opener. The full restore text is compared.test_a_window_that_lost_the_opener_still_names_the_newest_steer(:265),test_a_steered_turn_opened_by_a_nudge_does_not_name_an_earlier_request(:280) andtest_a_steered_turn_opened_by_an_inject_does_not_name_an_earlier_request(:296): the cases where the walk must not reach past a row that may have opened the turn into an earlier, finished request.test_a_requeued_steer_is_not_carried_into_the_prompt_that_drains_it(:312): a steer markedrequeuedis not in the restore, so the prompt that drains it holds its text once.test_a_steer_after_a_long_stream_survives_the_cap(:329): a 5000-character reply, then a steer; the steer is in the restore, after the cut reply.test_without_steers_the_cap_cuts_where_it_always_did(:347): a control over eight chunk shapes against the joined-then-cut reference.No other test file changes:
test/context_composition_contract_helpers.py,test/test_chat_runner_coverage.pyandtest/test_slack_handler_turn_outcomes.pyare as on main.Before the change, in a checkout of main (95abd91) with this branch's test file copied in,
python -m pytest -n0 -p no:cacheprovider -q test/test_history_restore_preambles.py -k TestCancelledTurnPreambleSteer, RC=1 in 3 of 3 runs:With the change, the same command, RC=0 in 3 of 3 runs:
9 passed, 12 deselected.Mutants, one line each, run once each on this head with
replay.pyput back after each, overtest/test_history_restore_preambles.pyandtest/test_interrupted_turn_steers.py, all RC=1, each failing only the tests named:test/test_interrupted_turn_steers.py.steer_delivery_ids: the no-steer test.nudgeorsubagentrow: the nudge test.injectrow: the inject test.requeuedexclusion removed from_STEER_STATES_NOT_TAKEN: the requeued test here and the Resume restore's requeued test.Repeats of the class on this head: 20 of 20 at
-n0,9 passedeach; 10 of 10 at-n 4 --dist loadgroup --max-worker-restart=2withtest/test_history_pagination_projection.pyandtest/test_stop_turn_boundary_mirror.pyas co-tenants,36 passedeach time.Neighbours on this head,
-n0: the three test files the earlier revision of this PR touched (test/test_chat_runner_coverage.py,test/test_history_restore_preambles.pyandtest/test_slack_handler_turn_outcomes.py),164 passedin each of 3 runs. In one run,553 passed: the test files that name the two preamble builders or the replay module (test/test_context_composition_contract.py,test/test_context_composition_contract_facade.py,test/test_interrupted_turn_steers.py,test/test_automation_steer_row_role.py,test/test_regenerate_swap.py,test/test_decisions_model_route_apply.py,test/test_slack_handler_composition_contract.py,test/test_slack_handler_composition_contract_golden.py,test/test_context_management_doc.py), the two that read the touched docs (test/test_ephemeral_sessions.py,test/test_history_locking_remediation_dashboard_save.py), andtest/test_history_pagination_projection.py,test/test_stop_turn_boundary_mirror.pyandtest/test_history_composition_contract.py. The steer tests patch no module-global.Gates on this head, each exit code read before any pipe, all RC=0: flake8 and isort on
src/kiro_crew/context_assembly/replay.pyandtest/test_history_restore_preambles.py; the black formatting gate (4 changed files in scope, 2 checked); the comment-history gate withCOMMENT_HISTORY_BASE_REFatorigin/main; the flake-pattern ratchet (64 passed); the docs-lint gate with its self-test;mypyonsrc/kiro_crew/context_assembly/replay.py, the onesrc/file this PR changes (no issues in 1 source file). The diff touches nowebsite/file and no deploy template, so the website gates and thecfn-lintcheck were not run.Not run:
scripts/local-gate.pyandscripts/run_scoped_tests.py --surface backend, the full-suite-sized runs that CI repeats on the merge ref.Manual verification
N/A: the tests drive the real builder over a real
ConversationLog, and no gateway or dashboard was started. The callers are not changed here. One check outside the tests: the dashboard's row builder_build_message_entry(src/kiro_crew/dashboard/chat_persistence.py:586on 95abd91), run on a row carrying the meta thatsteer_into_running_turnstores (src/kiro_crew/dashboard/chat_delivery.py:1024-1033on 95abd91), returnedmeta.steeras the booleanTrue, so a stored steer row matches_is_steer_row.Related Issues
Tracking: #20269, #20270. Landed on main, the reader half of this fix: #23388.
Pattern harvest
Rule candidate: review-prompt
Pattern: a backwards search for the row that opened a turn, keyed on role alone, when a row of that role can be injected into a running turn (a steer is a
userrow). The web client'sopensTurnand the two Python restores each carry their own copy of this search.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)