Skip to content

Commit 8bfeff6

Browse files
vdmkotaicodex
authored andcommitted
fix(opencode): require the exact NotFoundError name for a confirmed miss
A substring match let any status-less error named *NotFound* (UpstreamNotFoundError, ProviderNotFoundError) pass as a missing session and silently start an empty one. OpenCode's API generates exactly name "NotFoundError" for every 404, so match it exactly. Co-authored-by: codex <[email protected]>
1 parent d14ca6e commit 8bfeff6

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,14 +1001,12 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
10011001
// An explicit non-404 status seals its subtree: a 500 whose serialized
10021002
// body echoes a NotFoundError name — or that is itself named
10031003
// *NotFound* — is a real failure, never a miss.
1004-
NodeAssert.equal(
1005-
isOpenCodeNotFound({ status: 500, body: { name: "NotFoundError" } }),
1006-
false,
1007-
);
1008-
NodeAssert.equal(
1009-
isOpenCodeNotFound({ name: "UpstreamNotFoundError", status: 500 }),
1010-
false,
1011-
);
1004+
NodeAssert.equal(isOpenCodeNotFound({ status: 500, body: { name: "NotFoundError" } }), false);
1005+
NodeAssert.equal(isOpenCodeNotFound({ name: "UpstreamNotFoundError", status: 500 }), false);
1006+
// A "NotFound"-flavored name that isn't OpenCode's exact `NotFoundError`
1007+
// is not a confirmed miss even without a sealing status.
1008+
NodeAssert.equal(isOpenCodeNotFound({ name: "UpstreamNotFoundError" }), false);
1009+
NodeAssert.equal(isOpenCodeNotFound({ cause: { name: "ProviderNotFoundError" } }), false);
10121010
NodeAssert.equal(
10131011
isOpenCodeNotFound(
10141012
new Error("x", { cause: { status: 502, body: { name: "NotFoundError" } } }),

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function parseOpenCodeResume(raw: unknown): { readonly sessionId: string } | und
8888
* is `throwOnError: true`, so `session.get` rejects on every non-2xx) must
8989
* propagate, or a transient blip resets a live thread to an empty one — the
9090
* #3604 silent context loss. Decides on structured signals only, never free
91-
* text: a numeric 404 or a `NotFoundError` name, found via a bounded walk
91+
* text: a numeric 404 or the exact `NotFoundError` name, found via a bounded walk
9292
* over `cause`/`body`/`error`/`data`. An explicit non-404 status seals its
9393
* subtree so a wrapped "NotFound" name can't reclassify a real failure.
9494
* Exported for unit testing.
@@ -120,7 +120,7 @@ export function isOpenCodeNotFound(cause: unknown): boolean {
120120
}
121121

122122
const name = record.name;
123-
if (typeof name === "string" && name.toLowerCase().includes("notfound")) {
123+
if (typeof name === "string" && name.toLowerCase() === "notfounderror") {
124124
return true;
125125
}
126126

@@ -1242,7 +1242,7 @@ export function makeOpenCodeAdapter(
12421242
Effect.map((response) => response.data),
12431243
Effect.catchIf(
12441244
(cause) => isOpenCodeNotFound(cause),
1245-
() => Effect.succeed(undefined),
1245+
() => Effect.void,
12461246
),
12471247
)
12481248
: undefined;
@@ -1302,7 +1302,6 @@ export function makeOpenCodeAdapter(
13021302
}
13031303
const createdSession = yield* runOpenCodeSdk("session.create", () =>
13041304
client.session.create({
1305-
title: `T3 Code ${input.threadId}`,
13061305
permission: buildOpenCodePermissionRules(input.runtimeMode),
13071306
}),
13081307
);

0 commit comments

Comments
 (0)