Skip to content

Commit 1485ba9

Browse files
fix(server): a Claude resume rejected before the prompt keeps the native session
When Claude Code ends the query before the turn attaches (for example a rejected --resume-session-at point), the prompt was never offered, but the start failure was not treated as a pre-prompt refusal. The context handoff stayed pending, so the next send skipped resume and replaced the native session with a summary. Treat that adapter error as refused before prompt. Fixes #34756 AI-assisted; verified with the tests and tools listed above.
1 parent df7ac55 commit 1485ba9

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ import {
244244
} from "@t3tools/provider-core/server/subagentProjection";
245245

246246
export const CLAUDE_PROVIDER = ProviderDriverKind.make("claudeAgent");
247+
/** The query exited before the turn attached, so the prompt was never offered. */
248+
export const CLAUDE_QUERY_ENDED_BEFORE_TURN_DETAIL =
249+
"Claude provider query ended before the turn could start.";
247250
const CLAUDE_AGENT_SDK_QUERY_PROTOCOL = "claude-agent-sdk.query" as const;
248251

249252
interface ClaudeCacheCreation {
@@ -12127,7 +12130,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1212712130
yield* Ref.update(activeTurn, (current) => (current === context ? null : current));
1212812131
return yield* new ProviderAdapter.ProviderAdapterProtocolError({
1212912132
driver: CLAUDE_PROVIDER,
12130-
detail: "Claude provider query ended before the turn could start.",
12133+
detail: CLAUDE_QUERY_ENDED_BEFORE_TURN_DETAIL,
1213112134
});
1213212135
}
1213312136
if (

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import * as Predicate from "effect/Predicate";
2626
import * as Schema from "effect/Schema";
2727

2828
import * as ServerConfig from "../config.ts";
29+
import {
30+
CLAUDE_PROVIDER,
31+
CLAUDE_QUERY_ENDED_BEFORE_TURN_DETAIL,
32+
} from "./Adapters/ClaudeAdapterV2.ts";
2933
import { withWorkspaceLease } from "../workspace/workspaceLease.ts";
3034
import * as GitWorkflowService from "../git/GitWorkflowService.ts";
3135
import * as ProjectService from "../project/ProjectService.ts";
@@ -95,14 +99,16 @@ class WorktreeRecreateNoBaseError extends Schema.TaggedError<WorktreeRecreateNoB
9599
}
96100

97101
const isProviderTurnStartError = Schema.is(ProviderTurnStartError);
102+
const isProviderAdapterProtocolError = Schema.is(ProviderAdapter.ProviderAdapterProtocolError);
98103
const isProviderAdapterOpenSessionError = Schema.is(
99104
ProviderAdapter.ProviderAdapterOpenSessionError,
100105
);
101106

102107
/**
103108
* Claude refuses these before it reads the prompt: replacing a process running background work,
104109
* launch arguments whose appended system prompt or settings cannot be read, or MCP registration
105-
* that never answers while the query opens.
110+
* that never answers while the query opens. A query that ends before the turn attaches (such as a
111+
* rejected resume point) never received the prompt either.
106112
*/
107113
const PROMPT_REFUSAL_TAGS = [
108114
"ClaudeBackgroundWorkBlocksQueryReplacementError",
@@ -114,6 +120,9 @@ const PROMPT_REFUSAL_TAGS = [
114120

115121
const refusedBeforePrompt = (error: unknown): boolean =>
116122
PROMPT_REFUSAL_TAGS.some((tag) => Predicate.isTagged(error, tag)) ||
123+
(isProviderAdapterProtocolError(error) &&
124+
error.driver === CLAUDE_PROVIDER &&
125+
error.detail === CLAUDE_QUERY_ENDED_BEFORE_TURN_DETAIL) ||
117126
(Predicate.hasProperty(error, "cause") && refusedBeforePrompt(error.cause));
118127

119128
const startFailureMessage = (error: Error): string => {

0 commit comments

Comments
 (0)