Repository navigation
refactor(dashboard): split state.py helpers and _ChatSlot into owners - #20507
Conversation
Sensitive change reviewHead commit: 93b3ea9
|
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. [UX-REVIEWED] 6cc9f23 Description read[DESCRIPTION-READ] 84df4dfe2f8c903138f9a6072ede725aa8b4029a9b47479491264db439cf06b6 That sha256 names everything this verdict read: the PR description, plus the 3 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 to check. What this change shipsInventory (8 items) — 8 justifiedIntent: shrink
[FIRST-PRINCIPLES-REVIEWED] 6cc9f23 Description read[DESCRIPTION-READ] b0cbb7df7f16012d723cb9305e479d9538a92e166993b71f847b8551370c4f13 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 that the full backend suite is green, not just local-gate's diff-related subset: the patch targets that still work depend entirely on [DESIGN-REVIEWED] 6cc9f23 Description read[DESCRIPTION-READ] 752fd79b7ba3650dd9d4702b7bbf697741bc09f4714547388d316b6d0af5105a 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: |
|
Sensitive change reviewHead commit: 0f98bc9
|
93b3ea9 to
0f98bc9
Compare
|
0f98bc9 to
06400e4
Compare
|
Sensitive change reviewHead commit: 06400e4
|
|
Head
|
|
|
HOLD at e102da1 for maintainer review. No defect found. The split reads as a mechanical move. The new owner lines are field annotations, method bindings, init__fields calls and docstrings. This matches the independent AST audit in #20507 (review). Every review lane on this head is PASS, the Design punchline has a disposition, and all checks are green. Why it is held: the PR edits src/kiro_crew/security_posture.py ( KiroCrew/src/kiro_crew/security_posture.py Lines 2286 to 2291 in e102da1 — crew-pr-reviewer (r107) |
e102da1 to
d12393d
Compare
|
[operator: bolichen97] Rebased onto main Six text conflicts, all path references, resolved by keeping main's new split-module names and this PR's
Local: every |
Sensitive change reviewHead commit: d12393d
|
d12393d to
a7e8613
Compare
|
Sensitive change reviewHead commit: a7e8613
|
dashboard/state.py was 11,318 lines. Its module helpers and the _ChatSlot class move into dashboard/state_parts/: owners named for one responsibility each, plus chat_slot.py for the class. state.py stays the import path and the patch surface; it imports the owners eagerly and composes them with kiro_crew._facade_mirror, so every module-level name it bound and every patch target keeps resolving to the same object. _ChatSlot is split by binding, not inheritance. The class keeps its __slots__, one declaration per field, its constructor and properties, and binds each method to the unchanged function in its collaborator. Each collaborator also sets the defaults of the fields it drives in init_<x>_fields, called in the order those fields were first set. What stays in state.py is one run of its own lines: the import block and DashboardState, with five definitions the class needs here moved verbatim to just after it, then the re-exports and the mirror. state.py: 11,318 -> 5,386 lines. DashboardState moves in a follow-up. Part of #20192
Sensitive change reviewHead commit: 6cc9f23
|
Problem / Motivation
Goal: Bring
dashboard/state.pyunder the 2,000-line cap in two steps; this first step moves its module helpers and the_ChatSlotclass intodashboard/state_parts/owners while every import path, patch target and behaviour stays the same.src/kiro_crew/dashboard/state.pyis 11,326 lines: about 3,200 lines of module helpers,_ChatSlot(3,250 lines, of which__init__alone is 1,305) andDashboardState(4,845 lines). The campaign rule is that no hand-written file exceeds 2,000 lines, and a file this size takes about 40 commits a week, so every feature PR that touches it pays for its size in review and in merge conflicts.Why it matters
A reader looking for "how a slot's todo list works" or "where recovery prompts are built" has to search one 11k-line file whose two classes are each larger than most modules in the repo. The split gives each responsibility one file named for it, and a place for new code to go, without asking any caller or test to change.
Not a goal
DashboardStatestays instate.pyin this PR; it moves in the follow-up (Part of refactor: cap every hand-written source and test file at 2,000 lines #20192), which bringsstate.pyto about 550 lines._ChatSlotkeeps every field on itself (learn-cron-dashboard, "canonical owners of their mutable containers").What changed (motivation → approach → change)
state.pystays the import path and the patch surface. The code it held moves to the new packagedashboard/state_parts/, which the facade imports eagerly and composes withkiro_crew._facade_mirror(the campaign's shared mechanism), so amonkeypatch.setattrormock.patchofkiro_crew.dashboard.state.<name>reaches every owner that reads the name, as it did in the one-module file._ChatSlotis split by binding, not inheritance.state_parts/chat_slot.pykeeps the class with its__slots__, one typed declaration per field, the constructor and the properties, and binds each method as a one-line class attribute (set_todo = _slot_todo.set_todo). The method's body moves unchanged into the collaborator that owns its responsibility, as a function whose first parameter isself. The class attribute IS that function, so its signature, source, coroutine kind and identity are whatMagicMock(spec=...),autospec,inspect.getsourceandpatch.objectsee. Each collaborator also owns the defaults (and their comments) of the fields it drives, ininit_<x>_fields, which the constructor calls in the order those fields were first set.What stays in
state.pyis one unbroken run of its original lines: the import block andDashboardState. Five definitions the class needs in this module move, verbatim, to just after it:_build_infoandset_build_info(the constructor reads the global the setter rebinds),request_slot_origin(a source pin counts its text in this file),_DEFAULT_PORTand_SSE_INTERVAL_SECS. The re-exports and the mirror follow. The three namesDashboardStatereads while itsclassstatement runs are imported just above the logger.dashboard/state_parts/)transcript_rows.pychat_messageframe and note,append_and_surfaceinjected_turns.py*_RECOVERY_PREFIX, recovery deciders and prompt buildersnotification_log.pysource_links.pyslot_sidebar.pyslot_todo.pyslot_session.pyslot_turns.pyslot_ladder.pyslot_transcript.pyappend,update_message, disk-window bookkeeping, the lazy window,to_dictchat_slot.py_ChatSlotclassdashboard_services.pyDashboardStatereaches its coordinators throughsession_events.pystatus_payload.pyslot_directory.pySlotOrigin, the native-subagent output tail, genuine Slack linkssidebar_stores.pyslots_frame.pyslots_push.pystate.py: 11,343 → 5,376 lines.Four owners are under 150 lines here:
dashboard_services.py,status_payload.py,sidebar_stores.pyandslots_push.py. Each holds the module helpers of oneDashboardStateresponsibility, and the follow-up moves that responsibility'sDashboardStatemembers into the same file (665, 298, 767 and 936 lines there).Move audit
Of the 64 units
move_audit.pylists as changed, 63 are_ChatSlotmembers.replumb_audit.pyshows each equals its BASE unit once the recipe's allowed transforms are undone, and nothing else differs:self: _ChatSlotannotation on a moved method, so mypy checks its body as it did.own_methodsremoves the annotation from the runtime object.@staticmethodon_todo_text_line, which becomes the bindingstaticmethod(...).__init__split intoinit_<x>_fieldscalls. Every statement is verbatim. Each field annotation moves, with its BASE text, to a class-body declaration.The 64th is
_SERVED_INDEX, which resolvesPath(__file__)one.parentfurther because its owner is one directory deeper; the path it names is the same (test_state_parts_facade::test_the_served_index_is_the_path_the_one_module_file_resolved).Other justified edits:
_PROMPT_ROLEScomment, the_fallback_slot_modelcomment, andupdate_message's first docstring line._ChatSlot.durable_queue_entriesanddurable_queue_viewstay in the class. As module functions they would call themselves: each body calls theslot_queue_repositoryfunction of the same name.state.py's import block: nine stdlib and typing imports that nothing reads any more (no importer, no patch target, and not the facade's own code) are dropped: five whole lines go and three lines lose names.datetimestays bound, becausewindows_sim.colliding_clockpatches it through the facade. The BASE imports of project names that the facade binds only for importers and patches (the facade contract keeps every BASE public name bound) are named in_BOUND_FOR_IMPORTERSrather than marked# noqa; a marker would edit every one of those kept lines. OneTYPE_CHECKINGimport it no longer reads gets# noqa: F401, like its siblings.Diff alignment (L36):
git diffandgit diff --minimalagainst the base give the same + and - counts for each of the 74 changed files (state.py: +362 / -6,329), so the diff gates judge the same lines the minimal diff shows.Docs and citations
learn-cron-dashboard.mdgains the owner map: what lives where, and where new code goes.injected-messages.md,code-style.md,session.md,decisions.md,app-notifications.md,app-kit-platform.mdand two design notes name the owner file for the constructs they cite.channel_slots.py,chat_api/resume.py,chat_api/slot_detail.py,chat_persistence.py,chat_slack.py,chat_todo.py,slot_persistence/write_guards.py,apps/builtins/ops_mission_control/backend/http_routes/board.pyandapps/builtins/aws_control/crew/runtime/container/front/transcript.py;test_dashboard_updates_coverage.py,test_gateway_appkit_endpoints.py,test_last_message_preview_skips_stop_event.py,test_promise_only_recovery.py;RecoveryCard.tsx,SessionPulseSurveyCard.tsx,SessionSourceChips.tsx,unreadOnAttention.ts,store/chat/selectors.ts,scripts/capture-sidebar-chip-budget.mjs, and four vitest files inwebsite/src/test/(ChatSidebar.sourceChipExpand.test.tsx,RecoveryCard.test.tsx,chatSlice.continuable.test.ts,toolBlockedCard.test.ts);builtin_skills/team-lead/SKILL.mdand six RFCs.state_parts/injected_turns.py, namestranscriptRendering.tsx (render). That file holds the cron-wrapper strip; the comment namedChatPage.tsx.docs/feature-map/README.mdand thestate.pybullet oflearn-cron-dashboard.md. They are re-pointed in the follow-up, which rewrites that bullet anyway, so this diff stays under the review lanes' size cap; the owner map above that bullet already says where_ChatSlotlives.state.py(:668,:1459twice,:3200) are cited by symbol; their four.github/docs-lint-baseline.txtline-refrows are deleted by hand, and docs-lint passes.website/scripts/capture-compacting-stop.mjsreads the three notices it quotes fromstate_parts/session_events.py, their owner. Its own extraction code, run against that file, yields the same three texts it extracted from BASEstate.py..github/file-line-cap-baseline.txt:state.py's row is lowered to 5,376 (scripts/check_file_line_cap.pypasses).Backwards compatibility
Compatible: every module-level name
state.pybound still resolves through it, to the same object (frozen intest/test_state_parts_facade.pyandtest/campaign_facade_inventories/kiro_crew.dashboard.state.json)._ChatSlotkeeps every member with the same kind, coroutine-ness and signature,__qualname__(_ChatSlot.append) and identity with its body. Its fresh-instance defaults are unchanged too. Only__module__of_ChatSlot, of its moved methods and of the moved module functions now names the owner module.Logger names (L25): every owner logs through
logging.getLogger("kiro_crew.dashboard.state"), the BASE logger object, socaplogcaptures by that name andpatch("kiro_crew.dashboard.state.logger")keep working.Each public module-level function that moved is re-exported by the facade:
Reader: src/kiro_crew/dashboard/chat_regenerate.py:append_and_surface -- chat --
kiro_crew.dashboard.state.append_and_surfaceis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_runner.py:build_infra_retry_prompt -- chat --
kiro_crew.dashboard.state.build_infra_retry_promptis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_runner.py:build_refusal_recovery_prompt -- chat --
kiro_crew.dashboard.state.build_refusal_recovery_promptis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_runner.py:build_stale_recovery_prompt -- chat --
kiro_crew.dashboard.state.build_stale_recovery_promptis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_runner.py:build_tool_stall_recovery_prompt -- chat --
kiro_crew.dashboard.state.build_tool_stall_recovery_promptis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_handlers.py:chat_message_frame -- chat --
kiro_crew.dashboard.state.chat_message_frameis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/state.py:chat_message_note -- chat --
kiro_crew.dashboard.state.chat_message_noteis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_handlers.py:context_entry_expired -- chat --
kiro_crew.dashboard.state.context_entry_expiredis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/channel_slots.py:durable_row_count -- chat --
kiro_crew.dashboard.state.durable_row_countis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/state.py:ensure_tags_revision_epoch -- crew page --
kiro_crew.dashboard.state.ensure_tags_revision_epochis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/state_parts/injected_turns.py:extract_log_redirect_target -- chat --
kiro_crew.dashboard.state.extract_log_redirect_targetis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_persistence.py:is_quiet_end_row -- chat --
kiro_crew.dashboard.state.is_quiet_end_rowis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_api/resume.py:is_stop_event_row -- chat --
kiro_crew.dashboard.state.is_stop_event_rowis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_handlers.py:is_turn_interrupted -- chat --
kiro_crew.dashboard.state.is_turn_interruptedis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_api/resume.py:load_window_off_loop -- chat --
kiro_crew.dashboard.state.load_window_off_loopis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_tags.py:mint_tags_revision -- crew page --
kiro_crew.dashboard.state.mint_tags_revisionis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_api/slot_detail.py:parse_cls_meta -- chat --
kiro_crew.dashboard.state.parse_cls_metais the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_runner.py:parse_hook_continuations -- chat --
kiro_crew.dashboard.state.parse_hook_continuationsis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/channel_slots.py:row_mid -- chat --
kiro_crew.dashboard.state.row_midis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/chat_runner.py:should_queue_hook_continuation -- chat --
kiro_crew.dashboard.state.should_queue_hook_continuationis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/agent_sdk/backends.py:should_queue_refusal_recovery -- chat --
kiro_crew.dashboard.state.should_queue_refusal_recoveryis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/state.py:sweep_expired_notifications -- crew page --
kiro_crew.dashboard.state.sweep_expired_notificationsis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/channel_slots.py:note_crew_log_class -- chat --
kiro_crew.dashboard.state.note_crew_log_classis the moved function itself, re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/state.py:DashboardState.native_subagent_snapshots -- subagent -- reads
native_subagent_output_tailas a facade global, the moved function re-exported (test_state_parts_facade::test_a_moved_name_is_the_object_its_owner_holds)Reader: src/kiro_crew/dashboard/state.py:DashboardState -- chat -- the stuck-turn watchdog reads
stuck_turn_noticeas a facade global, the moved function re-exported (test_stuck_turn_watchdog)CI path references
N/A — no workflow path filter or file list names
dashboard/state.py.Tests
test/test_state_parts_facade.py(new, 19 tests) pins:sys.modulesfirst, the default);global-rebound globals (_TAGS_REVISION_*,_notification_io_pool, the lineage seed flags) have one holder and read live;_ChatSlot's member inventory (kind, coroutine, async-gen, signature) equals BASE;super(),__class__or name-mangled attribute, with a self-test;_SERVED_INDEXnames the same file it did;typing.get_type_hintsresolves every member as it did, except the named ones (enqueue_or_run_prompt, which namesDashboardState, and the class-body field declarations);state.py(test_slack_options_lifecycle,test_ws_event_scoping) hold overstate.pyjoined with every owner.test/test_facade_mirror_guards.pydiscoverskiro_crew.dashboard.stateand holds the family-wide checks for it: one object per name, no owner importing the facade, and every patched name reaching its readers. Each was shown red on a planted defect in this family.test_recovery_card_prefixes.pyandtest_recovery_marker_parity.pyreadstate.pyjoined with everystate_parts/owner;test_orphaned_approval_card.py::test_every_call_site_flags_dirtyand all threetest_serving_loop_unified.pyratchets add thestate_parts/owners to the files they scan;test_options_cap_contract.pyallowed row is nowdashboard/state_parts/slot_transcript.py;test_slot_running_readers.pykeys are nowstate_parts/chat_slot.py;test_security_posture.pycensus row is nowdashboard/state_parts/slot_turns.py.test_poisoned_escalation.py(upstream pin, integration-owner grant): its constructor exemption is re-keyed tostate_parts/chat_slot.py, plus the collaborator that sets the cells' defaults (slot_ladder.init_ladder_fields), because the cells' defaults moved withinit_ladder_fields. Assertions are unchanged; a stray write inslot_ladder.pyorslots_push.pystill fails it.NON_EGRESS_REDACTION_MODULESinsrc/kiro_crew/security_posture.pygains the six owners that call a redactor, in the "owner-driven components extracted from dashboard/state.py" block; they add no egress path.test/campaign_facade_inventories/kiro_crew.dashboard.state.jsonfreezes the facade's BASE public names and the module that holds each rebound one;test_campaign_facades_base_public_names.pyloads it.MonkeyPatch.context. They pass 5 runs at-n0and one at-n 3.local-gate.py --dry-runselects about 2,800 backend and 1,500 frontend files, over the campaign's ~600 cap, so the floor ran instead): the 487 test files that import, patch or readdashboard.state,DashboardStateor_ChatSlot, plus the mirror, registry and ratchet guards: 26,724 passed, 30 skipped, 4 xfailed at-n 3.test_flake_pattern_ratchet.pypasses at-n0.Manual verification
N/A. Unit coverage is sufficient for a structural move with no runtime surface change. Imports were checked in a scratch wheel install under
env -i.Screenshots / video
Why no screenshot: the only frontend edits are comments that name the file a mirrored backend constant now lives in; nothing renders differently.
Related Issues
Part of #20192
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)