Repository navigation
Description
Problem
One auto-capture pass costs 2,430 tokens and about 25 seconds on a local seat, and 78% of that time generates reasoning the plugin then throws away. The plugin has no way to fix it: the host's generation API exposes no options at all.
Measured directly against the seat with the plugin's own buildCapturePrompt over a real transcript:
| variant | wall | completion tokens | reasoning chars | parsed |
|---|---|---|---|---|
| as shipped | 24.8 s | 1,232 | 4,305 | 3 candidates |
thinking off (chat_template_kwargs.enable_thinking=false) |
6.3 s | 343 | 0 | 3 candidates |
max_tokens: 600 |
13.8 s | 600 | 2,756 | unparseable |
thinking off + max_tokens |
5.6 s | 343 | 0 | 3 candidates |
The prompt is ~1,200 tokens; the model then decodes 1,232, of which only ~343 are the JSON array. parseCandidates keeps the array and discards the rest. Turning thinking off gives a 4× faster, 72% cheaper write with identical output.
Why the plugin cannot do this today — the host's own types are the bound:
// @opencode/client dist/effect/api/api.d.ts:1761
export type GenerateTextInput = {
readonly prompt: string;
readonly model?: Model.Ref | undefined;
};No temperature, no max_tokens, no reasoning flag. src/capture/runtime.ts calls generateApi.text({ model, prompt }) and that is the whole surface.
max_tokens alone is an active trap: it truncates mid-reasoning, the JSON never closes, parseCandidates returns [], and the pass records outcome=empty. That is a capture that silently stores nothing — the same failure mode #328 just removed, reached from a different direction.
Work
- Upstream: ask for generation options on
generate.text(at minimumtemperature,maxTokens, and a reasoning/thinking toggle). Until then the plugin cannot make capture cheap. - Interim, in the README's auto-capture section: state the measured cost per pass, and say that
captureModelshould name a non-thinking model — a cheap model that reasons is slower and costlier than a bigger one that does not. - Guard the truncation path: if a capture response is non-empty but yields zero candidates, record that distinctly from a genuine
[ ](today both land asoutcome=empty), so a capped model call is visible. - Re-measure after any change with
capture-cost.ts/capture-fast.tsin the benchmark repo.
Found by the #315 benchmark work while comparing capture against an eliciting prompt (results9/CAPTURE-ANALYSIS.md). Related: #325, #328.
Activity
abogartz commentedon Nov 7, 2026
What can actually turn the reasoning off — measured
Two questions: does the seat honor a "stop thinking" field, and can the plugin reach it through the host?
On the seat (direct to the model server, no host in the way)
Same capture-shaped prompt, six spellings,
evo.local:8090serving Qwen3.8 Flash-Next Q4:chat_template_kwargs: {enable_thinking: false}reasoning_effort: "none"reasoning: {effort: "none"}thinking_budget_tokens: 0think: false(Ollama's field)reasoning_effort: "none"is the one to want: it is the OpenAI-standard field, it needs no backend-specific knowledge, and llama.cpp treats it as a hard per-request disable.chat_template_kwargsworks too but only where the chat template consumes it — llama.cpp #20182 and #20196 document models where it does nothing.Caveat worth keeping in view: disabling reasoning took this prompt from 3 candidates to 2. The speedup is real; the yield cost needs measuring on the benchmark before capture ships with it on.
Through the host: no route today
Verified on a live server with an instrumented plugin, not from types alone:
ctx.generate.textnever runs session hooks. Registered asession.hook("generate", …)successfully (ctx.sessionexposeshook, andSessionGenerate extends SessionContext extends SessionRequest, whoseoptionsis mutable) — the hook simply did not fire for agenerate.textcall. This is anomalyco/opencode #62096.ctx.session.generatedoes run the hook, so I setevent.options.chat_template_kwargs = {enable_thinking:false}there. It fired and the mutation was accepted, but the timing went the wrong way and the output was worse. Same capture prompt, three paths, one run:generate.textsession.generate, options untouchedsession.generate, options rewrittenThe rewrite did not disable thinking — the docs are explicit that provider options use "the selected protocol's semantic option names, not raw HTTP body fields", so a raw llama.cpp field is not forwarded. And
session.generateis not a drop-in for a stateless mine: it carries the session's own agent and history, which changed the answer (0 candidates: the model replied in character instead of emitting JSON).So: do not file a new upstream issue
This is already open, three times, and the asks are right:
generate.text./api/experimental/generateaccepts only{prompt, model}whileLLM.requestalready acceptssystem,messagesandgenerationanomalyco/opencode#49549 —/api/experimental/generateaccepts only{prompt, model}whileLLM.requestalready acceptssystem,messagesandgeneration.generate.text.The concrete ask to add to #47366 is one field: a way to pass
reasoningEffort: "none"(or an equivalent semantic option) on a transient generate call.What the plugin can do meanwhile
captureModelthat does not reason is strictly better than a cheap one that does.[ ].thinking-variants.ts(seat spellings) andprobe-capture4.sh(host paths) after any host change.Method note: the field names came from prior knowledge of llama.cpp/vLLM conventions; everything above is what the seat and the live host actually did.
abogartz commentedon Nov 7, 2026
Cost update from the #329 precision fix (#331): the added prompt rules make the capture pass more expensive, in the opposite direction from this issue.
Same capture-shaped prompt, thinking on: completion tokens 656 → 1,095, wall 11.4 s → 19.7 s (1.7×). So the two issues now pull against each other — precision costs roughly what disabling reasoning would save.
Neither offset is reachable through the host today:
reasoning_effortcannot be set from a plugin (upstream [FEATURE]: Allow provider-native options in stateless generate.text anomalyco/opencode#47366, #62096).captureModelcannot route around it either: the seat in use ignores themodelfield. All seven advertised names returned completion_tokens 694 and 1,713 reasoning characters on one prompt at temperature 0, and 202 / 0 withreasoning_effort: "none". Byte-identical counts across different architectures means one slot answered every request.One correction to my earlier comment here. I reported that thinking-off cut the prompt from 3 candidates to 2. On the fuller prompt that includes the explicit empty-array instruction, thinking-off keeps all 3. The yield cost is prompt-dependent, not guaranteed.
chore(release): 0.16.0 [skip ci]
abogartz commentedon Nov 11, 2026
The capture-pass figures here (prompt ~1,200 tokens, 1,232 completion, ~343 of it JSON) are capture-only measurements and remain the best account we have of what one pass decodes. What they are not is a session cost, and they exclude cache entirely. Read them as "one capture call", never as "what the plugin costs a session".
Cost retraction (#392). The token figure above came from
runSession().tokens = input + output + reasoning, with cache excluded and capture excluded. On this providerinputis only the uncached remainder: one run reported 13,393 of 187,856 tokens that actually moved — 7%. A metric that undercounts by 93% still produces a plausible number, and a plausible number gets quoted.Disposition: retracted as a cost claim. Do not quote it as tokens moved, saved, or spent. The stored wire logs for this run carry no provider
usageobject, so no recomputed figure exists.Corrected metric, in force:
work = session generation + capture generation, with cache read/write reported separately and never folded in. Two results survive it, both with n and seat named on #386: transport 0/5 to 5/5 (leak-checked, one seat) and reuse median 0.98x (n=6, no measurable effect).Rules now written down where contributors hit them: no cost claim below n=6 pairs per arm; a ratio at 6 <= n < 21 is labelled "20% resolution"; the word "cheaper" does not appear without an n, a seat and a metric named on the same line; no dollar figure without a hosted-provider measurement.
ocsi-triager commentedon Dec 1, 2026
Triager
Actionable — as the interim plugin-side pair the owner already ratified in this thread (truncation guard + README guidance), with the upstream ask and the live-seat re-measurement explicitly out of scope.
What survived on
6e33179, and what rottedThe mechanism is intact, verified against the installed code:
node_modules/@opencode/client/dist/effect/api/api.d.ts:1761(client 2.0.32) —GenerateTextInput = { readonly prompt: string; readonly model?: Model.Ref | undefined }. No temperature, nomaxTokens, no reasoning toggle.{ model, prompt }and nothing else:src/adapters/opencode/capture.ts:62-72—generateApi.text({ model: input.model, prompt: input.prompt }, { signal }), invoked fromsrc/runtime/capture.ts:602-609. The adjacent comment atsrc/runtime/capture.ts:611confirmsgenerate.textalso returns no usage receipt.parseCandidateskeeps only the first balanced JSON array —src/capture/candidates.ts:66, withfirstJsonArrayat:37-57and its own comment ":37-38: a model that truncates mid-array yields nothing, not garbage."src/runtime/capture.ts:1053-1058recordsrecordCaptureLagBestEffort(sid, lagMs, candidates.length ? "candidates" : "empty", …). A capped call truncated mid-reasoning and a genuine[]both land asoutcome=empty.Rotted claims, both already self-corrected by the owner in-thread:
src/capture/runtime.ts(cited in the body) no longer exists; the logic lives insrc/runtime/capture.ts+src/adapters/opencode/capture.ts.README.md:47-49(no cost claim below n=6 pairs per arm; "cheaper" never without n + seat + metric).Effect of the #603 work (
6e33179= PR #625,a132ea8+fd4f435): that change touchedsrc/host/capture.ts,src/status/metrics.ts,src/status/report.ts— plumbing that surfaces stop-reasons (auto_capture_finishreason codes,src/status/metrics.ts:313-327) into the human report. It added no model-call cost, so the ticket's timing premise is untouched. But it sharpens item 3's target: thecapture_lagoutcome value never reaches the report —src/status/metrics.ts:298-304readscapture_laglines as completion timestamps only. So a truncated pass still looks like an honest empty one even after #625; #625's report line (src/status/report.ts:232) is the established pattern should visibility beyond the evidence line ever be wanted.The unit
Four things wear number #330; two are no longer anybody's to do here. Item 1 (upstream ask) is owner-ruled shut — the 04:23 comment says "do not file a new upstream issue," the asks exist as anomalyco/opencode #47366/#49549/#62096. Item 4 (re-measure with
capture-cost.ts/capture-fast.ts) runs in the external benchmark repo against a live seat — not a unit this pipeline ships; confirmed neither file is in-tree. The owner's own comment already re-scoped the interim deliverable to what the fixer can still land in one reviewable diff, and both parts remain undone (README.md:76-80has no cost or model-choice guidance):Slice A — truncation guard (the real change). At
src/runtime/capture.ts:1053-1058, replace the boolean with a three-way outcome. The discriminator, so it need not be re-derived: a truncated call's text contains no balanced JSON array (firstJsonArray→null,src/capture/candidates.ts:37-57), while the genuine empty answer is the literal[]the prompt instructs the model to emit (src/capture/prompt.ts:54) — a found array that parses to zero items. So: candidates > 0 →"candidates"; text non-empty with no balanced array → a new distinct value (e.g."unparsed"); array found but zero items →"empty".parseCandidatesis total and cannot distinguish these itself (src/capture/candidates.ts:6-7), so the check must come from span presence at the call site, not from the returned array. Safe to extend: theoutcomeparameter is a free string (src/telemetry/record.ts:431-437), no status reader branches on its value, and no file underdocs/enumerates the current values.Slice B — README. In the auto-capture section (
README.md:76-80), state thatcaptureModelshould name a non-thinking model, and give the composition of one capture call as the owner's 2026-11-11 comment permits it — one capture call, seat named, n=1, never framed as cost, never the word "cheaper", honoringREADME.md:47-49and the #392 retraction. The ticket body's literal "state the measured cost per pass" mandates a forbidden quote; the fixer must write to the retraction, not to the body.Acceptance, checkable hermetically
test/capture/capture-parse.test.ts(parse-level) and the capture-runtime tests that already assert the lag receipt (fixtures today expect"empty"—test/status/status.test.ts:914,test/telemetry/evidence-write-policy.test.ts:132): a truncated response yields the new outcome,[]yields"empty", candidates yield"candidates".bun test test/capture test/statusgreen (package.json:76);bun x tsc --noEmit -p tsconfig.jsongreen.README.md:47-49+ the retraction rules.What the fixer is NOT on the hook for
Filing anything upstream; any live-seat or benchmark-repo measurement; surfacing the new value in
memory_status' human report (a defensible follow-on through #625's channel — out of this slice); any claim that this makes capture cheap — the speedup stays upstream-blocked, as the ticket itself says.Context the fixer needs that the body doesn't say
src/capture/runtime.ts→src/runtime/capture.ts/src/adapters/opencode/capture.ts).README.md:47-49outrank the ticket body's README wording.[]-vs-truncation discriminator is span presence infirstJsonArray, andparseCandidatesmust stay total.capture_lagoutcome is invisible to the status report by design (src/status/metrics.ts:298-304); "recorded distinctly" means the evidence line, and that is the whole acceptance bar.@architect
ocsi-architect commentedon Dec 1, 2026
Architect
Architect overview — #330, built on the triager's pass. Scope verified against
6e33179(= PR #625,a132ea8+fd4f435); every line below re-opened in the tree.The unit (unchanged from the triager's fence, confirmed still open)
Two slices, one reviewable diff:
capture_lagoutcome instead of"empty".captureModel; composition of one capture call, written to the Retract every cost claim that cannot reproduce under the corrected metric #392 retraction, not to the ticket body's wording.Out of scope, ratified: upstream ask (owner comment 2026-11-07T04:23Z: "do not file a new upstream issue"; asks live as anomalyco/opencode #47366/#49549/#62096); re-measurement with
capture-cost.ts/capture-fast.ts(external benchmark repo against a live seat; neither file is in-tree — confirmed; note the unrelated in-tree teststest/capture/capture-cost.test.ts/capture-cost-policy.test.tsexist, do not confuse them with the benchmark scripts); surfacing the new value in the human report (src/status/metrics.ts:298-304readscapture_laglines as completion timestamps only — outcome never reachessrc/status/report.ts; a report line through thereport.ts:232pattern is a deliberate follow-on, not this slice).Mechanism
The host API is the hard bound:
GenerateTextInputis{ prompt, model? }only — verified byte-identical atnode_modules/@opencode/client/dist/effect/api/api.d.ts:1761(client 2.0.32) — so the plugin cannot turn thinking off or cap output.src/adapters/opencode/capture.ts:62-72passes{ model, prompt }and nothing else (called fromsrc/runtime/capture.ts:602-609; the comment at:611confirms the response is{ text }with no usage receipt).The guard-relevant path:
src/runtime/capture.ts:633runsparseCandidates(text, captureMax); the recording atsrc/runtime/capture.ts:1054-1060collapses everything tocandidates.length ? "candidates" : "empty"— the line to edit is :1057. Bothtextandcandidatesare in scope there (same block as the parse).parseCandidates(src/capture/candidates.ts:66) is total and discards the distinction: a truncated response (no closing]) and a genuine[]both return[], becausefirstJsonArray(:39-61, comment:37-38) yieldsnullfor the former and"[]"for the latter. The prompt makes the genuine case a literal contract:src/capture/prompt.ts:149—- If nothing is worth remembering, output [ ].(plus:73"Output ONLY a JSON array…").The discriminator is therefore span presence, and it must come from a new export:
firstJsonArray(candidates.ts:39) andstripFences(:33) are module-private; onlyparseCandidates(:66) andparseModelRef(:163) are exported.Citation audit (triager → this pass)
Confirmed exact:
api.d.ts:1761;src/adapters/opencode/capture.ts:62-72;src/runtime/capture.ts:602-609and:611;candidates.ts:6-7(totality comment),:37-38(truncation comment),:66;src/status/metrics.ts:298-304(capture_lag = timestamps only);src/status/report.ts:232;README.md:47-49(cost-claim rules) andREADME.md:76-80(auto-capture section — no model-choice/cost guidance exists; the only "reasoning" mention,:80, is about transcript scrubbing);test/status/status.test.ts:914(fixtureoutcome: "empty");test/telemetry/evidence-write-policy.test.ts:132(directrecordCaptureLagBestEffort(…, "empty"));src/capture/runtime.tsabsent (moved tosrc/runtime/capture.ts+src/adapters/opencode/capture.ts).Corrected:
src/capture/prompt.ts:54→:149.:53-54is a developer comment about the contract ("anything else parses to []"); the instruction that makes a genuine empty a literal[]is at :149. The triager's reasoning stands; the fixer points tests at:149.src/runtime/capture.ts:1053-1058→:1054-1060, ternary at :1057 (1053 is the preceding block's brace).firstJsonArrayat:37-57→ function is:39-61(comment:37-38).metrics.ts:313-327reason block →:313-326(:327opensauto_capture_dispose).package.json:76defines the full-suitetestscript; the scoped acceptance commands below are variants of that runner.typecheckispackage.json:82.capture-cost.ts/capture-fast.tsin-tree" is true for scripts; two same-named tests exist undertest/capture/— unrelated, leave them alone.Slice A shape
src/capture/candidates.ts: add one exported total helper over the existing private machinery — semantics: given raw response text, does a balanced JSON array span exist (afterstripFences)? ReusefirstJsonArray; do not duplicate its scanner; do not touchparseCandidates— it stays total and behaviorally unchanged. Name is the fixer's; the contract istruefor[], fenced[], and any closed array;falsefor unclosed/truncated/no-array text.src/runtime/capture.ts:1057: three-way outcome —candidates.length > 0→"candidates"; empty/whitespace response →"empty"(the ticket scopes the guard to non-empty responses; leave the empty-text case as today); non-empty with no span → a new distinct token ("unparsed"is fine — pick one boring word, keep it clear of theauto_capture_finishreason list atmetrics.ts:316-323); span present but zero candidates →"empty"(see silences).outcomeis a plainoutcome: stringin bothrecordCaptureLag(src/telemetry/record.ts:265-270) andrecordCaptureLagBestEffort(:431-436) — no union to extend — and no reader branches on thecapture_lagoutcome (verified:metrics.ts:298-304reads onlyts; theoutcomebranches insrc/telemetry/ledger.ts:287-313are a different event).Slice B shape
README.md, auto-capture section (:76-80;captureModelis already named at:78): one composition sentence plus one guidance sentence.docs/reference/options.md:26is not edited. Hard constraints fromtest/host/claims.test.ts, which scans README + all ofdocs/with word-matching:claims.test.ts"a figure retracted in the data file never comes back"):bench/claims.jsonretracts only "20,506" and "10,009" — the capture-call figures (prompt ~1,200 tokens / ~1,232 completion / ~343 JSON) are not retracted and may appear, but only framed as one capture call, never session cost.:258-263): nosave|cut|reduce|lower|drop+ tokens + number, notokens saved/reduced/avoided/eliminated, no%/×+fewer|less|cheaper|reduction|dropwithin a sentence of "tokens" (sub-bullets are concatenated before matching).:290-293): never% fewer|less … tokenwithout the word "bytes". The title's "78%" must not be written next to "tokens".:343-356): banned outside the "Rules for any cost claim" block unless n + seat + metric share the line. Do not use the word at all; the owner's own framing is "strictly better", and a non-numbered recommendation ("prefer acaptureModelthat does not think/reason") carries no figure. The figure sentence names seat + n=1 + cache-excluded and says it is composition, not cost — honoringREADME.md:47-49and the Retract every cost claim that cannot reproduce under the corrected metric #392 disposition, which outrank the ticket body's "state the measured cost per pass".Acceptance (runnable at review)
bun test test/capture/capture-parse.test.ts— parse-level: the new helper returns span-present for[], fenced[], closed arrays; span-absent for truncated/no-array text;parseCandidatescases unchanged-green (totality preserved).bun test test/capture/capture-auto.test.ts— end-to-end three-way, following the existing pattern at:273-297(loaded.capture.generate.response = <text>→ triggersession.execution.succeeded→ wait for that session'scapture_lagline): truncated text → new token;"[]"→"empty"; candidates JSON →"candidates". Each case needs its own session id — cooldown is per session+trigger (README.md:78) and the window cursor otherwise returns before an evidence line is written.bun test test/capture test/status test/telemetry— regression: hand-written fixtures still valid (status.test.ts:914pins a fixture line,evidence-write-policy.test.ts:132calls the recorder directly with"empty", which stays a produced value; no existing runtime test asserts the outcome field — they only await line presence, so nothing there breaks).bun test test/host/claims.test.ts— required because Slice B edits README; the triager's acceptance list omitted it and this is where a wording slip lands.bun x tsc --noEmit -p tsconfig.json(script atpackage.json:82).Fail-before
Add the truncated-response case to
test/capture/capture-auto.test.tsfirst (unique session id; response like"I analyzed the session. Here are possible memories: [{\"type\":\"context\",\"scope\":\"x\",\"content\":\"…"— non-empty, no closing]). On pre-fix6e33179it records viasrc/runtime/capture.ts:1057and the assertionoutcome === "<new token>"fails withexpected "unparsed", actual "empty"— that is the fail-before line. The"[]"→"empty"case passes before and after; it exists to pin that the guard did not swallow the genuine answer. Ship the diff with the fail-before commit visible.Silences (report, do not fill beyond the stated defaults)
parseCandidatesdrops every item for validation): the ticket's literal words ("non-empty but yields zero candidates … distinctly from a genuine[]") would classify this as distinct; the span-presence shape keeps it"empty". This overview chooses"empty"— the failure the ticket names is truncation, and per-candidate refusals already write their own evidence lines — but the reviewer may overrule; do not silently invent a fourth value."empty"(ticket scopes the guard to non-empty responses).Push as
ocsi-fixer[bot]; merge stays human.@fix
abogartz-opencode-self-improvement commentedon Dec 1, 2026
🎉 This issue has been resolved in version 0.41.3 🎉
The release is available on:
Your semantic-release bot 📦🚀