Skip to content

refactor(session): compose SessionManager from session_parts owners - #21009

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/linecap-g19-session
Oct 17, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/linecap-g19-session

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Bring src/kiro_crew/session.py from 4,088 lines to 1,186 under the 2,000-line cap, with every caller, patch target and behaviour of SessionManager unchanged.

session.py held SessionManager (a 2,786-line class) plus the module helpers and constants around it. The class was already a delegating facade over session_allocation, session_lifecycle, session_cleanup, session_compaction, session_pool and session_background, but every delegation, state view and constant still lived in one file, so the file kept growing past the cap.

Why it matters

The repository rule is that no hand-written file exceeds 2,000 lines (scripts/check_file_line_cap.py). session.py was 4,088 lines with 18 commits in seven days, so every session change landed in an oversized file that reviewers and agents read in pieces.

Not a goal

  • Changing any session behaviour, ordering, lock or teardown path.
  • Splitting the existing collaborators (session_allocation.py, session_lifecycle.py, session_map.py, session_pid.py, session_storage.py, session_ledger.py); other campaign scopes own them.
  • Removing or renaming any SessionManager member, module-level name or patch target.
  • Moving ACP-layer reads out of session.py; the agent-SDK boundary keeps them there.

What changed (motivation → approach → change)

session.py is too large for one module, but tests patch its globals and the class's members in about 450 places, so the import path, patch seams and member set have to stay exactly as they are.

The split follows the binding shape acp/client.py already uses. Each member body moves verbatim into an owner module under src/kiro_crew/session_parts/ as a function whose first parameter is self: SessionManager, and the class binds it by name. A state view becomes a StateProperty (a typed property) the owner builds from the same getter and setter. Module-level helpers and constants move to three owners, and session.py imports back every name its own code reads. kiro_crew._facade_mirror keeps the patch surface whole: a patch through kiro_crew.session reaches every owner that reads the name.

Owner (session_parts/) Holds
policy limits, session-key vocabulary, compaction budget and thresholds, model fallback
provider_probes defensive provider probes, the ClaudeCodeProvider sentinel
record _Session, FirstTurnState, queued temp-file cleanup
state_views the 47 state views and the lazy state boundaries
claims registry reads, get_or_create, the ending fence, admission, queue
runtimes background, warm-pool and companion runtimes
turn_context compaction, reinjection, owed replay
links Slack, mirror and origin links
config_apply live config apply, cold-start widths
teardown reset, retire, destroy, stop, drain, close
sweeps the cleanup loop's wiring and watchdog hooks

session.py keeps the code that reads the ACP layer, because no new file may import it: __init__, _allocation_deps, _lifecycle_deps, the lazy ACP loaders and the four members that call them. It also keeps the two members that name SessionManager itself and the two listener setters whose bodies call same-named functions. The docstring's compaction and process-sweep sections move to the owners they describe. The session spec names each owner.

Backwards compatibility

Compatible: every BASE module-level name still resolves on kiro_crew.session to the same object (pinned by test/test_campaign_facades_base_public_names.py), every SessionManager member keeps its kind, coroutine-ness and signature (pinned by test/test_session_bindings.py), and monkeypatch/mock.patch through the facade reaches every owner (test/test_facade_mirror_guards.py).

Reader: src/kiro_crew/dashboard/chat_runner.py:process_shutdown_requested -- chat -- kiro_crew.session still binds it (imported back from session_parts.claims); the same object, pinned by test_campaign_facades_base_public_names
Reader: src/kiro_crew/dashboard/chat_turn/turn_marker.py:process_shutdown_requested -- chat -- reads chat_runner's re-export, which is the same object
Reader: src/kiro_crew/dashboard/handlers/mcp.py:process_shutdown_requested -- crew page -- imports it from kiro_crew.session, which binds it
Reader: src/kiro_crew/slack/events.py:unlink_queued_temp_paths -- chat -- imports it from kiro_crew.session, which binds it (imported back from session_parts.record)
Reader: src/kiro_crew/session_allocation.py:unlink_queued_temp_paths -- chat -- reached through AllocationDeps, which SessionManager._allocation_deps still builds in session.py

Tests

  • test/test_session_bindings.py (new): the frozen member inventory (287 members: kind, coroutine, signature digest, owner) and identity with each owner's object; each state view is a real property whose docstring and accessor bodies digest-equal BASE's; getattr_static and create_autospec read the class as at BASE; no bound body needs its class (super(), __class__, mangling); no owner imports the facade at run time; owners import lowest layer first; each owner's docstring names the fields it reads and writes (a self.__dict__["<f>"] key counts as field <f>); owners log under kiro_crew.session; moved classes keep kiro_crew.session as __module__; the mirror serves exactly the moved names the facade does not read; a patch through the facade reaches the owner and is undone; from kiro_crew.session import * binds BASE's 138 names. Every structural scan has a self-test. 410 cases, green in 5 shuffled-order runs at -n0 and in the -n 3 floor run.
  • Local floor: 317 test files that import or patch the session modules, plus the repo guards that scan them, at -n 3 with coverage: 22,185 passed, 2 failed. Both failures are pytest-timeout (120 s) on whole-tree scans under coverage and host load: test_app_backend_composition_contract.py::TestPatchSpellings::test_no_test_patches_a_forwarded_name_with_create_true and test_sync_io_in_async_gate.py::TestReportMode::test_report_runs_and_covers_the_baselined_files. Each passes alone (48.7 s and 36.3 s here; 45.4 s and 32.5 s on BASE). Another 182 tree-scanning test files: 12,580 passed. scripts/local-gate.py --dry-run selects 3,234 backend and 1,374 frontend files, so the floor runs instead and CI owns the full matrix.
  • Source-reading tests re-pointed or joined to the owners (assertions unchanged); each one goes red on a mutation of the construct in its new home: test_app_slot_ownership, test_reinjection_gate, test_turn_ceiling, test_decisions_compaction_hook, test_channel_transport_outbound_authz, test_pid_reader_ratchet, test_process_identity_structural, test_agent_import_hoist, test_agent_sdk_backend_identity, test_autocompact_default, test_session_provider_liveness.
  • test/campaign_facade_inventories/kiro_crew.session.json (new): kiro_crew.session's 115 BASE public names and the 100 it binds again by import, which test/test_campaign_facades_base_public_names.py checks resolve to the same objects.

Move audit

src/kiro_crew/session.py: 4103 -> 1181 lines; moved 37.99% (python-ast)

Every unit the audit lists as changed is binding re-plumbing: the member's body is the same AST, its self parameter is annotated SessionManager, and @property / @x.setter / @staticmethod give way to the class binding (x = _owner.x, StateProperty(_get_x, _set_x), staticmethod(_owner.f)). A normalized audit that applies exactly that re-plumbing finds 397 of the 399 BASE units unchanged (95.63% of lines). The two left over:

  • the module docstring: its compaction and process-sweep sections move verbatim into the session_parts.turn_context and session_parts.sweeps docstrings, and a pointer stays;
  • _companion_runtime_pids: its docstring drops a commit reference (rewords below).

Rewords on moved text, for the comment-history gate: # itself may no longer fit. → # itself may not fit.; Since the AcpRuntime unify (commit 0bf3b85a) every runtime records its → Every AcpRuntime records its; the ClaudeCodeProvider sentinel's comment says in present tense that Claude Code is driven through the ACP adapter.

Logger: every owner logs on logging.getLogger("kiro_crew.session"), the original module's logger, because about 40 caplog sites filter on that name. The moved classes _Session, FirstTurnState, _CompactCallback and _RecycleCallback keep __module__ == "kiro_crew.session".

Layout: an owner package, src/kiro_crew/session_parts/ (it has an __init__.py). The cross-platform added-line scan finds no POSIX-only primitive on the moved lines.

L36: git's default diff and --minimal add the same lines in all 53 changed files, src/kiro_crew/session.py included (473 and 473). The facade's class body lists the binding block and the two kept listener setters (set_unbind_listener, set_bind_listener, bodies unchanged) between _lifecycle_deps and __init__, and imports the mirror as import kiro_crew._facade_mirror as _facade_mirror: with main's session.py above 4,096 lines git's default diff otherwise re-shows the head of the kept __init__, and this layout is the one a measured search of 248 variants found that keeps both diffs equal (re-measured on every rebase).

Non-move position edits (L36), all in session.py's glue, bodies unchanged: the two kept listener setters set_unbind_listener and set_bind_listener sit before __init__ instead of at the end of the class, the binding block follows _lifecycle_deps, and one blank line in the mirror tail is gone. Why: git's xdiff marks a line as multi-matching once it occurs more often than a limit that doubles from 64 to 128 when the older file passes 4,096 lines; main's session.py is now 4,103 lines, so its blank lines enter the comparison and the default diff otherwise mis-pairs the head of __init__.

Source pins and citations

Re-pointed or joined, assertions unchanged, each proven by a mutation of the construct in its new home that turns the test red:

Test Change
test/test_app_slot_ownership.py reads session_parts/turn_context.py (2 sites)
test/test_reinjection_gate.py _IMPLEMENTERS names session_parts/turn_context.py
test/test_turn_ceiling.py EXEMPT key session_parts/claims.py
test/test_decisions_compaction_hook.py allowlist row session_parts/turn_context.py
test/test_channel_transport_outbound_authz.py passthrough site ("session_parts/links.py", "set_mirror_link")
test/test_pid_reader_ratchet.py session.py row split into session_parts/claims.py + session_parts/provider_probes.py (total 144 unchanged)
test/test_process_identity_structural.py the owners join REAPER_MODULES; the pid-collection allowlist key is session_parts/runtimes.py
test/test_agent_import_hoist.py the owners join _HOISTED_FILES
test/test_agent_sdk_backend_identity.py, test/test_autocompact_default.py, test/test_session_provider_liveness.py read the facade joined with every owner

Prose citations corrected (path or symbol only): src/kiro_crew/session_pid.py (2), session_cleanup.py (2), session_token_sig.py, pycache_gc.py, sandbox_argv.py (the cleanup_stale_sandbox_profiles docstring), and the root conftest.py docstring of _isolate_sandbox_mount_source_roots; and in docs, session.md, slack-gateway.md, resource-protection.md, learn-cron-dashboard.md, security.md, metrics.md, heartbeat.md, session-control.md, agent-host-contract.md, tool-stall-watchdog-placement.md, seven RFCs and the RFC index. The session.py:NNN line citations among them become symbol names, and their docs-lint line-ref rows are pruned.

Baselines (own rows only, by hand): .github/file-line-cap-baseline.txt drops the session.py row, and .github/docs-lint-baseline.txt drops the ten line-ref rows of the rewritten citations.

The one cite first relayed to a live scope, sandbox_argv.py's "periodic cleanup sweep in session.py", is corrected here now that its scope has finished.

CI path references

None. No workflow path filter or explicit file list names session.py. Outside CI logic, AUTOSDE.yaml's harness-parity rule gains the path src/kiro_crew/session_parts/*.py next to src/kiro_crew/session.py.

Manual verification

N/A — a structural move with no behaviour change; the unit floor below covers it.

Related Issues

Part of #20192

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 15, 2026 23:59
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision a48fb2bf90379a479d3e98dbdc6e4f2ee302c54a 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 15, 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 a48fb2bf90379a479d3e98dbdc6e4f2ee302c54a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that test_session_bindings.py's patch-reach cases cover a name both session.py and an owner bind, since that is where a facade patch could miss.

[DESIGN-REVIEWED] a48fb2b

Description read

[DESCRIPTION-READ] e04d5c75df393bc0b05c6c83a27958991e545fd728f4caa7e8f24d6d13b3067c

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 a48fb2bf90379a479d3e98dbdc6e4f2ee302c54a — 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 that the two pytest-timeout failures in the local floor run (whole-tree scans, ~45 s each, also slow on BASE) pass on CI's matrix.

What this change ships

Inventory (8 items) — 8 justified

Intent: bring session.py under the 2,000-line cap that AGENTS.md mandates, with no change in behaviour or patch surface. This is a FIX (a refactor).

  1. session.py shrinks from 4,088 lines to 1,186, and its members move into 11 session_parts/ owner modules that the class binds by name. — justified
  2. The session.py row is removed from .github/file-line-cap-baseline.txt. — justified
  3. StateProperty is a typed property subclass that keeps SessionManager meeting the collaborator protocols under mypy. It is used for all 47 state views. — justified
  4. The facade-mirror install keeps patches made through kiro_crew.session reaching every owner. It reuses the existing kiro_crew/_facade_mirror.py. — justified
  5. test_session_bindings.py freezes the member inventory, and a new kiro_crew.session.json inventory follows the existing pattern of 50+ *_bindings and campaign_facade_inventories files. — justified
  6. The AUTOSDE agent-SDK boundary rule now also covers session_parts/*.py, so moved code stays under the rule it was under before. — justified
  7. Docstrings, specs and RFC prose now point at the new owners, and stale session.py line-refs are dropped from the docs-lint baseline. No RFC status changed. — justified
  8. Eleven source-reading tests now point at the owner modules, with their assertions unchanged. — justified

[FIRST-PRINCIPLES-REVIEWED] a48fb2b

Description read

[DESCRIPTION-READ] bdfdcb12bbd5ae9b9ea65b4ec18a40b032413a71dd2f337fa0dcbfcbafbe2c64

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.

@bolichen97
bolichen97 enabled auto-merge (squash) October 16, 2026 00:05
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] a48fb2b

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable a48fb2bf90379a479d3e98dbdc6e4f2ee302c54a: <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 a48fb2bf90379a479d3e98dbdc6e4f2ee302c54a and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a48fb2b

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

@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 16, 2026
@bolichen97
bolichen97 force-pushed the refactor/linecap-g19-session branch from d347b46 to fb37eba Compare October 16, 2026 07:15
@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Oct 16, 2026
@bolichen97
bolichen97 force-pushed the refactor/linecap-g19-session branch from fb37eba to 613d409 Compare October 16, 2026 07:44
@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
bolichen97 force-pushed the refactor/linecap-g19-session branch from 613d409 to 22c46b7 Compare October 16, 2026 08:34
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision 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 16, 2026
@bolichen97
bolichen97 force-pushed the refactor/linecap-g19-session branch from 22c46b7 to 2a4a77b Compare October 16, 2026 09:50
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 2a4a77b
  • What rule changed: no rule changed; the only sensitive file touched is src/kiro_crew/sandbox_argv.py, where one docstring line of cleanup_stale_sandbox_profiles now names session_parts/sweeps.py instead of session.py as the module that wires the periodic cleanup sweep.
  • Before -> after (what was allowed/blocked, now): nothing allowed or blocked changes; the edit is a comment-only path citation and the function's code, arguments and behaviour are byte-identical.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a reader follows the docstring to a file that no longer wires the sweep; no command, secret or user access can be affected by a docstring.
  • Evidence checked (which sandbox result proves it): git diff of sandbox_argv.py is a single docstring line; cleanup_stale_sandbox_profiles is wired at session_parts/sweeps.py in SessionManager._cleanup_deps; no sandbox run is needed for a docstring.
  • Tools still work (which tools/commands were run, result): test_sandbox_refactor_facade.py, test_sandbox_launcher_import_hoist.py and test_darwin_libc_handle_ratchet.py passed locally (542 passed) with the edited file.
  • Backward compatible (old config / old data / old callers still work, how checked): the function signature and module exports are untouched, so every caller and config works as before; checked by the facade tests above.
  • Existing tests (which suites passed on this head): CI runs the full backend matrix on this head; locally the 26-file touched set and cold mypy passed on the same tree before the rebase (range-diff identical).
  • How to undo: revert the one docstring line in src/kiro_crew/sandbox_argv.py, or revert this PR's single commit.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: this head (2a4a77baa8, on main 0ad64e6096) supersedes 22c46b73ae, which an outside tool pushed to this branch. It carries the same split, plus three path-only citation fixes that 22c46b73ae lacks:

Upstream changes to session.py since the first push, ported into their new homes:

Upstream Change New home
#20779 _Session.extra_env / reasoning_effort_override fields; SessionManager.retire_effort_override session_parts/record.py; session_parts/claims.py (bound in the claims group)
#20240 check_context_usage(..., *, defer_compaction=False) session_parts/turn_context.py

test/test_session_bindings.py's inventory gains the new member and the new signature digest. Under L52 the facade inventory now lives in test/campaign_facade_inventories/kiro_crew.session.json. Every other rebase conflict was a shared row or doc line, resolved by keeping both sides. CI is re-running.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/sandbox_argv.py

  • @bolichen97 posted a complete reasoning template for a48fb2b.

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

bolichen97 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author
  • rebutted: the bindings test already pins all 286 members

test_the_member_set_is_the_frozen_inventory asserts SessionManager's member set equals the frozen 286-row _MEMBERS table in test/test_session_bindings.py.
test_each_member_keeps_its_kind_shape_and_owner checks each member's kind, coroutine flag and signature digest, and that the class attribute IS its owner module's function.
The 47 StateProperty views are pinned against BASE's docstrings and accessor bodies; getattr_static and create_autospec read the class as at BASE.
The file runs in the backend shards CI runs on this head, and passed 5 shuffled-order local runs on the same tree.

@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

Copy link
Copy Markdown
Contributor

HOLD at 2a4a77b. This is a policy hold. I found no defect.

The move checks out. I compared session.py at the merge-base with session.py plus the 11 session_parts owners on this head. All 322 SessionManager function bodies appear unchanged (docstrings excluded). Every module-level function, class and constant is identical. The class keeps its 286 member names, and each binding names its owner's function or StateProperty by the same name. Main has not touched session.py since the merge-base. All AI lanes are PASS or report no findings, the First Principles punchline is answered, and CI is green.

Why it waits for a human: the diff edits a sandbox file (src/kiro_crew/sandbox_argv.py) and a token file (src/kiro_crew/session_token_sig.py), though both edits are docstring-only. It also moves the process-killing and teardown paths into session_parts/teardown.py, session_parts/sweeps.py and session_parts/runtimes.py, and re-points the outbound-authz guard test. A maintainer's review clears this hold. Nothing is required of the author.

— crew-pr-reviewer (r107)

@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
bolichen97 force-pushed the refactor/linecap-g19-session branch from 2a4a77b to 7684b52 Compare October 16, 2026 22:46
@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 16, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 7684b52
  • What rule changed: no rule changed; the only sensitive file touched is src/kiro_crew/sandbox_argv.py, where one docstring line of cleanup_stale_sandbox_profiles now names session_parts/sweeps.py instead of session.py as the module that wires the periodic cleanup sweep.
  • Before -> after (what was allowed/blocked, now): nothing allowed or blocked changes; the edit is a comment-only path citation and the function's code, arguments and behaviour are byte-identical.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a reader follows the docstring to a file that no longer wires the sweep; no command, secret or user access can be affected by a docstring.
  • Evidence checked (which sandbox result proves it): git diff of sandbox_argv.py is a single docstring line; cleanup_stale_sandbox_profiles is wired at session_parts/sweeps.py in SessionManager._cleanup_deps; no sandbox run is needed for a docstring.
  • Tools still work (which tools/commands were run, result): test_sandbox_refactor_facade.py, test_sandbox_launcher_import_hoist.py and test_darwin_libc_handle_ratchet.py passed locally (542 passed) with the edited file.
  • Backward compatible (old config / old data / old callers still work, how checked): the function signature and module exports are untouched, so every caller and config works as before; checked by the facade tests above.
  • Existing tests (which suites passed on this head): CI runs the full backend matrix on this head; locally the 57-file touched set (4456 passed) and cold mypy passed on the same patch before the in-slot rebase (identical -U0 patch).
  • How to undo: revert the one docstring line in src/kiro_crew/sandbox_argv.py, or revert this PR's single commit.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: this head (7684b52824, on main 140e38ba59) supersedes 2a4a77baa8. #21009 had gone CONFLICTING.

Upstream changes to session.py since the last push, ported into their new homes:

Upstream Change New home
#21215 POOL_DECISIONS gains six reasons and two comment lines session_parts/policy.py (main's block, byte-identical)
#21219 new SessionManager.replace_mirror_link_if session_parts/links.py, bound in the links group; test/test_session_bindings.py gains its inventory row

test/test_channel_transport_outbound_authz.py keeps #21219's new writer rows with this PR's session_parts/links.py re-point. session.md, metrics.md and two RFC lines keep main's text with this PR's citations.

Main's session.py is now over 4,096 lines, and at that size git's default diff starts counting blank lines when it aligns. The facade's glue is re-laid so the default diff and --minimal still add the same lines in every file (473 and 473 for session.py): the binding block and the two kept listener setters now sit before __init__, and the mirror is imported as import kiro_crew._facade_mirror as _facade_mirror. No body changed. CI is re-running.

@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
session.py was 4,103 lines, over the 2,000-line cap, and kept growing
because every SessionManager delegation, state view and constant lived
in one file. It is now a 1,181-line facade over eleven owner modules in
src/kiro_crew/session_parts/.

Each member body moves verbatim into its owner as a function whose
first parameter is self, and the class binds it by name; each state view
is a StateProperty the owner builds from the same getter and setter.
Module-level helpers and constants move to policy, provider_probes and
record. kiro_crew._facade_mirror keeps the patch surface whole: a patch
through kiro_crew.session reaches every owner that reads the name, and a
derived __all__ keeps the star-import set.

session.py keeps the code that reads the ACP layer (the agent-SDK
boundary forbids it in a new file), the two members that name
SessionManager itself and the two listener setters. Owners log on the
kiro_crew.session logger and moved classes keep that module name.

test/test_session_bindings.py pins the frozen member inventory, owner
identity, the state views against BASE, the binding constraints and the
mirror. Source-reading tests are re-pointed or joined to the owners with
their assertions unchanged; specs, RFC citations and source comments name
the new homes; the file's line-cap and docs-lint rows are pruned.

Part of #20192
@bolichen97
bolichen97 force-pushed the refactor/linecap-g19-session branch from 7684b52 to a48fb2b Compare October 16, 2026 23:36
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: a48fb2b
  • What rule changed: no rule changed; the only sensitive file touched is src/kiro_crew/sandbox_argv.py, where one docstring line of cleanup_stale_sandbox_profiles now names session_parts/sweeps.py instead of session.py as the module that wires the periodic cleanup sweep.
  • Before -> after (what was allowed/blocked, now): nothing allowed or blocked changes; the edit is a comment-only path citation and the function's code, arguments and behaviour are byte-identical.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a reader follows the docstring to a file that no longer wires the sweep; no command, secret or user access can be affected by a docstring.
  • Evidence checked (which sandbox result proves it): git diff of sandbox_argv.py is a single docstring line; cleanup_stale_sandbox_profiles is wired at session_parts/sweeps.py in SessionManager._cleanup_deps; no sandbox run is needed for a docstring.
  • Tools still work (which tools/commands were run, result): test_sandbox_refactor_facade.py, test_sandbox_launcher_import_hoist.py and test_darwin_libc_handle_ratchet.py passed locally (542 passed) with the edited file.
  • Backward compatible (old config / old data / old callers still work, how checked): the function signature and module exports are untouched, so every caller and config works as before; checked by the facade tests above.
  • Existing tests (which suites passed on this head): CI runs the full backend matrix on this head; locally the 57-file touched set (4456 passed) and cold mypy passed on the same patch before the in-slot rebase (identical -U0 patch).
  • How to undo: revert the one docstring line in src/kiro_crew/sandbox_argv.py, or revert this PR's single commit.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: this head (a48fb2bf90, on main 9fba246d0c) supersedes 7684b52824, which conflicted with #20507 on one rfc-session-address-model.md line. That line keeps main's text, and this PR's _fold_key citation is re-applied. Nothing else changed: the -U0 patch is otherwise identical, and the default diff and --minimal still agree in every file. 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
  • rebutted: the patch-reach cases already use names both the facade and an owner bind

test_a_patch_through_the_facade_lands_on_the_owner_and_is_undone in test/test_session_bindings.py patches four names that kiro_crew.session and an owner both bind: cleanup_stale_sandbox_profiles and _build_child_map (the facade's own imports, also imported by session_parts/sweeps.py), _provider_has_active_turn (defined in session_parts/provider_probes.py, imported back by the facade) and _STATELESS_PREFIXES (defined in session_parts/policy.py, imported back).
Each case asserts the owner's own global is the sentinel during the patch and the original after undo; test_a_patch_of_a_served_name_reaches_every_owner_reading_it covers a name only owners bind (_MAX_ORIGIN_LINKS).
test/test_facade_mirror_guards.py also walks every name the test corpus patches through kiro_crew.session and checks each holder binds the same object.

@bolichen97

bolichen97 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author
  • rebutted: both whole-tree scans pass in CI's matrix on this head

test/test_app_backend_composition_contract.py and test/test_sync_io_in_async_gate.py run in CI's backend shards, and all 21 Backend Tests jobs on this head (the eight Linux 3.12 and eight Windows file shards plus the IPv6, sandbox, container and lock-owner lanes) finished success, so neither scan failed or timed out there.
Locally they hit pytest-timeout only inside a coverage-traced, -n 3 floor run on a loaded shared host; alone each took 48.7 s and 36.3 s, against 45.4 s and 32.5 s on BASE.

@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 17, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved by a maintainer. The triage automation held this on a size, path, category or move-check rule only; every review lane is clean.

@bolichen97
bolichen97 merged commit c83a519 into main Oct 17, 2026
106 of 107 checks passed
@bolichen97
bolichen97 deleted the refactor/linecap-g19-session branch October 17, 2026 01:32
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 17, 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.

3 participants