Skip to content

Commit 5ef7503

Browse files
committed
feat(opencode): live parity run through user-facing controls (M6.6)
The opt-in parity fixture (test/integration/opencode-parity.mjs) drives the full Fusion protocol through the user-facing command surface only (/fusion-run, /fusion-status, /fusion-stats, /fusion-resume, /fusion-clean, /fusion-mode) against the installed v2.2.5 host, and supersedes the failed 2026-10-30 CLI workflow run: - run 1 (ephemeral): configure -> run -> scout -> execute -> file review -> revise -> audit -> final fix -> "## Fusion summary", one executor child across all three delegations, fixture.txt progressing alpha -> beta -> gamma; - run 2 (persistent mode): a new run completes through the same controls on second.txt; - real per-run usage totals from observed readings (stats1: 4/4 turns reported, 15885 input / 738 output tokens; stats2: 1/1, 5539 input); - resume parity: owning-session presentation (no recovery owed), cross-session not-attached presentation with the owning run and the concrete operator-resolution command, and post-clean absence; - clean parity: settled ephemeral and persistent runs released, unfinished runs refused. Review follow-up found in the live run: a persistent-mode run stays armed (runActive true, phase "complete") after it settles, and fusion_clean refused it - leaving no user-facing cleanup path. Clean now treats phase "complete" as settled in both checks and releases the run in either mode, refusing only unfinished work; unit-pinned for armed-settled release and unfinished refusal. Fixture hardening from the live chase: server-driven with a two-phase boot seeding only the provider plus opencode account credential rows (a bare provider key is rejected by the gateway workspace policy in serve mode), supervisor-session discovery (the prompted turn may run in a different session than the command's), supervisor reset honoring, and stuck-turn recovery for the upstream parent-completion gap (anomalyco/opencode#36349) via interrupt + clean + reissue. 374 tests, type checking, and the model-free smoke pass.
1 parent 839299c commit 5ef7503

4 files changed

Lines changed: 437 additions & 4 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"test:ownership-cross-process": "bun test/integration/cross-process-ownership.mjs",
3030
"test:opencode-real-child": "bun test/integration/opencode-real-child.mjs",
3131
"test:opencode-lifecycle": "bun test/integration/opencode-real-child-lifecycle.mjs",
32-
"test:opencode-scout": "bun test/integration/opencode-scout.mjs"
32+
"test:opencode-scout": "bun test/integration/opencode-scout.mjs",
33+
"test:opencode-parity": "bun test/integration/opencode-parity.mjs"
3334
},
3435
"peerDependencies": {
3536
"@earendil-works/pi-agent-core": "^1.0.0",

‎src/opencode/index.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,14 @@ export default {
648648
/** Release settled Fusion resources for a session, or a settled workspace record left by another one. */
649649
async function cleanWorkspace(sessionID: string): Promise<string> {
650650
if (resetting || starting || configuring || promptInFlight) throw new Error("A Fusion run transition is in progress.");
651+
// A persistent-mode run stays armed (runActive true) after it settles;
652+
// phase "complete" is the settled marker, so it releases like any
653+
// other settled run instead of deadlocking the session's cleanup.
654+
const cleanable = (state: { runActive: boolean; phase: string }): boolean => state.runActive && state.phase !== "complete";
651655
const run = runs.get(sessionID);
652656
if (run) {
653657
if (hasUnconfirmedPrompt(run)) throw new Error("Fusion prompt delivery is unconfirmed. Retry /fusion-run with the same task before cleaning.");
654-
if (run.controller.state.runActive) throw new Error("The Fusion run is still active; finish and reset it before cleaning.");
658+
if (cleanable(run.controller.state)) throw new Error("The Fusion run is still active; finish and reset it before cleaning.");
655659
const error = run.controller.resetError(false, run.reconciling);
656660
if (error) throw new Error(`${error} Clean releases settled resources only.`);
657661
if (scoutInFlight || hasBackgroundScout()) throw new Error("A Fusion scout is still running; wait for it to stop before cleaning.");
@@ -672,13 +676,13 @@ export default {
672676
const owned = await registry.inspect(workspace);
673677
if (!owned) return "No Fusion resources to clean in this workspace.";
674678
if (owned.manifest.recovery !== "settled") throw new Error(`The workspace Fusion record is ${owned.manifest.recovery}; reconcile it or run the explicit operator resolution before cleaning.`);
675-
if (owned.manifest.state.runActive || scoutInFlight || hasBackgroundScout()) throw new Error("A Fusion run or scout is still active; clean it from its owning session after it finishes.");
679+
if (owned.manifest.state.runActive && owned.manifest.state.phase !== "complete" || scoutInFlight || hasBackgroundScout()) throw new Error("A Fusion run or scout is still active; clean it from its owning session after it finishes.");
676680
// An adopted run's held lease is the same record: release through it
677681
// rather than claiming the workspace a second time in this process.
678682
const holder = [...runs.values()].find((candidate) => candidate.lease && candidate.lease.manifest.runId === owned.manifest.runId);
679683
if (holder?.lease) {
680684
const error = holder.controller.resetError(false, holder.reconciling);
681-
if (error || holder.controller.state.runActive) throw new Error("The owning Fusion run is still active; clean it from its owning session after it finishes.");
685+
if (error || cleanable(holder.controller.state)) throw new Error("The owning Fusion run is still active; clean it from its owning session after it finishes.");
682686
await store.removeSettled(holder.runId);
683687
await holder.lease.release();
684688
holder.lease = undefined;

0 commit comments

Comments
 (0)