Repository navigation
Description
Context
PR #4270 can emit a terminal provider receipt before any upstream dispatch. In the provider relay, a refusal after prepare() but before dispatch emits cancelled without a prior dispatched event. The documented contract is one receipt per dispatched attempt (ProviderRelayOptions.observe, packages/ui-sdk/src/server/provider-relay.ts:219-220), and docs/integration-contract/package-api.md:6204-6206 says provider observe({outcome:"dispatched",...}) reports an actual transport start. observeProvider inserts any first receipt for an attempt id, so a pre-dispatch cancelled persists an unknown-cost provider_relay_usage row for work that never left the host (observeProvider, packages/ui-server/src/brain/turn-budgets.ts:244-258; budget semantics in docs/decisions/cost-tracking.md, "Relayed CLI provider requests (#1673)").
Pre-dispatch terminal receipts at main a3395c4b2:
- Ordinary relay: the final charge/egress fence (
packages/ui-sdk/src/server/provider-relay.ts:544-545) and a refusedoperation.dispatch(send)(packages/ui-sdk/src/server/provider-relay.ts:548-549) callreport("cancelled", null)beforeobserve("dispatched")at line 550. - Gemini Files cleanup (DELETE): admission refusal, the header charge,
prepare()refusal, the final fence and a refused dispatch all callobserve("cancelled")beforeobserve("dispatched")(packages/ui-sdk/src/server/provider-relay.ts:702-719).
Receipts after line 550 / 719 (header failure, interrupted response, final response fence, client disconnect) follow a real dispatch and are correct.
The final review accepted deferral: unknown spend does not itself block, Files attempts price at zero, and the window is narrow. This is a bookkeeping follow-up, not an admission bypass.
Previously blocked by #3609 (closed as completed 2026-11-21); no open dependency remains.
Scope
Emit a provider attempt receipt (any outcome) only for an attempt whose upstream request was actually started, in both the ordinary relay path and the Files cleanup path. Keep the caller's refusal response and the refused diagnostic unchanged.
Out of scope
Admission, budget or pricing rules; the preparing diagnostic callback; the proxy's own committed events; receipts for attempts that did dispatch; changing the ProviderRelayReceipt shape.
Acceptance criteria
- Emit a provider attempt receipt only if the operation actually dispatched; a prepare/final-fence/dispatch refusal publishes no dispatched or terminal attempt and leaves no
provider_relay_usagerow. - Preserve exactly one terminal receipt for a started attempt, including a constructor-returned request that later fails.
- Cover ordinary, Files and cleanup paths with prepare-refused, fence-refused and started-then-failed controls; assert receipt count, cost projection and caller refusal.
- Prove the regression test fails under a mutation (restoring a pre-dispatch
report("cancelled")) on its named assertion, and update the contract if any caller-visible behavior changes.
Verification
Keyless offline: bun run test packages/ui-sdk/tests/provider-relay.test.ts packages/ui-sdk/tests/provider-relay-files.test.ts packages/ui-sdk/tests/provider-relay-refusal.test.ts, plus packages/ui-server/tests/provider-relay-budgets.test.ts, which drives observeProvider. Record failing-first and mutation receipts.
Contract impact
Brings behavior in line with the documented observe contract; no shape change. If SDK consumers can observe fewer receipts, note it in docs/integration-contract/package-api.md near the dispatched-receipt paragraph and add a ui-sdk changeset (CONTRACT: commit).
Part of #3597.
2026-11-23 triage at main a3395c4: restructured into the task template, replaced the stale docs/http-api.md pointer with the package-API contract and cost-tracking decision, enumerated every pre-dispatch receipt by line, and made the #3609 blocker historical (closed). Criteria unchanged apart from naming the usage row and the mutation.
Activity
schlessera commentedon Nov 21, 2026
Unblocked: #3609 is closed, so
scripts/sync-project.tsis removing theblockedlabel.