Skip to content

Give capture a provider receipt: generate.text returns no usage #395

Open

Description

@abogartz

Part of #386. Spawned by #387 / PR #394.

Goal

Capture's model call carries a real provider receipt, so the plugin can report its own cost instead of estimating it.

Findings

PR #394 ships an estimate (chars/4, labelled receipt=none) because no receipt exists. This is what was measured, with a throwaway plugin against a running host on 2026-11-11:

  • ctx.generate exposes exactly one member: text.
  • generate.text({ model, prompt }) resolves to { text } — no usage, no tokens.
  • Capture emits no usage event of its own. Every bench store holds one status/<session>.json and its measured covers only the session's turns, so there is no second session to attribute either.
  • ctx.session exposes create, prompt, wait, get. session.create works from a plugin; session.prompt({ sessionID, model, text }) accepted the call and blocked — it did not return within the probe window.

Cost of the thing being measured: roughly 4.7k tokens per session on the bench seat, about a third of the session's own generation, 94% of it reasoning. The estimate cannot see reasoning at all, so it understates.

Acceptance criteria

  1. A capture call produces provider-reported token counts (input, output, reasoning, cache read) inside the plugin process, not an estimate.
  2. capture_cost evidence switches from receipt=none to a named source, and captureCost() keeps both kinds distinguishable — a window with mixed sources must not present one as the other.
  3. The base4 transport result is re-verified after the change (empty store 0/5, seeded 5/5). If moving capture onto a session changes what capture writes, that is a behaviour change and the transport result is the thing that would show it.
  4. The estimate path is kept, not deleted: a host that still exposes no receipt must degrade to the labelled estimate rather than to zero.
  5. The bench's billedFrom and the plugin's own number agree within 2% on the same wire log — this is AC 4 of Bill capture and cache: per-session token accounting the plugin can report itself #387, unreachable until criterion 1 is met.

Two routes, and the cost of each

  1. Upstream. Ask for usage on the generate.text result. Cheapest by far; outside this repo's control.
  2. ctx.session.create + prompt + wait. Works without upstream, but capture stops being a fire-and-forget text call: it becomes a session, with an agent, a system prompt and a lifecycle. That is a behaviour change to the one component whose output the transport benchmark measures, so criterion 3 is not optional.

Explicit non-goal

Do not raise the estimate's confidence. A chars/4 number does not become a receipt by being rounded, renamed, or moved into a column that looks like the session's.

Activity

  1. added
    capture
    severity:medium
    on Nov 11, 2026
  2. abogartz commented on Nov 11, 2026

    @abogartz
    OwnerAuthor

    Partial implementation in #401 — the host limitation is now pinned in CI; AC 1 still needs route 1 (upstream) or a deliberate route-2 decision.

    Machine-checked premise. The fake model attaches usage: {prompt_tokens: 111, completion_tokens: 22, total_tokens: 133} to every final chunk; a standalone probe plugin inside a real host (v2.2.5) on the session.context seam records what ctx.generate.text resolves to: generateKeys=["text"], resultKeys=["text"], usage=null — with the provider's numbers on the wire. The gap is the host's contract, not the provider's silence. When upstream ships usage the test fails on purpose and becomes the trigger to flip capture_cost off receipt=none.

    Route 2 not taken, deliberately: session.create+prompt+wait makes capture a session with an agent and lifecycle — a behaviour change to the one component the transport benchmark measures — and the original probe found session.prompt blocked within the probe window. AC 3 exists for exactly that risk; taking it needs a quiet seat with the transport arm ready (F19).

    AC 4 already met by #394: no receipt degrades to the labelled chars/4 estimate, never a zero; #401 touches no production path.

    The upstream ask (route 1), for forwarding: Please expose provider-reported usage (input, output, reasoning, cache read/write) on the generate.text result in the plugin context. Capture cost is currently unbillable: the provider sends usage on the wire, the host drops it at the plugin boundary, and a chars/4 estimate cannot see reasoning at all — which is 94% of the capture call. Probe and repro: #401.

  3. added 2 commits that reference this issue on Nov 12, 2026
  4. added
    enhancement
    tier:micro
    tier:standard
    and removed
    tier:micro
    on Nov 20, 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

    captureenhancementseverity:mediumtier:standard

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions