Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@effect/platform-node-shared": "catalog:",
"@effect/sql-sqlite-bun": "catalog:",
"@ff-labs/fff-node": "0.9.4",
"@opencode-ai/sdk": "^1.3.15",
"@opencode-ai/sdk": "^1.18.14",
"@pierre/diffs": "catalog:",
"effect": "catalog:",
"node-pty": "^1.1.0",
Expand Down
23 changes: 22 additions & 1 deletion apps/server/src/provider/Layers/OpenCodeAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {
throw runtimeMock.state.promptAsyncError;
}
},
prompt: async (input: unknown) => {
runtimeMock.state.promptCalls.push(input);
if (runtimeMock.state.promptAsyncError) {
throw runtimeMock.state.promptAsyncError;
}
},
messages: async () => ({ data: runtimeMock.state.messages }),
revert: async ({ sessionID, messageID }: { sessionID: string; messageID?: string }) => {
runtimeMock.state.revertCalls.push({
Expand Down Expand Up @@ -212,6 +218,16 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {
})(),
}),
},
v2: {
session: {
prompt: async (input: unknown) => {
runtimeMock.state.promptCalls.push(input);
if (runtimeMock.state.promptAsyncError) {
throw runtimeMock.state.promptAsyncError;
}
},
},
},
}) as unknown as ReturnType<OpenCodeRuntimeShape["createOpenCodeSdkClient"]>,
loadOpenCodeInventory: () =>
Effect.fail(
Expand Down Expand Up @@ -750,7 +766,9 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
});

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

Expand Down
43 changes: 35 additions & 8 deletions apps/server/src/provider/Layers/OpenCodeAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1481,14 +1481,41 @@ export function makeOpenCodeAdapter(
});
}

yield* runOpenCodeSdk("session.promptAsync", () =>
context.client.session.promptAsync({
sessionID: context.openCodeSessionId,
model: parsedModel,
...(context.activeAgent ? { agent: context.activeAgent } : {}),
...(context.activeVariant ? { variant: context.activeVariant } : {}),
parts: [...(text ? [{ type: "text" as const, text }] : []), ...fileParts],
}),
// A steer sends into the busy session. Use the v2 prompt endpoint with
// `delivery: "steer"` so opencode promotes the message at the next safe
// provider-turn boundary (i.e. after the current tool call) instead of
// deferring it until the whole turn finishes — matching the behavior of
// typing into a native opencode session. Fresh turns keep the legacy
// async prompt since they start the agent loop themselves.
const sendPrompt =
steeringTurnId !== undefined
? context.client.v2.session.prompt({
sessionID: context.openCodeSessionId,
prompt: {
text: text ?? "",
...(fileParts.length > 0
? {
files: fileParts.map((part) => ({
uri: part.url,
mime: part.mime,
...(part.filename !== undefined ? { name: part.filename } : {}),
})),
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Invalid steer file attachment fields

Medium Severity

Steer attachments map legacy file parts into v2 prompt.files with a mime field. OpenCode’s v2 PromptInput.FileAttachment request shape accepts uri plus optional name / description / mention; mime is response-only and inferred by the server. Mid-turn steers that include attachments can fail validation or drop files.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b49bea4. Configure here.

: {}),
},
delivery: "steer",
})
: context.client.session.promptAsync({
sessionID: context.openCodeSessionId,
model: parsedModel,
...(context.activeAgent ? { agent: context.activeAgent } : {}),
...(context.activeVariant ? { variant: context.activeVariant } : {}),
parts: [...(text ? [{ type: "text" as const, text }] : []), ...fileParts],
});
Comment on lines +1490 to +1514

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sendPrompt holds an already-started Promise rather than a thunk, so the HTTP request fires while the generator is building the value instead of when runOpenCodeSdk runs it. That breaks the Effect boundary in two visible ways: the request is no longer tied to the effect's execution/interruption, and a synchronous throw from the SDK call (e.g. client.v2 missing or argument validation) escapes Effect.tryPromise's catch, surfacing as a defect instead of an OpenCodeRuntimeError, so it bypasses toRequestError and the tapError recovery that resets session state and emits turn.aborted.

Consider keeping it a thunk so construction happens inside the effect:

const sendPrompt = () =>
  steeringTurnId !== undefined
    ? context.client.v2.session.prompt({ /* ... */ })
    : context.client.session.promptAsync({ /* ... */ });

yield* runOpenCodeSdk(
  steeringTurnId !== undefined ? "session.prompt" : "session.promptAsync",
  sendPrompt,
).pipe(/* ... */);

Posted via Macroscope — Effect Service Conventions


yield* runOpenCodeSdk(
steeringTurnId !== undefined ? "session.prompt" : "session.promptAsync",
() => sendPrompt,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SDK call escapes error handling

Medium Severity

The steer/fresh prompt is invoked before runOpenCodeSdk, and the helper only returns that already-created promise. Synchronous throws from the SDK client therefore bypass Effect.tryPromise, so they never become OpenCodeRuntimeError / ProviderAdapterRequestError, and the fresh-turn tapError rollback path never runs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b49bea4. Configure here.

).pipe(
Effect.mapError(toRequestError),
// On failure of a fresh turn: clear active-turn state, flip the
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading