Skip to content

A capture pass spends 78% of its time generating reasoning it discards; generate.text exposes no generation options #330

Done

Description

@abogartz

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

  1. Upstream: ask for generation options on generate.text (at minimum temperature, maxTokens, and a reasoning/thinking toggle). Until then the plugin cannot make capture cheap.
  2. Interim, in the README's auto-capture section: state the measured cost per pass, and say that captureModel should name a non-thinking model — a cheap model that reasons is slower and costlier than a bigger one that does not.
  3. Guard the truncation path: if a capture response is non-empty but yields zero candidates, record that distinctly from a genuine [ ] (today both land as outcome=empty), so a capped model call is visible.
  4. Re-measure after any change with capture-cost.ts / capture-fast.ts in the benchmark repo.

Found by the #315 benchmark work while comparing capture against an eliciting prompt (results9/CAPTURE-ANALYSIS.md). Related: #325, #328.

Activity

  1. added
    enhancement
    on Nov 7, 2026
  2. abogartz commented on Nov 7, 2026

    @abogartz
    OwnerAuthor

    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:8090 serving Qwen3.8 Flash-Next Q4:

    body field wall completion reasoning chars parsed
    baseline 8.5 s 536 1,245 3 candidates
    chat_template_kwargs: {enable_thinking: false} 2.1 s 134 0 2 candidates
    reasoning_effort: "none" 1.9 s 134 0 2 candidates
    reasoning: {effort: "none"} 8.5 s 536 1,245 ignored
    thinking_budget_tokens: 0 2.6 s 186 0 3 candidates
    think: false (Ollama's field) 8.2 s 536 1,245 ignored

    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_kwargs works 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.text never runs session hooks. Registered a session.hook("generate", …) successfully (ctx.session exposes hook, and SessionGenerate extends SessionContext extends SessionRequest, whose options is mutable) — the hook simply did not fire for a generate.text call. This is anomalyco/opencode #62096.

    • ctx.session.generate does run the hook, so I set event.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:

      path ms candidates
      generate.text 9,323 (the normal capture result, promoted)
      session.generate, options untouched 15,036 1
      session.generate, options rewritten 23,574 0

      The 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.generate is 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:

    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

    1. README: name the measured cost per pass, and say a captureModel that does not reason is strictly better than a cheap one that does.
    2. Keep the truncation guard from this issue's work list: a non-empty response that yields zero candidates must be recorded distinctly from a genuine [ ].
    3. Re-measure with thinking-variants.ts (seat spellings) and probe-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.

  3. abogartz commented on Nov 7, 2026

    @abogartz
    OwnerAuthor

    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_effort cannot be set from a plugin (upstream [FEATURE]: Allow provider-native options in stateless generate.text anomalyco/opencode#47366, #62096).
    • captureModel cannot route around it either: the seat in use ignores the model field. All seven advertised names returned completion_tokens 694 and 1,713 reasoning characters on one prompt at temperature 0, and 202 / 0 with reasoning_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.

  4. abogartz commented on Nov 11, 2026

    @abogartz
    OwnerAuthor

    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 provider input is 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 usage object, 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.

  5. added
    capture
    severity:medium
    on Nov 14, 2026
  6. added
    tier:standard
    on Nov 23, 2026
  7. ocsi-triager commented on Dec 1, 2026

    @ocsi-triager

    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 rotted

    The mechanism is intact, verified against the installed code:

    • The host bound is byte-identical to the ticket's quote, same line number: 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, no maxTokens, no reasoning toggle.
    • The call site is still { model, prompt } and nothing else: src/adapters/opencode/capture.ts:62-72 — generateApi.text({ model: input.model, prompt: input.prompt }, { signal }), invoked from src/runtime/capture.ts:602-609. The adjacent comment at src/runtime/capture.ts:611 confirms generate.text also returns no usage receipt.
    • Discarding the reasoning is real: parseCandidates keeps only the first balanced JSON array — src/capture/candidates.ts:66, with firstJsonArray at :37-57 and its own comment ":37-38: a model that truncates mid-array yields nothing, not garbage."
    • The ticket's central gap, item 3, still holds exactly: src/runtime/capture.ts:1053-1058 records recordCaptureLagBestEffort(sid, lagMs, candidates.length ? "candidates" : "empty", …). A capped call truncated mid-reasoning and a genuine [] both land as outcome=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 in src/runtime/capture.ts + src/adapters/opencode/capture.ts.
    • The title's 78 %/2,430-token figures are single-run (n=1) and predate fix(capture): stop storing the session's own brief as a durable memory (#329) #331; the owner's 2026-11-07T04:49Z comment measured the prompt rules making a pass 1.7× more expensive, and the 2026-11-11T18:46Z comment retracted the token figure as a cost claim — quotable only as the composition of "one capture call", never as cost. The measurement-hygiene rules are now in-tree at 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 touched src/host/capture.ts, src/status/metrics.ts, src/status/report.ts — plumbing that surfaces stop-reasons (auto_capture_finish reason 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: the capture_lag outcome value never reaches the report — src/status/metrics.ts:298-304 reads capture_lag lines 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-80 has 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". parseCandidates is 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: the outcome parameter is a free string (src/telemetry/record.ts:431-437), no status reader branches on its value, and no file under docs/ enumerates the current values.

    Slice B — README. In the auto-capture section (README.md:76-80), state that captureModel should 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", honoring README.md:47-49 and 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

    • New/extended tests in 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/status green (package.json:76); bun x tsc --noEmit -p tsconfig.json green.
    • Reviewer reads the README delta against 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

    1. Paths moved (src/capture/runtime.ts → src/runtime/capture.ts / src/adapters/opencode/capture.ts).
    2. The Retract every cost claim that cannot reproduce under the corrected metric #392 retraction + README.md:47-49 outrank the ticket body's README wording.
    3. The genuine-[]-vs-truncation discriminator is span presence in firstJsonArray, and parseCandidates must stay total.
    4. capture_lag outcome 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.
    5. Test trap for capture-runtime tests: each case needs its own session id or the window cursor returns before any evidence line is written.

    @architect

  8. ocsi-architect commented on Dec 1, 2026

    @ocsi-architect

    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:

    • Slice A — truncation guard: a capture response that contains no balanced JSON array records a distinct capture_lag outcome instead of "empty".
    • Slice B — README auto-capture guidance: prefer a non-thinking 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 tests test/capture/capture-cost.test.ts / capture-cost-policy.test.ts exist, do not confuse them with the benchmark scripts); surfacing the new value in the human report (src/status/metrics.ts:298-304 reads capture_lag lines as completion timestamps only — outcome never reaches src/status/report.ts; a report line through the report.ts:232 pattern is a deliberate follow-on, not this slice).

    Mechanism

    The host API is the hard bound: GenerateTextInput is { prompt, model? } only — verified byte-identical at node_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-72 passes { model, prompt } and nothing else (called from src/runtime/capture.ts:602-609; the comment at :611 confirms the response is { text } with no usage receipt).

    The guard-relevant path: src/runtime/capture.ts:633 runs parseCandidates(text, captureMax); the recording at src/runtime/capture.ts:1054-1060 collapses everything to candidates.length ? "candidates" : "empty" — the line to edit is :1057. Both text and candidates are 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 [], because firstJsonArray (:39-61, comment :37-38) yields null for 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) and stripFences (:33) are module-private; only parseCandidates (:66) and parseModelRef (: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-609 and :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) and README.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 (fixture outcome: "empty"); test/telemetry/evidence-write-policy.test.ts:132 (direct recordCaptureLagBestEffort(…, "empty")); src/capture/runtime.ts absent (moved to src/runtime/capture.ts + src/adapters/opencode/capture.ts).

    Corrected:

    1. src/capture/prompt.ts:54 → :149. :53-54 is 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.
    2. src/runtime/capture.ts:1053-1058 → :1054-1060, ternary at :1057 (1053 is the preceding block's brace).
    3. firstJsonArray at :37-57 → function is :39-61 (comment :37-38).
    4. metrics.ts:313-327 reason block → :313-326 (:327 opens auto_capture_dispose).
    5. package.json:76 defines the full-suite test script; the scoped acceptance commands below are variants of that runner. typecheck is package.json:82.
    6. "Neither capture-cost.ts/capture-fast.ts in-tree" is true for scripts; two same-named tests exist under test/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 (after stripFences)? Reuse firstJsonArray; do not duplicate its scanner; do not touch parseCandidates — it stays total and behaviorally unchanged. Name is the fixer's; the contract is true for [], fenced [], and any closed array; false for 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 the auto_capture_finish reason list at metrics.ts:316-323); span present but zero candidates → "empty" (see silences).
    • Plumbing is free: outcome is a plain outcome: string in both recordCaptureLag (src/telemetry/record.ts:265-270) and recordCaptureLagBestEffort (:431-436) — no union to extend — and no reader branches on the capture_lag outcome (verified: metrics.ts:298-304 reads only ts; the outcome branches in src/telemetry/ledger.ts:287-313 are a different event).

    Slice B shape

    README.md, auto-capture section (:76-80; captureModel is already named at :78): one composition sentence plus one guidance sentence. docs/reference/options.md:26 is not edited. Hard constraints from test/host/claims.test.ts, which scans README + all of docs/ with word-matching:

    • Retracted-figure scan (claims.test.ts "a figure retracted in the data file never comes back"): bench/claims.json retracts 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.
    • Token-saving regex (:258-263): no save|cut|reduce|lower|drop + tokens + number, no tokens saved/reduced/avoided/eliminated, no %/× + fewer|less|cheaper|reduction|drop within a sentence of "tokens" (sub-bullets are concatenated before matching).
    • Percentage+tokens rule (:290-293): never % fewer|less … token without the word "bytes". The title's "78%" must not be written next to "tokens".
    • "cheaper" (: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 a captureModel that does not think/reason") carries no figure. The figure sentence names seat + n=1 + cache-excluded and says it is composition, not cost — honoring README.md:47-49 and 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".
    • No issue numbers, dates, or investigation narration in shipped strings.

    Acceptance (runnable at review)

    1. 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; parseCandidates cases unchanged-green (totality preserved).
    2. 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> → trigger session.execution.succeeded → wait for that session's capture_lag line): 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.
    3. bun test test/capture test/status test/telemetry — regression: hand-written fixtures still valid (status.test.ts:914 pins a fixture line, evidence-write-policy.test.ts:132 calls 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).
    4. 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.
    5. bun x tsc --noEmit -p tsconfig.json (script at package.json:82).

    Fail-before

    Add the truncated-response case to test/capture/capture-auto.test.ts first (unique session id; response like "I analyzed the session. Here are possible memories: [{\"type\":\"context\",\"scope\":\"x\",\"content\":\"…" — non-empty, no closing ]). On pre-fix 6e33179 it records via src/runtime/capture.ts:1057 and the assertion outcome === "<new token>" fails with expected "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)

    • Closed-but-all-rejected array (span found, parseCandidates drops 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.
    • Whitespace-only response: stays "empty" (ticket scopes the guard to non-empty responses).
    • Token naming: no spec constraint; any distinct value satisfies the ticket.
    • Yield parity of thinking-off: per the owner's own correction, it is prompt-dependent; Slice B must not promise identical candidates from a non-thinking model.
    • Nothing here makes capture cheap; the speedup stays upstream-blocked and the diff must not imply otherwise.

    Push as ocsi-fixer[bot]; merge stays human.

    @fix

  9. abogartz-opencode-self-improvement commented on Dec 1, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.41.3 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

    captureenhancementreleasedseverity:mediumtier:standard

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions