fix: bound stream accounting finalization - #3
Open
Marketen wants to merge 2 commits into
Open
Conversation
Marketen
force-pushed
the
fix/bound-stream-finalization
branch
from
September 9, 2026 11:01
bf4fb5f to
68fd97e
Compare
hcastc00
force-pushed
the
fix/finish-reason
branch
from
September 9, 2026 11:11
51d2ff4 to
b06d16a
Compare
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.
Issue
PR #2 delays
finish_reasonand[DONE]until trailing usage and accounting finish. Its five-second timer only cancels the provider read, while proof persistence andRecordSuccessrun withcontext.WithoutCancel. If metering is unreachable, its three five-second attempts can therefore hold a normal streaming response for about 15 seconds; Tinfoil proof persistence can extend that to about 30 seconds.Fix
Start one absolute five-second finalization deadline when the completion event is observed, and apply the remaining budget to the cancellation-detached proof and metering context. This preserves accounting after a client disconnect, but proof/metering retries can no longer outlive the response finalization budget. Bare-EOF streams receive the same bounded accounting context.
Example
Before: provider finishes at
t=0; metering is down;[DONE]may be held until roughlyt=15s(t=30sfor Tinfoil).After: provider finishes at
t=0; the shared deadline expires att=5s; outstanding accounting calls are canceled and the gateway emits the retained completion.Validation
go test ./...go vet ./...git diff --check