Skip to content

Commit e51c0d6

Browse files
authored
fix(server): a Claude hook that drops a prompt now shows its reason (pingdotgg#21231)
1 parent 3cc98ba commit e51c0d6

2 files changed

Lines changed: 83 additions & 2 deletions

File tree

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,6 +4198,78 @@ describe("ClaudeAdapterV2 background wake turns", () => {
41984198
),
41994199
);
42004200

4201+
it.effect("shows a hook-dropped Claude prompt once and skips info-level lines", () =>
4202+
Effect.gen(function* () {
4203+
const harness = yield* makeWakeHarness;
4204+
const now = yield* DateTime.now;
4205+
yield* harness.runtime.startTurn(
4206+
makeClaudeTestTurnInput({
4207+
threadId: harness.threadId,
4208+
providerThread: harness.providerThread,
4209+
now,
4210+
attemptId: RunAttemptId.make("claude-hook-dropped-prompt-attempt"),
4211+
text: "Deploy to production",
4212+
attachments: [],
4213+
}),
4214+
);
4215+
const notice = "Prompt dropped by a hook: Deploys are frozen until Monday.";
4216+
const uuid = "00000000-0000-4000-8000-000000000305";
4217+
yield* Queue.offer(
4218+
harness.sdkMessages,
4219+
claudeSdkFrame({
4220+
type: "system",
4221+
subtype: "informational",
4222+
content: "Started in the background: agent-1",
4223+
level: "info",
4224+
session_id: WAKE_NATIVE_SESSION,
4225+
uuid: "00000000-0000-4000-8000-000000000307",
4226+
}),
4227+
);
4228+
yield* Queue.offer(
4229+
harness.sdkMessages,
4230+
claudeSdkFrame({
4231+
type: "system",
4232+
subtype: "informational",
4233+
content: notice,
4234+
level: "warning",
4235+
prevent_continuation: true,
4236+
session_id: WAKE_NATIVE_SESSION,
4237+
uuid,
4238+
}),
4239+
);
4240+
yield* Queue.offer(
4241+
harness.sdkMessages,
4242+
makeResultFrame({
4243+
uuid: "00000000-0000-4000-8000-000000000306",
4244+
result: notice,
4245+
numTurns: 0,
4246+
terminalReason: null,
4247+
}),
4248+
);
4249+
yield* Queue.take(harness.terminalReceipts);
4250+
const notices = harness.events.flatMap((event) =>
4251+
event.type === "turn_item.updated" && event.turnItem.type === "system_notice"
4252+
? [event.turnItem]
4253+
: [],
4254+
);
4255+
assert.lengthOf(notices, 1);
4256+
assert.equal(notices[0]?.message, notice);
4257+
assert.equal(notices[0]?.status, "completed");
4258+
assert.equal(notices[0]?.nativeItemRef?.nativeId, uuid);
4259+
assert.equal(harness.terminalEvents()[0]?.status, "completed");
4260+
assert.isFalse(
4261+
harness.events.some(
4262+
(event) => event.type === "message.updated" && event.message.role === "assistant",
4263+
),
4264+
);
4265+
}).pipe(
4266+
Effect.scoped,
4267+
Effect.provide(
4268+
Layer.mergeAll(NodeServices.layer, IdAllocator.layer, McpProviderSessions.layer),
4269+
),
4270+
),
4271+
);
4272+
42014273
it.effect(
42024274
"runs native compaction and keeps its context watermark separate from billed usage",
42034275
() =>

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,6 +3005,8 @@ interface ActiveClaudeTurnContext {
30053005
fallbackText: string;
30063006
fallbackNativeItemId: string;
30073007
emittedNativeItemIds: Set<string>;
3008+
// The CLI repeats a notice that ends a prompt as the turn's result text.
3009+
noticeTexts: Set<string>;
30083010
};
30093011
readonly reasoning: {
30103012
messageId: string | null;
@@ -7180,9 +7182,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
71807182
return;
71817183
}
71827184

7183-
if (message.type === "system" && message.subtype === "model_refusal_fallback") {
7185+
if (
7186+
message.type === "system" &&
7187+
(message.subtype === "model_refusal_fallback" ||
7188+
(message.subtype === "informational" && message.level !== "info"))
7189+
) {
71847190
const now = yield* DateTime.now;
71857191
const nativeItemId = message.uuid;
7192+
context.assistant.noticeTexts.add(message.content);
71867193
yield* emitProviderEvent({
71877194
type: "turn_item.updated",
71887195
driver: CLAUDE_PROVIDER,
@@ -7802,7 +7809,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
78027809
context.assistant.emittedNativeItemIds.size === 0 &&
78037810
context.assistant.fallbackText.length === 0 &&
78047811
resultText !== null &&
7805-
resultText.text.length > 0
7812+
resultText.text.length > 0 &&
7813+
!context.assistant.noticeTexts.has(resultText.text)
78067814
) {
78077815
context.assistant.fallbackText = resultText.text;
78087816
context.assistant.fallbackNativeItemId = resultText.nativeItemId;
@@ -8677,6 +8685,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
86778685
fallbackText: "",
86788686
fallbackNativeItemId: `assistant:${turnInput.runId}`,
86798687
emittedNativeItemIds: new Set(),
8688+
noticeTexts: new Set(),
86808689
},
86818690
reasoning: {
86828691
messageId: null,

0 commit comments

Comments
 (0)