Skip to content

Commit c5c78e4

Browse files
committed
fix(server): keep the Codex lock error as the in-use error's cause
Turn start shows the in-use error's own message, since the cause is Codex's raw lock text.
1 parent 80f2ac6 commit c5c78e4

6 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3739,6 +3739,11 @@ describe("CodexAdapterV2 post-settle continuation", () => {
37393739
assert.equal(error._tag, "ProviderAdapterThreadInUseError");
37403740
assert.nestedPropertyVal(error, "providerThreadId", harness.providerThread.id);
37413741
assert.include(error.message, "open in another Codex client");
3742+
assert.nestedPropertyVal(
3743+
error,
3744+
"cause.errorMessage",
3745+
`thread ${nativeThreadId} already has an active writer`,
3746+
);
37423747
}).pipe(
37433748
Effect.provide(
37443749
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6714,6 +6714,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
67146714
driver: CODEX_PROVIDER,
67156715
providerThreadId: threadInput.providerThread.id,
67166716
detail: CODEX_THREAD_IN_USE_MESSAGE,
6717+
cause,
67176718
})
67186719
: new ProviderAdapter.ProviderAdapterResumeThreadError({
67196720
driver: CODEX_PROVIDER,

‎apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ effectIt.effect("fails the run instead of replacing a native thread another clie
11711171
driver: ProviderDriverKind.make("codex"),
11721172
providerThreadId: ProviderThreadId.make("new-provider-thread"),
11731173
detail,
1174+
cause: new Error("thread native-resume-thread already has an active writer"),
11741175
}),
11751176
});
11761177

‎apps/server/src/orchestration-v2/ProviderTurnStartService.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ export class ProviderTurnStartError extends Schema.TaggedError<ProviderTurnStart
6565
) {}
6666

6767
const isProviderTurnStartError = Schema.is(ProviderTurnStartError);
68+
const isProviderAdapterThreadInUseError = Schema.is(
69+
ProviderAdapter.ProviderAdapterThreadInUseError,
70+
);
6871

6972
/**
7073
* Claude refuses these before it reads the prompt: replacing a process running background work,
@@ -568,8 +571,10 @@ export const layer: Layer.Layer<
568571
title: failed.title,
569572
failure: makeProviderFailure({
570573
cause: failed.error,
571-
message:
572-
nestedCause instanceof Error
574+
// Its own message says what to do; the cause is the provider's raw lock error.
575+
message: isProviderAdapterThreadInUseError(failed.error)
576+
? failed.error.message
577+
: nestedCause instanceof Error
573578
? nestedCause.message
574579
: typeof nestedCause === "string"
575580
? nestedCause

‎packages/provider-core/src/server/ProviderAdapter.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export class ProviderAdapterThreadInUseError extends Schema.TaggedError<Provider
237237
driver: ProviderDriverKind,
238238
providerThreadId: ProviderThreadId,
239239
detail: Schema.String,
240+
cause: Schema.Defect(),
240241
},
241242
) {
242243
override get message(): string {

‎packages/provider-core/src/server/failure.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ it("explains a native thread another client is writing to", () => {
165165
driver: ProviderDriverKind.make("codex"),
166166
providerThreadId: ProviderThreadId.make("provider-thread:in-use"),
167167
detail: "This conversation is open in another Codex client.",
168+
cause: new Error("thread provider-thread:in-use already has an active writer"),
168169
});
169170
const cause = new ProviderAdapter.ProviderAdapterTurnStartError({
170171
driver: ProviderDriverKind.make("codex"),

0 commit comments

Comments
 (0)