Skip to content

refactor(core): advance sessions before running steps - #45358

Merged
kitlangton merged 1 commit into
v2from
advance-step
Aug 26, 2026
Merged

refactor(core): advance sessions before running steps#45358
kitlangton merged 1 commit into
v2from
advance-step

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Why

The Session runner distributes inbox scheduling across its drain loop, nested Step loop, and separate compaction/move probes. Its retry loop also carries input-promotion state even though promotion only happens before the first attempt.

What Changes

The drain now alternates between advancing the Session and executing a logical Step:

const next = yield* advanceToStep()
if (next._tag !== "Ready") return next
continuing = yield* runStep(next.context, step)

advanceToStep owns eligible control dispatch, instruction preparation, input promotion, and the first loaded context. runStep receives that context and a fixed logical step number; later attempts refresh context without delivering more input.

  • Removes runSteps, eligible, the separate pending-compaction/move helpers, and the one-use Session lookup helper.
  • Uses one control selection path instead of asking each control handler to inspect the inbox.
  • Keeps queue policy in the runner rather than exposing it on Compaction.
  • Removes 17 production lines and adds five characterization tests separately. No new scheduler service or framework.

Scheduling Contract

Situation Preserved behavior
Initial instructions unavailable Ordinary input remains pending; eligible controls can still run
Queued control at Location entry May run before a carried model continuation
Follow-up steer cancelled during preparation The Step stays steer-only; queued prompts and controls wait for proper dispatch
First Physical Attempt Uses the context prepared by advanceToStep exactly once
Retry or overflow rebuild Refreshes instructions/model/history without promoting pending input

Manual compaction delivery and start remain atomic. Its summary work remains interruptible and failure settlement stays protected. Movement returns to process-global execution to acquire the destination Location.

Scope

Core runner sequencing only. No queue/steer policy, public protocol, durable event, retry-budget, or manual-compaction interface change. Preserves the upstream background-recovery changes.

This is an alternative to #45335, not a stacked follow-up; the two approaches should not be combined. The independent interrupt/wait PR #45337 is unaffected.

Verification

# packages/core
bun run test test/session-runner.test.ts test/session-step.test.ts test/session-compaction.test.ts test/config/compaction.test.ts test/session-execution.test.ts test/session-run-coordinator.test.ts
bun run test test/session-runner.test.ts --test-name-pattern 'preflighting unavailable|Location entry before|refreshes preparation after|steer is cancelled during preparation|manual compaction|queued compaction|move|shares retry' --rerun-each 10
bun run test
bun typecheck
bun run build

# packages/sdk (isolated configuration)
bun run ../core/script/test.ts
  • Full Core suite: 2,341 passed, 16 skipped, no failures.
  • Focused runner/attempt/compaction/execution/coordinator coverage: 239 passed.
  • Repeated scheduling and recovery cases: 220 passed across ten repetitions.
  • Isolated SDK suite: 24 passed.
  • Core typecheck and build passed; workspace pre-push typecheck passed all 32 tasks.
  • Formatting, Effect simplification checks, and diff whitespace checks passed. Oxlint reported no errors and three pre-existing warnings in the test file.
  • The cancelled-steer regression test failed on the first refactor cut and passed after preserving the follow-up delivery scope. The move variant also verifies transport closure and durable movement, not merely inbox consumption.

@kitlangton
kitlangton merged commit cf347cd into v2 Aug 26, 2026
10 checks passed
@kitlangton
kitlangton deleted the advance-step branch August 26, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant