Skip to content

fix: bound stream accounting finalization - #3

Open
Marketen wants to merge 2 commits into
fix/finish-reasonfrom
fix/bound-stream-finalization
Open

fix: bound stream accounting finalization#3
Marketen wants to merge 2 commits into
fix/finish-reasonfrom
fix/bound-stream-finalization

Conversation

@Marketen

@Marketen Marketen commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Issue

PR #2 delays finish_reason and [DONE] until trailing usage and accounting finish. Its five-second timer only cancels the provider read, while proof persistence and RecordSuccess run with context.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 roughly t=15s (t=30s for Tinfoil).

After: provider finishes at t=0; the shared deadline expires at t=5s; outstanding accounting calls are canceled and the gateway emits the retained completion.

Validation

  • go test ./...
  • go vet ./...
  • git diff --check
  • Extended the stream accounting test to assert that metering receives the bounded finalization deadline.

@Marketen
Marketen force-pushed the fix/bound-stream-finalization branch from bf4fb5f to 68fd97e Compare September 9, 2026 11:01
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