Skip to content

A job keeps its earlier spending when it runs again - #2305

Merged
santoshkumarradha merged 93 commits into
app/v3from
c42/job-lifetime-spend
Nov 3, 2026
Merged

santoshkumarradha merged 93 commits into
app/v3from
c42/job-lifetime-spend

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Summary

A job's Spent figure was the current run's only, so starting a stopped job again dropped what it had already spent. A job now keeps its earlier spending. The per-run cap does not change.

 ClearJobRun(job)          # every door that clears a run with money on it
+  job.SpentBefore += run spend + pre-run chat spend
   job.Stream = nil

 JobSpent(job)             # this run: cap, wire `cost`, daily rail. Unchanged
+JobLifetimeSpent(job)     # SpentBefore + JobSpent: wire `lifetime_cost`, Spending by repo and model
  • Start and Bring back clear the work and keep the money. Run as new makes a separate job at zero.
  • A late receipt for an earlier run adds only its growth to SpentBefore. It does not charge the new run, and a repeat adds nothing.
  • Undo Stop keeps money reported since the Stop.
  • A job from before this change, whose earlier run is already gone, shows only its saved total. Its lost money is not recovered from the ledger: a ledger tag and workspace can be shared by local and remote factories, so neither proves which factory spent it.

Evidence

Measured on one real job that was stopped and started again:

Before Start After Start Total
wire cost 0.138363 0.030189 not shown
tagged ledger rows 0.138363 0.030189 0.168552
  • Before: restart test: lifetime read the current run only, and Run as new could read the earlier job's ledger money through a shared ledger name.
  • After: TestRestartKeepsJobLifetimeSpend, TestRunnerLaunchKeepsEarlierRunMoney, TestBringBackKeepsLifetimeMoney, TestRunAsNewStartsWithoutLifetimeMoney, TestLateOldRunUsageKeepsLifetimeWithoutChargingNewRun, TestStopUndoKeepsMoneyReportedAfterStop, TestFactoryLifetimeCostUsesTaggedLedgerWithoutLoweringKnownSpend pass.
  • go test ./internal/factory/... ./internal/appwire/... ./internal/manual/... and the whole of go test ./cmd/codeaf pass at this head.

Pressed live in the desktop app on a real repository, with deepseek/deepseek-v4.1-flash: a job run, stopped, started over from the first step, stopped again:

Earlier run This run Total Shown
saved job 0.091891 0.090403 0.182294 page and menu: Spent $0.18, $0.09 of $5.00 this run
tagged ledger rows 0.182294
  • Spending for the week showed $0.76; all tagged ledger rows sum to 0.755011.
  • Spending by model read 0.479761 by model plus 0.136887 unknown, which is 0.616648: the saved job totals. The 0.138 gap to the ledger is one job from before this change, stopped and restarted on an older build. It shows its saved $0.03, not the ledger's $0.17.
  • The live press found that the desktop bridge dropped lifetime_cost, and that the per-job average read this run only. Both are fixed in the desktop app.

Limits:

  • A desktop app without those fixes keeps showing this run's figure.
  • Spending by repository and model places a job's whole lifetime on its latest run's start day, so a range holding only a second run includes the first run too. These are placed job totals, not per-call range totals.
  • Earlier money has no model split, so it stays unknown by model.
  • The cap stays per run on purpose, so each Start still gets a fresh cap. That is awaiting a product decision.
  • A late receipt from before this change has no saved lease, machine and person, so it cannot add late usage.
  • An older binary still running can rewrite a saved job and drop SpentBefore and Archived, like any newly added saved field. This change adds no version fence.

Merge Danger

Door: two-way

The new saved field and wire field are additive and optional.

Blast Radius: spending

Spending by repository and model will read higher for restarted jobs.

🤖 Generated with Claude Code

santoshkumarradha and others added 30 commits November 2, 2026 23:22
Competing manager opens remain owned after Talk selects another journal. Recognize the saved owner for live budget admission and spending. Match receipt rebuilds to the journal identity as well as the cell identity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Validate durable ownership against the candidate store. A local worker mirror must share the owning floor manager path before taking an extra manager charge. Seed journal headers and titles from the session folder metadata in either layout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Old ownership marks keep their root, job and repository matching.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Match call facts across aliases, retaining repeated calls under a single alias and leaving historical rows untouched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep the held-manager fast path and recheck after locking. Network reads no longer hold the floor-wide mint lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GitHub issues supply Created (github/source.go issueItem); Store.Create preserves it and api transport carries it. Independent factories can therefore share ID, Repo, Num and Created. The remote door must use its mirror; owned runners still consult their floor. Remote manager deduplication remains unsupported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Assert historical ledger bytes remain unchanged and repeated refresh imports no saved call twice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Exercise exported Refresh with separate equal-cost calls, microdollar rounding, and repeated ledger IDs. Normalize Go formatting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Match each alias to saved calls in order, using receipt precision for cost and allowing live usage to precede its seal. Count repeated row IDs once and append only missing calls, preserving historical ledger bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Record the legacy prefix assumption for calls sharing a seal. Final review retains no blocking findings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Live meters persist logical round totals before interruption. Result folds replace the round high-water mark so retries cannot add receipts twice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
santoshkumarradha and others added 27 commits November 3, 2026 03:53
Clarify the retained round receipt behavior in the shipped manual.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Newly opened unmetered chats report only their segment spending.
Normalize it against the persisted round receipt before the runner
subtracts acknowledged spending. Keep recorded rows monotonic when
a later result is smaller, without treating float size as segment identity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local and remote workers share worktree paths, so tags and workspaces cannot safely recover factory spending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Validate acknowledged archived receipts before the current worktree machine so late cumulative growth survives Bring back and machine replacement without charging the new run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ledger recovery has no reader now, so the wire field and its floor scan go.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@santoshkumarradha
santoshkumarradha marked this pull request as ready for review November 3, 2026 12:45
@santoshkumarradha
santoshkumarradha merged commit 29e1139 into app/v3 Nov 3, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the c42/job-lifetime-spend branch November 3, 2026 13:09
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