Skip to content

A job's budget covers all its runs - #2353

Merged
santoshkumarradha merged 70 commits into
app/v3from
c52/budget-per-job
Nov 5, 2026
Merged

santoshkumarradha merged 70 commits into
app/v3from
c52/budget-per-job

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

What a person saw

A job's budget only limited the current run. Start, Carry on, Rerun and Start over each began with a fresh count, so a job with a $5 budget could spend far more across its runs.

What changes

  • The cap now compares the job's whole spending, saved runs plus this run, with its budget. Start, Carry on, Rerun, Start over and Bring back all keep to it. Run as new remains a separate job.
  • A job already over its cap stops with a stated question, not silently: "budget of $0.01 reached · job total $0.01 · raise it to $5, or stop?".
  • A new paid step past the cap needs a person's raise. Auto can't raise. A Manual raise above the total resumes work; at or below it the job stays held.
  • The factory decides. A paid step reports in before it starts, and that report sends any spend not yet reported first, so a worker with an old copy of the job can't start another paid step past the cap.
  • Reports no longer hold up the worker's heartbeat: a stalled report used to delay lease renewal, a person's Stop and other signals by about 5 s, and now none of them wait on it. A step waits at most 5.5 s for its answer. If the factory doesn't answer, the same round retries every second for up to two minutes, without using an attempt.
  • No double count, and no money lost after a raise.
  • Approved publish, merge and Publish anyway keep going at the cap, since they make no model call. A person's Stop stays available.
  • A raise on a stopped job saves and succeeds, and the job stays stopped until a person starts it.

Wire

spending_limit.{spent,next_limit} and questions[].{spent,next_limit} now mean the job's total. cost stays per run.

What stays the same

Stage attempt limits and step costs, pipeline intake start.max_cost, the daily rail and Pareto model selection keep their meanings. A pipeline's default_budget supplies the job ceiling, which now covers all runs.

Limits

  • An older job uses only its saved total; money lost from old saved records isn't rebuilt from the ledger.

  • The call that crosses the cap is already paid for, so a job can end above its budget by that one call. No priced call follows it: the running step stops once the crossing is recorded. Live, at a budget set 5% above the first run's cost, that call was $0.0003 to $0.0005 when the prompt was cached and $0.003 to $0.0046 when it wasn't, which took the total to between 1.00 and 1.89 times the budget. On a $5 budget the same call is about 0.1%.

  • A call admitted just before the crossing is recorded is cancelled before it replies, and records no cost. On the provider's own account, 36 requests cut at 50, 100 and 200 ms were billed $0 while 3 uncut ones matched to the sixth decimal. That covers this model and its route only. A provider that bills a cut call would cost up to one unanswered call per stop, uncounted.

  • During a stalled report the job shows running, with its last acknowledged step and spend, no question, and no line saying why it's waiting. After the two-minute retry window the job keeps its round and lease and keeps trying to report. When the factory answers, the round resumes on its own without using an attempt, or the person gets the cap question if the job's total has reached its cap.

  • A heartbeat still has its own 5 s limit.

Validation

  • Red first through the real start path: TestAppFactoryLifetimeBudget, a late receipt, unreported spend at admission, publish and merge at the cap, Publish anyway at the cap, and a raise on a stopped job.
  • TestAPauseAndResumeReachTheRunner and the resume path ran 30 of 30 after a race fix here.
  • go vet, internal/factory/..., internal/manual, internal/appwire and the whole cmd/codeaf package pass on this head.
  • TestLiveJobTotalBudgetAcrossRerun with deepseek/deepseek-v4.1-flash for every role: 10 of 10 on this head. In every run the job total, ledger and spending agree after a raise to $5.
  • That check now records every call and has its own limit. It accepts only a call cut with no reply at or past the cap, and a hedged try cancelled before it was sent. It presses try again only after the job asked, and fails if a press brings no later round and no later paid call. It also fails if any priced call follows the crossing.

🤖 Generated with Claude Code

santoshkumarradha and others added 30 commits November 3, 2026 09:02
Cap decisions read SpentBefore plus current run spend; receipt accounting and cost retain their meanings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep raise fixture below its initial cap; let real cap checks stop completed receipts before further spending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The proxy must acknowledge its first replay before a retry withdraws the old worker request; later cleanup reports need no extra replay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adapt the c34 live lane to stop a paid job and Start over, reach the job-total budget with the second run below its own cap, then raise and reconcile lifetime spend with the ledger. Bound every paid request under a separate $0.30 ceiling and verify all recorded models.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Worker reports advanced the whole-job version between the page read and budget raise. Track budget revisions and compare under the item lock, preserving conflicts with other budget edits and refusing ended jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Return conflict instead of stale so desktop reconciliation cannot overwrite a budget changed back by another editor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Compare authoritative spending under the item lock. Preserve the incoming receipt, park the job with its job total question, and withdraw execution through the existing wire response.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
santoshkumarradha and others added 10 commits November 4, 2026 09:46
Deliver spending newer than an acknowledged retry before admitting paid work. Let valid person-approved Publish anyway finish its post at the cap while keeping model phases gated. Save raises on stopped jobs without attempting continuation.

Also close the pre-existing pause resume race while canceled controls settle spending receipts. Resume waits for release before reviving the saved chat.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion from a stuck job

A call the budget stop cancels before any reply has no cost to record, and a
model that keeps ending replies without a report runs the step out of
attempts, when the job asks. The check failed on both. It now accepts only a
cut with no reply at or past the cap, presses try again only when the job
asked and the last press made progress, asserts no priced call follows the
crossing, and reports what it waited on under its own limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wledge to finish writing

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps both reserve behaviours: the locked job decides thread-only, and a job at
its budget takes no lease. A stopped job at its budget is held without a cap
question, so the Stop stays what the job says.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CLAassistant

CLAassistant commented Nov 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

santoshkumarradha and others added 13 commits November 4, 2026 17:53
Apply gained a capWait argument on this branch. This test has no budget
question, so it passes false, and it keeps its earlier behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its Stop and pending reply stay, a raise doesn't resume it, and it still takes
no lease. The signal retry test held its first heartbeat until the step
entered, while the step's admission report waited on that same delivery loop;
it now answers heartbeats until the step has entered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Measure report stalls through the real worker loop and HTTP boundary without model calls. Both report paths block lease renewals and queued signals for the request timeout. Keep timing observations assertion-free for the requested baseline.

Stop before changing admission: TestBudgetAdmissionCountsUnreportedRoundSpend and TestBudgetAdmissionDrainsOlderPendingSpend require the factory answer before another executor starts, because their extra lifetime spend exists only on the factory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Serialize running-job admission and periodic reports on one reporter so
spend deltas keep their acknowledgment order without blocking signals.
Keep factory approval before each step and cancel admission waits on Stop.
Join the reporter before cleanup and guard shared delivery state.
Keep the budget-wait acknowledgment on late updates so a parked lease
is not withdrawn and a completed chat is not resumed and charged again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Admission errors withdrew the runner and final reporting could release the job
as backlog. Retry the saved unspent round after the drive and reporter settle,
without consuming attempts, and bound the complete admission wait to 5.5 seconds.

Prove automatic retry counts and spend, the full queued report/flush/admission
chain, and cancellation plus report/heartbeat lease-loss accounting. Exercise
both undelivered and replayed reports, late spend, receipt replay and reporter
goroutine termination under the race detector. Keep the existing stall tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Retry expiry cleared the retrying guard, allowing final delivery to return a
withdrawn, unspent round to backlog. Keep the lease and round while flushing
reports, then resume through the existing same-round Hold path after delivery
catches up. The separate retained-result recovery block remains authoritative.

Prove state through work(), real report and heartbeat doors, and GET /v1/jobs.
Cover answers before and after expiry, exact spend deltas, authoritative budget
withdrawal, unchanged attempt limits, and joined worker/reporter shutdown.
Document admission recovery and its separate result-delivery deadline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A heartbeat can resume a parked worker while its reporter sends a cap
question frozen from the old mirror. ApplyReport reopened it after the
server had saved the higher cap and answered the question.

After folding usage, ignore cap questions below the authoritative cap.
Keep questions at exhaustion and cover both Continue and budget edits
with a deterministic HTTP replay. Preserve admission and reporting paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cover equality, reports whose own cost crosses the raised cap, and reports
that remain below it through the worker HTTP report seam. Verify non-cap
questions and all other report contents survive the cap-question filter.
Exercise a frozen leased-worker report, continuation, and the next cap stop
without admitting a third paid step.

Mutation checks fail for <=, filtering before addCost, removing the guard,
filtering all question kinds, and dropping the whole report. Restore every
mutation before the final repeated tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both sides kept in the two conflicts with #2370: the raise test's job gets
the owner's tier and its earlier spend, and Doors.SignOff checks write
access before the lifetime cap. The lifetime budget and late-usage tests
now record the owner's tier, which #2370 requires before a job can write.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@santoshkumarradha
santoshkumarradha marked this pull request as ready for review November 5, 2026 07:29
@santoshkumarradha
santoshkumarradha merged commit ce8e526 into app/v3 Nov 5, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the c52/budget-per-job branch November 5, 2026 07:29
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.

2 participants