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
46 changes: 46 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6555,6 +6555,52 @@ describe("ClaudeAdapterV2 background wake turns", () => {
),
);

it.effect("does not count a live model change's stdout echo as background work", () =>
Effect.scoped(
Effect.gen(function* () {
const harness = yield* makeWakeHarness;
yield* harness.runtime.startTurn(
makeClaudeTestTurnInput({
threadId: harness.threadId,
providerThread: harness.providerThread,
now: yield* DateTime.now,
attemptId: RunAttemptId.make("attempt-model-change-echo"),
text: "Hello",
attachments: [],
}),
);
yield* harness.offerAndWait(turnOneResult);
yield* Queue.take(harness.terminalReceipts);

// Claude Code answers set_model with this replayed user frame before the next turn attaches.
yield* harness.offerAndWait(
claudeSdkFrame({
type: "user",
message: {
role: "user",
content:
"<local-command-stdout>Set model to `claude-fable-5-2`</local-command-stdout>",
},
parent_tool_use_id: null,
isReplay: true,
uuid: "00000000-0000-4000-8000-000000000e01",
session_id: WAKE_NATIVE_SESSION,
}),
);
assert.isFalse(yield* harness.hasPendingBackgroundWork);
}).pipe(
Effect.provide(
Layer.mergeAll(
IdAllocator.layer,
McpProviderSessions.layer,
NodeServices.layer,
NodeCrypto.layer,
),
),
),
),
);

it.effect.each([
{
content: { type: "advisor_tool_result_error", error_code: "overloaded" },
Expand Down
13 changes: 13 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3618,6 +3618,17 @@ function isClaudeTurnStartMessage(message: SDKMessage): boolean {
return message.type === "system" && message.subtype === "init";
}

// Claude Code replays a local command's stdout, such as set_model's "Set model to", as a user frame.
function isClaudeLocalCommandEcho(message: SDKMessage): boolean {
return (
message.type === "user" &&
"isReplay" in message &&
message.isReplay === true &&
typeof message.message.content === "string" &&
message.message.content.startsWith("<local-command-stdout>")
);
}

function isClaudeRootTurnFrame(message: SDKMessage): boolean {
return (
isClaudeTurnStartMessage(message) ||
Expand Down Expand Up @@ -9374,6 +9385,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
readonly message: SDKMessage;
}) {
const message = wakeInput.message;
// An idle echo is no wake: buffered, it reads as background work and blocks switches.
if (isClaudeLocalCommandEcho(message)) return;
const isNotification =
message.type === "system" && message.subtype === "task_notification";
const isPendingTaskNotification =
Expand Down
Loading