Skip to content

spike(opencode): does opencode run --command <phase> load the sequant skill? (#862 P0 precondition, resolves OQ-8/OQ-9) #992

Closed

Description

@admarble

Epic: M0 Blocked by: — Tier: judgment Doc: docs/internal/graph-2026-09/PLAN.md §4 (opencode seam), §5 I-3, I-8, §7 D7, §9 OQ-8/OQ-9, docs/internal/graph-2026-09/lab-notes-phase0.md §1

Why

#862's stated load-bearing unknown (Risk 1) is whether the model actually
loads .claude/skills/<phase>/SKILL.md when a .opencode/commands/<phase>.md
wrapper asks it to. The 09-03→06 field run proved transport, not skills. The
driver (#862 (node 12)) must be built against an observed contract and a recorded
fixture, not an imagined one.

Scope

  • may touch: docs/investigations/opencode-driver-spike.md, src/lib/workflow/drivers/__fixtures__/opencode-run-*.ndjson (recorded real output, secrets scrubbed), a throwaway scratch worktree of this repo (deleted before the PR)
  • not in scope: any src/ change; any driver code; the hook shim.

Preconditions

  • AC-0: an opencode provider key is present in the environment — Verify: opencode --version → 1.18.27 or newer, and the spike doc records the model id used and its $ (I-8). Without a key, the node stops and reports; it does not guess.

Acceptance criteria

  • AC-1: skill-load observed or refuted — Verify: grep -cE 'SEQUANT_QA_VERDICT|### Verdict' src/lib/workflow/drivers/__fixtures__/opencode-run-qa.ndjson ≥ 1 for a run of opencode run --command qa <issue> --format json --auto --dir <scratch worktree> with a wrapper .opencode/commands/qa.md that instructs loading the qa skill; if the count is 0 after two wrapper phrasings, the doc's verdict line reads KILL and names what the model did instead.
  • AC-2: NDJSON event inventory — Verify: jq -r '.type' src/lib/workflow/drivers/__fixtures__/opencode-run-qa.ndjson | sort -u is pasted into the doc and includes at least text and step_finish; every event type seen has a one-line description of its payload.
  • AC-3: the three field-run traps have a recorded mitigation — Verify: the doc has a table with rows 32K step clamp, /tmp permission kill, process-group kill, each with the exact config or spawn option that mitigated it (OPENCODE_CONFIG_CONTENT payload; allow rule or scratch relocation; detached + group kill) and the command that reproduced it — or, where the trap could not be provoked on the pinned opencode version, the controlling command that refuted it and the version it was tried on (amended 2026-09-07 per PLAN §9 OQ-19: the spike disproved the /tmp kill on 1.18.27 and could not provoke the clamp in three controls; a refutation with its command is the deliverable, not a failure).
  • AC-4: go/no-go posted — Verify: gh issue view 862 --comments | grep -c 'Spike verdict: GO\|Spike verdict: KILL' ≥ 1, and the comment lists which feat: add opencode agent driver — first backend that can inherit the full skill methodology #862 P0 ACs change as a result (e.g. reasoning-budget field in run.opencode).
  • AC-5: cost recorded — Verify: the doc's cost table has $ and wall time per run; total under $5.

Done when

#862 has a spike verdict with a committed real NDJSON fixture and a mitigation table, so #862 (node 12) can be specified against observed behavior.


Part of #862. Planned by /graph-plan 2026-09-06; run with /graph-run. Plan: docs/internal/graph-2026-09/PLAN.md, graph: docs/internal/graph-2026-09/issue-graph.md, node file: docs/internal/graph-2026-09/issues/06-*.md.

Activity

  1. added
    graph-2026-09
    on Sep 7, 2026
  2. admarble commented on Sep 7, 2026

    @admarble
    ContributorAuthor

    Runner context (graph-run, 2026-09-06): the plan for this graph is on PR #998 (branch docs/graph-plan-2026-09), not yet on main. Read it from the branch, not the working tree:

    git show origin/docs/graph-plan-2026-09:docs/internal/graph-2026-09/PLAN.md
    git show origin/docs/graph-plan-2026-09:docs/internal/graph-2026-09/issues/NODE-FILE.md
    

    PLAN §5 invariants are binding here: I-4 (hook/skill copies byte-identical: md5 -q a b c | uniq | wc -l → 1), I-5 (gate tests ship a Mutation-verified: record in the PR body), I-6 (stop at PR — never gh pr merge, never close the issue), I-9 (run the Verify commands verbatim; never reason an AC done). Base is main 20e2a867 (v2.13.1); no code drift from the plan base c3c1b0a8 beyond the version bump. Stay inside the may touch list in the node file.

    Node file: issues/06-NEW-opencode-skill-load-spike.md.

    AC-0 precondition (verified by the runner): OPENROUTER_API_KEY is present in the harness process environment; opencode auth list shows 0 stored credentials and only the OpenRouter/Perplexity env keys. Use an OpenRouter-routed model id (list them with opencode models) and record the exact id and $ per run (I-8). Hard cost cap: total under $5 (AC-5) — stop and record KILL/partial rather than exceed it. No src/ changes; the scratch worktree is deleted before the PR; fixture output has secrets scrubbed.

  3. admarble commented on Sep 7, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (5 ACs + 1 precondition, 2 directories)

    AC Quality Check

    lintAcceptanceCriteria — 5/5 pass, 0 flagged. Every AC carries an executable Verify: command. No vague/unmeasurable/open-ended patterns.

    Two notes:

    • No AC declares an Evidence: field, so extractAcceptanceCriteria infers verificationMethod: manual for all five. Correct here (this is a spike; evidence is recorded command output, not a test run) — but it means no testgen phase and QA must run the Verify: commands verbatim (I-9).
    • detectBehaviorRule: 0/5 trigger → no Rule Touchpoints section.

    Scope Assessment

    Non-Goals: ⚠️ No literal Non-Goals heading — the parser missed the - not in scope: line under ## Scope, which does bound scope correctly. Parser-literal miss, not a real scope gap.

    Metric Value Status
    Feature count 1 ✅
    AC items 5 ✅
    Directory spread 2 ✅

    Verdict: ⚠️ SCOPE_WARNING — triggered solely by the missing Non-Goals heading. All three metrics green. shouldEnableQualityLoop → false.

    In-flight conflicts: none. 9 live worktrees scanned; zero touch drivers/ or docs/investigations/. Both deliverables are new files. A worktree for this issue already exists (feature/992-spike-opencode-...) — /spec did not create one and none is needed for planning.


    Free findings that change the plan (probed this session, $0)

    F1 — Skill discovery is already proven; only invocation needs a paid run. opencode debug skill (local, no model call) returns 25 skills, including:

    qa    /Users/tony/Projects/sequant/.claude/skills/qa/SKILL.md
    

    All 20 sequant project skills resolve, plus 5 from ~/.claude/skills/. opencode holds the full body: 173,010 chars vs 174,981 on disk (delta = stripped frontmatter) — ~43K tokens injected per skill load. This splits OQ-8 in two: (a) discovery/resolution = PASS at $0, (b) does the model actually call the skill tool when a wrapper asks — still the paid question. Record (a) as the doc's baseline; spend only on (b).

    F2 — The global config contaminates every run. opencode debug config in this repo resolves ~/.config/opencode/opencode.jsonc, which already carries the 32K-clamp mitigation (z-ai/glm-5.3-flash → options.reasoning.max_tokens: 20000). If the spike runs that model, AC-3's mitigation will appear to work for a reason the driver cannot ship, and the fixture is not reproducible for anyone else. Build the config explicitly via OPENCODE_CONFIG_CONTENT and record opencode debug config before/after. (--pure disables plugins, not config.)

    F3 — AC-1's grep is necessary but not sufficient. ### Verdict: is guessable: the wrapper names the qa phase, and the verdict vocabulary leaks from the issue. A model that never loaded the skill can emit it — which is precisely #862 Risk 1 ("silently laundering a low-fidelity review"). A fixture that passes on the grep alone cannot support #862 AC-4's skill-not-loaded error. See Derived ACs.

    F4 — Cost accounting. opencode stats is cumulative ($0.71 already banked from 9 prior sessions). AC-5 needs per-run figures: take a stats delta around each run, or read step_finish payloads. Do not count the banked $0.71 against the $5 cap.

    F5 — No timeout/gtimeout on this machine. Bounding the paid run needs a perl -e 'alarm'/node wrapper. Redirect NDJSON to a file, never a pipe (background + pipe yields empty output).


    Acceptance Criteria

    AC-0 (precondition): opencode present and provider key available

    Verification: Manual (command output) — already satisfied: opencode --version → 1.18.27 (meets floor); opencode auth list → 0 stored credentials, OPENROUTER_API_KEY present in env.
    Scenario: Given the harness env → When opencode --version and opencode auth list run → Then version ≥ 1.18.27 and a provider key is listed; otherwise stop and report, do not guess.
    Assumptions: The key remains valid at run time; model id + $ are recorded per I-8.

    AC-1: skill-load observed or refuted

    Verification: Integration Test (recorded real output)
    Scenario: Given a scratch worktree with .opencode/command[s]/qa.md instructing a qa skill load → When opencode run --command qa <issue> --format json --auto --dir <scratch> runs → Then grep -cE 'SEQUANT_QA_VERDICT|### Verdict' …/opencode-run-qa.ndjson ≥ 1; if 0 after two wrapper phrasings, the doc's verdict line reads KILL and names what the model did instead.
    Assumptions: The QA target has a real diff to review; the model tier is recorded (see OQ-1); the grep is corroborated per AC-6.

    AC-2: NDJSON event inventory

    Verification: Integration Test
    Scenario: Given the recorded fixture → When jq -r '.type' … | sort -u runs → Then its output is pasted into the doc, includes at least text and step_finish, and every listed type has a one-line payload description.
    Assumptions: --format json emits one JSON object per line for the whole session (unproven — a non-NDJSON envelope is a live possibility to record, not assume).

    AC-3: the three field-run traps have a recorded mitigation

    Verification: Manual (doc table) + Integration (repro commands)
    Scenario: Given the doc → When read → Then a table has rows 32K step clamp, /tmp permission kill, process-group kill, each with the exact config or spawn option that mitigated it (OPENCODE_CONFIG_CONTENT payload; allow rule or scratch relocation; detached + group kill) and the command that reproduced it.
    Assumptions: Reproducing the clamp requires running without the global mitigation (F2). Traps came from a confidential third-party project — the doc and the #862 comment stay anonymized; record behavior, never the source project.

    AC-4: go/no-go posted

    Verification: Integration Test
    Scenario: Given the spike concluded → When gh issue view 862 --comments | grep -c 'Spike verdict: GO\|Spike verdict: KILL' runs → Then ≥ 1, and the comment lists which #862 P0 ACs change (e.g. a reasoning-budget field in run.opencode).
    Assumptions: Posting to #862 is an outward-facing write on a live issue — intended by the AC, but it lands under the user's account.

    AC-5: cost recorded

    Verification: Manual (doc table)
    Scenario: Given the doc → When the cost table is read → Then it has $ and wall time per run and a total under $5.
    Assumptions: Per-run cost comes from a stats delta or step_finish, not raw opencode stats (F4).


    Implementation Plan

    Phase 1 — Free ground truth (no spend)

    1. From inside the scratch worktree (not the main checkout), run opencode debug skill and confirm qa resolves to <scratch>/.claude/skills/qa/SKILL.md. Worktrees have a .git file, not a directory — feat: add opencode agent driver — first backend that can inherit the full skill methodology #862's "walks up to the git worktree root" claim is untested against exactly that shape. Record the result either way.
    2. Resolve the command-dir convention: the binary contains both .opencode/command and .opencode/commands. Probe with a nonexistent command name first (fails before any model call, $0), then confirm which directory the real name loads from.
    3. Snapshot opencode debug config, then author an explicit OPENCODE_CONFIG_CONTENT payload so no global state leaks into the fixture (F2).
    4. Pick the QA target: a merged issue whose PR has a small diff, checked out so git diff origin/main...HEAD is non-empty. Small diff = cheap run.

    Phase 2 — Guardrails before spending

    1. Permission deny rules are mandatory. --auto auto-approves everything not explicitly denied, and the qa skill's own template ends by posting a GitHub comment and editing labels. Deny gh issue comment, gh issue edit, gh pr *, git push, git commit in the config payload — otherwise a paid run mutates a live issue. This also exercises the permission surface AC-3 needs.
    2. Spawn discipline: detached process group, NDJSON → file, wall-clock bound via perl -e 'alarm' (F5), stats delta captured before/after each run with a hard stop before $5.

    Phase 3 — The paid runs (≤ $5 total)

    1. Run A: wrapper phrasing 1, model per OQ-1. Capture NDJSON.
    2. Evaluate three independent skill-load signals: (i) the AC-1 grep; (ii) a tool-call event in the stream naming the qa skill; (iii) a low-salience canary phrase copied from deep inside qa/SKILL.md and absent from the wrapper.
    3. If (i) = 0, run B with phrasing 2 (AC-1 allows exactly two), then write GO or KILL naming what the model did instead.
    4. Scrub the fixture (API keys, absolute paths, any third-party residue) → commit as src/lib/workflow/drivers/__fixtures__/opencode-run-qa.ndjson. Sibling precedent exists: src/lib/workflow/__fixtures__/.

    Phase 4 — Record and report

    1. Write docs/investigations/opencode-driver-spike.md: verdict line, F1 discovery baseline, event inventory (AC-2), trap/mitigation table (AC-3), cost table (AC-5), model id and $ (AC-0/I-8).
    2. Post Spike verdict: GO|KILL on feat: add opencode agent driver — first backend that can inherit the full skill methodology #862 listing which P0 ACs change (AC-4), anonymized.
    3. Delete the scratch worktree, open the PR with only the doc and the fixture. Stop at PR — no merge, no issue close (I-6).

    Design Review

    1. Where does this logic belong? Nowhere in src/ — this is an observation node. Its entire output is a doc plus a recorded fixture that feat: add opencode agent driver — first backend that can inherit the full skill methodology #862 (node 12) consumes as its parser input (I-3: real recorded output, never a mock certifying a happy path).
    2. What's the simplest correct approach? Prove discovery for free (F1), then spend on exactly one question — invocation — with at most two wrapper phrasings. Rejected: building any part of the driver to "test" the contract; rejected: a full sequant run through opencode (an order of magnitude more spend for the same one bit).
    3. What existing pattern does this follow? docs/investigations/*.md (5 existing) for the write-up; src/lib/**/__fixtures__/ for recorded input. Both established.
    4. What would a senior reviewer challenge? "Your grep proves nothing" — F3, answered by AC-6. And "was the KILL the model's fault or opencode's?" — answered only if the model id and tier are recorded per run and the decisive attempt isn't run on the cheapest model available (OQ-1).

    Feature Quality Planning

    • Side-effect hazard (highest risk in this node). A --auto run of the qa skill with gh on PATH can post a real comment and edit labels on a live issue. Plan step 5 is not optional.
    • Reproducibility. Without F2's explicit config, the fixture records the user's machine, not opencode.
    • Confidentiality. AC-3's traps originate in a third-party project the user asked to keep unnamed. Behavior yes, attribution no.
    • Attribution of a KILL. A cheap-model KILL is a statement about the model, not about opencode. Record the tier.

    Derived ACs

    Source Derived AC Priority
    F3 / #862 AC-4 AC-6: the doc records all three skill-load signals (grep, skill tool-call event, canary phrase absent from the wrapper), not the grep alone — so the fixture can drive #862's skill-not-loaded error High
    F2 AC-7: the doc records the exact OPENCODE_CONFIG_CONTENT used and states whether ~/.config/opencode/opencode.jsonc was in effect for each run Medium

    These are proposals, not adopted scope — say the word and they go on the issue body.


    Open Questions

    1. Which model for the decisive run? — Recommendation: a mid-tier OpenRouter model (e.g. openrouter/anthropic/claude-sonnet-*) for run A, then one cheap-model run to record degradation if budget allows. Impact if wrong: a cheap-model KILL is unattributable and the spike answers nothing while still spending.
    2. src/ scope tension. may-touch grants src/lib/workflow/drivers/__fixtures__/*.ndjson; not-in-scope says "any src/ change". — Recommendation: read not-in-scope as "no .ts"; land the fixture as granted (.ndjson is outside tsconfig's compile surface; src/lib/workflow/__fixtures__/ is precedent). Impact if wrong: the fixture moves to __tests__/fixtures/ and feat: add opencode agent driver — first backend that can inherit the full skill methodology #862 AC-1's path changes.
    3. Which issue is the QA target? — Recommendation: a recently merged issue with a small diff. Impact if wrong: an oversized diff burns the budget on a run whose only load-bearing output is one grep.
    4. Adopt AC-6/AC-7? — Recommendation: adopt AC-6 (it is what makes the fixture usable downstream); AC-7 is cheap and can ride along.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: No testgen — all five ACs are manual/command-output with no code stubs to generate. No test — no UI. Quality loop off: a KILL verdict is a legitimate terminal outcome, not a defect to iterate on, and the $5 cap makes re-runs expensive; shouldEnableQualityLoop also returns false (the SCOPE_WARNING is only the missing Non-Goals heading). PLAN tiers this node judgment — run exec on the strong-model flip, not the sonnet/medium default in .sequant/settings.json. QA must execute every Verify: command verbatim (I-9), including re-running the greps against the committed fixture.


    Label Review

    Current: graph-2026-09
    Recommended: graph-2026-09, planned, no-browser-test
    Reason: planned marks phase-1 completion; no-browser-test states explicitly that a spike producing a doc and an NDJSON fixture has no UI surface. No enhancement — nothing ships to users from this node.
    Quality Loop: Won't auto-enable — shouldEnableQualityLoop is false despite SCOPE_WARNING, since the warning is a missing heading, not scope.

    → gh issue edit 992 --add-label planned --add-label no-browser-test

  4. added
    planned
    no-browser-test
    on Sep 7, 2026
  5. admarble commented on Sep 7, 2026

    @admarble
    ContributorAuthor

    Runner context (exec re-dispatch, 2026-09-07): the previous exec session for this issue was killed by the harness at 30 minutes of wall time (a hard no-progress ceiling on the launcher; it is not a credit or rate-limit problem, whatever the state says). The worktree survived with whatever was committed or left in the tree. This session has the same 30-minute ceiling. Work so it survives being cut off:

    1. Start by reading git log --oneline origin/main..HEAD and git status in the worktree and continue from the existing work — do not restart or re-derive.
    2. Commit a working increment at least every ~10 minutes (single-line conventional message, git commit as its own Bash call; wip:-style detail in the subject is fine as long as the type prefix is conventional). Uncommitted work is the only thing the cut-off loses.
    3. Run targeted tests in the foreground (timeout up to 600000). Do not start the full suite with run_in_background and then end your turn to wait — ending the turn ends the phase and the notification never arrives.
    4. Once the ACs pass, push and open the PR immediately; the PR body must carry the Mutation-verified: record for any gate-test AC (PLAN §5 I-5).
  6. admarble commented on Sep 7, 2026

    @admarble
    ContributorAuthor

    Runner context — salvage the killed session's evidence before spending again. The previous exec session had already observed the skill loading (its own words: "Verdict: GO. Spent so far: $1.12 of $5") and was reproducing the AC-3 traps when the harness cut it off. Nothing was written to the worktree. Its full transcript is at:

    /Users/tony/.claude/projects/-Users-tony-Projects-worktrees-feature-992-spike-opencode-does-opencode-run-command-phase-loa/7d5aac28-f20f-4a50-b1b0-651e1f312ea0.jsonl

    Mine it first (jq -r 'select(.type=="assistant") | .message.content[]? | select(.type=="text") | .text' <file> for narrative; tool_use inputs/results for the exact commands, NDJSON, and opencode stats deltas). Recorded NDJSON from those runs, if it was saved to disk, is the AC-1/AC-2 fixture — copy it in and scrub secrets rather than re-running. Two scratch worktrees from that session still exist and are yours to reuse or remove before the PR: /Users/tony/Projects/oc-spike-scratch (branch spike/992-oc-scratch) and /Users/tony/Projects/worktrees/scratch-992-opencode-spike (branch spike992-qa-target). Write docs/investigations/opencode-driver-spike.md and the fixture early and commit them, then fill in the trap table. Total cap stays $5 including the $1.12 already spent.

  7. added 3 commits that reference this issue on Sep 7, 2026
  8. admarble commented on Sep 7, 2026

    @admarble
    ContributorAuthor

    Runner verification — node 06 (PR #1005, final QA verdict AC_NOT_MET after 3 rounds — stopped for a human decision, not looped further)

    Verify commands from issues/06-NEW-opencode-skill-load-spike.md, run verbatim in the worktree at 54df1980 (diff = spike doc + recorded NDJSON fixture only; 0 files under src/ outside __fixtures__):

    AC Command / check Result
    AC-0 opencode --version → 1.18.27; model id + $ in the doc met (openrouter/anthropic/claude-sonnet-5, per-run $)
    AC-1 grep -cE 'SEQUANT_QA_VERDICT|### Verdict' …/opencode-run-qa.ndjson 5 — skill load observed; doc verdict line reads GO
    AC-2 jq -r '.type' … | sort -u step_finish step_start text tool_use — all four described, incl. text and step_finish
    AC-3 trap table with rows 32K step clamp, /tmp permission kill, process-group kill, each with mitigation + command all three rows present with a mitigation and the command run; only process-group kill reproduced. /tmp permission kill was refuted on 1.18.27 (reads succeed even under "*":"deny"); 32K step clamp survived three controls. This is the sole open item — see below.
    AC-4 Spike verdict: GO|KILL comment on #862 1
    AC-5 cost table with $ and wall per run; total under $5 $1.13, 1,563 s
    hygiene scratch worktrees deleted; no credentials in fixture/doc 0 scratch worktrees remain; 0 credential-shaped strings

    Why it stopped: AC-3 as worded demands, for each trap, "the command that reproduced it". The spike's evidence is that one of the three presupposed traps does not exist on the pinned opencode version and another could not be provoked in three controls. No further loop iteration can produce a reproduction of a refuted trap, and trying again would spend money against the $5 cap for nothing — the QA's own round-3 review reached the same conclusion and classified the finding pause_for_human. Per the run brief (verdicts are claims; an AC that contradicts the evidence is surfaced, not grown) I did not amend the AC or loop again.

    Decision needed from the owner (recorded as PLAN §9 OQ-19): amend AC-3 to "reproduced or refuted, with the controlling command recorded" and accept PR #1005 as the node's deliverable, or hold it and specify what reproduction you want. Either way node 12 (#862 P0) now builds against a fixture and a mitigation table that say the /tmp deny rule is not load-bearing and the clamp budget is a precaution — that changes its AC-8 wording.

    Run history: exec attempt 1 reached GO at $1.12 but was killed at the launcher's 30-minute ceiling with nothing committed; attempt 2 likewise; attempt 3 salvaged the transcript, committed the fixture and doc, and three QA rounds fixed the metadata path, an unverified deny-rule claim, and the wall-time total. Nothing fixed beyond the agent's work. Merge decision is yours — I will not merge.

  9. admarble commented on Sep 7, 2026

    @admarble
    ContributorAuthor

    Runner decision on OQ-19 (A+ pass, 2026-09-07): AC-3 in the body above is amended to accept "reproduced, or refuted with the controlling command and version" — the QA-recommended option — because the owner asked for every wave-1 PR to reach READY_FOR_MERGE, and the only open item on PR #1005 was that wording. The spike's evidence stands unchanged: process-group kill reproduced and mitigated; /tmp permission kill refuted on 1.18.27 (reads succeed under "*":"deny"); 32K clamp not provoked in three controls. Node 12 (#862) AC-8 should read the deny rule as non-load-bearing and the clamp budget as a precaution. QA will be re-run against the amended AC.

  10. added a commit that references this issue on Sep 8, 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

    graph-2026-09no-browser-testplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions