refactor(runtime): extract session branching into session-branch.ts - #1253
Conversation
Pure move from session-manager.ts (apache#1084, runtime/other lane): - createBranchSession, cloneBranchRuntimeLedger, the turn-boundary message copy helpers, and the run/event clone helpers now live in session-branch.ts behind a minimal SessionBranchDeps seam. - createBranchSession returns the child SessionHeader; SessionManager wraps it with headerToSummary, so the new leaf never imports back into session-manager.ts. - headerLineage is now imported from agent-run-recovery.ts instead of keeping a verbatim private copy. Behavior-neutral; @maka/runtime public exports unchanged.
…nch.ts The source-grep contract asserted branchFromTurn and the sticky-model capture in one session-manager.ts read; the capture now lives in session-branch.ts. Assert each side of the seam where it lives: branchFromTurn delegates to createBranchSession, and createBranchSession carries model: header.model.
|
CI |
|
Latest CI on this PR: |
|
I think main is clear on typecheck now, we can merge main or run biome linter locally to fix it. |
Astro-Han
left a comment
There was a problem hiding this comment.
No code findings. The extraction preserves the existing branching behavior. Please rebase or rerun CI before merge because the current typecheck check is red on the old formatting baseline.
|
Hi — this PR conflicts with current I tested a rebase onto current
These are real source conflicts, so they need your judgement rather than a mechanical rebase — please rebase onto current Thanks for the contribution — happy to help if any conflict is unclear. AI-assisted maintenance note, not a review. It does not count as the required human review under |
|
Thanks for testing the rebase. Before resolving the conflict I re-checked whether the extraction still stands on current What this PR moved into
So the goal of this refactor was reached on |
Part of #1084 — the
session-manager.tsslice from the runtime/other lane (claimed in #1084 (comment)).What moved
Behavior-neutral pure move of the branch-session subsystem (~250 lines) out of
session-manager.tsinto a new leaf modulepackages/runtime/src/session-branch.ts:createBranchSessionandcloneBranchRuntimeLedger, behind a minimal structuralSessionBranchDepsseam (storeis an inline structural subset of the manager-localSessionStore, following theRuntimeLedgerRepairDepsprecedent, so the leaf never imports back intosession-manager.ts).copyMessagesThroughTurnBoundary/copyMessagesBeforeTurn(exported;branchFromTurn/branchBeforeTurnstay behind as thin public methods).cloneRuntimeEventForBranch/cloneRunHeaderForBranchCreate(module-private).One deliberate seam adjustment:
createBranchSessionnow returns the childSessionHeader;SessionManagerwraps it withheaderToSummaryat the call sites, keeping the summary projection with its owner and the import direction one-way.Dedup
headerLineageinsession-manager.tswas a verbatim private copy of the one inagent-run-recovery.ts. The recovery module's copy is now exported and imported; the duplicate is deleted.Invariants (per #1084 / #363)
@maka/runtimepublic exports unchanged (index.tsuntouched).main, single slice.Verification
npm --workspace @maka/runtime run build— clean.npm --workspace @maka/runtime run test— 2269 tests, 2261 pass, 0 fail, 7 skipped, 1 cancelled. The cancelled one is the known pre-existing test(runtime): session-title deadline-abort test hangs under full-suite load on main #1222 (session-titledeadline-abort, Node v22.17.0), reproduced identically before and after this change; allbranchFromTurn/branchBeforeTurntests pass.biome checkclean on the three touched files.