Repository navigation
provider: a call stopped before its first streamed word keeps its charge (#2566) - #2592
Merged
Merged
Conversation
…rge (#2566) A paid streamed call cancelled before its first SSE frame lost its charge. The provider bills as soon as it accepts the request, but the socket was cut at once, so the generation id the first frame carries never arrived and Client.settle had nothing to ask a receipt for. The ledger got neither a priced reconciled row nor the unbilled marker. A stream that reconciles receipts now keeps its socket open for at most receiptStreamIDWait (100 ms) after its caller lets go, and cuts it the moment the first frame names the generation. A call nobody reconciles, and a direct service, are still cut at once. The cut carries the caller's own context cause, as the child context it replaces did. An abandoned hedged race also gave back its caller's pending-spend hold as soon as it returned, before its cut arms queued their receipts. abandon now holds one pending token until the drain has heard every arm, or for at most abandonGrace. On land/app-v3, TestMemoryLateReceiptReachesFactoryHeaderAfterQuit failed 12 of 15 runs before this fix and passed 20 of 20 with it. The new tests C1-C5 in internal/provider/receipt_cancel_test.go fail against dev's original code and pass with the fix. Not fixed here: a receipt still pending only in memory when the process exits (#2591's other half). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
AbirAbbas
added a commit
that referenced
this pull request
Nov 11, 2026
Brings the receipt fix for a call cancelled before its first streamed frame (#2566) onto the landing branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AbirAbbas
added a commit
that referenced
this pull request
Nov 11, 2026
The landing branch has a second receipt waiter that dev does not: WithReceiptSettlement, which the factory's books wait on at close and which also counts unmetered answers the pending token lets a job step past. #2592 bridges the seam between an abandoned race returning and its cut arms queueing their receipts only for the pending token, because that is the only waiter on dev. This holds the settlement token across the same drain, bounded by abandonGrace, as the land patch that took TestMemoryLateReceiptReachesFactoryHeaderAfterQuit from 12 failures in 15 to 20 passes in 20 did. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 11, 2026
AbirAbbas
added a commit
that referenced
this pull request
Nov 11, 2026
app/v3, the desktop engine line, lands on dev, and dev is the one trunk again. New work branches from dev and opens its pull request against dev. This is one squash commit because dev accepts only squash merges. The 906 commits reviewed on app/v3 and on the landing branch stay reachable, and bisectable, at the tag app-v3-final. One revert of this commit undoes all of it. The merge keeps every behaviour from both sides. Where they disagreed: - one rule, session.UsageCallID, recognises a paid call already in the spending ledger, so reopening a chat with no receipts no longer books its paid turns or folded task spend a second time; - a device's directory record is read before it is written (app/v3's rule); - automatic git maintenance is switched off only in the copies codeaf owns (dev's rule); - closing the desktop engine cancels and waits for everything it started, each within a stated bound, and a second close waits for the first. It also carries #2592 from dev: a call stopped before its first streamed word keeps its charge. On top of that it holds app/v3's factory settlement token across an abandoned race's drain, so a memory receipt that lands after quit reaches the ledger and the factory header. For dev's CLI users, the first model call of each process now reads the spending ledger once (about 0.6 us per row of history; a quit on a million-row ledger can wait on it, and nothing is lost). #2593 tracks taking it off the quit path. Known issues that land with it: the pool's errand tracker is keyed by profile, so in the desktop engine the first door to close cancels the other doors' pool errands (learning rows, not money); and a receipt still pending only in memory when the process exits is not recovered (#2591's other half). Fixes #2579 Fixes #2585 Co-Authored-By: Claude Fable 5.2 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong (#2566)
A paid streamed call cancelled before its first SSE frame arrived (Esc, a quit, a factory job withdrawn) lost its charge. The provider bills as soon as it accepts the request, but the socket was cut at once, so the generation id, which the first frame carries, never reached codeaf. Without that id
Client.settlehas nothing to ask a receipt for. The ledger got neither a pricedreconciledrow nor theunbilledmarker.An abandoned hedged race had a second, smaller gap. It gave back its caller's pending-spend hold as soon as it returned, before its cut arms had queued their receipts. So a closer waiting on pending spend could see nothing owed and stop waiting while a receipt was still on its way.
This was measured on land/app-v3 with
TestMemoryLateReceiptReachesFactoryHeaderAfterQuit, which failed 12 of 15 runs before the fix and passed 20 of 20 after it. This PR is the same fix ported todev.What changes
internal/provider/client.go: when a streamed call has a receipt sink and its caller cancels, the call waits for its generation id before cutting the socket.receiptStreamIDWait(100 ms) and cuts the moment the first frame names the generation.context.Cause, as the child context it replaces did. Rows and errors that read the cause see the same door as before.internal/provider/hedge.go:abandontakes oneWithReceiptPendingtoken before it returns and hands it back only after the drain has heard from every arm, or afterabandonGrace(1 s) if an arm never reports.models-and-cost.md): one sentence saying that a stop before the first word keeps the stream open at most a tenth of a second.The person's Esc does not wait on a shipped build. Every call is raced, the race answers its caller at once, and only the arm holds its socket. A build with no waiting controller returns only when the stream is cut, so there an Esc can wait up to the same 100 ms.
Not fixed here
unbilledmarker in that case.hedgeRace.settlereturns without draining, so a losing arm that is still holding its socket can queue its receipt after the caller has returned. This PR covers only the abandoned race.Tests
internal/provider/receipt_cancel_test.go, one test per contract item. C1 to C4 run through both the raced and the bare stream door.abandonGraceeven if an arm never reports.Local gates
gofmt,go build ./...andgo vet ./internal/provider/are clean.go test -count=1 ./internal/provider/passes.-count=10).go test ./internal/manual/andmake changelog-checkpass.make test-lawspasses.make pr-readypasses.🤖 Generated with Claude Code