Skip to content

Commit 5bac6eb

Browse files
fix(server): keep hidden Stop summaries out of assistant fallback
Record a passive Stop-hook notice's text before skipping it, so a result that repeats the summary cannot become fallback assistant text. Replace the recorded fixture and boundary table with one focused table. AI-assisted; verified with the tests and tools listed above.
1 parent b6b6f5d commit 5bac6eb

3 files changed

Lines changed: 76 additions & 13 deletions

File tree

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8339,6 +8339,70 @@ describe("ClaudeAdapterV2 background wake turns", () => {
83398339
),
83408340
);
83418341

8342+
// The passive row is the frame Claude 2.1.303 emits for a Stop hook returning a systemMessage.
8343+
it.effect.each([
8344+
{ name: "hides a passive summary", level: "notice", visible: false },
8345+
{ name: "shows a blocking notice", level: "notice", preventContinuation: true, visible: true },
8346+
{ name: "shows a warning", level: "warning", visible: true },
8347+
])("Claude Stop-hook notices: $name", ({ level, preventContinuation, visible }) =>
8348+
Effect.gen(function* () {
8349+
const harness = yield* makeWakeHarness;
8350+
yield* harness.runtime.startTurn(
8351+
makeClaudeTestTurnInput({
8352+
threadId: harness.threadId,
8353+
providerThread: harness.providerThread,
8354+
now: yield* DateTime.now,
8355+
attemptId: RunAttemptId.make("claude-stop-hook-notice-attempt"),
8356+
text: "Continue.",
8357+
attachments: [],
8358+
}),
8359+
);
8360+
const content = "Stop says: 40 scans, 0 findings";
8361+
yield* Queue.offer(
8362+
harness.sdkMessages,
8363+
claudeSdkFrame({
8364+
type: "system",
8365+
subtype: "informational",
8366+
content,
8367+
level,
8368+
...(preventContinuation === undefined
8369+
? {}
8370+
: { prevent_continuation: preventContinuation }),
8371+
session_id: WAKE_NATIVE_SESSION,
8372+
uuid: "00000000-0000-4000-8000-000000000820",
8373+
}),
8374+
);
8375+
yield* Queue.offer(
8376+
harness.sdkMessages,
8377+
makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000821", result: content }),
8378+
);
8379+
assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
8380+
assert.deepEqual(
8381+
harness.events.flatMap((event) =>
8382+
event.type === "turn_item.updated" && event.turnItem.type === "system_notice"
8383+
? [event.turnItem.message]
8384+
: [],
8385+
),
8386+
visible ? [content] : [],
8387+
);
8388+
assert.isFalse(
8389+
harness.events.some(
8390+
(event) => event.type === "message.updated" && event.message.role === "assistant",
8391+
),
8392+
);
8393+
}).pipe(
8394+
Effect.scoped,
8395+
Effect.provide(
8396+
Layer.mergeAll(
8397+
NodeServices.layer,
8398+
NodeCrypto.layer,
8399+
IdAllocator.layer,
8400+
McpProviderSessions.layer,
8401+
),
8402+
),
8403+
),
8404+
);
8405+
83428406
it.effect("shows a hook-dropped Claude prompt once and skips info-level lines", () =>
83438407
Effect.gen(function* () {
83448408
const harness = yield* makeWakeHarness;

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9333,22 +9333,24 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
93339333
return;
93349334
}
93359335

9336-
// Claude emits passive Stop summaries as notices. Warnings and notices
9337-
// that prevent continuation still need to explain why a hook blocked work.
93389336
if (
93399337
message.type === "system" &&
93409338
(message.subtype === "model_refusal_fallback" ||
9341-
(message.subtype === "informational" &&
9342-
message.level !== "info" &&
9343-
!(
9344-
message.level === "notice" &&
9345-
message.content.startsWith("Stop says: ") &&
9346-
message.prevent_continuation !== true
9347-
)))
9339+
(message.subtype === "informational" && message.level !== "info"))
93489340
) {
9341+
context.assistant.noticeTexts.add(message.content);
9342+
// A Stop hook's systemMessage arrives as a passive notice after every turn.
9343+
// Warnings and notices that prevent continuation explain a blocked turn.
9344+
if (
9345+
message.subtype === "informational" &&
9346+
message.level === "notice" &&
9347+
message.content.startsWith("Stop says: ") &&
9348+
message.prevent_continuation !== true
9349+
) {
9350+
return;
9351+
}
93499352
const now = yield* DateTime.now;
93509353
const nativeItemId = message.uuid;
9351-
context.assistant.noticeTexts.add(message.content);
93529354
yield* emitProviderEvent({
93539355
type: "turn_item.updated",
93549356
driver: CLAUDE_PROVIDER,

‎apps/server/src/orchestration-v2/Adapters/fixtures/claude-stop-system-message.ndjson‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)