Skip to content

🤖 refactor: move attempt identity and settlement receipts into AttemptLedger - #7677

Open
ThomasK33 wants to merge 2 commits into
refactor/task-stop-latchfrom
refactor/task-attempt-ledger-identity
Open

ThomasK33 wants to merge 2 commits into
refactor/task-stop-latchfrom
refactor/task-attempt-ledger-identity

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Summary

Moves attempt identity and settlement receipts out of TaskService into a new plain class, AttemptLedger (src/node/services/attemptLedger.ts). The move is move-only. taskService.ts drops from 21,470 to 20,972 lines. PR 8 of the TaskService split, on top of #7675. PR 9 adds send admission to the same class.

Implementation

  • Fields that moved, by reference: ownedAttemptByTaskId, attemptSettlementByTaskId, attemptSettlementListenersByTaskId, resumeFailureSettlementByTaskId and currentAttemptIdByTaskId. The last one is still write-only. It moved as it is, and 🤖 refactor: remove the unread currentAttemptIdByTaskId map and an orphaned comment in TaskService #7664 tracks it.
  • Methods that moved: begin, close and settle an owned attempt; the settlement receipt decision, read and write; the no-report boundary (attemptCannotStillReport); the settlement listeners and waits (waitForAttemptSettlement, waitForAttemptClosureToSettle, runUnderEventLockBounded); publishAttemptRotation; and recheckResumeFailureSettlement.
  • Facades: TaskService keeps one-line facades for waitForAttemptSettlement (public) and for the methods tests spy on or call through casts: closeAttemptAdmission, decideSettlementReceipt, writeSettlementReceipt, beginOwnedTaskAttempt, settleOwnedTaskAttempt and notifyAttemptSettlementListeners. Inside the ledger, calls to these methods go back through the TaskService facade, so spies see every call. Each such call is one extra synchronous hop, with no new await.
  • Stays on TaskService: recordWorkspaceTurnSettled and recordWorkspaceTurnSuperseded, which coordinate three owners. Also currentTaskAttemptId, rotateAttemptForStartupRedrive, inspectAttemptOutcome and readAttemptOutcome.
  • Cross-class calls: TaskStopLatch never calls AttemptLedger directly. Both reach each other through TaskService closures.
  • Small deviations:
    • The pure one-line rowSupersedes moved to taskUtils.ts, because importing a value from taskService.ts would create a runtime import cycle.
    • AttemptSettlementEntry is now exported for import type.
    • deferChildStreamEnd now calls addAttemptSettlementListener instead of an inline copy of the same three statements.

Validation

  • The new file attemptLedger.test.ts has 43 tests on fake deps. They cover:
    • begin ordering
    • close and settle by the current owner only
    • the no-report boundary branches
    • the receipt decision closing the attempt in the same synchronous call
    • the order of the receipt writes, on a real temp dir
    • persist order (receipt, then settle)
    • the resume-failure recheck
    • wait subscribe, timeout and abort
  • Other test files changed only their cast targets.
  • CRAP: four moved functions are above CC 8. With coverage they score CRAP 14.2 (runUnderEventLockBounded), 12, 10 and 10, under the CI limit of 15.

Risks

Medium-low. This code decides whether a task attempt can still report and writes its settlement receipts. A wiring mistake would refuse or lose a report. The settlement, settlement-receipt, attempt-admission 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

…tLedger

Move the owned attempts, the closure/settlement entries, their listeners,
the failed-reawaken settlements owed and the write-only
currentAttemptIdByTaskId (#7664, moved as is) from TaskService into a plain
AttemptLedger class in attemptLedger.ts, with the methods that own them:
attempt begin/close/settle, the receipt decision and write, the no-report
boundary, rotation publication, release of reported attempts, the
closure and settlement waits and the resume-failure recheck.

TaskService builds it with call-time closures. Stop records, send
obligations and stream-end decisions stay with their owners and are reached
through those closures. beginOwnedTaskAttempt, closeAttemptAdmission,
settleOwnedTaskAttempt, decideSettlementReceipt, writeSettlementReceipt,
notifyAttemptSettlementListeners and the public waitForAttemptSettlement
stay on TaskService as one-line facades, and the ledger calls the spied
ones (and inspectAttemptOutcome) back through TaskService.
recordWorkspaceTurnSettled/Superseded and currentTaskAttemptId stay on
TaskService. rowSupersedes moves to taskUtils so both files can use it.
Tests that cast a moved field change only the cast target.

No behavior change: moved code is verbatim, statement order is kept and no
await is added.

Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33
ThomasK33 added this pull request to stack #7676 October 27, 2026 11:38
@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-27T11:44:01.785148Z 2f0833f Manual request
🔒 Security Review ✅ Completed 2026-10-27T11:45:58.178949Z 2f0833f 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.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: b54a81c964

ℹ️ 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 Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 2f0833ffce

ℹ️ 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: 2f0833ffce

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

github-actions Bot commented Oct 27, 2026 •

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.4s
🟢 a chat survives a restart of the server 1 step · 1 call 5.4s
🟢 compaction.e2e.ts · 1 passed 1 step · 1 call 4.6s
🟢 /compact replaces the old chat with a summary 1 step · 1 call 4.6s
🟢 pluginTrustRestart.e2e.ts · 1 passed 4 steps · 2 calls 9.7s
🟢 a trusted plugin hook stays trusted after the server restarts 4 steps · 2 calls 9.7s
🟢 settingsRoundTrip.e2e.ts · 1 passed 2 steps · 1 call 8.6s
🟢 a chat survives trips through Settings 2 steps · 1 call 8.6s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 4.3s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 4.3s
🟢 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 6.7s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 6.7s
🟢 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 25.9s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 4.4s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 4.0s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.5s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 3.1s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 7.2s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 2.7s

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

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 8.0k 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.3s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 5.3s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 5.6s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 5.6s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 8.2s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 8.2s

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

This branch has not been deployed

No deployments
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