Skip to content
TypeScript

fix(server): a Claude hook that drops a prompt now shows its reason (#21231)

fixfone51c0d677776
diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
index f5e16d35031..c47048bac19 100644
--- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
@@ -4198,6 +4198,78 @@ describe("ClaudeAdapterV2 background wake turns", () => {
),
);
+ it.effect("shows a hook-dropped Claude prompt once and skips info-level lines", () =>
+ Effect.gen(function* () {
+ const harness = yield* makeWakeHarness;
+ const now = yield* DateTime.now;
+ yield* harness.runtime.startTurn(
+ makeClaudeTestTurnInput({
+ threadId: harness.threadId,
+ providerThread: harness.providerThread,
+ now,
+ attemptId: RunAttemptId.make("claude-hook-dropped-prompt-attempt"),
+ text: "Deploy to production",
+ attachments: [],
+ }),
+ );
+ const notice = "Prompt dropped by a hook: Deploys are frozen until Monday.";
+ const uuid = "00000000-0000-4000-8000-000000000305";
+ yield* Queue.offer(
+ harness.sdkMessages,
+ claudeSdkFrame({
+ type: "system",
+ subtype: "informational",
+ content: "Started in the background: agent-1",
+ level: "info",
+ session_id: WAKE_NATIVE_SESSION,
+ uuid: "00000000-0000-4000-8000-000000000307",
+ }),
+ );
+ yield* Queue.offer(
+ harness.sdkMessages,
+ claudeSdkFrame({
+ type: "system",
+ subtype: "informational",
+ content: notice,
+ level: "warning",
+ prevent_continuation: true,
+ session_id: WAKE_NATIVE_SESSION,
+ uuid,
+ }),
+ );
+ yield* Queue.offer(
+ harness.sdkMessages,
+ makeResultFrame({
+ uuid: "00000000-0000-4000-8000-000000000306",
+ result: notice,
+ numTurns: 0,
+ terminalReason: null,
+ }),
+ );
+ yield* Queue.take(harness.terminalReceipts);
+ const notices = harness.events.flatMap((event) =>
+ event.type === "turn_item.updated" && event.turnItem.type === "system_notice"
+ ? [event.turnItem]
+ : [],
+ );
+ assert.lengthOf(notices, 1);
+ assert.equal(notices[0]?.message, notice);
+ assert.equal(notices[0]?.status, "completed");
+ assert.equal(notices[0]?.nativeItemRef?.nativeId, uuid);
+ assert.equal(harness.terminalEvents()[0]?.status, "completed");
+ assert.isFalse(
+ harness.events.some(
+ (event) => event.type === "message.updated" && event.message.role === "assistant",
+ ),
+ );
+ }).pipe(
+ Effect.scoped,
+ Effect.provide(
+ Layer.mergeAll(NodeServices.layer, IdAllocator.layer, McpProviderSessions.layer),
+ ),
+ ),
+ );
+
it.effect(
"runs native compaction and keeps its context watermark separate from billed usage",
() =>
diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
index ed7e82d285e..a16bf4c81e9 100644
--- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
@@ -3005,6 +3005,8 @@ interface ActiveClaudeTurnContext {
fallbackText: string;
fallbackNativeItemId: string;
emittedNativeItemIds: Set<string>;
+ // The CLI repeats a notice that ends a prompt as the turn's result text.
+ noticeTexts: Set<string>;
};
readonly reasoning: {
messageId: string | null;
@@ -7180,9 +7182,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
return;
}
- if (message.type === "system" && message.subtype === "model_refusal_fallback") {
+ if (
+ message.type === "system" &&
+ (message.subtype === "model_refusal_fallback" ||
+ (message.subtype === "informational" && message.level !== "info"))
+ ) {
const now = yield* DateTime.now;
const nativeItemId = message.uuid;
+ context.assistant.noticeTexts.add(message.content);
yield* emitProviderEvent({
type: "turn_item.updated",
driver: CLAUDE_PROVIDER,
@@ -7802,7 +7809,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
context.assistant.emittedNativeItemIds.size === 0 &&
context.assistant.fallbackText.length === 0 &&
resultText !== null &&
- resultText.text.length > 0
+ resultText.text.length > 0 &&
+ !context.assistant.noticeTexts.has(resultText.text)
) {
context.assistant.fallbackText = resultText.text;
context.assistant.fallbackNativeItemId = resultText.nativeItemId;
@@ -8677,6 +8685,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
fallbackText: "",
fallbackNativeItemId: `assistant:${turnInput.runId}`,
emittedNativeItemIds: new Set(),
+ noticeTexts: new Set(),
},
reasoning: {
messageId: null,