The best way to control Claude Code, Codex and more from any computer or phone
fix(server): show Claude's root refusal when it exits before the turn starts (#34621)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Sohaib Ali committed
Nov 15, 2026 at 00:00 UTC
dbbbe8b0d6efca2c27d331d0435d473192b0b69f
2 files changed
+51
-1
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+44
-1
@@ -13713,6 +13713,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
13713
13714
const openAdapterWhoseFirstQueryEndsBeforeItsFirstFrame = Effect.fnUntraced(function* (
13715
name: string,
13716
+ firstQueryExit: Stream.Stream<
13717
+ SDKMessage,
13718
+ ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError
13719
+ > = Stream.empty,
13720
) {
13721
const fileSystem = yield* FileSystem.FileSystem;
13722
const idAllocator = yield* IdAllocator.IdAllocatorV2;
@@ -13751,7 +13755,9 @@ describe("ClaudeAdapterV2 background wake turns", () => {
13755
// The first CLI exits without writing a frame.
13756
messages:
13757
opened === 1
13754
- ? Stream.empty.pipe(Stream.ensuring(Deferred.succeed(deadStreamEnded, undefined)))
13758
+ ? firstQueryExit.pipe(
13759
+ Stream.ensuring(Deferred.succeed(deadStreamEnded, undefined)),
13760
+ )
13761
: Stream.fromQueue(sdkMessages),
13762
offer: () => Effect.void,
13763
setModel: () => Effect.void,
@@ -13800,6 +13806,43 @@ describe("ClaudeAdapterV2 background wake turns", () => {
13806
return { runtime, turnInput };
13807
});
13808
13809
+ it.effect("shows Claude's root refusal when its query exits before the turn starts", () =>
13810
+ Effect.scoped(
13811
+ Effect.gen(function* () {
13812
+ const harness = yield* openAdapterWhoseFirstQueryEndsBeforeItsFirstFrame(
13813
+ "claude-query-refuses-root-before-frame",
13814
+ Stream.fail(
13815
+ new ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError({
13816
+ method: "fromAsyncIterable",
13817
+ cause: new ClaudeAdapterV2.ClaudeCodeRootRefusalError({
13818
+ cause: new Error("Claude Code process exited with code 1"),
13819
+ }),
13820
+ }),
13821
+ ),
13822
+ );
13823
+ const started = yield* harness.runtime
13824
+ .startTurn(harness.turnInput("a", 1))
13825
+ .pipe(Effect.exit);
13826
+ assert.isTrue(Exit.isFailure(started));
13827
+ if (Exit.isFailure(started)) {
13828
+ assert.strictEqual(
13829
+ makeProviderFailure({ cause: started.cause, class: "transport_error" }).message,
13830
+ "Claude Code exited before it started: --dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons",
13831
+ );
13832
+ }
13833
+ }).pipe(
13834
+ Effect.provide(
13835
+ Layer.mergeAll(
13836
+ IdAllocator.layer,
13837
+ McpProviderSessions.layer,
13838
+ NodeServices.layer,
13839
+ NodeCrypto.layer,
13840
+ ),
13841
+ ),
13842
+ ),
13843
+ ),
13844
+ );
13845
+
13846
it.effect("fails a turn whose Claude query ends before its first frame", () =>
13847
Effect.gen(function* () {
13848
const harness = yield* openAdapterWhoseFirstQueryEndsBeforeItsFirstFrame(
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+7
@@ -5007,6 +5007,8 @@ interface ClaudeLiveQueryContext {
5007
claudeCodeVersion: string | undefined;
5008
permissionMode: PermissionMode;
5009
stopping: boolean;
5010
+ // A turn that had not attached when the CLI exited fails its start with this cause.
5011
+ exitCause: Cause.Cause<ClaudeAgentSdkQueryRunnerError> | undefined;
5012
readonly subagentsFromEarlierProcesses: ReadonlySet<ActiveClaudeSubagent>;
5013
// Subagents this process still ran when a replacement took over; only its exit can end them.
5014
handedOffSubagents: ReadonlySet<ActiveClaudeSubagent>;
@@ -12674,6 +12676,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
12676
claudeCodeVersion: undefined,
12677
permissionMode: queryOptions.permissionMode,
12678
stopping: false,
12679
+ exitCause: undefined,
12680
handedOffSubagents: new Set(),
12681
subagentsFromEarlierProcesses: new Set(
12682
[...(yield* Ref.get(sessionSubagentsByTaskId)).values()].filter(
@@ -12753,6 +12756,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
12756
Effect.exit,
12757
Effect.flatMap(
12758
Effect.fnUntraced(function* (exit: ClaudeQueryStreamExit) {
12759
+ if (exit._tag === "Failure") context.exitCause = exit.cause;
12760
const heldContext = yield* Ref.get(activeTurn);
12761
if (
12762
(yield* Ref.get(queryContext))?.query === querySession &&
@@ -13006,6 +13010,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
13010
return yield* new ProviderAdapter.ProviderAdapterProtocolError({
13011
driver: CLAUDE_PROVIDER,
13012
detail: CLAUDE_QUERY_ENDED_BEFORE_TURN_DETAIL,
13013
+ ...(querySession.exitCause === undefined
13014
+ ? {}
13015
+ : { cause: querySession.exitCause }),
13016
});
13017
}
13018
if (