Skip to content

fix(bin): repair the OpenCode 2.0 worker adapter with standalone launches and v2 busy events - #20

Merged
twilwa merged 12 commits into
mainfrom
fm/fm-opencode-2-adapter
Sep 26, 2026
Merged

twilwa merged 12 commits into
mainfrom
fm/fm-opencode-2-adapter

Conversation

@twilwa

@twilwa twilwa commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Intent

Repair the OpenCode 2.0 harness adapter so Pi-style dispatch to MiMo 2.6 becomes possible. A platform scout (report ~/secondmates/sm-platform/data/ft-opencode-go-profile/report.md) found that MiMo works headless on OpenCode 2.0.16: opencode-go/mimo-v2.6-flash passed a one-file rename with run --standalone. Firstmate's interactive launch is broken on 2.0, though. fm-spawn passes a top-level --model flag that 2.0 dropped; only run -m provider/model#variant remains. It also omits --standalone, so workers would share the background service. The busy-state plugin, interrupt, exit and resume are unverified on 2.0. Scope: fix the opencode adapter in bin/fm-spawn.sh and bin/fm-harness.sh for the 2.0 launch flags and standalone mode, then verify the harness-adapters checklist (spawn, busy state, interrupt, exit, resume) and update the opencode reference. Low priority: Pi Luna measured faster and lighter, so this only unlocks an option; it authorizes no change to the dispatch strategy.

What Changed

  • bin/fm-spawn.sh now launches OpenCode workers in the form OpenCode 2.0 accepts. A worker with a set model runs as opencode mini --model <provider/model> --standalone --prompt …. A worker with no set model runs as opencode --standalone --prompt …. The old top-level --model flag is gone, and every worker now gets its own server instead of sharing the background service. The generated fm-busy-state.js plugin was rewritten for the 2.0 loader: it exports a default { id, setup } definition and reads context.event.subscribe(). It marks the worker busy on session.execution.started and idle on succeeded, failed or interrupted, following only the main session so a child session can't clear it.
  • OpenCode is now allowed only for crewmate and scout work, because its fm-primary-* plugins haven't been ported to the 2.0 loader yet. fm-spawn.sh refuses --harness opencode --secondmate, and fm_control_harness_supports_kind refuses a secondmate relaunch to OpenCode before it stops the running agent. OpenCode was also removed from the remote-secondmate harness lists in fm-spawn.sh, fm-remote-secondmate-control.sh and fm-remote-doctor.sh, and DOCTOR_SHA256 in fm-remote-entrypoint.sh was updated to match. fm-harness.sh gained a comment noting that opencode mini is still detected as opencode.
  • Added an opt-in live test, tests/fm-opencode-adapter-live-e2e.test.sh (runs only with FM_OPENCODE_ADAPTER_LIVE=1), which covers spawn, busy/idle, an Enter queued while busy, double-Escape interrupt, /exit, and resuming in a fresh pane. Updated the busy-wiring, fm-control and dispatch-profile tests. Updated the OpenCode harness reference, the harness-adapters skill, the README and the docs, and recorded the OpenCode 2.0.16 live evidence in docs/verification/runtime-backends.md.

Risk Assessment

✅ Low: The change is limited to the OpenCode worker launch string, the generated busy plugin, and harness allowlists and docs; it is covered by behavioral tests and a recorded live 2.0.16 guard run, and the dropped 1.x and secondmate support was explicitly authorized in earlier rounds.

Testing

  • ⏭️ Test - skipped

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⏭️ **Test** - skipped

Step was skipped.

✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @twilwa, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-26T03:10:14.027243Z 7fdab8b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sourcery-ai

sourcery-ai Bot commented Sep 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR migrates the OpenCode worker adapter from the 1.x launch and plugin contracts to OpenCode 2.x, using standalone model-aware launches and session execution events for reliable busy-state tracking. It limits OpenCode to verified crewmate/scout use, removes unsupported secondmate paths, updates documentation, and adds unit, dispatch-profile, and opt-in live lifecycle coverage.

Sequence diagram for the OpenCode 2.x worker lifecycle

sequenceDiagram
    participant Spawn as fm-spawn.sh
    participant OpenCode as OpenCode2
    participant Plugin as fm-busy-state plugin
    participant Busy as fm-busy-event.sh
    participant TurnEnd as Turn-end marker

    Spawn->>OpenCode: opencode --standalone --prompt
    Spawn->>OpenCode: mini --model provider/model --standalone --prompt
    OpenCode->>Plugin: session.execution.started
    Plugin->>Busy: apply busy
    OpenCode->>Plugin: session.execution.succeeded / failed / interrupted
    Plugin->>Busy: apply idle
    Plugin->>TurnEnd: touch turn-end file
Loading

State diagram for OpenCode 2.x busy-state tracking

stateDiagram-v2
    [*] --> Idle
    Idle --> Busy: session.execution.started
    Busy --> Idle: session.execution.succeeded
    Busy --> Idle: session.execution.failed
    Busy --> Idle: session.execution.interrupted
    Busy --> Busy: child session terminal event
    Idle --> [*]
Loading

Flow diagram for OpenCode 2.x dispatch support

flowchart TD
    Spawn["fm-spawn.sh dispatch"] --> Role{Role}
    Role -->|crewmate or scout| Model{Model pinned?}
    Role -->|secondmate| Reject["Reject: unsupported supervision plugins"]
    Model -->|no| Standalone["opencode --standalone --prompt"]
    Model -->|yes| Mini["opencode mini --model provider/model --standalone --prompt"]
    Standalone --> Worker["OpenCode 2.x isolated worker"]
    Mini --> Worker
Loading

File-Level Changes

Change Details Files
Updated OpenCode worker launches and busy-state integration for the OpenCode 2.x CLI and plugin API.
  • Use standalone workers and route pinned models through mini --model, while preserving an unpinned main-TUI launch.
  • Replace the v1 named-hook plugin with a default id/setup definition consuming session.execution.* events.
  • Latch busy state to the first active session, ignore child-session terminal events for state clearing, and touch turn-end notifications for all terminal events.
bin/fm-spawn.sh
bin/fm-harness.sh
bin/fm-busy-lib.sh
tests/fm-busy-adapter-wiring.test.sh
tests/fm-spawn-dispatch-profile.test.sh
Constrained OpenCode to verified worker roles and removed unsupported secondmate and remote-secondmate paths.
  • Reject OpenCode secondmates because the existing primary plugins are incompatible with the 2.x loader.
  • Remove OpenCode from remote secondmate launch, relaunch, doctor, and documentation allowlists.
  • Clarify the OpenCode 2.x limitation and lifecycle semantics in the architecture, configuration, README, trace-context, and harness reference documentation.
bin/fm-spawn.sh
bin/fm-remote-secondmate-control.sh
bin/fm-remote-doctor.sh
README.md
docs/architecture.md
docs/configuration.md
docs/remote-secondmates.md
docs/trace-context.md
.agents/skills/harness-adapters/references/harness/opencode.md
Added automated coverage for the new dispatch behavior and live OpenCode 2.x worker lifecycle.
  • Register an opt-in live Herdr test covering model-pinned launch, standalone isolation, busy/idle transitions, queued input, interrupt, exit, and resume.
  • Extend wiring tests to exercise the v2 async event stream, all terminal events, and child-session isolation.
  • Record OpenCode 2.0.16 verification evidence and broaden the live guard to accept OpenCode 2 or later.
tests/fm-opencode-adapter-live-e2e.test.sh
tests/fm-test-run.sh
tests/fm-busy-adapter-wiring.test.sh
tests/fm-spawn-dispatch-profile.test.sh
docs/verification/runtime-backends.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7fdab8bf0c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bin/fm-spawn.sh
# opencode's fm-primary plugins export only the v1 named hook, which the 2.0
# loader rejects, so an opencode secondmate would run with no primary
# supervision until those plugins are ported to the default-definition loader.
if [ "$KIND" = secondmate ] && { [ "$HARNESS" = muse ] || [ "$HARNESS" = gemini ] || [ "$HARNESS" = agy ] || [ "$HARNESS" = devin ] || [ "$HARNESS" = opencode ]; }; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject OpenCode in the pre-stop capability check

When an existing OpenCode secondmate is relaunched through fm-control.sh or the secondmate restart path, fm_control_harness_supports_kind still accepts opencode for secondmate. The preflight therefore permits the relaunch to stop the running agent, after which this new refusal makes fm-spawn.sh fail and leaves the secondmate without a replacement. Add OpenCode to the control-plane kind exclusion so the operation refuses before stopping anything.

AGENTS.md reference: AGENTS.md:L97-L100

Useful? React with 👍 / 👎.

…, fixed: tests/fm-on.test.sh failed with "not ok - the trusted doctor could not bootstrap while git was unavailable". Rule that broke: DOCTOR_SHA256, pinned in bin/fm-remote-entrypoint.sh, must equal the sha256 of the tracked bin/fm-remote-doctor.sh. When git is missing on a remote host, the entrypoint runs the doctor only if the hashes match. The PR removed opencode from HARNESS_TOOLS in the doctor, which changed its hash from 78efccd6… to e4c77379…, but left the pin unchanged. That pin exists only at bin/fm-remote-entrypoint.sh:34, and only tests/fm-on.test.sh checks it. Nothing pins the entrypoint's own hash, so updating it breaks nothing else. Fix: set the pin to e4c773796654ef7a166b124a2c42b127e547391570633879c65828ffb6abd161. Verified: `bash tests/fm-on.test.sh` now prints "ok - doctor bootstrap remains authenticated when git is unavailable" and ALL TESTS PASSED. ci-1 (Behavior portable serial 2), not caused by this PR, no code change: in CI, tests/fm-remote-secondmate-lifecycle-e2e.test.sh passed all its checks, then its cleanup failed with "rm: cannot remove '/tmp/fm-remote-secondmate-e2e.*': Directory not empty". The same error failed main's CI run 36196602199 before this branch existed, so this is an existing flake, and nothing in this PR touches that cleanup. I could not get a clean local pass of this test. On this host (load average about 30) it stopped twice at "not ok - remote spawn never reached its blocked inheritance write". A copy of the base commit c4fa12f failed the same way at the same step, so the cause is host load, not this PR. CI got past that step on this branch. ci-3 (PR must be raised via no-mistakes), not a code problem, no code change: the check failed with "Required no-mistakes pipeline steps are not completed: test (status=skipped)". It reads the pipeline attestation produced by the outer executor, so no source change can fix it. Changed file: bin/fm-remote-entrypoint.sh (one line). Nothing is committed
@twilwa
twilwa force-pushed the fm/fm-opencode-2-adapter branch from 021524d to 8107bd2 Compare September 26, 2026 05:02
@twilwa twilwa changed the title fix(bin): repair OpenCode 2.0 worker launch and busy-state plugin fix(bin): repair the OpenCode 2.0 worker adapter with standalone launches and v2 busy events Sep 26, 2026
@twilwa twilwa closed this Sep 26, 2026
@twilwa twilwa reopened this Sep 26, 2026
@twilwa

twilwa commented Sep 26, 2026

Copy link
Copy Markdown
Owner Author

Final disposition for head 6015b2f:

  • Validation: isolated no-mistakes gate on claude-opus-5-5 passed for this head (attestation recorded in the review ledger).
  • Review feedback: the Codex P1 finding (OpenCode offered as a secondmate runtime) is addressed by db8076a, which excludes OpenCode from secondmate launches; the other items are a Sourcery rate-limit notice and informational summaries.
  • CI: re-run against current main after the Lint 1 memory fix (ci(bin): split full ShellCheck lint into three single-worker partitions #25) merged; Lint 1, Lint 2, Lint 3 and every behavior shard pass. The only red check is 'PR must be raised via no-mistakes', which fails only because the local test step is skipped for fork-local changes and is waived under the standing fork policy.
  • Merging under the repository's standing merge policy.

@twilwa
twilwa merged commit 72fbbce into main Sep 26, 2026
57 of 62 checks passed
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.

1 participant