Skip to content

ui-sdk: omit provider attempt receipts before upstream dispatch #4370

Open

Description

@schlessera

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 refused operation.dispatch(send) (packages/ui-sdk/src/server/provider-relay.ts:548-549) call report("cancelled", null) before observe("dispatched") at line 550.
  • Gemini Files cleanup (DELETE): admission refusal, the header charge, prepare() refusal, the final fence and a refused dispatch all call observe("cancelled") before observe("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_usage row.
  • 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

  1. added
    type: fix
    area: ui-sdk
    priority: p2
    blocked
    on Nov 21, 2026
  2. added this to the 0.45.0 milestone on Nov 21, 2026
  3. schlessera commented on Nov 21, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #3609 is closed, so scripts/sync-project.ts is removing the blocked label.

  4. added
    agent-ready
    and removed
    blocked
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-sdkpriority: p2type: fix

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions