From d6d60f8d3e55fece71d0764611d41361941bbad6 Mon Sep 17 00:00:00 2001 From: Sisyphus Date: Thu, 17 Sep 2026 10:11:27 +0800 Subject: [PATCH] fix(agent): /acp must not wake the model under OpenCode V2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenCode V2's session.synthetic defaults to delivery="steer" and, unless resume:false, calls execution.wake(sessionID) — every /acp invocation started a model turn on behalf of a status query. Observed live in TUI: the model answered its own injected status panel with an unprompted assistant message. Pass resume:false so rendering stays inert. --- src/agent/opencode-v2.ts | 6 ++++-- tests/opencode-v2.test.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/agent/opencode-v2.ts b/src/agent/opencode-v2.ts index b84a5c47a7..d40508cf08 100644 --- a/src/agent/opencode-v2.ts +++ b/src/agent/opencode-v2.ts @@ -87,7 +87,7 @@ interface V2CatalogModelEntry { export interface V2PluginContext { session?: { hook?: (name: string, cb: (e: V2HttpRequestEvent) => void | Promise) => void | Promise; - synthetic?: (input: { sessionID: string; text: string }) => Promise; + synthetic?: (input: { sessionID: string; text: string; description?: string; resume?: boolean }) => Promise; }; tool?: { transform?: (cb: (editor: V2ToolEditor) => void) => void | Promise; @@ -256,7 +256,9 @@ export function createOpencodeV2Setup(options: OpencodeV2SetupOptions = {}): (ct } } try { - await ctx.session?.synthetic?.({ sessionID: sid, text }); + // resume:false — OpenCode V2 defaults to delivery "steer" + execution.wake(), which would + // start a model turn on every /acp invocation with no user input (spurious empty turns). + await ctx.session?.synthetic?.({ sessionID: sid, text, resume: false }); } catch (err) { console.error(`[bili-opencode] /acp render failed: ${err instanceof Error ? err.message : String(err)}`); } diff --git a/tests/opencode-v2.test.ts b/tests/opencode-v2.test.ts index c3b3c7de35..a38b920088 100644 --- a/tests/opencode-v2.test.ts +++ b/tests/opencode-v2.test.ts @@ -80,7 +80,7 @@ function makeFakeCtx() { let signal: AbortSignal | undefined; const addedTools: FakeAddedTool[] = []; const addedCommands: FakeAddedCommand[] = []; - const syntheticCalls: Array<{ sessionID: string; text: string }> = []; + const syntheticCalls: Array<{ sessionID: string; text: string; description?: string; resume?: boolean }> = []; let modelRequestCb: ((e: Record) => void | Promise) | undefined; const disposed: number[] = []; @@ -91,7 +91,7 @@ function makeFakeCtx() { modelRequestCb = cb; return { dispose: () => { disposed.push(1); } }; }, - synthetic: async (input: { sessionID: string; text: string }) => { + synthetic: async (input: { sessionID: string; text: string; description?: string; resume?: boolean }) => { syntheticCalls.push(input); return {}; }, @@ -355,6 +355,7 @@ test("v2 setup: /acp command registered and renders proxy status panel via synth await until(() => fake.syntheticCalls.length === 1); assert.equal(fake.syntheticCalls[0].sessionID, "ses_acp_1"); assert.match(fake.syntheticCalls[0].text, /ACP-PANEL-OK/); + assert.equal(fake.syntheticCalls[0].resume, false); } finally { cleanup(); } @@ -373,6 +374,7 @@ test("v2 setup: /acp reports no proxy detected via synthetic when no proxy", asy await acp.execute({ sessionID: "s_nopx" }); await until(() => fake.syntheticCalls.length === 1); assert.match(fake.syntheticCalls[0].text, /no proxy detected/); + assert.equal(fake.syntheticCalls[0].resume, false); } finally { cleanup(); }