2. modularize session runtime - #2185
Conversation
Refs ENG-5938; fixes #2185
Refs ENG-5938; fixes #2185
Refs ENG-5938; fixes #2185
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit dc66f16. Configure here.
8b91b2f to
f134103
Compare
Prime Agent performance — completedPR Overall: 0 regressed · 0 improved · 17 no clear change.
Python runtime
Sandbox cost: ~$0.0926 — no inference calls. Methodology and samplesMain resolved at 2026-09-10T23:42:51.258326+00:00. Harness
|

Note
Extract session runtime components from
AgentSessioninto dedicated modulesAgentSessionstate and helpers withSessionInputScheduler,SessionInputDispatcher,SessionCommitFence,TurnPreparer,SessionRetry, andSessionBashinstances to modularize the session runtime.AgentSessiondelegates internal state management to the new modules in agent-session.ts; any out-of-tree code relying on the removed inline fields or private methods will break.Macroscope summarized f134103.
Note
High Risk
This is a large refactor of core session concurrency (input pump, commit fencing, retries, and bash ordering); regressions would affect admission, cancellation, branch navigation, and idle/passivation semantics even if behavior is intended to be unchanged.
Overview
Pulls the session turn lifecycle out of
AgentSessioninto dedicatedsession/*modules while keeping the same public APIs, event shapes, recovery format, and ordering rules.AgentSessionnow wiresSessionInputScheduler(serialized pump, epochs, admission vs queued-work pauses, abort/update-restart suspension),SessionInputDispatcher(action selection, batching, rollback/settlement against the existing action store),SessionCommitFence(FIFO commit leases and reentrancy),TurnPreparer/prepared-actions(execution policies, prepared turns/commands, recovery snapshots),SessionRetry(auto-retry, auth-stale, completion reservation), andSessionBash(user/direct shell runs, deferred transcript output). Inline implementations and types move out ofagent-session.ts;waitForPromiseOrAbortmoves toutils/wait-for-abort.ts. Recovery andTurnExecutionPolicyexports are re-exported from the session facade.The README documents ownership boundaries for scheduling, commit coordination, shell commands, retry, and turn preparation. New unit tests under
test/session/(plus scheduler usage in goal-continuation tests) cover fence ordering, bash slot/transient behavior, and related edge cases.Reviewed by Cursor Bugbot for commit f134103. Bugbot is set up for automated code reviews on this repo. Configure here.