Skip to content

POC: fold a turn's spend through spendAfterWrite - #4425

Closed
cursor[bot] wants to merge 16 commits into
claude/project-thread-2ksmgsfrom
poc/shorter-turn-spend
Closed

cursor[bot] wants to merge 16 commits into
claude/project-thread-2ksmgsfrom
poc/shorter-turn-spend

Conversation

@cursor

@cursor cursor Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Draft. This PR does not merge.

What this subtracts

turnSpendOf was building a one-request task row by hand: the last harness run, the last model key, and the blank writer / admittedAt / recovered fields. spendAfterWrite on a blank row with part: "settle" is that row. taskSpendView still folds it, with status: "completed", so a turn still reads like a finished task.

Diff vs 7b7e828: packages/harness-manager/src/session-flow.ts +4/−16.

What still passes

pnpm --filter @flow-state-dev/harness-manager exec vitest run --root . test/turn-spend.spec.ts — 6 passed.

The hand-built row and this fold return the same view for an empty ledger, an API-key run, a subscription run, model calls only, a harness run mixed with model calls, and two api-key runs of one harness plus a subscription run. That check was local and is not in this branch.

Do not merge

Fold the subtraction into #4423. Close this PR unmerged after that lands.

Open in Web View Automation 

claude added 14 commits October 31, 2026 23:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
…t (FIX-2398)

- taskSpendView gains costUsd: the sum of vendor-reported charges, null when
  none (a subscription run reports none; never an estimate).
- harnessSessionFlow records each turn's spend (taskSpendView's shape) and
  endedAt at turn end, however the turn ended; hands harnesses an onUsage
  feed into the usage record; carries a harnessUsage action (usageReaders).
- ui registry gains a spend item, lifted from Claude Code-style's Spend;
  Kitchen Sink installs its byte copy.
- Goal check goals/harness-manager/a-turn-records-what-it-spent: PASS on real
  Claude Code; GOAL_CONTROL=no-turn-spend FAILs t and s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
Turn spend joins FIX-2384's turn-end sequencer as one more step; the
flow keeps one onFinished. Kitchen Sink installs run-changes.tsx so its
registry drift check passes on the stacked branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
…e request publishes its end (FIX-2398)

onFinished runs after runAction emits the terminal status, so a page that
refreshes on the end could read the turn before its spend landed (Codex,
spec PR #4398). The spend now lands in a tap after the harness step, or in
recordFailure's write for a turn that threw. A test captures session state
when request.completed is persisted. The goal's control is now main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
Codex: onFinished runs after the terminal status is published, so D2's
write moves inside the turn and the goal's control becomes main. Cursor's
scope notes answered in DECISIONS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
…to claude/project-thread-t857lk

# Conflicts:
#	apps/kitchen-sink/test/harness-turn.test.ts
…updated run-changes

The parent branch moved both registry files without updating the byte copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
… requestSpendView

Review on #4423: the session flow no longer hand-builds a task spend entry;
orchestration owns the request-to-view step. The turn-end write happens once
(a record that already ended keeps its end), and onUsage needs no cast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
@vercel

vercel Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Actions Updated
flow-state-dev-docs Ignored Ignored Nov 1, 2026 12:03am UTC
flow-state-dev-kitchen-sink Ignored Ignored Nov 1, 2026 12:03am UTC
flow-state-dev-ui Ignored Ignored Preview Nov 1, 2026 12:03am UTC
flow-state-dev-build-site Skipped Skipped Nov 1, 2026 12:03am UTC

Request Review

Turn spend stays a step inside the turn, before 2384's in-turn head write.
Kitchen Sink takes the parent's run-changes and run-checks copies; the
drift count is 40 with spend.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDfgRv9riWiVVdj8JG
The hand-built entry repeated spendAfterWrite. The export and turnEndOnce stay.

Co-authored-by: Jake Hoffner <jhoffner@users.noreply.github.com>
@cursor
cursor Bot force-pushed the poc/shorter-turn-spend branch from 62c911b to 78a103c Compare November 1, 2026 00:03
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Mechanism check (advisory, never blocks)

Rows from docs/mechanisms/mechanisms.yaml · labels: new-mechanism

New export Package Mechanism
requestSpendView @flow-state-dev/orchestration none (nearest: task, task-notice, task-flow-policy)

If an export is a new mechanism, add a row. CI filled the mechanical fields; job, builtOn and overlaps are yours. If it belongs to an existing row, say which in the PR.

  - id: TODO
    job: TODO
    package: "@flow-state-dev/orchestration"
    anchor: requestSpendView
    file: packages/orchestration/src/tasks/spend.ts
    builtOn: []  # TODO
    overlaps: []  # TODO
    status: canonical
    doc: TODO

@github-actions github-actions Bot added the new-mechanism A new public export matches no row of docs/mechanisms/mechanisms.yaml (advisory) label Nov 1, 2026
@jhoffner jhoffner closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-mechanism A new public export matches no row of docs/mechanisms/mechanisms.yaml (advisory)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants