Skip to content

Commit b49bea4

Browse files
committed
fix(provider): deliver opencode steers immediately at the next tool boundary
1 parent bad1143 commit b49bea4

4 files changed

Lines changed: 63 additions & 15 deletions

File tree

‎apps/server/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@effect/platform-node-shared": "catalog:",
2929
"@effect/sql-sqlite-bun": "catalog:",
3030
"@ff-labs/fff-node": "0.9.4",
31-
"@opencode-ai/sdk": "^1.3.15",
31+
"@opencode-ai/sdk": "^1.18.14",
3232
"@pierre/diffs": "catalog:",
3333
"effect": "catalog:",
3434
"node-pty": "^1.1.0",

‎apps/server/src/provider/Layers/OpenCodeAdapter.test.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {
183183
throw runtimeMock.state.promptAsyncError;
184184
}
185185
},
186+
prompt: async (input: unknown) => {
187+
runtimeMock.state.promptCalls.push(input);
188+
if (runtimeMock.state.promptAsyncError) {
189+
throw runtimeMock.state.promptAsyncError;
190+
}
191+
},
186192
messages: async () => ({ data: runtimeMock.state.messages }),
187193
revert: async ({ sessionID, messageID }: { sessionID: string; messageID?: string }) => {
188194
runtimeMock.state.revertCalls.push({
@@ -212,6 +218,16 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {
212218
})(),
213219
}),
214220
},
221+
v2: {
222+
session: {
223+
prompt: async (input: unknown) => {
224+
runtimeMock.state.promptCalls.push(input);
225+
if (runtimeMock.state.promptAsyncError) {
226+
throw runtimeMock.state.promptAsyncError;
227+
}
228+
},
229+
},
230+
},
215231
}) as unknown as ReturnType<OpenCodeRuntimeShape["createOpenCodeSdkClient"]>,
216232
loadOpenCodeInventory: () =>
217233
Effect.fail(
@@ -750,7 +766,9 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
750766
});
751767

752768
// Steer: OpenCode queues the prompt into the busy session, so the
753-
// active turn id is reused instead of opening a new turn.
769+
// active turn id is reused instead of opening a new turn. The steer is
770+
// delivered via the v2 prompt endpoint with steer delivery so the
771+
// message rides along with the next tool boundary.
754772
const steeredTurn = yield* adapter.sendTurn({
755773
threadId,
756774
input: "actually run 15",
@@ -766,6 +784,9 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
766784
NodeAssert.equal(session?.status, "running");
767785
NodeAssert.equal(String(session?.activeTurnId), String(turn.turnId));
768786
NodeAssert.equal(runtimeMock.state.promptCalls.length, 2);
787+
const steerCall = runtimeMock.state.promptCalls.at(-1) as Record<string, unknown>;
788+
NodeAssert.equal(steerCall.delivery, "steer");
789+
NodeAssert.deepEqual(steerCall.prompt, { text: "actually run 15" });
769790
}),
770791
);
771792

‎apps/server/src/provider/Layers/OpenCodeAdapter.ts‎

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,14 +1481,41 @@ export function makeOpenCodeAdapter(
14811481
});
14821482
}
14831483

1484-
yield* runOpenCodeSdk("session.promptAsync", () =>
1485-
context.client.session.promptAsync({
1486-
sessionID: context.openCodeSessionId,
1487-
model: parsedModel,
1488-
...(context.activeAgent ? { agent: context.activeAgent } : {}),
1489-
...(context.activeVariant ? { variant: context.activeVariant } : {}),
1490-
parts: [...(text ? [{ type: "text" as const, text }] : []), ...fileParts],
1491-
}),
1484+
// A steer sends into the busy session. Use the v2 prompt endpoint with
1485+
// `delivery: "steer"` so opencode promotes the message at the next safe
1486+
// provider-turn boundary (i.e. after the current tool call) instead of
1487+
// deferring it until the whole turn finishes — matching the behavior of
1488+
// typing into a native opencode session. Fresh turns keep the legacy
1489+
// async prompt since they start the agent loop themselves.
1490+
const sendPrompt =
1491+
steeringTurnId !== undefined
1492+
? context.client.v2.session.prompt({
1493+
sessionID: context.openCodeSessionId,
1494+
prompt: {
1495+
text: text ?? "",
1496+
...(fileParts.length > 0
1497+
? {
1498+
files: fileParts.map((part) => ({
1499+
uri: part.url,
1500+
mime: part.mime,
1501+
...(part.filename !== undefined ? { name: part.filename } : {}),
1502+
})),
1503+
}
1504+
: {}),
1505+
},
1506+
delivery: "steer",
1507+
})
1508+
: context.client.session.promptAsync({
1509+
sessionID: context.openCodeSessionId,
1510+
model: parsedModel,
1511+
...(context.activeAgent ? { agent: context.activeAgent } : {}),
1512+
...(context.activeVariant ? { variant: context.activeVariant } : {}),
1513+
parts: [...(text ? [{ type: "text" as const, text }] : []), ...fileParts],
1514+
});
1515+
1516+
yield* runOpenCodeSdk(
1517+
steeringTurnId !== undefined ? "session.prompt" : "session.promptAsync",
1518+
() => sendPrompt,
14921519
).pipe(
14931520
Effect.mapError(toRequestError),
14941521
// On failure of a fresh turn: clear active-turn state, flip the

‎pnpm-lock.yaml‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)