@devries-cameron20 / t3code Mirror · read-only / commits / e51c0d6777
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 03:00 UTC

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

fixfon committed Oct 18, 2026 at 23:10 UTC e51c0d677776b63fd9f5c54a87eb8f756712728c
2 files changed +83 -2
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+72
@@ -4198,6 +4198,78 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4198 ),
4199 );
4200
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 +
4273 it.effect(
4274 "runs native compaction and keeps its context watermark separate from billed usage",
4275 () =>
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+11 -2
@@ -3005,6 +3005,8 @@ interface ActiveClaudeTurnContext {
3005 fallbackText: string;
3006 fallbackNativeItemId: string;
3007 emittedNativeItemIds: Set<string>;
3008 + // The CLI repeats a notice that ends a prompt as the turn's result text.
3009 + noticeTexts: Set<string>;
3010 };
3011 readonly reasoning: {
3012 messageId: string | null;
@@ -7180,9 +7182,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7182 return;
7183 }
7184
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 + ) {
7190 const now = yield* DateTime.now;
7191 const nativeItemId = message.uuid;
7192 + context.assistant.noticeTexts.add(message.content);
7193 yield* emitProviderEvent({
7194 type: "turn_item.updated",
7195 driver: CLAUDE_PROVIDER,
@@ -7802,7 +7809,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7809 context.assistant.emittedNativeItemIds.size === 0 &&
7810 context.assistant.fallbackText.length === 0 &&
7811 resultText !== null &&
7805 - resultText.text.length > 0
7812 + resultText.text.length > 0 &&
7813 + !context.assistant.noticeTexts.has(resultText.text)
7814 ) {
7815 context.assistant.fallbackText = resultText.text;
7816 context.assistant.fallbackNativeItemId = resultText.nativeItemId;
@@ -8677,6 +8685,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8685 fallbackText: "",
8686 fallbackNativeItemId: `assistant:${turnInput.runId}`,
8687 emittedNativeItemIds: new Set(),
8688 + noticeTexts: new Set(),
8689 },
8690 reasoning: {
8691 messageId: null,