6. consolidate session feature ownership - #2249
kevinjosethomas wants to merge 9 commits into
Conversation
Preserve existing public and historical module exports through explicit compatibility facades. Keep compaction, refinement, and shared context implementations with their session owners. closes #2190
Refs ENG-5934 and ENG-5938.
Prime Agent performance — completedPR Overall: 0 regressed · 0 improved · 17 no clear change.
Python runtime
Sandbox cost: ~$0.0917 — no inference calls. Methodology and samplesMain resolved at 2026-09-13T05:48:33.322113+00:00. Harness
|
|
Macroscope skipped reviewing this pull request. Per-review cost limit exceeded (workspace setting). This review would cost an estimated $50.56, which exceeds your per-review limit of $10.00. The top 3 files driving up this estimate:
Tip To get this pull request reviewed, you can:
|
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 c7b0f53. Configure here.
Remove only the pull-request base branch filter while preserving the contributor gate and existing jobs. Refs ENG-5934; closes #2249.
|
Hi — downstream line here (we run a fork with ~100 reliability commits on your 0.9.x; full context in Discussion #2239). We've been studying this refactor stack in detail because our fixes will need re-homing once it lands. The stack's shape is genuinely helpful for that. Four seams would make the re-home purely additive on our side, if they fit your plans:
And one heads-up in return: the stack's current tip still carries the waitForIdle spin defect you fixed in #2151 — Happy to share our implementations of any of the four (each has regression tests). Thanks for doing this split — the god object needed to go. |
|
hey @Dmatut7! Sorry for the inconvenience here-- we were shipping really fast, but now I'm taking the time to clean up the codebase, especially starting with the agent-session class 😅 I'll take a look at your 4 suggestions and see if we can add to the stack or a future PR. Thanks for reaching out! and would love to hop on a call and learn about your usecases with Prime Agent if you're available :) |

Context
This continues the coding-agent cleanup stack by finishing feature ownership after the earlier session extractions. Compaction, refinement and input still had implementations split between core and session, making related behavior difficult to find and change together.
Changes
Consolidates context algorithms, refinement planning and persistence, input actions, autonomy and child request contracts under their session owners. Separates daemon residency policy from the action queue and model search/shell requests from child handling. Public exports and historical import paths remain available through explicit compatibility exports. Validation rules, autonomous argument parsing, persistence, protocol and session behavior are preserved. Adds reusable refactoring conventions and the remaining migration ledger. The CI trigger now accepts stacked PR targets with its existing contributor checks and jobs unchanged.
Validation
Full repository checks and the complete GitHub CI matrix pass at c3311d9. The combined session suite passed 343 tests. Paired Prime Sandboxes exercised installed TUI input, CLI/daemon refinement ordering, real Python execution/interrupt/snapshot/restore, SDK exports and historical declarations against the pinned base. Independent review found no actionable regression. Initial SDK-name and missing-goal-interpreter fixture failures are retained in the evidence; separate corrections passed, including the unchanged goal assertions at the final stack head. Two live-provider compaction cases remain intentionally unexecuted.
The sandbox-tested product pin is c7b0f53; c3311d9 changes only the CI trigger. All sandbox resources were deleted. Current-head Bugbot passes and its compatibility-alias thread was resolved with the required compatibility rationale. Macroscope skipped at its cost cap, no new-head CodeQL check is present, and the automated benchmark report is complete. It flags +0.14 MB compressed artifacts (+1.22%) against then-current main b53c2e9; the other 16 metrics show no clear change under the harness thresholds. This compares the cumulative stack against main, not this follow-up in isolation. No performance improvement is claimed.
ENG-5934, ENG-5938. Stacked on #2194; kernel/runtime ownership follows in #2250.
Note
Consolidate session feature ownership by moving agent-session, context, and input modules from
core/tosession/core/into dedicatedsession/subpackages, leaving compatibility forwarding modules behindestimateContextTokens,estimateTokens), usage accounting (addAssistantUsage,subtractAssistantUsage,cloneUsage), prompt admission cancellation (PromptAdmissionCancelledError), RLM host request adapters (createRlmRunHostHandler,createRlmFindModelsHostHandler), and worker residency policies (canPassivateSession,canEvictWorker)SessionInputCheckpointsnow waits on the host'sisBusyForInputPumppredicate instead of directly checking scheduler suspension, preventing CPU spinning when bash, compaction, or retry work blocks queued inputcore/paths and newsession/paths; adds a regression test for the idle-spin fixcore/still work via forwarding modules but receive deprecation-by-redirect. TheSessionInputCheckpointsbusy check is now delegated toisBusyForInputPumpon the checkpoint host — any host implementation missing this predicate will break.Macroscope summarized 17e4ccc.
Note
Medium Risk
Large import-path and ownership refactor across session input scheduling and compaction/refinement boundaries, with one targeted idle-wait behavior change; mitigated by compatibility re-exports but easy to miss host wiring for
isBusyForInputPump.Overview
This PR relocates session execution from
core/intosession/feature folders (input, autonomy, compaction, refinement, context, children) whilecore/agent-session.tsand related modules become thin re-export facades so supported import paths and public API shapes stay the same.Responsibility splits move the action queue to
session/input/action-store.ts, prepared-action contracts tosession/input/prepared-actions.ts, autonomous runtime tosession/autonomy/, and daemon worker passivation/eviction out of the queue intomodes/daemon/workers/residency-policy.ts. Compaction/refinement algorithms and shared context helpers land with their session owners instead of staying split acrosscore/.Behavior fix:
SessionInputCheckpoints.waitForIdleOrSettlementnow waits on activity when the input pump is blocked (bash, compaction, retry) viaisBusyForInputPump, instead of spinning while queued input cannot dispatch.Docs/CI: adds
docs/refactoring.mdandsource-organization-plan.md, updates architecture/source-map guidance, and drops thepull_requestbranch filter on CI so stacked PR targets still run checks.Reviewed by Cursor Bugbot for commit 17e4ccc. Bugbot is set up for automated code reviews on this repo. Configure here.