Skip to content

refactor: compose every split facade through one shared helper - #20494

Merged
bolichen97 merged 1 commit into
mainfrom
fix/shared-facade-compose-16231
Oct 16, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/shared-facade-compose-16231

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Every split-module facade composes its owners through one shared helper, kiro_crew/_facade_compose.py, instead of nine private copies of the same code, with no change in behaviour.

Scope after the rebase onto main (2026-10-15): dashboard.chat_turn is left out of the swap. Since #20526, chat_turn.compose also finds its owners itself (chat_turn.owner_modules()) and binds on chat_runner every name an owner defines that the runner lacks; the shared helper has neither, and teaching it both would widen the helper's contract for the other eight facades. So chat_runner.py, chat_turn.compose and the chat runner contract tests are exactly main's; only chat_turn/__init__.py's closing docstring paragraph and the spec note it. The other eight facades compose through the shared helper. #16231 stays open for the chat_turn copy, so this PR now says Refs, not Closes.

Scope after the rebase onto main 0a008292c (2026-10-15): main's #20401 added subagent_parts.compose, the same statements as the shared helper with a required host (SubagentManager). It is folded in: subagent.py calls _facade_compose(globals(), owners, host=SubagentManager) and subagent_parts/__init__.py keeps only its docstring. Main's #20555 also added a direct ScriptHookStore._atomic_mutation rebind in hooks.py; it now calls the shared helper's public rebind.

Nine owner packages each carried their own private copy of compose / _functions_of / _rebind: slack.gateway_runtime, dashboard.chat_turn, dashboard.chat_api, dashboard.messaging_api, dashboard.file_api, dashboard.agent_admin, dashboard.server_runtime, hook_runtime and slack.handler_runtime. The eight host-less copies ran the same code (seven byte-identical, chat_turn's differing only in its docstring), and four contract tests pinned them byte-identical to each other. slack.gateway_runtime's copy also bound the orchestrator class's methods and requalified their names.

Why it matters

A fix to the rebind technique had to be made nine times, and the byte-identity pins were the only thing keeping the copies from drifting. Every new split added a tenth copy.

Not a goal

  • The design question from refactor(dashboard): compose the agents handlers from agent_admin owners #16786's Design lane (owners taking their seams explicitly instead of sharing the facade's globals, which would remove the # type: ignore lines): not attempted here; it changes how tests patch the facades.
  • No owner, facade or patch surface moves. What each facade exports and what tests patch is unchanged.

What changed (motivation → approach → change)

The copies existed only because each owner package's composition-contract test forbids importing that package from outside its facade, so no facade could reuse another's copy. A neutral module that no facade owns removes that constraint.

src/kiro_crew/_facade_compose.py holds the one compose(namespace, owners, host=None). Its body is the slack.gateway_runtime copy: with host=None it runs exactly the eight host-less copies' code, and with a host class it also swaps and requalifies that class's owner methods, as the Slack gateway's did. The private copies are deleted from nine package __init__.py files (hook_runtime/__init__.py, slack/gateway_runtime/__init__.py, subagent_parts/__init__.py and the six others; not dashboard/chat_turn/__init__.py, see the scope note), which keep only their docstrings (each now points at the shared helper and no longer explains why it kept its own copy). The nine facades (dashboard/chat_handlers.py, dashboard/handlers/messaging.py, dashboard/handlers/files.py, dashboard/handlers/agents.py, dashboard/server.py, hooks.py, slack/handler.py, slack/gateway.py, subagent.py) import compose as _facade_compose and call it once at their foot; the gateway passes host=GatewayOrchestrator and subagent.py passes host=SubagentManager. Comments and docstrings that named <package>.compose, and the composition paragraphs in docs/system-specs/modules/ (slack-gateway.md, learn-cron-dashboard.md, messaging.md, memory-skills-hooks.md, subagent.md), now name the shared helper.

Backwards compatibility

Compatible: the rebinding code is the same statements, called once per facade at the same point, so every function keeps its globals, __module__ and __qualname__.

Each removed compose had exactly one production caller, its own facade, plus the contract test's synthetic probe (grepped origin/main src/, test/, website/, scripts/, .github/ for <package>.compose(, _rebind(, _functions_of(, _requalify(). Every one is repointed here:

Reader: src/kiro_crew/dashboard/chat_runner.py:_chat_turn.compose -- chat -- unchanged: still calls chat_turn.compose (main's, with owner_modules() and name binding); test_chat_runner_composition_contract.py and test_chat_runner_compose_binding.py are main's, unchanged and green
Reader: src/kiro_crew/dashboard/chat_handlers.py:_chat_api.compose -- chat -- now calls _facade_compose.compose; test_chat_handlers_composition_contract.py test_a_second_facade_import_recomposes_the_owners_onto_it
Reader: src/kiro_crew/dashboard/handlers/messaging.py:_messaging_api.compose -- subagent -- now calls _facade_compose.compose, still before the owner-surface guard wraps the spawn routes; test_handlers_messaging_composition_contract.py
Reader: src/kiro_crew/dashboard/handlers/files.py:_file_api.compose -- chat -- now calls _facade_compose.compose; test_dashboard_files_composition_contract.py
Reader: src/kiro_crew/dashboard/handlers/agents.py:_agent_admin.compose -- crew page -- now calls _facade_compose.compose; test_dashboard_agents_composition_contract.py test_the_facade_composes_through_the_shared_helper
Reader: src/kiro_crew/dashboard/server.py:_server_runtime.compose -- chat -- now calls _facade_compose.compose; test_dashboard_server_composition_contract.py test_the_facade_composes_through_the_shared_helper
Reader: src/kiro_crew/hooks.py:_hook_runtime.compose -- cron -- now calls _facade_compose.compose at the same foot-of-module point, after the UNC memo priming; test_hooks_composition_contract.py test_the_facade_composes_through_the_shared_helper
Reader: src/kiro_crew/hooks.py:_hook_runtime._rebind -- cron -- main's ScriptHookStore._atomic_mutation rebind now calls the shared helper's public rebind (renamed from _rebind in _facade_compose.py), so hooks.py no longer imports hook_runtime; test_hooks_composition_contract.py test_the_store_mutation_guard_is_rebound_through_the_shared_helper
Reader: src/kiro_crew/subagent.py:_compose_parts -- subagent -- now calls _facade_compose.compose with host=SubagentManager, at the same foot-of-module point; test_subagent_parts_composition_contract.py test_the_facade_composes_through_the_shared_helper and test_compose_rebinds_functions_methods_and_members
Reader: test/test_subagent_parts_composition_contract.py:subagent_parts.compose -- release -- the synthetic probe now calls the shared helper with host=owner.Host
Reader: src/kiro_crew/slack/handler.py:_handler_runtime.compose -- chat -- now calls _facade_compose.compose; test_slack_handler_composition_contract.py test_the_facade_composes_through_the_shared_helper
Reader: src/kiro_crew/slack/gateway.py:_runtime.compose -- cron -- now calls _facade_compose.compose with host=GatewayOrchestrator; test_slack_gateway_composition_contract.py test_compose_rebinds_functions_methods_and_members
Reader: src/kiro_crew/dashboard/chat_handlers.py:_chat_api -- chat -- the facade's private package alias, read only by its compose call; no other reader on origin/main, dropped from _BASE_NAMES in test_chat_handlers_composition_contract.py
Reader: test/test_chat_handlers_composition_contract.py:test_compose_rebinds_functions_and_class_members -- release -- the five host-less probes and the gateway probe now call kiro_crew._facade_compose.compose, so both branches of the helper stay pinned; the chat runner probe still calls chat_turn.compose

Tests

  • Six synthetic-module probes (test_compose_rebinds_functions_and_class_members in the chat handlers, agents, files, messaging and hooks contracts; test_compose_rebinds_functions_methods_and_members in the Slack gateway contract) now call the shared helper; the gateway one passes host=Host, so both branches stay pinned.
  • The four byte-identity pins (test_the_compose_copy_matches_its_siblings in the agents, server, hooks and Slack handler contracts) become test_the_facade_composes_through_the_shared_helper: the facade's _facade_compose IS the shared helper, it is called exactly once, and the owner package's __init__ defines no function or class, so no copy can come back.
  • test_the_store_mutation_guard_is_rebound_through_the_shared_helper (hooks contract): the @contextmanager generator under ScriptHookStore._atomic_mutation, which compose cannot reach, is rebound with _facade_compose.rebind onto the facade's globals, and hooks.py names no _hook_runtime. Main's test_the_store_mutation_guard_reads_the_facade_globals still proves the patch reach.
  • test_subagent_parts_composition_contract.py::test_the_facade_composes_through_the_shared_helper (new): subagent._facade_compose is the shared helper, called once with host=SubagentManager, and subagent_parts/__init__.py defines no function or class.
  • Every other patch-reach, one-import-path and fresh/second-import test in the contracts is unchanged and green. The chat runner contract files are main's, untouched.

Runs on the rebased head (Linux, Python 3.12):

pytest the nine *_composition_contract.py files + test_chat_runner_compose_binding,
  test_chat_runner_turn_plumbing, test_gateway_runtime_bindings,
  test_apps_worker_slots, test_slack_handler_rendering   -> 1664 passed
isort / flake8 on every changed file; mypy on the helper,
  chat_handlers and chat_turn                              -> clean

Re-run on the head rebased onto main 0a008292c (after #20555 split hooks.py into more owners, and with subagent_parts folded in): the composition and hook files -> 1308 passed, and the subagent, hooks and facade-inventory contracts -> 406 passed; scripts/local-gate.py related set -> 17128 passed, 18 failed: 17 in test_acp_spawn_offload.py::TestRuntimeProjectedLaunchDocuments, which fail identically on a clean origin/main 0a008292c checkout on this host, and code_review_sage/tests/test_post_comments.py::TestDismissFinding::test_the_post_path_never_sends_a_dismissed_finding (TypeError in an awaitable mock under the parallel run), which passes 3 of 3 runs alone and touches no file in this diff; isort / flake8 on every changed file and mypy src/kiro_crew/ -> clean. black --check flags dashboard/handlers/files.py on origin/main too; left as is.

Manual verification

N/A — a pure refactor of import-time wiring; the composition contracts import each facade fresh and second-time in a child interpreter and check the rebinding directly.

Related Issues

Refs #16231 (stays open for the dashboard.chat_turn copy)

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 14, 2026 21:19
@bolichen97
bolichen97 requested a review from CrysisDeu October 14, 2026 21:19
@bolichen97
bolichen97 enabled auto-merge (squash) October 14, 2026 21:19
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/hook_runtime/__init__.py

  • src/kiro_crew/hooks.py

  • @iamwhatever: missing the ## Sensitive change review heading

How to clear this check:

  1. The PR author posts the template below as a PR comment, with
    every field filled (N/A needs a reason). Keep the
    Head commit line: it must name the current head SHA.
  2. The check turns green within a minute, with no push.
  3. A new push resets this check: post it again for the new head.

Only the author's comment counts this way. A reviewer can instead
paste the filled template into an "Approve" review on this head.
Merging still needs a reviewer's approval.

## Sensitive change review
- Head commit: 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49
- What rule changed:
- Before -> after (what was allowed/blocked, now):
- Worst case if wrong (breaks commands / leaks secret / locks user out):
- Evidence checked (which sandbox result proves it):
- No regression:
  - Tools still work (which tools/commands were run, result):
  - Backward compatible (old config / old data / old callers still work, how checked):
  - Existing tests (which suites passed on this head):
- How to undo:

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 14, 2026
@bolichen97
bolichen97 force-pushed the fix/shared-facade-compose-16231 branch from 165dee2 to 7ddda08 Compare October 14, 2026 21:55
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/dashboard/chat_persistence.py, test/test_chat_persistence_composition_contract.py since this head went green (8cd759c -> 37449b3); CI re-running.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49 — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

One copy of compose is still left: dashboard/chat_turn/__init__.py:179. It is deferred deliberately (#16231 stays open), so confirm that issue really tracks it before merge.

What this change ships

Inventory (6 items) — 6 justified

Intent: let a fix to the facade-rebind technique be made once instead of nine times, with no change in behaviour. This is a FIX (refactor).

  1. A new neutral module kiro_crew/_facade_compose.py holds the one compose(namespace, owners, host=None). It is called by eight facades, two of which pass host=. — justified
  2. The private compose/_functions_of/_rebind copies are deleted from eight owner-package __init__.py files, subagent_parts included. — justified
  3. The gateway and subagent facades pass host= as a keyword where they used to pass it by position, and subagent_parts.compose is folded in. — justified
  4. hooks.py now rebinds _atomic_mutation through the public rebind instead of hook_runtime._rebind. — justified
  5. Four test_the_compose_copy_matches_its_siblings byte-identity pins are deleted. The description names them, and with only one copy left their purpose no longer applies. — justified
  6. Docstrings, comments, five spec paragraphs and one facade-inventory note now name the shared helper. — justified

[FIRST-PRINCIPLES-REVIEWED] 6dad1f8

Description read

[DESCRIPTION-READ] ce645eb4a8138c11aae8b910c40449a0ac5205b95c7b17126f4e62b37c9dd176

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 Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that chat_turn.compose stays in step with _facade_compose.compose: this PR deletes the byte-identity pins, and #16231 is the only thing tracking it.

[DESIGN-REVIEWED] 6dad1f8

Description read

[DESCRIPTION-READ] 6f4b2ebc1e2c0817ebda9f6ebe934d33e022cfd316a17fcbc34b596f24ae1438

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 Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6dad1f8

Verdict parsed from the review's SHA-scoped output markers for commit 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6dad1f8

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49: <one-sentence reason>

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • First Principles PASS punchline: host=None must equal the eight deleted host-less copies

rebutted (checked, holds): AST-compared the shared helper against the deleted copies on the base commit 3572d1c, docstrings stripped.
_functions_of and _rebind are identical. The seven host-less def compose( bodies (chat_api, agent_admin, file_api, messaging_api, server_runtime, hook_runtime, slack/handler_runtime) hash to one value; chat_turn differs from them only in docstring text.
compose differs from them in exactly three places: the added host: type | None = None parameter; for cls in classes became for cls in classes if host is None else [*classes, host]; and the host-only qualname pass now sits behind if host is None: return.
With host=None the second is for cls in classes and the third returns before any added statement, so the executed statements are the old ones in the same order.
The host branch is the deleted slack.gateway_runtime copy verbatim. The probes pin both: six host-less test_compose_rebinds_functions_and_class_members and the gateway's test_compose_rebinds_functions_methods_and_members with host=Host.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 6dad1f872b63ccdfebcee194d0d8d3f4b5597e49 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 10 classified, 0 newly refused, 10 still allowed.
  • ubuntu-latest (platform posix): 10 classified, 0 newly refused, 10 still allowed.
  • windows-latest (platform windows): 4 classified, 0 newly refused, 4 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

TIGHTENING: None. This diff makes no security rule stricter. The five per-package compose copies are folded into one new shared helper, src/kiro_crew/_facade_compose.py, and hooks.py now calls that helper (-_hook_runtime.compose( → +_facade_compose(, -_hook_runtime._rebind(...) → +_facade_rebind(...)). When host is None, which is how hooks.py calls it, the new compose and rebind contain the same lines as the removed hook_runtime.compose and _rebind, apart from the _rebind → rebind rename. No deny pattern, sensitive-command tier, exfil shape, rule-catalog entry, path fence or validator changes anywhere in the patch. The only threat-related text that changes is a docstring rewrap that mentions files.is_sensitive_path.

ADJUDICATED: 14 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: Rows are posix (10) and windows (4). The diff adds no assumption about paths, separators, argv shape, interpreter or environment. The posix rows are the maintainers' own operations in the touched area: the composition-contract and deny-tier pytest runs, deny_diff.py, a facade-module check, a scoped diff, and read-only searches and reads. The windows rows cover the same operations in Windows spelling: a .venv\Scripts\python.exe interpreter path, the py launcher, Select-String, and type with \ separators. These rows check that the deny composite still treats ordinary work in this area the same way now that hooks.py gets its rebinding from the shared helper. Every platform the diff touches has candidates.

[SCOPE-REVIEWED] 6dad1f8

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 15, 2026
@bolichen97
bolichen97 force-pushed the fix/shared-facade-compose-16231 branch from 7ddda08 to 0e5b761 Compare October 15, 2026 19:03
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 15, 2026
@bolichen97
bolichen97 force-pushed the fix/shared-facade-compose-16231 branch from 0e5b761 to b7e4e30 Compare October 15, 2026 19:05
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rebased onto origin/main 8da5b41552 as one commit (b7e4e304df).

Choice: option (a), keep main's contract. dashboard.chat_turn is left out of the shared-helper swap. Since #20526, chat_turn.compose also finds its owners (owner_modules()) and binds missing names on chat_runner; _facade_compose has neither, and adding both would widen the helper for the other eight facades. So chat_runner.py, chat_turn.compose and the chat runner contract tests are exactly main's. Only docstrings and the spec note the exception. The link is now Refs #16231, since the chat_turn copy remains.

Conflicts resolved: chat_turn/__init__.py, chat_runner.py (main's), chat_handlers.py (main's new owners + shared helper import), learn-cron-dashboard.md (main's text, compose names updated).

Tests on this head: the nine composition contracts + test_chat_runner_compose_binding, test_chat_runner_turn_plumbing, test_gateway_runtime_bindings, test_apps_worker_slots, test_slack_handler_rendering: 1663 passed, 1 failed. The failure (test_dashboard_server_composition_contract.py::test_the_lazy_imports_stay_inside_the_functions_that_need_them, 84 == 83) fails the same on clean main. isort/flake8/mypy clean. No review dismissed, no overrides. Squash auto-merge still armed.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Oct 15, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 15, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

REQUEST_CHANGES at e39b24a, after a deeper read. This supersedes our earlier HOLD on this head.

On its own base the refactor is statement-for-statement equivalent; I checked the facades with an AST comparison. The problem is what happens when it meets current main.

  1. hooks.py will fail at import after the rebase. Main (#20555) now rebinds ScriptHookStore._atomic_mutation with _hook_runtime._rebind(...) right after compose (hooks.py). A git merge-tree of this head onto main auto-merges hooks.py with that line kept, while this PR drops the from kiro_crew import hook_runtime as _hook_runtime import. The result is a NameError when hooks.py loads, which takes down the shell deny gate's facade.
    Fix: rebase onto main and point that line at the shared helper (import _rebind from kiro_crew._facade_compose, or add a public rebind there). Make sure main's new hook owners also go through the shared helper.
  2. The branch now conflicts with main in src/kiro_crew/hook_runtime/__init__.py.

After the rebase, Sensitive Change Review needs the reasoning template for the new head, and a maintainer needs to approve the deny-gate facade rewiring. I did not run the code; the import failure comes from reading the merged file.

— crew-pr-reviewer (r105 deep check)

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 15, 2026
@bolichen97
bolichen97 force-pushed the fix/shared-facade-compose-16231 branch from e39b24a to 8fd7a82 Compare October 16, 2026 06:54
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] @iamwhatever thanks for the deeper read. Both points are fixed on the new head 8fd7a82 (rebased onto main 0a008292c, still one commit).

  1. fixed: hooks.py imported _hook_runtime only for main's ScriptHookStore._atomic_mutation rebind, and this PR dropped that import, so the merged file would raise NameError at load. _facade_compose._rebind is now the public _facade_compose.rebind, and hooks.py imports it as _facade_rebind and calls it for that rebind. hooks.py no longer names _hook_runtime at all.
    Main's new hook owners (hook_types, script_hooks) are in the one _facade_compose(...) call, so every hook owner goes through the shared helper. The helper already selects owner classes by __module__, the same rule hook_runtime.compose used.
    New test: test_hooks_composition_contract.py::test_the_store_mutation_guard_is_rebound_through_the_shared_helper (the facade's _facade_rebind is the helper's rebind, the generator's globals are kiro_crew.hooks, and hooks.py holds no _hook_runtime). Main's test_hooks_script_hooks.py::test_the_store_mutation_guard_reads_the_facade_globals still passes and proves the patch reach.
  2. fixed: the hook_runtime/__init__.py conflict was docstring-only. I kept main's text on moved classes and the contextmanager rebind and pointed it at the shared helper.

Local runs on the new head: import kiro_crew.hooks (and the gateway, server and chat runner facades) loads; the composition and hook files -> 1308 passed; local-gate.py related set -> 17293 passed, 17 failed, all in test_acp_spawn_offload.py::TestRuntimeProjectedLaunchDocuments, which fail the same on a clean origin/main checkout here; isort, flake8 and mypy clean.

dashboard/chat_turn keeps its own compose, unchanged.

The Sensitive Change reasoning for the new head and the maintainer approval of the deny-gate facade rewiring are still open human steps. Re-requesting your review.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Oct 16, 2026
Nine owner packages each carried a private copy of compose/_functions_of/
_rebind (slack.gateway_runtime, chat_api, messaging_api, file_api,
agent_admin, server_runtime, hook_runtime, slack.handler_runtime,
subagent_parts), kept identical only by contract-test pins.

Hoist one compose(namespace, owners, host=None) into the neutral
kiro_crew/_facade_compose.py, which no facade owns, so the per-package
import guards still hold. With host=None it runs the host-less copies'
code; with a host class it also swaps and requalifies that class's owner
methods, as the Slack gateway's and subagent's copies did. The nine
facades call it once at their foot; the package __init__ files keep only
their docstrings. Its rebind is public: hooks.py uses it for the one
function compose cannot reach, the generator under
ScriptHookStore._atomic_mutation.

dashboard.chat_turn keeps its own compose: since #20526 it also finds its
owners (owner_modules()) and binds on chat_runner every name an owner
defines that the runner lacks. That contract is the runner's alone, so
chat_runner and its tests are unchanged and only docstrings note it.

The byte-identity pins become "the facade composes through the shared
helper and the package defines no function"; the synthetic-module probes
call the shared helper. Pure refactor: no behaviour change.

Refs #16231
@bolichen97
bolichen97 force-pushed the fix/shared-facade-compose-16231 branch from 8fd7a82 to 6dad1f8 Compare October 16, 2026 07:20
@bolichen97

bolichen97 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] span=265b57de6a83 fixed in 6dad1f8 (still one commit).

  • subagent_parts keeps its own compose copy

fixed: subagent_parts.compose (added on main by #20401) is deleted; subagent_parts/__init__.py keeps only its docstring.
subagent.py now calls _facade_compose(globals(), owners, host=SubagentManager); the removed copy was the same statements with a required host, so behaviour is unchanged.
New pin: test_subagent_parts_composition_contract.py::test_the_facade_composes_through_the_shared_helper; the synthetic probe calls the shared helper with host=owner.Host.
dashboard.chat_turn stays on its own compose on purpose (owner discovery and name binding are the runner's contract); the body's scope note says so.
self-added: no

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] @iamwhatever one more push after my reply above: head is now 6dad1f8 (rebased onto main 9b99f5f, still one commit). It also folds in main's new subagent_parts.compose copy (First Principles asked for it), so subagent.py is the ninth facade on the shared helper. Your two points stay fixed as described. chat_turn keeps its own compose.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 16, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

  • Keep chat_turn.compose in step with the shared helper

accepted-and-deferred: chat_turn.compose stays its own copy on purpose; it also finds its owners and binds names on the runner, which the shared helper does not do.
It is tracked by #16231 (open, assignee bolichen97, labels deferred-finding and tier:T2), which this PR names with Refs, not Closes, so the merge leaves it open.
The chat runner contract tests (test_chat_runner_composition_contract.py, test_chat_runner_compose_binding.py) are main's and unchanged, so its own behaviour stays pinned.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

confirmed: #16231 is open, assigned to bolichen97, labelled deferred-finding and tier:T2, and its title names chat_turn first among the facades to hoist.
This PR says Refs #16231, not Closes, so the merge does not close it, and the body's scope note records why chat_turn keeps its own compose.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 16, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Hold. This PR is reserved for human review: it rewires the shell deny-gate facade (src/kiro_crew/hooks.py, src/kiro_crew/hook_runtime/__init__.py).

Both points from my r105 change request are fixed on this head. hooks.py now imports compose and rebind from kiro_crew._facade_compose (hooks.py#L39-L40), and the _atomic_mutation rebind goes through the shared helper (#L1626). Nothing names _hook_runtime any more, and the conflict is gone. Every AI lane passes, both PASS punchlines have dispositions, Security Scope Review finds no newly refused command, and the chat_turn copy left behind is tracked in #16231. Note that #16231 is due today.

To clear this:

  1. The author posts the Sensitive Change Review template for 6dad1f8. That check is red now.
  2. A maintainer reviews and approves the deny-gate facade rewiring.

I read the source and did not run the code.

Reviewed head: 6dad1f8

— crew-pr-reviewer (r107)

@bolichen97
bolichen97 merged commit 766c658 into main Oct 16, 2026
110 of 119 checks passed
@bolichen97
bolichen97 deleted the fix/shared-facade-compose-16231 branch October 16, 2026 18:34
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants