Skip to content

refactor(core): step ledger and classified settlement - #35235

Closed
kitlangton wants to merge 3 commits into
v2from
step-settlement
Closed

kitlangton wants to merge 3 commits into
v2from
step-settlement

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Implements the parked settlement refactor for the V2 runner (plan: branch settlement-ledger, PLAN.md). Follow-up to #35218 (step vocabulary) and #35227 (runner renames). Behavior-preserving: all 144 runner-adjacent tests pass with zero test-logic changes (one import path updated for the file rename).

1. refactor(core): rename LLM event publisher to step ledger

Pure rename: publish-llm-event.ts → step-ledger.ts, createLLMEventPublisher → createStepLedger, binding publisher → ledger. The object already owned the step's durable facts (assistant started, provider error, tool records, step settlement data); the name now says so.

2. refactor(core): derive continuation and held overflow from step ledger

Kills the attempt-scoped mutable evidence in attemptStep:

  • let needsContinuation (flipped inside the stream closure, read ~130 lines later) → derived ledger.hasLocalToolCalls(). Semantics preserved exactly: the ledger admits a local call at the same point the old flag was set — after the provider-executed and tools-disabled early returns.
  • let overflowFailure → ledger.holdOverflow(event) / ledger.heldOverflow(). The hold-back policy check (context overflow before any assistant output) stays at the call site; only the stash moved to the transcript owner.

The stream handler is now near-stateless: admit to ledger, spawn tool fibers.

3. refactor(core): classify step settlement once

The settlement block previously re-derived combinations of ~8 evidence booleans as it went. Now it classifies once —

Interrupted { questionDismissed } | ProviderFailed | ToolInfraFailed { cause } | Clean

— then runs flat, verdict-keyed effects. Effect ordering is load-bearing and unchanged: clear fibers before awaiting on interrupt, publish held overflow before classifying, failUnsettledTools before failAssistant, Step.Ended only on Clean, identical failure/interrupt propagation. LLM stream-failure handling stays before classification (it is evidence recording, not a settlement arm).

Reviewable decisions

  • Ledger owns evidence, not effects: failUnsettledTools / failAssistant / publishStepEnd stay in attemptStep where their ordering is visible. Deliberate boundary; could move later if the ledger grows.
  • Corner preserved during review: a tool-fiber failure alongside a provider error still settles those tools with Tool execution failed: <reason> before the orphan sweep, matching the old unconditional defect-settle order (the naive classify-once shape would have lost the defect message).
  • The hosted-calls-without-results fallback still runs for interrupted settlements with successful streams; the interrupt sweep has already settled everything, so it remains the same no-op as before.

Verification

  • 144 pass / 0 fail across session-runner, -recorded, -message, -tool-registry, -model, and run-coordinator suites (packages/core)
  • bun typecheck, prettier, oxlint clean

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