Skip to content

🤖 refactor: move the abort settle into turn-engine AttemptLoop - #7478

Merged
ThomasK33 merged 1 commit into
mainfrom
turn-engine/abort-settle
Oct 25, 2026
Merged

ThomasK33 merged 1 commit into
mainfrom
turn-engine/abort-settle

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

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:

  • 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.

Validation

  • 1030 targeted tests pass here (streamManager*, aiService, turnEngine, continuousCompactor, turnRequestBuilder, coreServicesRoot, serviceContainer, errorRecovery). The builder's wider run passed 2774 of 2774.
  • Scratch mutants on the moved code: 27 of 28 fail a test. A no-op TurnRegistry forward also fails a test. Not killed: dropping partialJournal.awaitPending before the abort partial write. The loop cleanup and closeStreamResources already wait for any write in progress.
  • 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 file in turnEngine/ imports streamManager.ts, and no import cycle exists.

Risks

Medium-low. A byte-identical move. TurnRegistry keeps its cleanupAbortedStream dep, 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

@ThomasK33
ThomasK33 added this pull request to stack #7398 October 25, 2026 11:44
@ThomasK33 ThomasK33 changed the title turn engine/abort settle 🤖 refactor: move the abort settle into turn-engine AttemptLoop Oct 25, 2026
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T20:56:16.913619Z 25df5f0 New commits
🔒 Security Review ✅ Completed 2026-10-25T20:57:15.301939Z 25df5f0 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 103b8b86ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 103b8b86ea

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 force-pushed the turn-engine/abort-settle branch 2 times, most recently from c898e4e to bed4f29 Compare October 25, 2026 15:07
@ThomasK33
ThomasK33 force-pushed the turn-engine/abort-settle branch from bed4f29 to 2d74900 Compare October 25, 2026 17:13
@ThomasK33
ThomasK33 removed this pull request from stack #7398 October 25, 2026 17:13
@ThomasK33
ThomasK33 added this pull request to stack #7501 October 25, 2026 17:14
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 2d74900931

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 2d74900931

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 2d74900931

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 marked this pull request as ready for review October 25, 2026 18:03
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

27 agent steps · 7 replayed from cache · 31 model calls · 214.5k tokens (75% cached)
Spend: $0.09 of the $1.00 cap (proxy ledger)

All 14 tests in 9 files
Test Agent Time
🟢 chatRestart.e2e.ts · 1 passed 2 steps · 4 calls 24.3s
🟢 a chat survives a restart of the server 2 steps · 4 calls 24.3s
🟢 compaction.e2e.ts · 1 passed 3 steps · 7 calls 44.4s
🟢 /compact replaces the old chat with a summary 3 steps · 7 calls 44.4s
🟢 pluginTrustRestart.e2e.ts · 1 passed 4 steps · 2 calls 13.3s
🟢 a trusted plugin hook stays trusted after the server restarts 4 steps · 2 calls 13.3s
🟢 settingsRoundTrip.e2e.ts · 1 passed 3 steps · 4 calls 28.6s
🟢 a chat survives trips through Settings 3 steps · 4 calls 28.6s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 4.2s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 4.2s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 2.5s
🟢 the agent opens the playground workspace 2 steps · 1 call 2.5s
🟢 streamErrors.e2e.ts · 1 passed 1 step · 1 call 7.1s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 7.1s
🟢 todoNudge.e2e.ts · 1 passed 2 steps · 5 calls 23.3s
🟢 the agent finishes open TODO items after the turn-end nudge 2 steps · 5 calls 23.3s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 20.4s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 3.5s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 3.9s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.6s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 3.0s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 2.8s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 2.7s

e2e 0.20.0 · 2m 51s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 8.0k tokens (32% cached)
Spend: $0.01 of the $1.00 cap (proxy ledger)

All 3 tests in 3 files
Test Agent Time
🟢 electron/deepLink.e2e.ts · 1 passed 1 step · 1 call 5.2s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 5.2s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 6.8s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 6.8s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 5.9s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 5.9s

e2e 0.20.0 · 20.0s · electron · run artifacts

🟢 e2e agent repros (Haiku): no tests selected

Spend: $0.00 of the $1.00 cap (proxy ledger)

e2e 0.20.0 · 5.3s · 2 targets (web, phone) · run artifacts

@ThomasK33
ThomasK33 force-pushed the turn-engine/abort-settle branch from 2d74900 to 5b4d9c6 Compare October 25, 2026 19:45
@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 25, 2026
Base automatically changed from turn-engine/abort-settle-split to main October 25, 2026 20:54
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`_
@ThomasK33
ThomasK33 force-pushed the turn-engine/abort-settle branch from 5b4d9c6 to 25df5f0 Compare October 25, 2026 20:54
@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 25, 2026
@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 25, 2026
@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 25, 2026
Merged via the queue into main with commit d123d8b Oct 25, 2026
33 of 34 checks passed
@ThomasK33
ThomasK33 deleted the turn-engine/abort-settle branch October 25, 2026 22:12
yermakoffivan pushed a commit to yermakoffivan/mux that referenced this pull request Oct 26, 2026
…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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant