Skip to content

🤖 refactor: move send admission into AttemptLedger - #7678

Merged
ThomasK33 merged 1 commit into
refactor/task-attempt-ledger-identityfrom
refactor/task-attempt-ledger-admission
Oct 27, 2026
Merged

ThomasK33 merged 1 commit into
refactor/task-attempt-ledger-identityfrom
refactor/task-attempt-ledger-admission

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Summary

Moves send admission out of TaskService into the AttemptLedger class that #7677 added. The move is move-only. taskService.ts drops from 20,972 to 20,307 lines. PR 9 of the TaskService split, on top of #7677.

Implementation

  • Fields that moved, by reference: admittedSendsByTaskId and reawakeningsInFlight. The new accessor sendsOf(taskId) returns the live set (or a shared empty set), never a copy. beginReawakening / endReawakening replace the four direct writes, and the end is still a conditional delete.
  • Methods that moved:
    • Admission: admitTaskWorkspaceTurn (with the admitSendToCurrentAttempt step from 🤖 refactor: split the five longest stop and attempt methods in TaskService #7674), createAdmittedSend and its four token steps, resolveEnqueuedSendDispatch and dischargeAdmittedSend.
    • Queries: attemptAdmissionOpen, hasPendingAdmissions, hasLiveReawakening and resolveStreamAttemptAtEvent.
    • Lineage: evaluateAttemptLineage, readUnownedSettlementProof and their module helpers.
    • Retirement: claimRetiredAttempt and tombstoneUnpublishedReservation.
  • Facades: TaskService keeps one-line facades for admitTaskWorkspaceTurn (seam), evaluateAttemptLineage, resolveStreamAttemptAtEvent, claimRetiredAttempt and tombstoneUnpublishedReservation. Tests spy on these or call them through casts.
  • Stays on TaskService:
    • captureReawakeningStopFence and reawakeningOvertakenByStop touch only stop epochs and the config, not ledger state.
    • The coordinators recordWorkspaceTurnSettled and recordWorkspaceTurnSuperseded now read the sends through sendsOf.
  • Cross-class calls: TaskStopLatch's admittedSends closure now returns this.attemptLedger.sendsOf(taskId), still through TaskService. The ledger reaches stop state and stream-end decisions through TaskService closures.
  • Import cycle: ATTEMPT_CLOSURE_SETTLE_WAIT_MS now lives in attemptLedger.ts, and taskService.ts re-exports it. Without that, the ledger would import a value from taskService.ts and create a runtime import cycle.

Validation

  • Statement order, the sync/async shape, the "add to the set last" order in createAdmittedSend, and the re-reads after awaits are unchanged.
  • attemptLedger.test.ts adds tests on fake deps. They cover:
    • send identity and ownership
    • every refusal leaving no obligation behind
    • disposal order
    • first admission wins, with the extra stopStream and the recheck
    • staleness and the dequeue gate
    • reawakening begin and end
    • the lineage re-read after the closing wait
    • the row-changed and row-unreadable refusals in readUnownedSettlementProof
    • each outcome of the claim and the tombstone
  • Three TaskService test files changed only their cast targets.
  • CRAP: every moved function scores CRAP 15 or less with coverage. The highest is claimRetiredAttempt at CC 15 with 100 % line coverage, and move relief also applies because its facade drops from 15 to 1.

Risks

Medium. Send admission decides whether a message may start a turn under a task's current attempt. A wiring mistake would refuse a valid send or let a stale send through. The attempt-admission, stale-attempt-effects and report-decision suites pass, and they changed only their cast targets.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $68.74

AttemptLedger now owns the send obligations (admittedSendsByTaskId) and the
reawakenings in flight, with the code that reads them: admission
(admitTaskWorkspaceTurn and its token callbacks), discharge, the stale and
dequeue gates, the stream-attempt lookup, lineage and unowned-settlement
proofs, and the workflow claim and tombstone. TaskService keeps same-name
facades for admitTaskWorkspaceTurn, evaluateAttemptLineage,
resolveStreamAttemptAtEvent, claimRetiredAttempt and
tombstoneUnpublishedReservation, and reads sends through sendsOf. Stop latch
and stream-end state stay with their owners and are reached through
TaskService closures. Move only: no behaviour change.

Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33
ThomasK33 added this pull request to stack #7676 October 27, 2026 12:28
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T14:29:15.571155Z 718067b Manual request
🔒 Security Review ✅ Completed 2026-10-27T14:28:21.302746Z 718067b Manual request
ℹ️ 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 Security Review · Automatically triggered

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

Reviewed commit: 718067bf3c

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.

@github-actions

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

22 agent steps · 7 replayed from cache · 15 model calls · 46.3k tokens (24% 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 1 step · 1 call 5.5s
🟢 a chat survives a restart of the server 1 step · 1 call 5.5s
🟢 compaction.e2e.ts · 1 passed 1 step · 1 call 4.5s
🟢 /compact replaces the old chat with a summary 1 step · 1 call 4.5s
🟢 pluginTrustRestart.e2e.ts · 1 passed 4 steps · 2 calls 10.3s
🟢 a trusted plugin hook stays trusted after the server restarts 4 steps · 2 calls 10.3s
🟢 settingsRoundTrip.e2e.ts · 1 passed 2 steps · 1 call 10.6s
🟢 a chat survives trips through Settings 2 steps · 1 call 10.6s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 7.9s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 7.9s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 2.9s
🟢 the agent opens the playground workspace 2 steps · 1 call 2.9s
🟢 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 1 step · 1 call 2.8s
🟢 the agent finishes open TODO items after the turn-end nudge 1 step · 1 call 2.8s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 24.9s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 3.8s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 3.8s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.3s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 3.4s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 6.7s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 3.0s

e2e 0.20.0 · 1m 19s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 7.9k tokens (22% cached)
Spend: $0.02 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 5.3s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 5.3s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 4.9s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 4.9s

e2e 0.20.0 · 17.4s · 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

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: 718067bf3c

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 718067bf3c

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

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 27, 2026
Merged via the queue into main with commit 0ce0f7b Oct 27, 2026
63 of 66 checks passed
@ThomasK33
ThomasK33 deleted the refactor/task-attempt-ledger-admission branch October 27, 2026 15:32
yermakoffivan pushed a commit to yermakoffivan/mux that referenced this pull request Oct 27, 2026
## Summary

Moves the stream-end decisions out of `TaskService` into a new plain
class, `StreamEndLedger` (`src/node/services/streamEndLedger.ts`). The
move is move-only. `taskService.ts` drops from 20,307 to 20,023 lines.
PR 10, the last PR of the TaskService stop-and-attempt split, on top of
coder#7678.

Across this stack (coder#7674, coder#7675, coder#7677, coder#7678 and this PR),
`taskService.ts` goes from 21,742 to 20,023 lines. The stop and attempt
state now lives in three owner classes: `TaskStopLatch`, `AttemptLedger`
and `StreamEndLedger`.

## Implementation

- **Fields that moved:** `streamEndDecisionsByTaskId` (readonly, because
tests read it) and `deferredTaskStreamEnds`. The inline value type of
`deferredTaskStreamEnds` is now the named interface
`TaskStreamEndDeferral`, with the same fields and comments.
- **Methods that moved, with names and statement order kept:**
`runStreamEndHandler`, `deferChildStreamEnd`,
`registerStreamEndDecision`, `findStreamEndDecision`,
`findPendingStreamEndDecision`, `resolveStreamEndDecision`,
`pruneStreamEndDecisions`, `reconcileDeferredTaskStreamEnd` and
`resolveDecisionOfReportedAttempt`.
- **Coordinators stay:** `recordWorkspaceTurnSettled` and
`recordWorkspaceTurnSuperseded` stay on TaskService. Their decision
loops become one `settleTurn` / `rebindTurn` call each, at the same
position, so the order across the three owners does not change.
- **Same-tick order:** the stream-end listener in the constructor keeps
its one-tick order (snapshot, origin, register, run).
- **Stays on TaskService:** `handleStreamEnd`, `inspectAttemptOutcome`
and `reawakenInterruptedTask`. A later plan covers these long methods.
- **Cross-class calls:** the `AttemptLedger` and `TaskStopLatch`
closures `findStreamEndDecision`, `pruneStreamEndDecisions` and
`discardStreamEndDecisions` now point at `streamEndLedger` through
TaskService. The three classes never call each other directly.
- **Facades:** none. No test spies on, patches or casts a moved method.

## Validation

- The new file `streamEndLedger.test.ts` has 21 tests on fake deps. They
cover:
  - decision identity
  - find order
  - the order of resolve, prune, stop recheck and drain
  - the prune rules
  - settle and rebind of turns
- handler outcomes (a return gives nonreport, a throw gives
indeterminate)
  - the deferral listener
  - each branch of `reconcileDeferredTaskStreamEnd`
- Three TaskService test files changed only their cast targets. Prettier
re-wrapped some of the longer lines.
- CRAP: every moved function scores CRAP 13 or less with coverage. The
highest is `reconcileDeferredTaskStreamEnd` at CC 13 with 100 % line
coverage.

## Risks

Medium-low. The stream-end decision says whether a child's last stream
ended in a report. A wiring mistake would hold or drop a report, or hold
a stop latch. The report-decision, settlement-receipt and child-goal
suites pass, and they changed only their cast targets.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high` • Cost: `$68.74`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high
costs=68.74 -->

Signed-off-by: Thomas Kosiewski <tk@coder.com>
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