Repository navigation
refactor(slack): run handle_message as phases in handler_runtime owners - #21040
Conversation
Sensitive change review
|
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Before merging, check the 30 rewritten leaf statements: the permit and verdict closures, now What this change shipsInventory (8 items) — 8 justifiedIntent: bring
[FIRST-PRINCIPLES-REVIEWED] 35dc7e2 Description read[DESCRIPTION-READ] 9c6b296af30aa4f3fc43cd8f78f7e563f11d49a87302b918e4ef3ed9df8e3662 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 golden transcripts reach the hand-off-heavy edges (compaction replay, session-not-found retry, an orphan reject mid-stream), since those are where a stale [DESIGN-REVIEWED] 35dc7e2 Description read[DESCRIPTION-READ] 9ec54cc81d900baf43928bfb0db0bd73fa2cf4e734d1024f26e674626e7f6b12 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: |
|
|
261348b to
da7392f
Compare
Sensitive change review
|
da7392f to
81f5556
Compare
|
Repair push:
Red guard:
|
81f5556 to
7c997d2
Compare
|
|
Round 2 push: |
93511ca to
b7b3590
Compare
Sensitive change review
|
|
Refresh push:
|
|
|
|
slack/handler.py is 3,789 lines and handle_message alone is 2,187, so moving whole definitions cannot bring the file under the repository's 2,000-line cap. handle_message keeps its entry and inbound admission, then runs its turn as three phases over one _SlackTurn: _dispatch_before_turn (dispatch.py), _run_turn (turn.py) and _deliver_answer (delivery.py). The stream loop hands each tool call and permission request to permission_ladder.py, which also takes the approval prompt and the click that answers it, and four agent-name helpers move to agent_names.py. The facade's compose() runs every owner on its globals, so a patch of kiro_crew.slack.handler.<name> still reaches the moved code. handler.py is now 1,063 lines. Each phase body keeps its text: it opens with aliases of the turn values it reads and ends by copying onto the turn what the next phase reads, and the delivery's permit and verdict closures become the turn's methods. Guards that read the turn's code by path now read the owner that holds each construct, and the composition contract maps every guarded construct to the exact files that hold it. Part of #20192
b7b3590 to
35dc7e2
Compare
Sensitive change review
|
|
MAIN_RED #5 refresh: The reds at
Nothing upstream since Gates on the rebased head (pytest |
|
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved on the watch holder's request. Every check on the head passes; the triage cron held it on a size, path, checklist or lane-note rule. Any standing lane note stays on the record.
Problem / Motivation
Goal: Bring
src/kiro_crew/slack/handler.pyunder the repository's 2,000-line cap by splitting its 2,187-linehandle_messageinto named phases inslack/handler_runtime/, with the native Slack turn behaving exactly as before.slack/handler.pyis 3,789 lines, andhandle_messagealone is 2,187 of them, so movingwhole definitions cannot bring the file under the cap: the turn itself has to be cut into
pieces that can live elsewhere.
Part of #20192
Why it matters
The rule is that no hand-written file exceeds 2,000 lines, and this file changes most
weeks (12 commits in the last 7 days), so it needs headroom: every feature PR that touches
the native turn would otherwise land on top of the cap. One 2,187-line coroutine is also
hard to review: a change to the permission ladder, the delivery verdict or the pre-turn
commands means reading the whole turn.
Not a goal
and the provider is the same, in the same order.
compose()composition.handler_runtimeowners' code (only comments that name where amoved construct now runs), to any gate's strictness, or to the tests' assertions beyond
the composition contract's own rows (its owner rows, the moved-name count 70 -> 81 and
shape digest, and its two placement tests replaced by the exact-holder map
_GUARDED_TOKEN_HOMES, as the campaign's design review approved).handle_messageorhandle_interactionaccept or return.What changed (motivation → approach → change)
handle_messagekeeps its signature, docstring and entry (the stats count, the threadkeys, the channels-governance gate, the hydration and inbound admission), then builds one
_SlackTurnand runs three phases in order. Each phase is the old body text: it openswith read-only aliases of the turn values it reads and ends by copying onto the turn what
the next phase reads.
slack/handler_runtime/)dispatch.py_dispatch_before_turn: the short-circuits that answer without the model (hook reply,status,sessions, privacy modifiers,!commands, keyword commands) and the first OPTIONS expiry;maybe_handle_keyword_command,_handle_sessions_commandturn.py_SlackTurn(the turn's state, plus its permit and single verdict) and_run_turn, the turn body from the queued reaction to thefinallypermission_ladder.py_request_approval,handle_interaction, the steer and orphan-reject helpers: everyapprove_tool/reject_toolsitedelivery.py_deliver_answer: the answer's delivery and verdict, then what the finished turn postsagent_names.py_iter_cc_agent_namesstays in the facade below the matcher it reads, so its home-path lines are not re-addedBecause the owners run on the facade's globals, every patch of
kiro_crew.slack.handler.<name>reaches the moved code unchanged. Guards that read theturn's code by path now read the owner that holds each construct (path, row or join edits
only; in the composition contract, owner rows and the exact-holder map), and the
composition contract maps each guarded construct to its exact home files.
Backwards compatibility
Compatible: every name
slack/handler.pybound before is still bound there, the sameobject (pinned by
test_slack_handler_composition_contract.py, and by the facade's frozeninventory
test/campaign_facade_inventories/kiro_crew.slack.handler.json), and the golden Slack /SEL / session-manager transcripts are unchanged.
Reader: src/kiro_crew/slack/interactions.py:handle_interaction -- chat -- imports it from
kiro_crew.slack.handler, which re-exports thepermission_ladder.pyfunction composed onto its globals;test_slack_handler_composition_contract.py::test_golden_transcript[interaction_edges]Reader: src/kiro_crew/slack/transport_dispatch.py:maybe_handle_keyword_command -- chat -- imports it from
kiro_crew.slack.handler, which re-exports thedispatch.pyfunction;test_slack_handler_composition_contract.py::test_golden_transcript[keyword_commands]Tests
test/test_handler_turn.py(new):SLACK_TURN_FUNCTIONS, the function list that thechecks which read
handle_message's source share, ishandle_messageand its phases inrun order;
_SlackTurnraisesUnboundLocalErrorfor a valueread before it is set;
release_permit/book_success/book_failurekeep theclosures' order, idempotence and side effects; every turn value a phase reads is set
before it and every hand-off has a reader (with synthetic self-tests that go red); every
facade import is read by the facade or an owner, and a function-local import in its own
function (the property the new
setup.cfgF401 row stands in for, with two redself-tests); no phase leaves a stale value on the turn (a value a later phase reads,
through an alias or in place, that the phase rebinds in its body, an
exceptarm or itsfinallyis copied in the hand-off that ends the phase, which returnsTrueonly there,with red self-tests); the "Slack messages" sink redacts the final answer at its own
boundary; the sync-io-in-async gate still flags a call planted in each owner coroutine.
46 tests; 5 runs at
-n0and one at-n 3pass.test_slack_handler_composition_contract.py: owner rows, the moved-name count (70 -> 81)and shape digest (recomputed at the base); the two placement tests become
_GUARDED_TOKEN_HOMES, an exact holder set per guarded construct, plus its counts intheir homes. These are the only assertion edits in a test this PR does not add.
test/campaign_facade_inventories/kiro_crew.slack.handler.json(new): the facade's 200public names at the base, read by
test_campaign_facades_base_public_names.py, withhandle_interactionandmaybe_handle_keyword_commandchecked to be their owners' ownobjects in a fresh interpreter.
proven by a mutation in the new home that turns the guard red:
test_transport_permission_floor,test_messaging_deny_notice,test_hooks,test_turn_ceiling,test_memory_v2_isolation,test_reinjection_gate,test_runtime_death_is_a_process_event,test_security_posture,test_messaging_auto_title,test_options_click_validation,test_slack_options_lifecycle,test_agent_spec_hardened_reads,test_persist_off_loop,test_name_grant_surfaces,test_slack_status_keyword.Move audit
move_audit.py(campaign tool, BASE213339f671):handle_messageis decomposed, not moved whole. A statement-level audit finds everyBASE statement of it unchanged in the facade or an owner except 30 leaf statements
(63 lines): the two docstring wordings below, and the delivery's permit and verdict
closures (
_release_permit()->turn.release_permit(),_book_success()->turn.book_success(),await _book_failure()->await turn.book_failure(), theirbodies as
_SlackTurnmethods withself.re-plumbing,_verdict_booked/_had_errorread off the turn). Other edits, all asserted by the recipe: bare
return->return False(7 in the dispatch, 4 in the turn body),continue->returnand therejected-click
break->return Truein the two ladder branches, the read-onlyaliases at each phase start and the hand-off blocks at each end (the turn carries the
turn body's
linked_session_keyasrouted_link_key, because an attribute of that name is asession's channel link to
test_crew_log_class_recorder),_user_text: str(adeclared type mypy needs once the closure lives in an owner), 18 comment wordings that
named a place now in another phase or carried "no longer", and two
nosemgreplines._reject_orphaned_tool: its docstring's "no longer" is reworded (the comment-historygate reads moved lines).
Expr: the facade's_facade_compose(...)call (the shared helper), with the five newowners in its tuple.
maybe_handle_keyword_command,_handle_sessions_command,_should_auto_approve_spawn,_steer_host_deny,_request_approval,handle_interaction.Logger: owner functions read the facade's
logger, so log records still come fromkiro_crew.slack.handler.Diff alignment
Every changed file adds the same lines under git's default diff and
--minimal, excepttwo whose default diff re-shows blank lines only:
docs/system-specs/modules/slack-gateway.md(109 / 106: three blank lines) and
test/test_slack_handler_composition_contract.py(137 / 135: two blank lines). Every block order of the new contract tests and every
paragraph order of the rewritten spec section gives the same or a larger difference; the
re-shown lines are blank (an accepted alignment exception).
CI path references
None: no workflow path filter or file list names
slack/handler.py.Re-points and citations
Guards that read a construct by path now read the owner that holds it (path, row or join
edits; no assertion changed):
test_transport_permission_floor,test_messaging_deny_notice,test_hooks,test_turn_ceiling,test_memory_v2_isolation,test_reinjection_gate,test_runtime_death_is_a_process_event,test_security_posture(census row split 3 -> 2 + 1),
test_messaging_auto_title,test_options_click_validation,test_slack_options_lifecycle,test_agent_spec_hardened_reads,test_persist_off_loop,test_name_grant_surfaces,test_slack_status_keyword; negative scans read the facade andevery owner. Each re-point has a mutation in the new home that turns its guard red. Beyond
paths, rows and joins, the only assertion edits are the composition contract's own rows
(owner rows, the moved-name count 70 -> 81, the shape digest) and its two placement tests,
replaced by
_GUARDED_TOKEN_HOMESas the campaign's design review approved; the twohandle_messagesource readers take their function list fromtest_handler_turn.py.Citations corrected (comments and docstrings only):
platform/interfaces.py,slack/events.py(2),slack/transport_dispatch.py,session_map.py; in the unchanged owners,handler_runtime/stream.py(the_AnswerStreamdocstring and four comments on the turn loop's catch-all),
handler_runtime/commands.py(3) and
handler_runtime/turn_context.py;test_hooks.py:2093,test_messaging_auto_title.py:537and:681,test_messaging_deny_notice.py:727,test_options_click_validation.py:298, and thefailure message at
test_runtime_death_is_a_process_event.py:1164;slack/handler.pyas the home of moved code, andops-mission-control.md's note that its Slack board is a separate egress boundary fromthe Slack messages sink (now
slack/handler_runtime/delivery.py).setup.cfgturns F401 off forslack/handler.py(theslack/gateway.pyprecedent);test_handler_turn.pyasserts the property it stood for..github/file-line-cap-baseline.txtloses its
slack/handler.pyrow (now 1,065 lines); the baselined files that grow are listedbelow.
Redaction sink row moves with its code (visible change)
The "Slack messages" row of
security_posture._REDACTION_SINKSnow namesslack/handler_runtime/delivery.py, which holds the sink's final redaction pass, so thesecurity posture panel shows that path instead of
slack/handler.py. The sink-redactschecks then read the module that actually redacts the posted answer.
slack/handler.py,which keeps only
_display_redactor(the canonical-order pair the delivery's fallback egressuses), moves into
NON_EGRESS_REDACTION_MODULES, anddelivery.pyleaves that list. The OpsMission Control row's detail now says "a separate egress boundary from the Slack messages
sink" rather than naming
slack/handler.py. A new test intest_handler_turn.pypins thesink's own pass: with the render made pass-through and a key split across two chunks (so the
per-chunk pass sees no whole key), the final posted text is still redacted, both on the no-stream
chat.updatefallback and in the text the stream is sealed with. Dropping delivery's finalcredential pass turns both cases red. With that pass dropped, the 36 test files that drive
handle_messagewith credential-shaped text andtest_security_posture.pyall stayed green(3,299 tests), so this test is the one that notices.
Baselined growth (L56 addendum 1)
Two baselined test files grow past their row on main. Their rows stay exactly as main has them:
test/test_slack_options_lifecycle.pyhandle_messagesource readers read the handler's phase functions as one text (imported fromtest_handler_turn.py)test/test_slack_handler_composition_contract.py_GUARDED_TOKEN_HOMES, which replaces the two placement tests; accepted at Master review 26227984Baselined growth (L56 addendum 1b)
src/kiro_crew/security_posture.pyNON_EGRESS_REDACTION_MODULES:slack/handler.py,slack/handler_runtime/dispatch.py,slack/handler_runtime/permission_ladder.py,slack/handler_runtime/turn.py(the block's comment is rewritten in place, with no added lines)References not edited (cost)
website/src/pages/settings/SecurityPanel.test.tsx:211: a mocked posture row reads'handler.py — final pass'; the "Slack messages" sink is nowslack/handler_runtime/delivery.py.Gate floor
scripts/local-gate.py --dry-runselects 2,835 backend and 1,382 frontend files, over thecampaign's local cap, so the floor ran instead: every test file that imports, patches or
reads the handler or its owners, the re-pointed guards and the repository guards that scan
them (166 files,
-n 3): 11,959 passed. Coldmypy src/kiro_crew(2,437 files): clean.black, isort and flake8 on the changed files,
check_black_formatting,check_subprocess_encoding,check_agent_sdk_boundary,check_sync_io_in_async, thecomment-history, brand, harness-parity, memory-store-seam and feature-map gates,
docs_lint.py(and--test),check_file_line_cap.pyandtest_flake_pattern_ratchet.py: all pass. Semgrep 1.78 (the CI rule set) over the changedfiles reports no finding the base did not already have. Per-file line coverage from the
floor run:
agent_names.py97.8%,dispatch.py99.1%,turn.py95.1%,permission_ladder.py94.7%,delivery.py81.3%,handler.py98.0%.A wheel built from a
git archiveof the commit, installed in a fresh venv, importsthe facade and every new owner under an isolated HOME.
Manual verification
N/A — a structural move: the 65 recorded golden transcripts replay byte-identical, and
the existing handler, interaction and transport suites pass unchanged.
Related Issues
Part of #20192
Follow-up: #21320 (the deferred comment citation above)
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)