Skip to content

refactor(dashboard): split session_transfer and handlers_instances - #21111

Merged
iamwhatever merged 1 commit into
mainfrom
refactor/linecap-s09-session-transfer
Oct 19, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
refactor/linecap-s09-session-transfer

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Bring dashboard/session_transfer.py (3,095 lines) and dashboard/handlers_instances.py (2,871 lines) under the 2,000-line cap with no behaviour change, so new session-transfer and Instances work lands in small modules that each own one responsibility.

Both files were over the repository's 2,000-line cap (.github/file-line-cap-baseline.txt). Part of the line-cap campaign.

Part of #20192

Why it matters

A file this size is where every new transfer or Instances feature lands, so it keeps growing, review diffs get harder to read, and the cap baseline cannot shrink. Splitting by responsibility tells the next contributor where their change goes.

Not a goal

  • dashboard/server.py, the scope's third file. It follows as a separate stacked PR, because moving its entrypoints needs a restructure of its composition-contract test.
  • Any behaviour, API, log-name, error-text or registry-count change.
  • Fixing pre-existing test shapes the split touches (one vacuous AST test is recorded below for a follow-up).

What changed (motivation → approach → change)

Whole top-level definitions move verbatim into sibling owner modules. Each original path stays the import path and the patch surface as a kiro_crew._facade_mirror facade, so monkeypatch.setattr(session_transfer, …) or mock.patch("…handlers_instances.X") still reaches every owner that reads the name, as it did in the one-module file.

Facade (lines) Keeps Owners (lines)
session_transfer.py (739) the sending side's bundle assembly, where the outbound redaction runs session_transfer_staging (307) bundle format, staging dirs, bundle files · session_transfer_layers (435) Layer A/B reads, Layer B writes on arrival · session_transfer_intake (834) admitting and parsing an arriving body · session_transfer_install (1123) validating and installing it
handlers_instances.py (1527) the registry, connection, remote-update, search and send routes handlers_instances_gate (317) owner gate, audit, registry access, chain policy · handlers_instances_peer (1209) the routes that read a peer, and the proxy

Rows keyed by path follow the code: in security_posture.py the receive-side scrub is listed in NON_EGRESS_REDACTION_MODULES (inbound sanitisation; session_transfer.py stays the registered "Session transfer bundle" sink), the "Peer live-session list" sink names the peer owner, and the baseline-redactor census row, error-code-baseline.json rows (totals unchanged) and the two .github/file-line-cap-baseline.txt rows move or go. The instances spec, the module index and the feature map name the owners.

Backwards compatibility

Compatible: every BASE name stays reachable at its original path (test/campaign_facade_inventories/kiro_crew.dashboard.{session_transfer,handlers_instances}.json freezes them); the moved functions are the same objects.

Reader: src/kiro_crew/dashboard/routes/chat.py:session_transfer.api_chat_slot_import -- chat -- served by the facade; test_session_transfer.py drives POST /api/chat/slots/import through it
Reader: src/kiro_crew/dashboard/session_export.py:write_bundle_file -- chat -- from kiro_crew.dashboard.session_transfer import write_bundle_file resolves through the facade; test_session_export.py
Reader: src/kiro_crew/dashboard/session_export.py:release_bundle_files -- chat -- bound on the facade (imported from its staging owner); test_session_export.py
Reader: src/kiro_crew/dashboard/handlers_instances.py:local_instance_label -- crew page -- imported from the session_transfer facade; test_session_transfer.py send tests
Reader: src/kiro_crew/dashboard/session_transfer_staging.py:write_bundle_json -- chat -- called by write_bundle_file in the same owner; test_session_transfer.py
Reader: src/kiro_crew/dashboard/routes/connections.py:handlers_instances.api_instances_capabilities -- crew page -- route registered by facade attribute; test_remote_crew_capabilities.py
Reader: src/kiro_crew/dashboard/routes/connections.py:handlers_instances.api_instances_approval_state -- crew page -- same registration; test_remote_crew_capabilities.py
Reader: src/kiro_crew/dashboard/routes/connections.py:handlers_instances.api_instances_versions -- crew page -- same registration; test_instances_remote_update.py
Reader: src/kiro_crew/dashboard/routes/connections.py:handlers_instances.api_instances_chat_slots -- crew page -- same registration, identity pinned by test_remote_crew_peer_slots.py
Reader: src/kiro_crew/dashboard/routes/connections.py:handlers_instances.api_instances_proxy -- crew page -- same registration, identity pinned by test_remote_crew_peer_slots.py
Reader: src/kiro_crew/dashboard/handlers_instances_peer.py:read_peer_slots -- crew page -- called by api_instances_chat_slots in the same owner; test_remote_crew_peer_slots.py
Reader: src/kiro_crew/dashboard/handlers_crew_turn.py:ProxyReplyUnredactable -- crew page -- module-level import from the facade still binds the same class; test_crew_turn_proxy.py

Move audit

move_audit.py --base 27ab9383e2 --head HEAD:

  • src/kiro_crew/dashboard/session_transfer.py: 3098 -> 739 lines; moved 100.0% (python-ast) (97/97 units, 0 changed)
  • src/kiro_crew/dashboard/handlers_instances.py: 2871 -> 1527 lines; moved 100.0% (python-ast) (68/68 units, 0 changed)

Glue only: owner imports, the mirror install and its TYPE_CHECKING manifest, # noqa: F401 on project imports the facade's own code no longer reads, and stdlib/third-party imports it no longer reads deleted (owners bind them; the mirror serves them). One kept line edited: each facade binds logger by its literal dotted name, the same object its owners bind (L25: log names unchanged; the mirror's one-object rule also holds under python -m).

Also moved: the facade header's note on why chat_handlers is imported function-locally now sits in session_transfer_install, beside the code it governs; the facade keeps a two-line pointer.

Comment-only edits in moved code (comments only, so the move audit still matches every unit), where the prose named the module it moved out of: the proxy's audit note (handlers_instances_peer) names api_instances_search_sessions in the facade and _audit in handlers_instances_gate, and the owner-gate note (handlers_instances_gate) names the routes "of handlers_instances". Docstrings are left byte-identical, since they are part of each unit's AST: api_chat_slot_import's "see the module docstring" (session_transfer_install.py:337) and the refusal helper's "local to this module" still read as they did in the one-module file.

Class names: the seven moved exception classes (_DiskFull, _UploadsBusy, _ExpansionBusy, _NeverFits, _MemoryWaitTimedOut in session_transfer_intake; PeerSlotsUnavailable, ProxyReplyUnredactable in handlers_instances_peer) keep their facade's __module__, set after each owner's body, because a raised class renders as module.qualname in a traceback. The four other moved classes (TransferBundle, LayerBEvents, _PrefixPublication, PeerSlots) keep the owner's __module__: a search of src/ and test/ finds no reader of their module name (no response body, SEL record, log capture, pickle or __module__-based selection).

L36: git diff and git diff --minimal add and delete the same lines in every file (session_transfer.py +145/-2504 both, handlers_instances.py +89/-1433 both).

Docs citations (L29)

  • docs/request-for-change/rfc-remote-crew-sidebar.md (4 path cites), rfc-conductor-remote-dispatch.md (api_instances_proxy) and rfc-outbound-instance-transport.md (api_instances_proxy, read_peer_slots) -> handlers_instances_peer.py.
  • docs/request-for-change/plans/2026-09-23-outbound-instance-transport.md (the PATCH immutability set) -> handlers_instances_gate.py.
  • docs/request-for-change/rfc-arrival-provenance-filing.md status line and docs/request-for-change/README.md (arrival filing) -> session_transfer_install.py.
  • docs/system-specs/modules/instances.md, docs/system-specs/modules/README.md, docs/feature-map/README.md (4 rows): the owners named where code now lives.
  • docs/feature-map/README.md, the Project AWS profile row: the match and spawn injection now cites session_allocation.py and session_allocation_parts/, where that code lives on main.

Tests

  • No test logic changed. Source-reading tests that scanned one file now scan the facade and its owners (path joins, assertions unchanged), each proven by a mutation in the new home:
    • test_r6_owner_gate_regression.py::test_every_instances_route_runs_the_guard: counts routes of the facade and the peer owner against their _guard sites (19 == 19, as at BASE).
    • test_apps_instances_loop_offload.py::test_no_direct_registry_call_in_instances_handler_async_frames: scans the facade, the gate owner (_chain_refusal) and the peer owner.
    • test_r6_owner_gate_regression.py _GATED_MODULES lists the peer owner, so _walk selects the same 74 routes as at BASE (dumped at both commits).
    • test_transcript_derivation_seam.py _PUBLISH_MODULES lists the two handlers_instances owners.
    • test_session_transfer.py::test_staging_helpers_sweep_orphans_on_first_use: its private module copy is the staging owner, where the helpers live.
    • test_session_transfer.py::test_importer_never_answers_404_or_405: reads the facade and all four owners.
    • test_transcript_derivation_seam.py::…::test_the_known_derivers_do_not_use_plain_reads: the four owners join the deriver set.
    • test_session_transfer.py::test_import_never_reads_the_whole_body_into_memory: path joined to its new homes; vacuous at BASE, because it matches only ast.FunctionDef and the three handlers are async; tracked in test(session_transfer): the whole-body buffering guard never inspects the async handlers #21314.
  • New: test_session_transfer_intake.py and test_handlers_instances_peer.py pin the seven exception classes to their facade's __module__ (one parametrized assertion each; dropping an assignment turns it red).
  • Gate floor (local, Python 3.12): 137 related and guard test files at -n 3: 7,260 passed, 5 xfailed, 1 failed (the then-red-on-main test_dashboard_server_composition_contract.py::test_the_lazy_imports_stay_inside_the_functions_that_need_them, fixed on main by test: pin the composition contract's lazy-import count at 84 #20930); after the review fold and the rebase onto 310ad48b5f, the 51 transfer/instances and guard files plus test_warm_task_brief.py: 2,649 passed; mypy src/kiro_crew clean (2,454 files); flake-pattern ratchet 56 passed; black, isort, flake8, comment-history, brand, harness-parity, subprocess-encoding, agent-sdk, sync-io, memory-seam, feature-map, docs-lint and check_file_line_cap.py (0 failures) all pass; semgrep (the CI packs + semgrep/) with --baseline-commit reports 0 new findings; per-owner line coverage on the narrow set 89–100%; an installed wheel imports all eight modules. The two new pin tests passed 5 runs at -n0 and one at -n 3. local-gate.py --dry-run selects 64 backend files (all included) and 366 frontend cross-surface files (not run: no website/ change).

Manual verification

N/A — a verbatim move; the unit and contract suites above exercise every moved path, and an installed-wheel import smoke loads every new module.

Related Issues

Part of #20192

Follow-up: #21314 (the whole-body buffering guard's AST match never reaches the async handlers; pre-existing at BASE, moved unchanged here)

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

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: b0da9b2
  • What rule changed: no rule changed; security_posture.py registries re-key two redactor call sites to the files the code moved to, dashboard/session_transfer_install.py (receive-side scrub, added to NON_EGRESS_REDACTION_MODULES) and dashboard/handlers_instances_peer.py (the "Peer live-session list" sink).
  • Before -> after (what was allowed/blocked, now): the same redaction calls run on the same data in the same order; only the module path each registry row names changes, so every sink is still classified and nothing new is allowed or blocked.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a moved redactor site left unregistered would fail the posture drift guard in CI; no runtime behaviour depends on these rows.
  • Evidence checked (which sandbox result proves it): no sandbox path changed; mutation proofs turn test_security_posture.py red when either row is removed or pointed back at the old file, and the census row is red when the moved log_api_access(origin=...) line loses origin=.
  • Tools still work (which tools/commands were run, result): the session-transfer import/export and Instances proxy suites (test_session_transfer, test_instances, test_remote_crew_chaining, test_r6_owner_gate_regression and the guard set) pass on this head: 2,477 passed.
  • Backward compatible (old config / old data / old callers still work, how checked): yes, both modules stay as mirror facades that bind every public name they bound before, pinned by their test/campaign_facade_inventories/ files; no config or data format changes.
  • Existing tests (which suites passed on this head): test_security_posture, test_session_transfer, test_instances, test_r6_owner_gate_regression, test_transcript_derivation_seam, test_error_code_contract, test_campaign_facades_base_public_names and test_mirrored_owner_storage all passed.
  • How to undo: revert this single commit; the registries and the moved code return together.

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 16, 2026 06:46
@bolichen97
bolichen97 requested a review from buluoray October 16, 2026 06:46
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security_posture.py

  • @bolichen97 posted a complete reasoning template for 4c70200.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4c70200e6f0d861a98803269ed8556d28890a7e7 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 added the readiness: checking Automated validation is still running label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Check that classifying session_transfer_install.py as non-egress hasn't hidden a receive-side surface that the single "Session transfer bundle" sink covered implicitly before.

[DESIGN-REVIEWED] 4c70200

Description read

[DESCRIPTION-READ] 2edeeb85a2ae49e84eb91cfc6252fe8f0d07c32cf7eb5985fc4b8e6c3e731d19

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 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4c70200e6f0d861a98803269ed8556d28890a7e7 — 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

Check one thing before merge: the move audit was run against base 27ab9383e2, but the PR now sits on 518b36d1. Re-run it against the current base.

What this change ships

Inventory (8 items) — 8 justified

Intent: get two dashboard modules under the 2,000-line cap with no change in behaviour (ADDITION of module structure, refactor framing).

  1. session_transfer.py is split into four owner modules (staging, layers, intake, install); the original path stays as a _facade_mirror facade — justified
  2. handlers_instances.py is split into a gate owner and a peer owner; the original path stays as a facade — justified
  3. The seven moved exception classes keep their facade's __module__, so traceback names don't change — justified
  4. The "Peer live-session list" redaction sink now points at handlers_instances_peer.py — justified
  5. session_transfer_install.py is added to NON_EGRESS_REDACTION_MODULES as an inbound scrub — justified
  6. Two rows leave the file-line-cap baseline, and the error-code-baseline.json rows move — justified
  7. New facade inventory JSONs pin every base name at its original path — justified
  8. Tests that scan whole modules now cover the owner modules, and the spec, RFC and feature-map citations are re-pointed to them — justified

[FIRST-PRINCIPLES-REVIEWED] 4c70200

Description read

[DESCRIPTION-READ] 3930d2136155cb4469d3bdee9f2516182a3cdf06f541ff478f4bfd509dbd4a4e

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 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 4c70200e6f0d861a98803269ed8556d28890a7e7 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 4c70200

Verdict parsed from the review's SHA-scoped output markers for commit 4c70200e6f0d861a98803269ed8556d28890a7e7.

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

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 4c70200e6f0d861a98803269ed8556d28890a7e7 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4c70200

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

@bolichen97
bolichen97 enabled auto-merge (squash) October 16, 2026 07:05
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 16, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • rebutted: owner filename lists in the source-scan joins

The joins name each owner the way their guards already name every scanned file: explicit path tables such as _PUBLISH_MODULES, the fence's derivers set and test_r6's _GATED_MODULES. Each row is a reviewed claim that the file is in scope.
This PR moves code verbatim. In guards it does not own, it may only re-point paths or join facade and owner texts, with every assertion unchanged. Each join is mutation-proven: deleting the construct in its new owner turns the test red.
Deriving the list from the facade's owner tuple would be new selection logic in tests outside this change. It is proportional as its own change, not inside a move. A sixth owner already means editing that tuple and the frozen inventory in test/campaign_facade_inventories/, and its author re-points these joins the same way.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • verified: session_transfer_install.py redacts arrivals only; outbound scrubs stay in session_transfer.py

Every redactor call in session_transfer_install.py runs on the receive path of POST /api/chat/slots/import. It scrubs the arrived title and origin label (redact_exfiltration_urls, then redact_credentials), and the off-loop _build_redacted_rows pass runs chat_handlers._redact_history_rows over the arrived rows before they become a slot.
The outbound scrubs did not move. build_source_record (workspace and project through redact_exfiltration_urls, redact_credentials and redact_local_paths) and _assemble_bundle (every assistant turn) are still in session_transfer.py, which stays the registered "Session transfer bundle" sink. The staging, layers and intake owners make no redactor calls.
test_security_posture pins both rows: removing the non-egress entry, or pointing the peer sink back at the facade, turns its omission scan red.

@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

Sensitive change review

  • Head commit: 7c89656
  • What rule changed: no rule changed; security_posture.py registries re-key two redactor call sites to the files the code moved to, dashboard/session_transfer_install.py (receive-side scrub, added to NON_EGRESS_REDACTION_MODULES) and dashboard/handlers_instances_peer.py (the "Peer live-session list" sink).
  • Before -> after (what was allowed/blocked, now): the same redaction calls run on the same data in the same order; only the module path each registry row names changes, so every sink is still classified and nothing new is allowed or blocked.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a moved redactor site left unregistered would fail the posture drift guard in CI; no runtime behaviour depends on these rows.
  • Evidence checked (which sandbox result proves it): no sandbox path changed; mutation proofs turn test_security_posture.py red when either row is removed or pointed back at the old file, and the census row is red when the moved log_api_access(origin=...) line loses origin=.
  • Tools still work (which tools/commands were run, result): the session-transfer import/export and Instances proxy suites (test_session_transfer, test_instances, test_remote_crew_chaining, test_r6_owner_gate_regression and the guard set) pass on this head: 2,495 passed.
  • Backward compatible (old config / old data / old callers still work, how checked): yes, both modules stay as mirror facades that bind every public name they bound before, pinned by their test/campaign_facade_inventories/ files; no config or data format changes.
  • Existing tests (which suites passed on this head): test_security_posture, test_session_transfer, test_instances, test_r6_owner_gate_regression, test_transcript_derivation_seam, test_error_code_contract, test_campaign_facades_base_public_names and test_mirrored_owner_storage all passed.
  • How to undo: revert this single commit; the registries and the moved code return together.

@bolichen97
bolichen97 force-pushed the refactor/linecap-s09-session-transfer branch from b0da9b2 to 7c89656 Compare October 16, 2026 12:07
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased onto main to clear the docs/feature-map/README.md conflict with #21054. The four peer-owner row edits were re-applied on main's rows, and the range-diff differs only in context. The same commit corrects one citation in that file: in the Project AWS profile row, the match and spawn injection now names session_allocation.py and session_allocation_parts/, where #21032 moved it. The Windows shard 2 red on the previous head was test_campaign_facades_base_public_names (WinError 206), which #21062 fixed on main; that fix is in this base. CI is 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 merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Oct 16, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • verified: session_transfer_install.py has no outbound path

The owner makes no client calls: no ClientSession, proxy, fetch or peer send. Everything it writes stays local: the slot, its transcript prefix, the durable save and the audit line.
Its only bytes off the host are the HTTP reply to the import request that delivered the bundle. That reply carries ok, the slot key, the marked title (scrubbed on arrival by redact_exfiltration_urls and redact_credentials), a message count and resume_mode. It goes back to the sender, which already holds that session. The code is unchanged from BASE.
The outbound halves stay in session_transfer.py, which is still the registered "Session transfer bundle" sink: build_source_record and _assemble_bundle (what a bundle carries), plus the send path in the instances facade.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • verified: no egress path moved into session_transfer_install.py

The owner holds only the receive side of POST /api/chat/slots/import: _validate_bundle, _install_arrived_bundle and its helpers. It opens no outbound connection and sends no bundle, and every redactor call in it scrubs arrived data: the title, the origin label, and the rows in the off-loop _build_redacted_rows pass.
Every egress scrub stays in session_transfer.py: build_source_record (redact_exfiltration_urls, redact_credentials, redact_local_paths) and _assemble_bundle. That module stays the registered "Session transfer bundle" sink.
test_security_posture pins the classification: removing the non-egress row turns its omission scan red.

@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 16, 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 7c89656.

The move itself looks sound. I parsed both originals at the merge base and all eight head modules without running them: all 105 function and method bodies are AST-identical. The module-level changes are only facade glue: the mirror install, literal logger names equal to the old name, and module pins on the seven exception classes. The AI lanes have no findings, and the install-owner egress question is answered with evidence.

One thing to fix: Not a goal and Tests say test_import_never_reads_the_whole_body_into_memory is vacuous at BASE and that a follow-up was filed, but no issue is linked and I could not find one (test_session_transfer.py#L3769). Please open one issue for it, or fix it here, and link it in the description.

This PR also changes src/kiro_crew/security_posture.py and moves the Instances owner gate, peer proxy and inbound redaction code, so a human reviewer needs to sign off after that.

— crew-pr-reviewer (r107)

@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 16, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • verified: the import route's answers carry no arrived message content

Each of the import route's answers goes only to the caller of POST /api/chat/slots/import, which is the instance that sent the bundle. Success returns ok, the new slot key, the marked title (the arrived title after redact_exfiltration_urls and redact_credentials), the message count and resume_mode. The 409 and 429 answers carry fixed text and a code. The structural 400s from _validate_bundle name a message index, and at most echo the sender's own bundle_version or a rejected role value. No message content, transcript row or Layer B event appears in any response.
These bodies moved verbatim: the move audit reports every unit unchanged, so the answers are byte-for-byte BASE behaviour. Classing the module non-egress records that it holds the receive-side scrub. What leaves the host in a bundle is still assembled and redacted in session_transfer.py, the registered "Session transfer bundle" sink.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • verified: no egress path moved into session_transfer_install.py

The owner holds only the receive side of POST /api/chat/slots/import: _validate_bundle, _install_arrived_bundle and its helpers. It opens no outbound connection and sends no bundle, and every redactor call in it scrubs arrived data: the title, the origin label, and the rows in the off-loop _build_redacted_rows pass.
Every egress scrub stays in session_transfer.py: build_source_record (redact_exfiltration_urls, redact_credentials, redact_local_paths) and _assemble_bundle. That module stays the registered "Session transfer bundle" sink.
test_security_posture pins the classification: removing the non-egress row turns its omission scan red.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Oct 18, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 5090fba
  • What rule changed: no rule changed; security_posture.py registries re-key two redactor call sites to the files the code moved to, dashboard/session_transfer_install.py (receive-side scrub, added to NON_EGRESS_REDACTION_MODULES) and dashboard/handlers_instances_peer.py (the "Peer live-session list" sink).
  • Before -> after (what was allowed/blocked, now): the same redaction calls run on the same data in the same order; only the module path each registry row names changes, so every sink is still classified and nothing new is allowed or blocked.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a moved redactor site left unregistered would fail the posture drift guard in CI; no runtime behaviour depends on these rows.
  • Evidence checked (which sandbox result proves it): no sandbox path changed; mutation proofs turn test_security_posture.py red when either row is removed or pointed back at the old file, and the census row is red when the moved log_api_access(origin=...) line loses origin=.
  • Tools still work (which tools/commands were run, result): the session-transfer import/export and Instances proxy suites (test_session_transfer, test_instances, test_remote_crew_chaining, test_r6_owner_gate_regression and the guard set) pass on this head: 2,689 passed.
  • Backward compatible (old config / old data / old callers still work, how checked): yes, both modules stay as mirror facades that bind every public name they bound before, pinned by their test/campaign_facade_inventories/ files; no config or data format changes.
  • Existing tests (which suites passed on this head): test_security_posture, test_session_transfer, test_instances, test_r6_owner_gate_regression, test_transcript_derivation_seam, test_error_code_contract, test_campaign_facades_base_public_names and test_mirrored_owner_storage all passed.
  • How to undo: revert this single commit; the registries and the moved code return together.

@bolichen97

Copy link
Copy Markdown
Contributor Author

@iamwhatever this is another rebase with no content change: the PR conflicted with main's docs/feature-map/README.md rows again. This head is 819a885 rebased onto main a82fcba. Main's rows are kept, and this PR's five row edits are re-applied on them. The eight code files are byte-identical, and the range-diff shows only context lines. Re-requesting your review.

@bolichen97
bolichen97 force-pushed the refactor/linecap-s09-session-transfer branch from 819a885 to 5090fba Compare October 18, 2026 14:45
@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: passed Eligible automated validation passed for the current revision labels Oct 18, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • verified: session_transfer_install.py has no outbound path

The owner makes no client calls: no ClientSession, proxy, fetch or peer send. Everything it writes stays local: the slot, its transcript prefix, the durable save and the audit line.
Its only bytes off the host are the HTTP reply to the import request that delivered the bundle. That reply carries ok, the slot key, the marked title (scrubbed on arrival by redact_exfiltration_urls and redact_credentials), a message count and resume_mode. It goes back to the sender, which already holds that session. The code is unchanged from BASE.
The outbound halves stay in session_transfer.py, which is still the registered "Session transfer bundle" sink: build_source_record and _assemble_bundle (what a bundle carries), plus the send path in the instances facade.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • verified: the import route's replies carry no peer text beyond what the sender itself sent

session_transfer_install.py's web.json_response replies go only to the caller of POST /api/chat/slots/import, the instance that sent the bundle. Success returns the new slot key, the marked title (the arrived title after redact_exfiltration_urls and redact_credentials), a message count and resume_mode. The 409 and 429 replies are fixed text plus a code.
The structural 400s from _validate_bundle name a message index and may echo, unredacted, the sender's own bundle_version or a rejected role value. That is the requester's own field, returned to the requester; no message content, transcript row or Layer B event is ever echoed. These bodies moved verbatim (the move audit reports every unit unchanged), so they behave exactly as at BASE.
Every outbound scrub of a bundle stays in session_transfer.py: build_source_record and _assemble_bundle. That module remains the registered "Session transfer bundle" sink, and test_security_posture turns red if the non-egress row is removed.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention labels Oct 18, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 2f7103d
  • What rule changed: no rule changed; security_posture.py registries re-key two redactor call sites to the files the code moved to, dashboard/session_transfer_install.py (receive-side scrub, added to NON_EGRESS_REDACTION_MODULES) and dashboard/handlers_instances_peer.py (the "Peer live-session list" sink).
  • Before -> after (what was allowed/blocked, now): the same redaction calls run on the same data in the same order; only the module path each registry row names changes, so every sink is still classified and nothing new is allowed or blocked.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a moved redactor site left unregistered would fail the posture drift guard in CI; no runtime behaviour depends on these rows.
  • Evidence checked (which sandbox result proves it): no sandbox path changed; mutation proofs turn test_security_posture.py red when either row is removed or pointed back at the old file, and the census row is red when the moved log_api_access(origin=...) line loses origin=.
  • Tools still work (which tools/commands were run, result): the session-transfer import/export and Instances proxy suites (test_session_transfer, test_instances, test_remote_crew_chaining, test_r6_owner_gate_regression and the guard set) pass on this head: 2,615 passed.
  • Backward compatible (old config / old data / old callers still work, how checked): yes, both modules stay as mirror facades that bind every public name they bound before, pinned by their test/campaign_facade_inventories/ files; no config or data format changes.
  • Existing tests (which suites passed on this head): test_security_posture, test_session_transfer, test_instances, test_r6_owner_gate_regression, test_transcript_derivation_seam, test_error_code_contract, test_campaign_facades_base_public_names and test_mirrored_owner_storage all passed.
  • How to undo: revert this single commit; the registries and the moved code return together.

@bolichen97
bolichen97 force-pushed the refactor/linecap-s09-session-transfer branch from 5090fba to 2f7103d Compare October 18, 2026 20:53
@bolichen97

Copy link
Copy Markdown
Contributor Author

@iamwhatever this is another rebase with no content change: the PR conflicted with main's docs/feature-map/README.md rows again. This head is 5090fba rebased onto main 2afaa8e, with main's rows kept and this PR's five row edits re-applied on them. The eight code files are byte-identical, and the range-diff shows only context lines. Re-requesting your review.

@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 18, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 13d5a1b
  • What rule changed: no rule changed; security_posture.py registries re-key two redactor call sites to the files the code moved to, dashboard/session_transfer_install.py (receive-side scrub, added to NON_EGRESS_REDACTION_MODULES) and dashboard/handlers_instances_peer.py (the "Peer live-session list" sink).
  • Before -> after (what was allowed/blocked, now): the same redaction calls run on the same data in the same order; only the module path each registry row names changes, so every sink is still classified and nothing new is allowed or blocked.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a moved redactor site left unregistered would fail the posture drift guard in CI; no runtime behaviour depends on these rows.
  • Evidence checked (which sandbox result proves it): no sandbox path changed; mutation proofs turn test_security_posture.py red when either row is removed or pointed back at the old file, and the census row is red when the moved log_api_access(origin=...) line loses origin=.
  • Tools still work (which tools/commands were run, result): the session-transfer import/export and Instances proxy suites (test_session_transfer, test_instances, test_remote_crew_chaining, test_r6_owner_gate_regression and the guard set) pass on this head: 2,620 passed.
  • Backward compatible (old config / old data / old callers still work, how checked): yes, both modules stay as mirror facades that bind every public name they bound before, pinned by their test/campaign_facade_inventories/ files; no config or data format changes.
  • Existing tests (which suites passed on this head): test_security_posture, test_session_transfer, test_instances, test_r6_owner_gate_regression, test_transcript_derivation_seam, test_error_code_contract, test_campaign_facades_base_public_names and test_mirrored_owner_storage all passed.
  • How to undo: revert this single commit; the registries and the moved code return together.

@bolichen97

Copy link
Copy Markdown
Contributor Author

@iamwhatever this is another rebase with no content change: the PR conflicted with main's docs/feature-map/README.md rows after the App.tsx split (#21953). This head is 2f7103d rebased onto main 1709685, with main's rows kept and this PR's five row edits re-applied on them. The eight code files are byte-identical, and the range-diff shows only context lines. Re-requesting your review.

session_transfer.py (3,095 lines) and handlers_instances.py (2,868)
were over the 2,000-line cap. Whole top-level definitions move,
verbatim, into sibling owner modules; each original path stays the
import path and the patch surface as a _facade_mirror facade, so a
monkeypatch or mock.patch through it still reaches every owner that
reads the name.

session_transfer.py keeps the sending side's bundle assembly, where
the outbound redaction runs. Its owners: session_transfer_staging
(bundle format, staging dirs, bundle files), session_transfer_layers
(Layer A and B reads, Layer B writes on arrival),
session_transfer_intake (admitting and parsing an arriving body) and
session_transfer_install (validating and installing it).

handlers_instances.py keeps the registry, connection, remote-update,
search and send routes. Its owners: handlers_instances_gate (owner
gate, audit, registry access, chain policy) and handlers_instances_peer
(the routes that read a peer, and the proxy to it).

Path-keyed rows follow the code: the receive-side scrub is listed as
non-egress, the peer live-session sink names the peer owner, the
baseline-redactor census, error-code rows and line-cap rows move, and
the instances spec and feature map name the owners. Source-reading
tests that scanned one file now scan the facade and its owners.

Part of #20192
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 4c70200
  • What rule changed: no rule changed; security_posture.py registries re-key two redactor call sites to the files the code moved to, dashboard/session_transfer_install.py (receive-side scrub, added to NON_EGRESS_REDACTION_MODULES) and dashboard/handlers_instances_peer.py (the "Peer live-session list" sink).
  • Before -> after (what was allowed/blocked, now): the same redaction calls run on the same data in the same order; only the module path each registry row names changes, so every sink is still classified and nothing new is allowed or blocked.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a moved redactor site left unregistered would fail the posture drift guard in CI; no runtime behaviour depends on these rows.
  • Evidence checked (which sandbox result proves it): no sandbox path changed; mutation proofs turn test_security_posture.py red when either row is removed or pointed back at the old file, and the census row is red when the moved log_api_access(origin=...) line loses origin=.
  • Tools still work (which tools/commands were run, result): the session-transfer import/export and Instances proxy suites (test_session_transfer, test_instances, test_remote_crew_chaining, test_r6_owner_gate_regression and the guard set) pass on this head: 2,649 passed.
  • Backward compatible (old config / old data / old callers still work, how checked): yes, both modules stay as mirror facades that bind every public name they bound before, pinned by their test/campaign_facade_inventories/ files; no config or data format changes.
  • Existing tests (which suites passed on this head): test_security_posture, test_session_transfer, test_instances, test_r6_owner_gate_regression, test_transcript_derivation_seam, test_error_code_contract, test_campaign_facades_base_public_names and test_mirrored_owner_storage all passed.
  • How to undo: revert this single commit; the registries and the moved code return together.

@bolichen97

Copy link
Copy Markdown
Contributor Author

@iamwhatever this is another rebase with no content change: the PR conflicted with main's docs/feature-map/README.md rows after #21918. This head is 13d5a1b rebased onto main 518b36d, with main's rows kept and this PR's five row edits re-applied on them. The eight code files are byte-identical, and the range-diff shows only context lines. Re-requesting your review.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • verified: the receive side stays under the census and the omission scan; no surface was hidden

At BASE, session_transfer.py held both halves under the one "Session transfer bundle" sink. Two guards that do not depend on that sink still cover the receive half.
First, the omission scan in test_security_posture requires every module that calls a redactor to be either a registered sink or a NON_EGRESS_REDACTION_MODULES row. Dropping the new row turns it red, so the install owner cannot go unclassified. Second, _BASELINE_LOG_SITE_CENSUS counts its log_api_access(origin=...) site, re-keyed to dashboard/session_transfer_install.py: 1; removing origin= turns it red.
The receive side has no egress of its own: its only answers go back to the sender of the import request. The sink keeps covering everything a bundle carries off the host (build_source_record, _assemble_bundle).

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • fixed (evidence): move audit re-run against this head's base 518b36d

move_audit.py --repo . --base 518b36d104 --head 4c70200e6f: session_transfer.py 3098 -> 739 lines, 97/97 units moved, 0 changed. handlers_instances.py 2871 -> 1527 lines, 68/68 units moved, 0 changed. Both are 100.0%, the same as at every earlier base.
The rebases since 27ab938 changed no moved unit. Each was checked before its push: the eight code files are byte-identical across every rebase, and the -U0 patch is identical on every non-row file. The description's Move audit line will name the current base at the next push. Editing it now would restart every lane and reset readiness for a one-hash change.

@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.

Approve at 4c70200.

The split is a faithful move. I parsed the merge-base session_transfer.py and handlers_instances.py and the eight head modules without running them: 160 of 161 top-level units are AST-identical, and every name a moved unit reads resolves in its owner to the same import as at the base. The one changed unit is logger, which each owner binds by the original module's literal name, so log names do not change.

The security_posture.py edits only follow the moved code. The Peer live-session list sink now names handlers_instances_peer.py, where that route and its redactor calls now live. The new NON_EGRESS_REDACTION_MODULES row classifies the receive-side owner, while the outbound Session transfer bundle sink stays on session_transfer.py. No row is dropped and no redactor call changed.

The vacuous body-buffering guard is tracked in #21314, which describes the fix. All AI lanes are clean or answered on this head, and every check is green.

Reviewed head: 4c70200

— crew-pr-reviewer (r111)

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