Repository navigation
Description
Context
We run the OpenCode engine across seven production repositories (an internal platform on top of gh-aw: triage, review, and maintenance loops).Documented as https://workflows.platform.plainconcepts.dev Two gaps in the engine harness keep hurting us, and we now ship a small fork of shared/opencode.md to cover them. A working port of both changes against current main is here for reference:
main...CKGrafico:gh-aw:opencode/multi-model-roster
We would rather upstream them than maintain the fork. Below is the plan, with the exact code, in enough detail for an implementing agent to follow.
Problem 1: the provider declares exactly one model
The harness builds the proxy provider with only the run model:
models: { [model]: { name: model } },Repositories that give their OpenCode agents different model: values (a cheap triage model, a stronger review model) get runs where anything but the lead model fails to resolve. The repository configuration syntax invites per-agent models, but the engine cannot serve them, so teams drift back to one model for every job and lose the cost and latency split that motivated the config in the first place.
Change 1: a model roster
Next to the existing GH_AW_LLM_PROVIDER validation in the harness-script, read GH_AW_OPENCODE_MODELS (comma-separated), trim, drop empty entries and duplicates, and always include the lead model from OPENCODE_MODEL:
const rosterEnv = process.env.GH_AW_OPENCODE_MODELS || "";
const roster = rosterEnv
.split(",")
.map(entry => entry.trim())
.filter((entry, index, all) => entry && all.indexOf(entry) === index);
if (!roster.includes(model)) roster.unshift(model);Then declare the roster instead of the single model:
models: Object.fromEntries(roster.map(entry => [entry, { name: entry }])),Every model rides the same proxy, so the deny-all provider policy and the placeholder key are untouched. No schema change is needed: it is an environment variable read by the harness script, so a workflow opts in from env: on the job that sets OPENCODE_MODEL. A workflow without the variable gets a single-model provider, exactly today's behavior.
Problem 2: runs that end clean but deliver nothing
opencode run exits zero when the model answers in text. An agent that writes "let me run the safeoutputs command" and stops has delivered nothing, and the step reports success. In our triage loops this was the most common failure mode: the model narrates a plan, never makes the tool call, and the workflow ends green with no output.
The max-turns guard already covers the ceiling case. This is the opposite case: too few turns, clean exit, empty safe outputs.
Change 2: continue the session instead of ending empty
After a clean run, check GH_AW_SAFE_OUTPUTS (already present on worker jobs, pointing at outputs.jsonl). If the run exited zero, did not hit the turn ceiling, produced a session ID from the event stream, and the safe outputs file is still empty, continue the same session and tell it to finish:
for (let nudge = 1; nudge <= 2; nudge++) {
if (result.exitCode !== 0 || maxTurnsHit || hasSafeOutputs() || !sessionID) break;
log(`No safe output yet, continuing the session (nudge ${nudge} of 2)`);
result = await runProcess({
command,
args: [...commandArgs, "--session", sessionID],
stdin: "Your last message ended without a tool call, so nothing has been delivered and this run is about to end with no output. Do not explain or plan: continue the task now and finish with the safe-output call the task names.",
// env, logging, and event handling are identical to the first run
});
}Two attempts at most. Non-zero exits, turn-ceiling hits, existing safe outputs, and missing session IDs are never continued.
One implementation detail that matters: extract the current onStdoutLine callback into a named handleEvent function before the first run. Both the initial run and every continuation must share it, since session ID capture, turn counting, and finished-part reconciliation all happen there. The fs require gains existsSync.
Documentation
The doc comment below the frontmatter should gain two short paragraphs: one for the roster (variable, format, and that the policy surface does not change) and one for the continuation (what gets continued, what never does). The port branch carries both.
Validation
- Unit tests for roster parsing: unset and empty variables, whitespace, duplicates, lead-model dedupe.
- Unit tests for the continuation gate: each of the four skip conditions.
engine-conformance-opencodeshould keep passing; regenerate locks withmake build && ./gh-aw compile --validate --verbosesince five internal workflows import the file.- Manual smoke: a workflow whose OpenCode config sets
model:per agent, plus a prompt that tempts the model into narrating instead of calling tools. The roster resolves the models; the continuation turns a clean empty run into a delivered one.
Both changes run in our fleet now, verified end to end on a triage loop that classifies issues, comments, and publishes verdicts. Happy to adjust naming, or to split this into two issues if you prefer; they touch the same file and the same run, so we bundled them.
Activity