Repository navigation
FIX-2288: a task's run reports its model, harness and live token count (stacked on FIX-2145) - #4149
Conversation
…ger reads pending spend Core gains readRequestSpend and one shared conversion from a request's spend to tokens per source; HarnessRunSpend gains runId and model. The engine ledger keeps one entry per run (latest report wins) and reads its pending slice without taking it. Claude Code reports at init, per model message (once per message id) and at the end from the whole-query count; Codex at start, per turn and at the end; Cursor likewise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
The request admitted for a task writes what it has spent so far every 2 s while it changes, on the lease driver's ticker (now shared), and settles the ending's spend in one write before the task's check. The new recordSpend verb is fenced by the row's identity only and implemented on both task backings. listTasks' action rows carry a folded spend view; the model's tool leaves it out. ER-9 amended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
Documents a task's spend (task board, coding agents, worker usage, the core/orchestration/harness READMEs), adds the changeset, and adds the goal goals/shift-manager/a-task-shows-its-model-and-tokens with its seven controls. Writes a request's spend to its admitted task directly (no target seam), and fixes a narrowing error in claude-code's running-sum report. Resolves leftover merge-conflict markers in packages/codex/README.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
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. |
There was a problem hiding this comment.
Simplify review (FIX-2288)
Verdict: approve. The layered design is the right one for what FIX-2288 asks: core/engine own the request spend ledger and requestSpendSources; workforce folds at request end; orchestration persists live + settle on the task row so Shift Manager can show rising counts mid-run (goal b:rising). A “request-end only” design would be smaller but would not meet the stated outcome.
What went further than strictly necessary (and when to trim)
| Area | Observation | Cleaner alternative (if you revisit) |
|---|---|---|
| Task row shape | Full requests[] × settled/live source arrays + harness/model metadata |
If you ever only need the folded TaskSpendView on the row, persist that summary and drop most of schema/spend.ts nesting — at the cost of per-request audit on the row. |
| Source spend types | RequestSpendSource in core, plus taskSpendSourceSchema and sourceSpendSchema in orchestration/workforce |
Single requestSpendSourceSchema (+ billing enum) exported from @flow-state-dev/core/types; orchestration/workforce import it. Removes as TaskSpendSource[] casts in spend.ts. |
| No-op detection | JSON.stringify in spendAfterWrite and the spend tick |
Repo norm is looseDeepEqual from @flow-state-dev/core/helpers (CAS/state paths). Worth aligning — especially on the 2s tick path after spend stabilizes. |
| Goal lab | ~870 lines, fsdev.config.mts largely copied from FIX-2145; controls patch task-request.ts for SPEND_TICK_MS |
Share lab harness under goals/shift-manager/lib/; expose tick cadence from a stable export (tasks/spend or task-board index — already re-exported) so goals do not depend on patching implementation constants. Integration tests already cover a lot; goal is UI/regression theater — justified, but heavy. |
| Harness ledger | request-spend-ledger harness delta/changeOf logic |
Heavy but forced by cumulative harness reports + multi-ending requests + live reads. I would not simplify this without a product change. |
Performance (non-blocking)
- Live ticks: full
taskSpendSchema.parseon every write scales with historical requests on the row; acceptable for v1, watch long-lived boards. - Parallel lease renewal + spend tick CAS on the same row during long runs — by design, not N+1.
What I would not change
- Reusing
startTickerfrom lease renewal for spend ticks. - Workforce simplification to
requestSpendSourcesonly. - FIX-2288 harness
reportHarnessSpendchurn in claude/codex/cursor — needed for live totals.
Skipped (needs product call, not review blockers)
- Collapsing task spend and worker usage into one store.
- Removing the goal in favor of tests only.
Nice work on keeping conversion in core and a single write path (recordSpend → spendAfterWrite). Follow-ups above are mostly maintainability, not correctness.
Sent by Cursor Automation: Review For Best Approach
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a6b440119a
ℹ️ 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".
Second look + architecture pass (scoped to this PR's diff against #4013's branch)Verdict: Right shape. The task-row
Considered and left alone
Coherence and known edge
Generated by Claude Code |
There was a problem hiding this comment.
Code Snob — already tight. No POC.
Head a6b440119. I read packages/core/src/types/request-end.ts (readRequestSpend, requestSpendSources, addRequestSpendSource), packages/core/src/types/harness.ts (HarnessRunSpend), packages/engine/src/execution/request-spend-ledger.ts (since, sameRun, changeOf, pending), the spend reports in packages/claude-code/src/sdk/agent.ts, packages/codex/src/agent.ts, and packages/cursor/src/agent.ts, spentTokensOf in packages/claude-code/src/sdk/translate.ts, packages/workforce/src/workers/worker-usage.ts, packages/orchestration/src/tasks/spend.ts, packages/orchestration/src/tasks/schema/spend.ts, recordSpend in both task stores, startTicker in packages/orchestration/src/tasks/lease-renewal.ts, the tick and settle in packages/orchestration/src/task-board/task-request.ts, the listTasks fold in packages/orchestration/src/skills/task-tools-capability.ts, and the goal lab under goals/shift-manager/a-task-shows-its-model-and-tokens/.
A rewrite would not shrink the contract.
- One conversion is the shared count.
sourcesOfandaddSourceare the two workforce call sites. Inlining them drops a comment. - The ledger keeps one entry per
runId.pendingissincewithout taking.sameRunandchangeOfare how an ending hands on the change since the last ending. A second structure would be longer. - The row keeps settled and live per request, plus the harness, the harness model, and the called model. The view sums sources and reads those names. A source has no harness model, and merge order is first-seen, so the names cannot be derived from the source list. A slimmer source would need its own merge beside
addRequestSpendSource. - Both stores'
recordSpendis the identity fence plusspendAfterWrite.patchRefthrows andpatchOnereturns a decline. One body does not fit both. - The live write is
startTicker(the lease timer),writeSpend, andsettleSpend. The tick'sJSON.stringifycompares the raw spend;spendAfterWritecompares the stored entry. - The three reporters follow what each vendor sends: Claude Code sums once per message id and lets the result replace that sum, Codex reports
turn.completed, Cursor adds cache tokens on a finished turn. A shared reporter still leaves that math. Claude's cache sum matches the expression insidespentTokensOf, which reads a result message. - The goal lab copies the worker-usage lab and adds Cursor, mid-run pauses, and the research leg. Its controls patch those source lines. Sharing the lab would move the lines both goals' patches name.
Left as recorded: D1 on the row per request, D2 the 2s tick on the lease timer, D3 the model from the run, the identity-only fence, listTasks carrying the fold, model tools omitting it. The PR's known edge (a run reported again after an ending counts twice in Usage runs) stays; closing it adds code.
Sent by Cursor Automation: Code Snob
- Cursor's settled report names the model the run settled on, as the handle does. - The request ledger keys model calls in last-called order, so a task names the model it called last (A, B, A reads A). - A terminal task never reads live: a dead request's live part keeps its tokens but no ending will clear it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c9eeba294
ℹ️ 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".
- Cursor reports the init message's model at once, not at the first turn's tokens. - A spend write checks the row's incarnation nonce when both sides carry one, so a row recreated within a millisecond does not take the old request's spend. - The request that last reported its harness or model is kept last, so a resumed request's new model wins over a later-admitted request's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
…to claude/project-thread-ldiw1v
…to claude/project-thread-ldiw1v
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 92c850cd1c
ℹ️ 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".
…to claude/project-thread-ldiw1v
…ation Codex: a request continued in a new process gets a ledger that recovers model calls from the log but not harness runs, so its first live write replaced the dead run's recorded harness tokens. Each admission now writes under its own id; a live part another admission left unsettled has its harness sources settled. Also: the goal opens main's renamed shift-coordinator worker, and the by-session control carries the row's incarnation now that recordSpend checks it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0155ad9429
ℹ️ 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".
…n't orphan its continuation Codex: the engine can publish an interruption before the old run's ending runs, so a write from a new admission doesn't mean the old one died. Each admission of a request is now its own entry, and the view supersedes an unsettled entry once a later admission of the same request exists: its harness tokens still count, its model calls (which the continuation recovers) don't, and it stops reading live. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
…to claude/project-thread-ldiw1v # Conflicts: # packages/claude-code/src/sdk/agent.ts
… harness now reports as it goes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
|
Architect: not approving yet. The eight Codex P2 threads (spend ordering, abandoned and late admissions, incarnation check, Cursor model reporting in |
|
All eight Codex P2 threads are resolved now. I checked each one against its fix commit and test, and Codex's last pass on 2393a27 found nothing new. I also resolved Cursor's Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
…to claude/project-thread-ldiw1v # Conflicts: # packages/cursor/src/agent.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a79a2b59e9
ℹ️ 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".
A generator's finished steps reach the row's live part as they end, but the log records a block's calls only when the block finishes. A continuation recovers only the logged part, so dropping all of a superseded admission's model calls lost an unfinished block's steps. Each admission now records what its ledger recovered when admitted, and a superseded live part counts its model calls less what the next admission recovered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
…erge Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
…to claude/project-thread-ldiw1v
…to claude/project-thread-ldiw1v
…to claude/project-thread-ldiw1v
… they go The merge resolves the spend ledger: recovered harness runs seed the run map under keys of their own. A block's own spend seam now also reads pending spend (a task's live write reads it from the block), and its trace lists a run that reports as it goes once, at its latest report. A superseded admission's live part now counts less every source its continuation recovered, harness runs included, since the log now carries those too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0bc5922b2
ℹ️ 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".
A continuation that died before its first spend tick left no entry, so the run before it was counted less the next continuation's recovery, which also holds what the dead one logged. The admission now writes its recovered spend at once, so each admission's baseline is on the row before it spends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NczDiChY1mUtWVrVLDDgdP
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1486bd7ad5
ℹ️ 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".


Requested by Jake · project thread
Stacked on #4013 (FIX-2145). The base is #4013's branch. When #4013 merges, this PR changes its base to
main. Until then, do not merge it.listTasksgives harnessclaude-code, the model the run reported, and tokens that go up every 2 s while the run worksnullwithunreported: trueuntil the turn ends. Never 0Goal check:
goals/shift-manager/a-task-shows-its-model-and-tokens/, no model. PASS, legs a to g, 108 s. Every control fails on its named signal:end-onlyfails b:rising,zero-unreportedfails c:null,last-attempt-onlyfails d:1500,config-modelfails b:model,from-tracesfails e:same-numbers,add-resultfails b:exact and f:equal,by-sessionfails g:own-only. The verdict log is ingoal.md.What changes
readRequestSpend(ctx)reads the request's spend since its last ending.HarnessRunSpendgets optionalrunIdandmodel. A later report for the same run replaces the earlier one. The conversion from a request's spend to tokens per source moves here from workforce.pending()reads without taking.message.idonce, and its result replaces the running sum.spendfield on the task row. A newrecordSpendverb, fenced only by row identity, on both task stores. A 2 s tick in the task's admission, and a settle in its request-end hook before the check.listTasksfolds the field into{ harness, model, inputTokens, outputTokens, unreported, live }. The task tools that a model reads do not show it.Where the build differs from the spec
by-sessioncontrol writes to every running task of the same worker. The spec's version passed, because the identity fence already refuses those writes.Checks:
pnpm typecheckandpnpm lintpass, and so do the vocabulary and naming sweeps. Tests pass in core, orchestration, workforce, claude-code, codex and cursor. Engine: 4 120 tests pass. In the full run, 5 time out at 5 s, and a different set each run; those files pass when run alone.Known edge: if a harness run reports again after an ending, worker usage counts that run twice in
runs. Token totals are correct.Spec:
specs/issues/FIX-2288/(#4120) · Linear FIX-2288 · epic FIX-2152Generated by Claude Code