Repository navigation
Pin the generate.text receipt gap in CI (#395) - #401
Conversation
…reports usage Part of #386, addresses #395 (does not close: AC 1 needs upstream or route 2). #395's premise was probed by hand on 2026-11-11 and hand probes rot. This makes the limitation machine-checked: the fake model now attaches `usage: {prompt_tokens: 111, completion_tokens: 22, total_tokens: 133}` to every final chunk -- the shape a real openai-compatible provider sends -- and a standalone probe plugin records, inside a real host process on the session.context seam, what `ctx.generate.text` actually resolves to. Result, pinned by e2e/generate-receipt.test.ts: `ctx.generate` exposes exactly ["text"], the result carries exactly ["text"], and `usage` is null -- with the provider's numbers on the wire. The gap is the host's contract, not the provider's silence. When upstream surfaces usage (route 1), resultKeys grows, this test fails, and the failure is the trigger to flip it and switch capture_cost from receipt=none to a named source. Route 2 (session.create + prompt + wait) is NOT implemented, deliberately: it turns capture from a fire-and-forget text call into a session with an agent and a 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 precisely because that route could change what capture writes; taking it is a decision for a quiet seat with the transport arm ready, not a drive-by. AC 4 (keep the estimate path) is already met by PR #394: no receipt degrades to the labelled chars/4 estimate, never a zero, and this change touches no production path. - e2e/support/fake-model.ts: usage on the final chunk - e2e/support/probe-plugin/: standalone { id, setup } plugin, session.context hook, model shape { providerID, id } (the host rejects modelID -- the error named the key, so the probe doubles as the shape documentation) - e2e/support/harness.ts: makeGuest takes extraPlugins - e2e/generate-receipt.test.ts: the characterization Co-authored-by: OpenCode <[email protected]>
Adversarial review — APPROVE_WITH_NITSReviewed head The core characterization is true and proven end-to-end: the host parses provider usage into message tokens, then the Seam proofThe probe and the real plugin run in one host process (both logged the same pid). Decisive step: the real plugin's own Wire proofRaw SSE from the fake model: The host itself sends P2 — The test cannot detect loss of its own premise
Nothing asserts that the provider actually reported usage. The distinction this PR exists to pin — "the host's contract, not the provider's silence" — becomes unprotected the moment the fake model drifts. Fix: after the turn, assert the probe's generate call reached the fake model, for example expect((await fake.requests()).some((r) => String(r.messages?.at(-1)?.content) === "probe receipt")).toBe(true);Response bytes are deterministic from that request, as shown above. P2 — "AC 4 already met by #394" is false against any merged tree
The flip instruction "switch P2 — The "route 2 deliberately not taken" premise is stale on both hostsThe body says the original hand probe found Declining route 2 for behaviour-change and AC 3 reasons remains sound judgment. Citing a block that no longer reproduces is not. Fix: correct the body and #395's findings. NITs
ResidualCI e2e runs Efficacy table
Version matrix
The characterization is version-stable across both testable hosts: no red CI, no silent mis-pin. Measured numbers
Hygiene: guests are fully hermetic ( |
The characterization test read only the probe plugin's own file, so deleting the fake model's `usage` block left it green: it could not tell the host's contract apart from a provider that had stopped reporting. The fake now records the final chunk it actually wrote (served.jsonl, exposed at /__served), and the test requires both that the probe's generate call reached the model and that the chunk served back to it carried prompt_tokens 111 / completion_tokens 22. Also from the review: - #394 is OPEN and `capture_cost` is not on any merged tree. The header and the flip instruction now say "PR #394 (open)" instead of sending a future author to a symbol that is not on main. - Route 2 is not blocked. Re-probed with a 20 s timeout on every await, it resolves in 37-80 ms on v2.2.5 and 39-62 ms on the CI pin v2.0.26, and the route-2 session's assistant message carries the provider's numbers in the guest db. The comment now gives the real reason to decline it: it changes what capture writes, which is exactly what AC 3 measures. - Guests this test creates are removed in afterAll, and startFake() reaps its own temp dir in stop(), so a full e2e pass leaves no psi-e2e-fake-* behind. - Each contract gets its own expectation message, so an unrelated new ctx.generate member cannot be read as the usage flip. - The probe plugin types its context structurally in its own file, which returns the branch to main's 542 lint warnings.
Review fixes — 240e887All six findings addressed. No production path touched; this stays a characterization PR. What changedF1 — the test can now detect loss of its own premise. F2 — the #394 references. The test header and the AC table now say "PR #394 (open)" and state plainly that F3 — route 2. Re-probed in scratch with a 20 s hard timeout on every await. The route is not blocked; measurements below. The test comment and the body now give the reason that survives the measurement — route 2 changes what capture writes, which is what AC 3 measures — and they state the latency and that the numbers are reachable that way. The probe itself is not committed. F4 — temp dirs. The test removes its guests in F5 — the three F6 — the flip trigger no longer leans on printed comments. Each contract carries its own expectation message, and the usage check runs first, so a usage flip always reports as the flip even when Mutation table (each row observed, not inferred)
The first row is the finding itself: before this commit the test could not see the provider stop reporting. Host matrix
Route-2 measurements (scratch probe, not committed)
The route-2 session's assistant message in the guest db carried Gate
Not fixed, and why
|
There was a problem hiding this comment.
Approving.
The characterization now proves its own premise: the test asserts the probe's call reached the fake model and that the chunk the fake served carried the provider's usage, so removing that field turns the test red instead of silently passing. The host-contract conclusion holds on both the local host and the CI-pinned version, and the route-2 rationale is corrected to the real one.
Full gate green, CI green. Not merged — the merge is left to a human.
|
🎉 This PR is included in version 0.24.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Part of #386. Addresses #395 — does not close: AC 1 needs upstream (route 1) or a deliberate route-2 decision.
What this is
#395's premise (
generate.textreturns no usage) was probed by hand on 2026-11-11. Hand probes rot; this makes the limitation machine-checked in CI.The fake model attaches
usage: { prompt_tokens: 111, completion_tokens: 22, total_tokens: 133 }to every final chunk — the shape a real openai-compatible provider sends. A standalone probe plugin records, inside a real host process on the samesession.contextseam the plugin injects through, whatctx.generate.textactually resolves to.Result, pinned by
e2e/generate-receipt.test.ts:Object.keys(ctx.generate)["text"]["text"]result.usagenull— with the provider's numbers on the wireThe gap is the host's contract, not the provider's silence.
The premise is checked from both ends
A test that reads only the plugin's own file cannot tell "the host dropped the receipt" from "the provider stopped sending one": deleting the fake model's
usageblock left the first version green. The fake model now records the final chunk it actually wrote (served.jsonl, exposed atGET /__served), and the test requires all of:ctx.generate.textcall appears in the fake model's request log;prompt_tokens: 111 / completion_tokens: 22 / total_tokens: 133andfinish_reason: "stop";{ text }withusage: null.Delete the
usageblock and the test goes red with a message namingfinalChunk().When this test flips
Three assertions, three expectation messages, checked flip-first so a red always names the right contract:
usagecapture_costreads, once #394 landsresultKeysusage, that is the flip above; anything else is a new member to add to the listgenerateKeysctx.generategained a member — that alone is not the usage flipThe instruction rides on the expectation, not on a comment, so it survives someone editing the prose.
AC status, stated before review
capture_costswitches to a named source, both kinds distinguishablemain—capture_costdoes not exist on this branch. This PR touches no production pathbilledFromagrees within 2%Route 2: declined for cost, not blocked
An earlier version of this body said the original hand probe found
session.promptblocked within the probe window. That no longer reproduces. Re-probed 2026-11-12 in an isolated guest against both hosts, with a 20 s hard timeout on every await:session.create→session.prompt→session.waitThe route-2 session's assistant message carries the provider's numbers in the guest db —
{"input":111,"output":22,"reasoning":0,"cache":{"read":0,"write":0}}— so those numbers are reachable that way today, on both hosts.Route 2 is still declined, for the reason that survives the measurement: capture stops being a fire-and-forget text call and becomes a session — an agent, a system prompt, the full tool list on the wire (26 tools offered, against the bare generate call's none), and a lifecycle. That changes what capture writes, and AC 3 is the benchmark of exactly that output. Taking route 2 is a decision for a quiet seat with the transport arm ready, not a drive-by on a degraded one (F19).
Verification
@opencode/[email protected]and selected withOPENCODE_BIN.usageblock → FAIL; inject ausageinto the probe's result → FAIL with the flip-trigger message; add an unrelatedctx.generatemember → FAIL with the "not the flip" message; restore → PASS.main(the threenoExplicitAnythe first version added are gone — the probe now types its context structurally in its own file); unit 1190 pass / 19 skip / 0 fail; e2e 31 pass / 0 fail.psi-e2e-*guest and nopsi-e2e-fake-*behind — this test removes its guests inafterAll, andstartFake().stop()now reaps its own directory. Thepsi-e2e-pack-*directoryinstallPacked()creates is a separate pre-existing leak, left alone here.