Repository navigation
🤖 refactor: move the abort settle into turn-engine AttemptLoop - #7478
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
c898e4e to
bed4f29
Compare
bed4f29 to
2d74900
Compare
|
@codex review |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
🟢 e2e stories (Haiku): 14 passed27 agent steps · 7 replayed from cache · 31 model calls · 214.5k tokens (75% cached) All 14 tests in 9 files
e2e 0.20.0 · 2m 51s · web · run artifacts 🟢 e2e Electron stories (Haiku): 3 passed3 agent steps · 3 model calls · 8.0k tokens (32% cached) All 3 tests in 3 files
e2e 0.20.0 · 20.0s · electron · run artifacts 🟢 e2e agent repros (Haiku): no tests selectedSpend: $0.00 of the $1.00 cap (proxy ledger) e2e 0.20.0 · 5.3s · 2 targets (web, phone) · run artifacts |
2d74900 to
5b4d9c6
Compare
Layer 5 slice 7, step 2 of 2. StreamManager no longer owns the abort settle that TurnRegistry runs after a hard or soft stop. This commit moves cleanupAbortedStream and its parts, unchanged, into turnEngine/AttemptLoop.ts. Why AttemptLoop: its module comment already says it settles every terminal outcome, and it holds the other two (completeStream for stream-end, persistStreamError for errors). The abort settle runs the same steps on the same state: usage, the reasoning backfill, the session usage settle, the partial, the terminal event, unregistering, then terminalCompletion and the completion settle. Its lost-race guard (terminalCompletion already set) is a contract with those two paths and with settleStreamProcessing, and now all of them live in one file. AttemptLoop already had seven of the eight deps it needs (only the display registry is new). TurnRegistry would have needed six new deps plus a wider turnEvents Pick, type imports of TurnResources, PartialJournal and UsageLedger, and TurnResources built before it in StreamManager. Moved from streamManager.ts: - Methods cleanupAbortedStream (now public: TurnRegistry calls it), persistAbortedStreamUsage and finishAbortedStream. - Module code: AbortedStreamUsage, buildStreamAbortEvent and abortedPartialMetadata. Rewrites outside the moved blocks: - StreamManager wires TurnRegistry's cleanupAbortedStream dep to this.attemptLoop.cleanupAbortedStream. The forward reads the field at call time because AttemptLoop is built after TurnRegistry. TurnRegistry itself does not change, except its module comment. - AttemptLoopDeps gains toolCallDisplayRegistry (Pick "close"). Its partialJournal Pick adds awaitPending, writeAbortPartial and settleAbort, and its turnEvents Pick adds deliver. StreamManager passes its toolCallDisplayRegistry. - AttemptLoop imports hasCommitWorthyParts (historyService), StreamAbortEvent and StreamAbortReason, and the ToolCallDisplayRegistry type. streamManager.ts drops the imports only the moved code used. Lines: 262 added and 262 removed in moved blocks, 32 added and 29 removed outside them. streamManager.ts goes from 1467 to 1185 lines. AttemptLoop.ts goes from 889 to 1173 lines. No turnEngine module imports streamManager.ts. No import cycles. The test-only commit two back pins ten survivors of the unsplit function. Scratch mutations on this commit, against the streamManager, turnEngine, aiService and agentSession suites: 28 of 29 fail a test (one of them, run by hand, makes the TurnRegistry forward a no-op). Not killed: skipping partialJournal.awaitPending before the abort partial write, which is equivalent (see the test commit). Gates: make static-check, make lint-eslint and make dry-check pass. crap-check against the parent passes with coverage (0 violations, 0 warnings). Wide suite: 2774 pass, 0 fail. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
5b4d9c6 to
25df5f0
Compare
…oder#7479) Layer 5u of the turn-engine split in stack #7398 (based on coder#7478). Layer 5 slice 9, part (a): split `WorkspaceStreamInfo` into six records, each with one owner module, in the new `turnEngine/turnState.ts`. This PR enforces the owner of two records (TurnHandles, PartialJournalState). Parts 9b to 9d enforce the other three. No behavior change. ## What changed ### Commit 1: tests first (`86d9c59a43`) Test-only commit before layer 5 slice 9a moves the stream's unlinkAbortSignal from a post-construction write in TurnEngine into the stream info literal. A scratch edit that drops the write (so the stream never unlinks the caller's signal) survived the existing tests. New test in streamManager.resources.test.ts, "stream resource scope": a stream started with a caller abort signal adds one abort listener to it, and the listener is gone once the stream completes. Scratch mutation on this commit: the edit now fails the test. No production code changes. ### Commit 2: records (`f6f91257ec`) Layer 5 slice 9a, the first of four stacked steps. No behavior change. WorkspaceStreamInfo was one flat interface in types.ts. It now lives in the new turnEngine/turnState.ts and is built from six records. Each record names its owner: the one module that writes its fields after TurnEngine builds the stream info. | Record | Owner | Enforced | |---|---|---| | TurnState | StepApply | 9d | | TurnSlot | TurnRegistry | 9b | | AttemptRequest | ProviderRequest | 9c | | TurnHandles | TurnResources | this commit | | PartialJournalState | PartialJournal | this commit | | UsageLedgerState | UsageLedger | already (coder#7412) | Enforcement follows coder#7412: WorkspaceStreamInfo extends an enforced record as Readonly, so a write from another module does not compile. The owner takes `WorkspaceStreamInfo & Record`, which TypeScript lets it write. The view is shallow: it stops reassigning a field, not changing the Map or array the field holds. Changes: - turnState.ts (new): the four new records, plus PartialJournalState and UsageLedgerState moved from types.ts. Fields keep their comments. The record field lists follow the accepted plan's sketch. The 45 fields are the old WorkspaceStreamInfo's, each in exactly one record. - types.ts loses WorkspaceStreamInfo, the two state records and their imports. It stays a leaf: turnState.ts imports it, not the reverse. - Callers import WorkspaceStreamInfo (and the two state records) from turnState.ts. PartialJournal and UsageLedger still re-export their record, and StreamManager still re-exports WorkspaceStreamInfo. - TurnHandles and PartialJournalState are now Readonly in WorkspaceStreamInfo. PartialJournal had no outside writer. TurnHandles had one: TurnEngine set unlinkAbortSignal right after createStreamAtomically returned. TurnEngine now passes it in the registration context, and createStreamInfo puts it in the literal. Nothing ran between the two points. - TurnResources.closeStreamResources takes `WorkspaceStreamInfo & TurnHandles`, since it writes resourceCleanup and unlinkAbortSignal. The parent commit pins the unlink: a scratch edit that drops unlinkAbortSignal from the literal now fails its test. Lines: turnState.ts is 227 lines, and types.ts goes from 540 to 365 lines. No import cycles. Gates: make static-check, make lint-eslint and make dry-check pass. crap-check against the parent passes with coverage (0 violations, 0 warnings). Wide suite: 2775 pass, 0 fail. ## Validation - The test in commit 1 passes on the parent `103b8b86ea` and kills a scratch mutant that survived there (dropped `unlinkAbortSignal` call). - 1031 targeted tests pass here (streamManager*, aiService, turnEngine, continuousCompactor, turnRequestBuilder, coreServicesRoot, serviceContainer, errorRecovery), and `make typecheck` passes. The builder's wider run passed 2775 of 2775. - `make static-check`, `make lint-eslint`, `make dry-check` and the CRAP check (with coverage, 0 violations and 0 warnings) pass with the parent as the base. No import cycle exists, and `types.ts` stays a leaf. ## Risks Low. Type-level change: each record is declared once and `WorkspaceStreamInfo` extends the enforced ones as `Readonly`, so an outside write fails to compile. The read-only view is shallow (Map and array contents stay mutable). The one runtime change passes `unlinkAbortSignal` in the registration context instead of assigning it right after `createStreamAtomically` returns. Nothing ran between those two points. --- _Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high` • Cost: `$77.40`_ <!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high costs=77.40 -->
Layer 5t of the turn-engine split in stack #7398 (based on #7477). Layer 5 slice 7, part (b): move the abort settle into
turnEngine/AttemptLoop.ts, next to the stream-end and error settles. No behavior change.What changed
Layer 5 slice 7, step 2 of 2. StreamManager no longer owns the abort
settle that TurnRegistry runs after a hard or soft stop. This commit
moves cleanupAbortedStream and its parts, unchanged, into
turnEngine/AttemptLoop.ts.
Why AttemptLoop: its module comment already says it settles every
terminal outcome, and it holds the other two (completeStream for
stream-end, persistStreamError for errors). The abort settle runs the
same steps on the same state: usage, the reasoning backfill, the session
usage settle, the partial, the terminal event, unregistering, then
terminalCompletion and the completion settle. Its lost-race guard
(terminalCompletion already set) is a contract with those two paths and
with settleStreamProcessing, and now all of them live in one file.
AttemptLoop already had seven of the eight deps it needs (only the
display registry is new). TurnRegistry would have needed six new deps
plus a wider turnEvents Pick, type imports of TurnResources,
PartialJournal and UsageLedger, and TurnResources built before it in
StreamManager.
Moved from streamManager.ts:
persistAbortedStreamUsage and finishAbortedStream.
abortedPartialMetadata.
Rewrites outside the moved blocks:
this.attemptLoop.cleanupAbortedStream. The forward reads the field at
call time because AttemptLoop is built after TurnRegistry. TurnRegistry
itself does not change, except its module comment.
partialJournal Pick adds awaitPending, writeAbortPartial and
settleAbort, and its turnEvents Pick adds deliver. StreamManager passes
its toolCallDisplayRegistry.
StreamAbortEvent and StreamAbortReason, and the ToolCallDisplayRegistry
type. streamManager.ts drops the imports only the moved code used.
Lines: 262 added and 262 removed in moved blocks, 32 added and 29
removed outside them. streamManager.ts goes from 1467 to 1185 lines.
AttemptLoop.ts goes from 889 to 1173 lines. No turnEngine module imports
streamManager.ts. No import cycles.
The test-only commit two back pins ten survivors of the unsplit
function. Scratch mutations on this commit, against the streamManager,
turnEngine, aiService and agentSession suites: 28 of 29
fail a test (one of them, run by hand, makes the TurnRegistry forward a
no-op). Not killed: skipping partialJournal.awaitPending before the
abort partial write, which is equivalent (see the test commit).
Gates: make static-check, make lint-eslint and make dry-check pass.
crap-check against the parent passes with coverage (0 violations, 0
warnings). Wide
suite: 2774 pass, 0 fail.
Validation
partialJournal.awaitPendingbefore the abort partial write. The loop cleanup andcloseStreamResourcesalready wait for any write in progress.make static-check,make lint-eslint,make dry-checkand the CRAP check (with coverage, 0 violations and 0 warnings) pass with the parent as the base. No file inturnEngine/importsstreamManager.ts, and no import cycle exists.Risks
Medium-low. A byte-identical move. TurnRegistry keeps its
cleanupAbortedStreamdep, and StreamManager wires it to AttemptLoop at call time, because AttemptLoop is built after TurnRegistry. A wiring mistake would show as an abort that leaves the turn unsettled (no stream-abort event, no partial commit).Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:high• Cost:$74.69