From 1281ba637db2d5b15ede4ec49af628434810d271 Mon Sep 17 00:00:00 2001 From: Harry Yep Date: Wed, 22 Jul 2026 17:14:02 +0800 Subject: [PATCH 1/2] fix(fusion): transport completion contract for peer wrappers --- plugins/fusion/scripts/worker-lifecycle.mjs | 9 ++ tests/fusion-worker-lifecycle.test.mjs | 168 ++++++++++++++++++++ 2 files changed, 177 insertions(+) diff --git a/plugins/fusion/scripts/worker-lifecycle.mjs b/plugins/fusion/scripts/worker-lifecycle.mjs index bb54357..ae03d67 100644 --- a/plugins/fusion/scripts/worker-lifecycle.mjs +++ b/plugins/fusion/scripts/worker-lifecycle.mjs @@ -245,6 +245,9 @@ function completionContract(agentType, prompt) { if (canonical === "fusion:job-collector") { return "collector"; } + if (PEER_JOB_FOOTER_AGENTS.has(agentType)) { + return "transport"; + } if (canonical === "fusion:deep-reasoner" || (!/^verification:\s*\S/im.test(prompt) && /^acceptance:\s*\S/im.test(prompt))) { return "coverage"; } @@ -392,6 +395,9 @@ function completedReport(record, message) { if (record.completionContract === "collector" || canonicalWorkerAgentType(record.agentType) === "fusion:job-collector") { return COLLECTOR_END_MARKER.test(normalized); } + if (record.completionContract === "transport" || PEER_JOB_FOOTER_AGENTS.has(record.agentType)) { + return record.agentType === "grok:grok-review-runner" || peerJobIdFromCollectedResult(normalized) != null; + } if (record.completionContract === "coverage" || canonicalWorkerAgentType(record.agentType) === "fusion:deep-reasoner") { return COVERAGE_END_MARKER.test(normalized); } @@ -428,6 +434,9 @@ function retryInstruction(record) { if (record.completionContract === "collector" || canonicalWorkerAgentType(record.agentType) === "fusion:job-collector") { return "Return the exact collector command output, including its terminal `collector:` marker. This is the only retry."; } + if (record.completionContract === "transport" || PEER_JOB_FOOTER_AGENTS.has(record.agentType)) { + return "The transport relay is incomplete. Return the companion output verbatim, including its `job:` and `state:` footer lines. This is the only retry."; + } if (record.completionContract === "coverage" || canonicalWorkerAgentType(record.agentType) === "fusion:deep-reasoner") { return "The task is not deliverable yet. Complete the requested coverage check and return the actual result. End with `delivery: complete` plus `coverage: complete`. This is the only retry."; } diff --git a/tests/fusion-worker-lifecycle.test.mjs b/tests/fusion-worker-lifecycle.test.mjs index 1112595..757c256 100644 --- a/tests/fusion-worker-lifecycle.test.mjs +++ b/tests/fusion-worker-lifecycle.test.mjs @@ -2218,6 +2218,174 @@ test("an acceptance brief uses the analysis completion contract", (t) => { assert.strictEqual(record(box).transportStatus, "done"); }); +test("peer transport dispatches record the transport completion contract", (t) => { + for (const agentType of ["codex:codex-rescue", "grok:grok-rescue"]) { + const box = sandbox(t); + const peerDispatch = dispatch(box, { subagent_type: agentType, prompt: "bounded peer brief" }); + run(box, peerDispatch); + run(box, { + ...peerDispatch, + hook_event_name: "PostToolUse", + tool_response: { isAsync: true, status: "async_launched", agentId: "transport-contract-" + agentType } + }); + assert.strictEqual(record(box).completionContract, "transport"); + } +}); + +test("a codex peer relay footer completes without a retry and backfills its job id", (t) => { + const box = sandbox(t); + const peerJobId = "a".repeat(32); + const peerDispatch = dispatch(box, { subagent_type: "codex:codex-rescue", prompt: "bounded peer brief" }); + run(box, peerDispatch); + run(box, { + ...peerDispatch, + hook_event_name: "PostToolUse", + tool_response: { isAsync: true, status: "async_launched", agentId: "codex-transport-relay" } + }); + + const stopped = run(box, { + hook_event_name: "SubagentStop", + session_id: "session-1", + cwd: box.cwd, + transcript_path: box.transcript, + agent_id: "codex-transport-relay", + agent_type: "codex:codex-rescue", + stop_hook_active: false, + last_assistant_message: ["```text", "companion result prose", "job: " + peerJobId, "delivery: foreground", "semantic: unverified", "state: done", "```", "relay commentary after the envelope"].join("\n") + }); + + assert.strictEqual(stopped.stdout, ""); + const completed = record(box); + assert.strictEqual(completed.retryCount, 0); + assert.strictEqual(completed.failureKind, null); + assert.strictEqual(completed.peerJobId, peerJobId); + assert.strictEqual(completed.transportStatus, "ready_uncollected"); +}); + +test("a grok peer relay footer completes without a retry and captures its job id", (t) => { + const box = sandbox(t); + const peerJobId = "b".repeat(32); + const peerDispatch = dispatch(box, { subagent_type: "grok:grok-rescue", prompt: "bounded peer brief" }); + run(box, peerDispatch); + run(box, { + ...peerDispatch, + hook_event_name: "PostToolUse", + tool_response: { isAsync: true, status: "async_launched", agentId: "grok-transport-relay" } + }); + + const stopped = run(box, { + hook_event_name: "SubagentStop", + session_id: "session-1", + cwd: box.cwd, + transcript_path: box.transcript, + agent_id: "grok-transport-relay", + agent_type: "grok:grok-rescue", + stop_hook_active: false, + last_assistant_message: ["companion result prose", "grok-session: grok-session-123", "job: " + peerJobId, "state: done"].join("\n") + }); + + assert.strictEqual(stopped.stdout, ""); + const completed = record(box); + assert.strictEqual(completed.retryCount, 0); + assert.strictEqual(completed.failureKind, null); + assert.strictEqual(completed.peerJobId, peerJobId); + assert.strictEqual(completed.transportStatus, "ready_uncollected"); +}); + +test("an incomplete peer relay receives one transport retry before terminal delivery failure", (t) => { + const box = sandbox(t); + const peerDispatch = dispatch(box, { subagent_type: "codex:codex-rescue", prompt: "bounded peer brief" }); + run(box, peerDispatch); + run(box, { + ...peerDispatch, + hook_event_name: "PostToolUse", + tool_response: { isAsync: true, status: "async_launched", agentId: "codex-incomplete-relay" } + }); + const stopPayload = { + hook_event_name: "SubagentStop", + session_id: "session-1", + cwd: box.cwd, + transcript_path: box.transcript, + agent_id: "codex-incomplete-relay", + agent_type: "codex:codex-rescue", + stop_hook_active: false, + last_assistant_message: "companion result prose\nstate: done" + }; + + const retried = run(box, stopPayload); + assert.strictEqual(retried.stdout.trim().split("\n").length, 1); + const retryOutput = JSON.parse(retried.stdout); + assert.strictEqual(retryOutput.decision, "block"); + assert.strictEqual(retryOutput.reason, "The transport relay is incomplete. Return the companion output verbatim, including its `job:` and `state:` footer lines. This is the only retry."); + assert.strictEqual(record(box).retryCount, 1); + + const exhausted = run(box, stopPayload); + assert.strictEqual(exhausted.stdout, ""); + const incomplete = record(box); + assert.strictEqual(incomplete.transportStatus, "incomplete"); + assert.strictEqual(incomplete.failureKind, "delivery"); + assert.strictEqual(incomplete.retryCount, 1); +}); + +test("a stale verification contract still accepts a codex peer relay footer", (t) => { + const box = sandbox(t); + const peerJobId = "c".repeat(32); + const peerDispatch = dispatch(box, { subagent_type: "codex:codex-rescue", prompt: "bounded peer brief" }); + run(box, peerDispatch); + run(box, { + ...peerDispatch, + hook_event_name: "PostToolUse", + tool_response: { isAsync: true, status: "async_launched", agentId: "codex-stale-contract" } + }); + updateWorkerRecord(record(box).taskId, envFor(box), (current) => ({ ...current, completionContract: "verification" })); + + const stopped = run(box, { + hook_event_name: "SubagentStop", + session_id: "session-1", + cwd: box.cwd, + transcript_path: box.transcript, + agent_id: "codex-stale-contract", + agent_type: "codex:codex-rescue", + stop_hook_active: false, + last_assistant_message: ["companion result prose", "job: " + peerJobId, "state: done"].join("\n") + }); + + assert.strictEqual(stopped.stdout, ""); + const completed = record(box); + assert.strictEqual(completed.completionContract, "verification"); + assert.strictEqual(completed.retryCount, 0); + assert.strictEqual(completed.peerJobId, peerJobId); + assert.strictEqual(completed.transportStatus, "ready_uncollected"); +}); + +test("a grok review runner raw JSON result completes without a transport retry", (t) => { + const box = sandbox(t); + const worker = createWorkerRecord({ + taskId: "fusion-" + "d".repeat(24), + sessionId: "session-1", + agentType: "grok:grok-review-runner", + workspaceRoot: box.cwd + }, envFor(box)); + updateWorkerRecord(worker.taskId, envFor(box), (current) => ({ ...current, agentId: "grok-review-json", transportStatus: "running" })); + + const stopped = run(box, { + hook_event_name: "SubagentStop", + session_id: "session-1", + cwd: box.cwd, + transcript_path: box.transcript, + agent_id: "grok-review-json", + agent_type: "grok:grok-review-runner", + stop_hook_active: false, + last_assistant_message: "{\"review\":\"accepted\",\"findings\":[]}" + }); + + assert.strictEqual(stopped.stdout, ""); + const completed = record(box); + assert.strictEqual(completed.retryCount, 0); + assert.strictEqual(completed.failureKind, null); + assert.strictEqual(completed.transportStatus, "done"); +}); + test("job collector completion requires a terminal marker and fails closed on the legacy unstructured marker", (t) => { const box = sandbox(t); const peerJobId = "a".repeat(32); From 1021ef2e9d8bcefc2e8a7ba4a14d626a7e0e7f1f Mon Sep 17 00:00:00 2001 From: Harry Yep Date: Wed, 22 Jul 2026 17:21:11 +0800 Subject: [PATCH 2/2] chore: release 0.0.36 --- .claude-plugin/marketplace.json | 8 ++++---- CHANGELOG.md | 4 ++++ plugins/codex/.claude-plugin/plugin.json | 2 +- plugins/fusion/.claude-plugin/plugin.json | 2 +- plugins/grok/.claude-plugin/plugin.json | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index fb68ad9..3acce87 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -6,14 +6,14 @@ "email": "hi@okis.dev" }, "description": "Multi-model orchestration marketplace for Claude Code.", - "version": "0.0.35", + "version": "0.0.36", "plugins": [ { "name": "grok", "source": "./plugins/grok", "displayName": "Grok Companion", "description": "Local Grok CLI delegation: task, review, resumable history, best-of-n tournaments, background jobs, stats, and setup health checks.", - "version": "0.0.35", + "version": "0.0.36", "author": { "name": "Harry Yep" }, @@ -34,7 +34,7 @@ "source": "./plugins/codex", "displayName": "Codex Companion", "description": "First party local Codex CLI delegation for tasks, reviews, resumable threads, and durable background jobs.", - "version": "0.0.35", + "version": "0.0.36", "author": { "name": "Harry Yep" }, @@ -55,7 +55,7 @@ "source": "./plugins/fusion", "displayName": "Fusion Orchestrator", "description": "Multi-model orchestration: tier agents, routing rules, blind panel, ultra fleet, model config, and drift doctor.", - "version": "0.0.35", + "version": "0.0.36", "author": { "name": "Harry Yep" }, diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e199fc..beaa2bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # changelog +## 0.0.36 + +- peer transport wrappers get their own completion contract: 0.0.35's SubagentStop matcher expansion routed `codex:codex-rescue`, `grok:grok-rescue`, and `grok:grok-review-runner` through the claude worker deliverable gate, whose `verification` contract demands a final message ending in `delivery: complete` plus `verification: passed`; a verbatim companion relay ends with the engine envelope (`job:`, `state:`) instead, so every foreground peer delivery burned its single truncation recovery retry arguing with the gate, took a false `failureKind: delivery`, and terminalized as `incomplete`, which the notification reconcile guard skips, breaking notification driven auto collection and forcing a stop collection block on every peer package (observed two of two in the first 0.0.35 session against twenty nine of twenty nine clean on 0.0.34 the same day); dispatches now record a `transport` contract, `completedReport` accepts a relay whose footer parses through `peerJobIdFromCollectedResult` (the same parser settlement identity backfill uses, with `grok:grok-review-runner` always deliverable because its terminal output may be raw json validated by the review consumer), a matching transport retry message covers genuinely truncated relays, and the guards also match the agent type so records created before the fix settle correctly after a hot deploy + ## 0.0.35 - codex adapts to cli 0.145.0: task runs forward `--output-schema ` end to end (rescue raw args, exec argv, structured output capture, and a `structured: parsed/invalid/unavailable` footer in the render), adversarial review gains a json schema verdict contract at `plugins/codex/schemas/adversarial-review-verdict.schema.json`, native `review` rejects `--output-schema` because tested versions silently ignore it there, and the 0.144.4 models cache schema drift workaround is deleted with the tested interval moving to 0.145.0 to 0.146.0 diff --git a/plugins/codex/.claude-plugin/plugin.json b/plugins/codex/.claude-plugin/plugin.json index d9d27cd..d16794c 100644 --- a/plugins/codex/.claude-plugin/plugin.json +++ b/plugins/codex/.claude-plugin/plugin.json @@ -2,7 +2,7 @@ "$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json", "name": "codex", "displayName": "Codex Companion", - "version": "0.0.35", + "version": "0.0.36", "description": "First party local Codex CLI delegation for tasks, reviews, resumable threads, and durable background jobs.", "author": { "name": "Harry Yep" diff --git a/plugins/fusion/.claude-plugin/plugin.json b/plugins/fusion/.claude-plugin/plugin.json index 716e7c2..e6e31c6 100644 --- a/plugins/fusion/.claude-plugin/plugin.json +++ b/plugins/fusion/.claude-plugin/plugin.json @@ -2,7 +2,7 @@ "$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json", "name": "fusion", "displayName": "Fusion Orchestrator", - "version": "0.0.35", + "version": "0.0.36", "description": "Multi-model orchestration: tier agents, routing rules, blind panel, ultra fleet, model config, and drift doctor.", "author": { "name": "Harry Yep" diff --git a/plugins/grok/.claude-plugin/plugin.json b/plugins/grok/.claude-plugin/plugin.json index f553298..b24ae49 100644 --- a/plugins/grok/.claude-plugin/plugin.json +++ b/plugins/grok/.claude-plugin/plugin.json @@ -2,7 +2,7 @@ "$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json", "name": "grok", "displayName": "Grok Companion", - "version": "0.0.35", + "version": "0.0.36", "description": "Local Grok CLI delegation: task, review, resumable history, background jobs, stats, and setup health checks.", "author": { "name": "Harry Yep"