Skip to content

fix(amico-run): read critic/planner model from the engine session record (#1347) - #2184

Open
jacktrnr wants to merge 2 commits into
mainfrom
fix/1347-run-reports-model
Open

jacktrnr wants to merge 2 commits into
mainfrom
fix/1347-run-reports-model

Conversation

@jacktrnr

@jacktrnr jacktrnr commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On the free tier, amico spec review discarded every judgment critic and amico plan compile exited 64, both with "the child did not report the model it ran as". opencode run --format json carries no model on any event (confirmed again here: only step_start / text / step_finish). That left the child's self-report as the only source, and free gateway models (e.g. opencode/nemotron-3.5-lightning-free) don't reliably name themselves. runAgent fails closed, so every free-tier critic and planner was lost.

Fix: read the model from the engine's session record

After the child exits, runAgent takes the sessionID from the event stream (every event carries one) and runs opencode export <sessionID> in the child's cwd with the child's allowlisted env. It then reads the assistant message's providerID/modelID. The engine writes those fields for the provider call it actually made. They are the same fields as the message.updated events that json mode suppresses.

The order of evidence is now:

  1. Engine session record. It wins, including over a self-report that disagrees.
  2. Child self-report. This is unchanged and is the fallback when the record can't be read: no session id, export fails or times out (30 s cap), or the record is malformed.
  3. Neither one: fail closed, as before.

Guards:

  • Never read the user message. Its model is the request (argv). A record with no assistant message fails closed.
  • Ambiguous records are rejected. If the assistant messages name more than one model, nothing is picked.
  • The session id is shape-checked (^ses_[A-Za-z0-9]+$) before it goes on argv.

spec review and plan compile both go through runAgent, so this one change fixes both symptoms.

Why not the engine-overlay change the issue suggested

I weighed two options:

  • (1) Overlay. Make run emit providerID/modelID in --format json.
  • (2) Parent-side. Get the model from what the parent already knows.

Within (2), taking the model from the --model the parent passed is ruled out. That is exactly what the check forbids: the ledger's critics[].model must be a verified fact, never the request ("a request masquerading as a fact"). The session record is the other form of (2), and it doesn't weaken that guarantee. It is the engine's record of the call it made, the same data (1) would put into the stream.

I chose the session record over the overlay for three reasons:

  • The overlay wouldn't fix the default setup. The child binary is $AMICO_CRITIC_BIN, else opencode on PATH, which is often stock upstream opencode. An overlay change only helps when the child happens to be the vendored Amicode engine. opencode export works with both: verified on stock opencode 1.19.6.
  • It's smaller. The overlay route needs a copy of upstream run.ts in the overlay, a manifest refresh, a binary rebuild, and a release before anyone benefits. This change is about 60 lines in agent_spawn.ts and touches no overlay files.
  • The guarantee is the same. Both options read the engine's assistant-message metadata. Neither trusts argv. Fail-closed still applies when the model is missing from every source.

Tradeoff: each child that answers costs one extra local export process (a database read, no model call).

The REPORT_RULE prompt text still asks the child to name itself. It is still the fallback, so I left it alone to avoid changing model behavior. Only the code comments that said self-report was "the only channel" were updated.

Tests (written first, RED on origin/main)

  • agent_spawn.test.ts, new describe (deliberate tooling: spec review critics + plan compile fail — child 'did not report the model it ran as' #1347). The fixture now emits sessionID like the real stream and answers export <sessionID>. Cases:

    • a child that can't name itself runs and is stamped with the engine-recorded model
    • the engine record beats a disagreeing self-report
    • only the user message, no assistant message: fails closed (the request is never stamped)
    • ambiguous record: no model is picked
    • the export runs as export <sid> in the child's cwd
    • no record: falls back to self-report

    A mutation check confirmed these fail when the precedence, the ambiguity rule, or the assistant-only rule is broken.

  • spec_review.test.ts and plan_compile.test.ts drive the real child path ($AMICO_CRITIC_BIN → runAgent → spawn) through a small wrapper script, test/fixtures/fake_agent_bin.ts. On the pre-fix agent_spawn.ts they fail with the issue's exact symptoms: critics: [], and plan compile returning exit_code: 64.

  • All existing tests are kept, including "DISCARDS a critic that will not name itself", which still holds with no engine record.

Results:

  • pnpm --filter @amicode/amico-run typecheck: clean.
  • vitest: agent_spawn / spec_review / plan_compile all green (113 tests).
  • Full amico-run suite: 2421 passed. The only failures are timeouts in upgrade-* tests under full parallel load; those tests pass alone and don't touch this code.
  • drift_gate: PASS (no overlay change).

Live verification (darwin-arm64, real opencode 1.19.6, AMICO_CRITIC_MODEL=opencode/nemotron-3.5-lightning-free)

  • amico spec review <spec> --json returned review_verdict: "approved". hidden-failure, decomposition and interface-boundary all ran, and every critic was stamped opencode/nemotron-3.5-lightning-free.

  • amico plan compile <spec> --json returned ok: true and wrote a plan, with compiled_by.model = opencode/nemotron-3.5-lightning-free.

  • Across 3 live reviews, two still lost one critic to unrelated causes:

    • one free-model answer was unparseable (model quality)
    • one child got database is locked from the shared engine DB

    I couldn't reproduce the lock with overlapping export + run children: 0 locks in 21 processes. Those failures still show up as degraded, as designed.

Closes #1347

🤖 Generated with Claude Code

…on record (#1347)

run --format json carries no model on any event, and free-tier gateway models do not
reliably self-report, so every critic and the planner were discarded. Read the
assistant message's providerID/modelID from `opencode export <sessionID>` (an
engine-observed fact, never argv) before falling back to self-report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cc0d3a85-fafc-4fba-9dd9-c2866ade0832
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…w and plan compile through the real child path (#1347)

- engine record beats a disagreeing self-report; the user message (the request) is never read;
  an ambiguous record does not pick; no record falls back to self-report
- spec review / plan compile tests via $AMICO_CRITIC_BIN, RED on the pre-fix code with the
  issue's exact symptoms
- comments no longer claim self-report is the only channel

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jacktrnr
jacktrnr marked this pull request as ready for review November 23, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deliberate tooling: spec review critics + plan compile fail — child 'did not report the model it ran as'

1 participant