Skip to content

fix(opencode): clarify review and efficient tool use, refresh native cassettes (Refs #772) - #778

Closed
agenteinstinct1-max wants to merge 2 commits into
dev-vibecodedfrom
arena/2688d42c-silvercode
Closed

agenteinstinct1-max wants to merge 2 commits into
dev-vibecodedfrom
arena/2688d42c-silvercode

Conversation

@agenteinstinct1-max

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #772

#772 stays open: this PR targets dev-vibecoded, and GitHub only auto-closes issues from PRs merged into the repository default branch (dev). The closing keyword is present to satisfy the linked-issue check in pr-standards.yml, not to close the issue.

This continues #776 (arena/6f7f66ad-silvercode, head 4c11b1b9407cf7423eeef768fcb42af9b70f0543, base a241c84e3b57c958977fd31d51cc3a30e84d341f). #776 carried the change and left it as a draft because three recorded cassettes rejected the new request body. This branch keeps #776's five files byte-identical and adds the missing cassette refresh, so it is the same change with the known-red blocker resolved. #776 is superseded by this PR; nothing here is a revert of it.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Two commits on top of a241c84e3b57c958977fd31d51cc3a30e84d341f, no history rewrite, no force-push, no rebase, no base revert.

9e09311 — #776's change, unchanged. The one shared prompt block is injected in LLMRequestPrep.prepare, so it applies to every agent, every provider and every effort level with no runtime fan-out, no effort gating, and no exemption for OAuth or fallback paths:

  • packages/opencode/src/agent/prompt/review.txt — Review may not author tests/scripts, make production edits, fix the implementation or take over Code/Work; existing non-destructive checks stay allowed. Review still evaluates premise, completion, instruction following and the Assessment/verdict envelope, including the bar on unsupported approval. Reading guidance is scope-first with batched range reads.
  • packages/opencode/src/session/prompt/efficiency.txt (new) — fast/quick/direct at every effort level; targeted searches then batched reads; independent read/grep/glob calls in parallel, dependent calls sequential.
  • packages/opencode/src/session/llm/request.ts — injects that block into the system prompt of every prepared request.
  • packages/opencode/test/session/ste-lite.test.ts — regression tests for prompt assembly across fast/medium/thorough and for the Review text contract.
  • specs/agent-effort.md — documents efficient work at every level.

26e98f8 — the cassette fix. The three native tool-loop cassettes assert the exact outgoing body, so the recorder rejected the new request before any assertion ran (Fixture "session/native-openai-oauth-tool-loop" does not match the current request: body: $.instructions expected … received …). Only the recorded request snapshots are refreshed; the recorded responses are byte-identical to what was originally recorded, which is why the tool-loop assertions (the get_weather call and "Paris is sunny") are untouched.

Why this seam and not an exemption: instructions are part of the recorded request protocol, so a request-body change must show up in the cassette. The alternatives were all worse — deleting or skipping the assertions, exempting $.instructions in the matcher, writing a test-only bypass in production code, or a paid re-record. Those are exactly the things this change must not do, so the fixture was refreshed truthfully instead.

How the cassettes were refreshed (offline, no provider contacted)

  • The new request snapshots were produced by the real recorder code path — HttpRecorderInternal.recordingLayer(cassette, { mode: "record", metadata, redactor: Redactor.make(redact) }) with the same url/body redactor and metadata the replay path uses — driven by the same test stack (Provider.node + LLM.node, real RequestExecutor, real LLM.stream, the same weather tool and tool loop). The bodies are what this code actually sends, not hand-written text.
  • That layer's upstream was a stub HttpClient that replayed the existing recorded response bytes in order, so no network call and no credential were used. The stub only fed back the original responses; it did not alter the request.
  • Before writing, the harness asserted the replays were unmodified: for each interaction the replayed response equals the original after transport decoding (the openai-oauth bodies are SSE and were compared text-to-text), and status, headers, method and URL are unchanged. Response objects were then left exactly as recorded.
  • metadata.recordedAt is preserved (the responses are the originals) and two fields are added — requestBodiesRecapturedAt and requestBodiesRecapturedFrom: "replayed-recorded-responses" — so provenance is explicit instead of a cassette silently claiming to be newer. A future live re-record drops them automatically, because the test's metadata does not contain them.
  • Diff per cassette: two request bodies plus the two metadata lines. The cassette format, the matcher, the ordering rules and every assertion are untouched.

Honest limits of the offline refresh

  • The response bytes were produced by the provider under the old prompt. The openai-responses stream echoes instructions inside its response objects, so that echo still shows the pre-change prompt even though the adjacent request now carries the new one. Rewriting the echo would fabricate provider output, so it is left as recorded.
  • A live re-record with RECORD=true plus OPENCODE_RECORD_* credentials (documented in llm-native-recorded.test.ts) remains the preferred refresh and clears that inconsistency. This PR's alternative — leaving three cassettes red — cannot be merged.
  • session/native-openai-tool-loop is still skipped: that cassette has never existed in the repo, so the "OpenAI API key" scenario skips rather than exercises the API-key path.

Scope

git diff a241c84 HEAD is exactly these eight paths, and every other tracked file matches the accepted tip byte for byte:

packages/opencode/src/agent/prompt/review.txt
packages/opencode/src/session/llm/request.ts
packages/opencode/src/session/prompt/efficiency.txt
packages/opencode/test/fixtures/recordings/session/native-anthropic-tool-loop.json
packages/opencode/test/fixtures/recordings/session/native-openai-oauth-tool-loop.json
packages/opencode/test/fixtures/recordings/session/native-zen-tool-loop.json
packages/opencode/test/session/ste-lite.test.ts
specs/agent-effort.md

Three fixture files beyond #776's five is the honest minimum: without them the change cannot be tested at all, and no code file was widened. Deliberately excluded: the four win-owner-death files from #773, the two TUI files #773 silently reverted, packages/opencode/src/session/llm.ts, and src/session/prompt.ts (owned by draft #770). specs/agent-effort.md is also edited by #770, so that documentation overlap still needs reconciling before integration.

How did you verify your code works?

Linux sandbox, 2 vCPU / 3 GB RAM. Bun 1.3.14 installed outside the repo; bun install --frozen-lockfile --ignore-scripts.

  • The three cassettes — bun test test/session/llm-native-recorded.test.ts: 3 pass, 1 skip, 0 fail, 24 assertions.
  • Causal control (mutant) — restoring only request.ts to a241c84 turns all three red again with the same $.instructions / $.input[0].content mismatch, then the tree was restored and re-verified clean. The fixtures therefore track the injection instead of being loosened to accept it.
  • Mutant control on the new test — with the production injection reverted, ste-lite.test.ts fails with Expected to contain: "Be fast, quick, and direct at every effort level"; it detects the change rather than passing vacuously.
  • Focused prompt tests — bun test test/session/ste-lite.test.ts test/agent/agent.test.ts test/session/system.test.ts test/session/review-specialization.test.ts test/session/llm-native-recorded.test.ts: 115 pass, 2 skip, 0 fail, 458 assertions.
  • Full session directory — bun test test/session: 865 pass, 8 skip, 1 todo, 0 fail across 36 files. fix(opencode): clarify review and efficient tool use (Refs #772) #776 reported 860 pass / 5 fail on the same directory; all five now pass, including the two it had flagged as pre-existing (session.processor model-switch during retry > … cancels retry promptly timing assertion and the order-sensitive session.llm.stream > sends temperature, tokens, and reasoning options for openai-compatible models). Both were also re-run in isolation here and passed, but they were genuinely flaky at fix(opencode): clarify review and efficient tool use (Refs #772) #776's head, so treat them as such rather than as fixed by this change.
  • Formatting / hygiene — prettier --check clean on the changed JSON, TS and spec files (the two .txt prompts have no parser, which is expected); git diff --check reports no whitespace errors; all three cassettes parse as JSON and their request bodies parse as JSON.
  • Typecheck — not verified on this head. No TypeScript file is modified beyond fix(opencode): clarify review and efficient tool use (Refs #772) #776's own diff, so this inherits fix(opencode): clarify review and efficient tool use (Refs #772) #776's tsc --noEmit exit 0. In this sandbox tsc --noEmit aborts with OOM (exit 134) and tsgo is SIGKILLed, at 3 GB with no swap; that is environmental, and I am not claiming a typecheck I did not get.

No CI run on this exact commit and no independent review is claimed. The tests exercise prompt assembly, cassette replay and text contracts, not model compliance in live use.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

agenteinstinct1-max and others added 2 commits November 1, 2026 06:24
Scoped replacement for #773, whose diff carried four unrelated Windows
owner-death test/fixture files and reverted two accepted TUI files because it
was based on a pre-a241c84 commit. This branch starts from the accepted tip
a241c84 and carries only the five owned
files: review.txt, session/llm/request.ts, session/prompt/efficiency.txt,
test/session/ste-lite.test.ts and specs/agent-effort.md.

Refs #772

Co-authored-by: arena-agent <[email protected]>
…iency prompt (Refs #772)

The shared efficient-tool-use block is injected in LLMRequestPrep.prepare, so
every provider request body carries it. The three native tool-loop cassettes
assert the exact outgoing body, so they rejected the new request before any
assertion ran (deterministically, on Linux and Windows alike).

This refreshes only the recorded *request* snapshots of those three cassettes
and leaves the recorded *responses* byte-identical:

- The snapshots were produced by the real recorder code path
  (HttpRecorderInternal.recordingLayer, mode "record", same url/body redactor
  and metadata the replay path uses), so the body, headers and URL are exactly
  what the current stack sends - not hand-written text.
- That recording layer ran against a stub upstream that replayed the existing
  recorded response bytes in order, so no provider was contacted and no
  credentials were used. Responses are unmodified, which is why the tool-loop
  assertions (get_weather call, "Paris is sunny") are unchanged.
- metadata keeps the original recordedAt (the responses are the originals) and
  adds requestBodiesRecapturedAt/requestBodiesRecapturedFrom so the provenance
  is explicit rather than a cassette that silently claims to be newer.

The diff per file is therefore the two request bodies plus two metadata lines.

Causal control: restoring packages/opencode/src/session/llm/request.ts to the
pre-change content makes all three cassettes fail again with the same
"$.instructions"/"$.input[0].content" mismatch, so the fixtures track the
injection instead of being loosened to accept it. The matcher, the assertions
and the cassette format are untouched. A live re-record with
OPENCODE_RECORD_* credentials remains the preferred refresh once available.

Refs #772

Co-authored-by: arena-agent <[email protected]>
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant