Repository navigation
refactor(dashboard): move the rest of the chat stream and its end into phases - #22682
Conversation
Sensitive change review
|
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. This is a verbatim move into phases, following the earlier PRs of the series. The private Notes
[DESIGN-REVIEWED] 480bf3a Description read[DESCRIPTION-READ] 6115492bbe5d7df8471857fee0e0e9f8c02f7f5cd482a59856f491055a1e388c 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: this is a behaviour-neutral split that the documented 2,000-line file cap requires. Every item either moves code to a new module or follows a moved construct to its new path. What this change shipsInventory (6 items) — 6 justifiedIntent: shrink
[FIRST-PRINCIPLES-REVIEWED] 480bf3a Description read[DESCRIPTION-READ] 838f9b53454207d7e45b745d8f4ab78a11759de578f539a897a219c1e1b9bdb1 That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: |
|
|
Sensitive change review
|
06ad7a9 to
5fed709
Compare
|
|
|
Hold at 5fed709: the branch conflicts with main. On this head the move looks faithful. The removed statements reappear in the phases apart from the plumbing and the 15 pruned fields, and none of those fields has a reader. The owners run on the runner's globals through — crew-pr-reviewer (r117) |
Sensitive change review
|
|
|
Sensitive change review
|
fb8b9ed to
bbd0747
Compare
|
|
…o phases The stream loop's remaining arms and the steps after the loop become phases that _run_chat awaits where the statements ran: the steer, session-event, MCP, todo and sub-agent arms and the stream's terminal (_on_*), then the stop recovery, the /compact answer, the answer settle, the turn-ending chain, the post-turn persist, the context usage and the Stop hook (_turn_*), each in the chat_turn owner of its responsibility; session_events, stop_recovery and turn_ending are new. A phase's return type names exactly the flows its call site dispatches. The statements move unchanged apart from that plumbing. Fifteen per-turn fields that never carry a value from one function to another are pruned: their copies go and the reads their own function's store dominates are bare again. The guards that read a moved construct by path read its new home, the await-free phases join the contract's pins, and moved comments, owner docstrings, the spec and the docs that placed these steps in chat_runner.py name the phase and its owner file. The final-message redaction sink stays on the runner, whose globals the passes it names run on. Part of #20192
Sensitive change review
|
bbd0747 to
480bf3a
Compare
|
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved by Crew Captain on head 480bf3a: Design and First Principles PASS on this head, UX skipped, all checks green, no merge conflict.
Problem / Motivation
Goal: Move the rest of the dashboard chat turn's stream loop and the steps after it out of
_run_chatinto phase functions in thechat_turnowners, sochat_runner.pysheds another 2,800 lines with no change to what a turn does.src/kiro_crew/dashboard/chat_runner.pyis about 7,400 lines after the previous PR of this series, and most of it is still_run_chat. The campaign rule is that no hand-written file goes over 2,000 lines. What is left in_run_chat'stryis the stream loop's remaining arms (steer, compaction, clear, agent switch, MCP, todo, sub-agent, and the stream's terminal) and the chain of steps that runs once the stream ends (stop recovery, the/compactanswer, the answer settle, the turn-ending chain, the post-turn persist, the context usage, the Stop hook).Why it matters
The runner cannot reach the cap while
_run_chatholds those arms and steps. After this PR,_run_chatkeeps only the text and thinking arms, the except arms and thefinally, which the last PRs of this series move.Not a goal
finallystay in_run_chat; later PRs of the series move them.What changed (motivation → approach → change)
The remaining stream arms and the steps after the stream loop become phases: coroutines that take the turn (and, for a stream arm, the event), which
_run_chatawaits where the statements ran. A phase reads the turn's values at its entry, copies each value it stores back onto the turn, and returns a_Flowmember where the statements returned, broke or continued; its return type names exactly the flows its call site dispatches._on_steer_consumed;_on_compaction_status,_on_clear_status,_on_agent_switched,_on_todo_updatesteer_queue;session_events(new)_on_mcp_*arms;_on_subagent_list,_on_subagent_activitymcp_session;native_cards_on_complete,_turn_context_usageturn_stats_turn_stop_recovery,_turn_persist_and_settlestop_recovery(new)_turn_compact_commandslash_commands/compactwhose compaction status did not arrive during the stream_turn_settle_answersegment_flush_turn_ending_chainturn_ending(new)_turn_stop_hookturn_spec_hooksFifteen
_ChatTurnfields that never carry a value from one function to another are pruned: theirturn.x = xcopies go and theturn.xreads that the same function's own store dominates become bare (74 sites, table under Claim). The "Dashboard final message" redaction sink stays ondashboard/chat_runner.py: the pass it describes is_flush_segment->_redact_segment(segment_flush) plus_persist_partial_reply(turn_reply_seams) for an interrupted reply, both on the runner's globals, while_turn_stop_hook's pass only builds the Stop hook's input after the reply is saved. Guards that read a moved construct by path read its new home, and moved comments, owner docstrings, the spec and the docs that placed these steps in_run_chatname the phase and its owner file.Backwards compatibility
Compatible: every name
chat_runnerbound at the base is still bound, as the same object (the base-names contract test), and every patch target still reaches the code it reached: the phases run on the runner's globals throughcompose, as the other owners do.Removes nothing: the PR moves statements of
_run_chatinto new private functions and drops per-turn fields no function reads; no public function, route, key or record is removed or renamed.Tests
_run_chatat the head, with each of its 28 phase calls replaced by the phase's body and only the phase plumbing undone (entry aliases, copies and reloads,turn.xforx, the_Flowexits and their dispatch, the bare declarations), is the same syntax tree as_run_chatat the base with its ten earlier phases inlined. Its self-test turns red on each of five planted changes. The scratch twin of the reload rule finds no read that sees a value a phase replaced._run_chatdispatches after its call, which mypy checks. The nine phases cut from blocks that never awaited (_on_mcp_server_initialized,_on_mcp_server_init_failure,_on_todo_update,_on_subagent_list,_on_subagent_activity,_on_compaction_status,_on_clear_status,_on_steer_consumed,_turn_context_usage) join the contract's_AWAIT_FREE_PHASES; anawaitadded to any of them turns its node red.chat_runner.py2 ->chat_runner.py1 +turn_stats.py1). Each changed test file passes 5 runs at-n0and one at-n 3; the flake-pattern ratchet passes.chat_runner,chat_turnor a moved name, plus the guards that scan them: 46,252 passed, 87 skipped, 5 xfailed, 0 failed (-n 3 --dist loadgroup); the 201 test files that read source text plus the changed tests: 10,372 passed, 5 skipped. The 8 cases oftest_chat_runner_redact_across_tool_boundary.pythat failed on main (main is red: test_chat_runner_redact_across_tool_boundary fails 8 cases since #22914 #23200) failed the same way, with the same messages, until fix(test): expect the whole reply on the linked-channel mirror #23201 fixed the test; on main with fix(test): expect the whole reply on the linked-channel mirror #23201 plus this patch, the file passes 47/47. CI runs the full suite.session_events86%,stop_recovery95%,turn_ending81%,steer_queue96%,mcp_session92%,native_cards98%,turn_stats98%,slash_commands98%,segment_flush96%,turn_spec_hooks92%; each clears the 80% floor on its own.src/kiro_crew: clean. semgrep 1.78 (CI configs, baseline at the base): 0 findings over the 37 changed Python files. black, isort, flake8, comment-history, brand, docs-lint, feature-map, harness-parity, agent-sdk boundary, subprocess-encoding, sync-io, memory-store, loop-lock and line-cap gates: clean. Installed-mode smoke: a wheel built from the head imports the runner and the new owners from the installed copy under an isolated HOME, and the phases and_Flowresolve onchat_runner.Manual verification
N/A — a structural move; the turn-level characterization suite, the phase-fidelity check, the reload rule and the mutation-proven guards are the verification.
Related Issues
Part of #20192
Follow-up: #21320 (the website comment cites listed under Claim).
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Move audit
_run_chatis the one changed unit: eighteen ranges leave it for phases, and the phase-fidelity check shows the rest of its body and every phase unchanged apart from the plumbing. Owners:session_events396 (new),stop_recovery552 (new),turn_ending584 (new),steer_queue649 -> 680,mcp_session646 -> 711,native_cards374 -> 434,turn_stats347 -> 948,slash_commands736 -> 874,segment_flush836 -> 1,393,turn_spec_hooks387 -> 746,turn_locals359 -> 350. The cut carries #21266's crewmate DM reply notification (post_turn_reply) into_turn_persist_and_settle, and #20867's post-compaction continuation into its phases with the rest of their ranges:_compaction_text_offset's store in the compaction-status arm into_on_compaction_status, and_continuation_answer_text/_branch_answer_textinto_turn_settle_answer, which reads the offset at entry (the field crosses into both phases, so_ChatTurndeclares it); #22592's composedredact(...)calls move with the agent-switch, native sub-agent,/compactand refusal-card ranges. #23050's whole-reply Slack mirror moves with the persist range (turn._reply_mids_snapshot, into_turn_persist_and_settle) and the Stop-hook range (the_turn_full_reply_textgate, the final-segment OPTIONS and the warning, into_turn_stop_hook); its_turn_full_reply_texthelper stays in the runner. #23111's whole-reply leg to a linked non-Slack channel (_cross_surface_reply_text(_turn_reply_segments(turn), ...)) moves with the Stop-hook range into_turn_stop_hook;_turn_reply_segmentsstays in the runner. #22914's single redaction window moves with its arms:_drop_wire_tail(turn)in the compaction-status, clear and agent-switch arms (session_events) and the/compactpurge (slash_commands), and the held-run settle at the head of_turn_settle_answer.L36:
git diff --numstatwith the default algorithm equals--minimalfor all 54 files (chat_runner.py93/2957,session_events.py396/0,stop_recovery.py552/0,turn_ending.py584/0,turn_stats.py603/2,segment_flush.py558/1,turn_spec_hooks.py360/1,security_posture.py7/5, and the cite edits).Claim
L30 (equal-strength re-keys, Master grant for this PR), each with a mutation red at the head:
test/metrics/test_context_trace.py: the closer-reading unpack is taken from the function that builds the closer payload.test/test_file_change_snapshots.py: the clear arm isinspect.getsource(_on_clear_status); the import names_on_clear_statusfor_run_chat.test/test_post_compaction_continuation.py: the answer chain head at either indentation (phase or loop).test/test_recovery_l1_chat_runner.py: the clear window starts atasync def _on_clear_status(; the history-debt predicate acceptsnot (?:turn\.)?_had_empty_response_verdict. Each form is proven on its own: a wrong verdict name in theturn.form and in the bare form both turn it red, and the bare form of the right name passes.test/test_reinjection_gate.py: the runner is read with itschat_turnowners as one module.test/test_runtime_death_is_a_process_event.py: thechat_turnowners count and clear as the runner's turn runtime.test/test_steer_requeue.py: the arm calls_on_steer_consumed, and the settle sits in that phase's head, measured past the phase's entry reads (x = turn.x), which are plumbing.test/test_turn_duration_recorded.py: the EVENT_COMPLETE persist row moves tochat_turn/turn_stats.py(chat_runner.py2 -> 1).test/test_wake_judge_feedback_service.py: the nudge gate acceptsturn._turn_landed(a flag a phase sets) as well as the bare name. Each form is proven on its own: a wrong flag in theturn.form and in the bare form both turn it red, so does dropping the flag, and the bare form of the right flag passes.L29 (Master grant, comment-only cites, no AST change):
test/test_dashboard_chat_compaction.py:206: """"The deferred-compaction wait at the end of _run_chat is a kiro-cli-only protocol step. claude-agent-acp performs /compact synchronously inside session/prompt and never emits_kiro.dev/compaction/status, so the handler must skipwait_for_compactionfor that backend or it sits blocked for 30 minutes and finally surfaces "Compaction timed out."" -> """"The deferred-compaction wait in_turn_compact_command(slash_commands) is a kiro-cli-only protocol step. claude-agent-acp performs /compact synchronously inside session/prompt and never emits_kiro.dev/compaction/status, so the handler must skipwait_for_compactionfor that backend or it sits blocked for 30 minutes and finally surfaces "Compaction timed out.""test/test_dashboard_chat_compaction.py:255: "patched at module scope:capabilities_ofserves three call sites in #_run_chatand patching it would answer for all three." -> "patched at module scope:capabilities_ofserves several call sites in the turn # (_on_complete,_turn_compact_command), and patching it would answer for all."test/test_dashboard_chat_token_usage.py:20: "persist_token_record is called from _run_chat." -> "persist_token_record is called from _on_complete (chat_turn/turn_stats.py)."test/test_acp_usage_cost.py:375: "The chat-runner persist gate (chat_runner.py) drops an all-zero row, so # the claude seam must produce a nonzero field for the row to be written." -> "The chat-runner persist gate (_on_complete in chat_turn/turn_stats.py) drops an # all-zero row, so the claude seam must produce a nonzero field for the row to be written."test/test_fallback_row_attribution_8560.py:235: "It deliberately survives a landed turn (_run_chat's usage row --" -> "It deliberately survives a landed turn (_on_complete's usage row inturn_stats--"test/test_slack_mirror_full_reply_23022.py:5: "The reply-publication block inchat_runner.pymust" -> "The reply-publication block (_turn_stop_hook) must"src/kiro_crew/dashboard/state_parts/slot_ladder.py:323: "dying mid-write still sees it), settled by _run_chat when the # consumed echo arrives (matched against the echo's snapshot text)," -> "dying mid-write still sees it), settled by _on_steer_consumed (steer_queue) # when the consumed echo arrives (matched against the echo's snapshot text),"Docs cites that placed a moved step in
_run_chat(SD27, Master review F1), each naming the phase and its owner file:docs/system-specs/modules/session.md:5318: "Every recovery wait in_run_chat" -> "Every recovery wait of a dashboard turn", and the L1 gateway-capacity row names_turn_ending_chain.docs/architecture/design-notes/session-slack-linking.md:134: the dashboard-to-Slack steps name_turn_openand_turn_dispatch_gates(steps 1-2),_on_tool_call(3),_turn_stop_hook(4) and_run_chat'sfinally(5).docs/system-specs/modules/acp-client.md:2105and:2274: the tool-stall continue-nudge and continuation ->_turn_stop_recovery(chat_turn/stop_recovery.py).docs/system-specs/modules/slack-gateway.md:1191: "_run_chat()mirrors" -> "the dashboard turn (_run_chat()and its phases) mirrors".Rows for moved code (L4, Master grant):
security_posture.pyNON_EGRESS_REDACTION_MODULES+session_events, +slash_commands(its reason comment, still seven lines, names the agent-switch name and the/compactsummary and failure-reason redactions);test_security_posture.pylog-site census (chat_runner.pyrow gone,session_events.py2);test_core_path_redact_before_bound.pyfloor (20 -> 22);test_no_config_dir_in_async.py(+turn_ending, +segment_flush, +session_events, +steer_queue, +stop_recovery, +turn_stats); the composition contract's owner set, homes and_AWAIT_FREE_PHASES;.github/docs-lint-baseline.txt(twoline-refrows deleted: the RFC cites are symbols now).The final-message sink is not re-keyed (Master ruling): the sink text is "Full-text redaction pass over the assembled assistant turn before it is finalized", and that pass is
_flush_segment->_redact_segmentinchat_turn/segment_flush.py, with_persist_partial_replyinchat_turn/turn_reply_seams.pyfor an interrupted reply. Both run on the runner's globals, so the row keeps its base keydashboard/chat_runner.py. The full-text pass in_turn_stop_hookonly builds the Stop hook's input after the reply is saved;turn_spec_hooksstays inNON_EGRESS_REDACTION_MODULESas at the base.Pruned
_ChatTurnfields (Master ruling): a field that never carries a value from one function to another loses itsturn.x = xcopies, and eachturn.xread the same function's own store dominates becomes the bare name; the stale-read check stays at 0. Eleven of them came from the previous PR's cut; the first four in the table are made by this cut's own stage and pruned with it, so the except arms read the bare names as at the base._own_fault_run_chat3 copies,_run_chat6 reads,_turn_stop_recovery1 copy_death_attempts_run_chat1 copy,_run_chat3 reads,_turn_stop_recovery1 copy_tcid_on_tool_result1 copy,_run_chat2 copies_open_construct_on_permission_request1 copy,_on_tool_call1 copy,_run_chat1 copy,_run_chat2 reads_requeue_text_run_chat3 copies,_run_chat3 reads,_turn_stop_recovery1 copy_requeue_payload_run_chat3 copies,_run_chat3 reads,_turn_stop_recovery1 copym_on_tool_call_update1 copy,_on_tool_result1 copy,_run_chat1 copy,_run_chat5 reads_row_on_tool_result1 copy,_run_chat1 copy,_run_chat3 readscmd_on_permission_request1 copyapproval_sent_on_permission_request7 copiesvalidated_tool_on_permission_request5 copies_parsed_input_on_permission_request6 copiespre_hook_results_on_permission_request3 copies_wt_key_on_tool_call1 copy_held_on_tool_call_update1 copyReferences not edited (cost, L50;
website/**is outside this PR, follow-up #21320): two comment cites in the frontend place the/compactfailure row inchat_runner. Its new home is_turn_compact_commandinsrc/kiro_crew/dashboard/chat_turn/slash_commands.py:website/src/pages/chat/CompactionCard.tsx:69,website/src/test/CompactionCard.test.tsx:55.Baselined growth (L56 addendum 1, 1b):
src/kiro_crew/security_posture.py(line-cap baseline row) grows by the twoNON_EGRESS_REDACTION_MODULESrows.Logger: moved code keeps the runner's logger; the phases run on the runner's globals, so
loggeriskiro_crew.dashboard.chat_runner's (L25).