From 6559288d4acd6c4b80c8da127846ec099b13af83 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 28 Apr 2026 11:37:24 +0100 Subject: [PATCH] fix(agents): hide successful resume fallback prefix --- .../bash-tools.exec-approval-followup.test.ts | 4 ++-- .../bash-tools.exec-approval-followup.ts | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/agents/bash-tools.exec-approval-followup.test.ts b/src/agents/bash-tools.exec-approval-followup.test.ts index 2680c886ec0..b99ebe1e5b1 100644 --- a/src/agents/bash-tools.exec-approval-followup.test.ts +++ b/src/agents/bash-tools.exec-approval-followup.test.ts @@ -132,7 +132,7 @@ describe("exec approval followup", () => { expect(callGatewayTool).not.toHaveBeenCalled(); }); - it("falls back to sanitized direct delivery when session resume fails", async () => { + it("falls back to sanitized direct delivery without alarming prefix for successful completions", async () => { vi.mocked(callGatewayTool).mockRejectedValueOnce(new Error("session missing")); await sendExecApprovalFollowup({ @@ -148,7 +148,7 @@ describe("exec approval followup", () => { expect(sendMessage).toHaveBeenCalledWith( expect.objectContaining({ - content: "Automatic session resume failed, so sending the status directly.\n\nall good", + content: "all good", idempotencyKey: "exec-approval-followup:req-session-resume-failed", }), ); diff --git a/src/agents/bash-tools.exec-approval-followup.ts b/src/agents/bash-tools.exec-approval-followup.ts index bdd5d4f6e85..1454277e9ef 100644 --- a/src/agents/bash-tools.exec-approval-followup.ts +++ b/src/agents/bash-tools.exec-approval-followup.ts @@ -120,6 +120,20 @@ function buildSessionResumeFallbackPrefix(): string { return "Automatic session resume failed, so sending the status directly.\n\n"; } +function shouldPrefixDirectFollowupWithSessionResumeFailure(params: { + resultText: string; + sessionError: unknown; +}): boolean { + if (!params.sessionError) { + return false; + } + const parsed = parseExecApprovalResultText(params.resultText); + if (parsed.kind !== "finished") { + return true; + } + return !normalizeLowercaseStringOrEmpty(parsed.metadata).includes("code 0"); +} + function canDirectSendDeniedFollowup(sessionError: unknown): boolean { return sessionError !== null; } @@ -173,7 +187,9 @@ async function sendDirectFollowupFallback(params: { return false; } - const prefix = params.sessionError ? buildSessionResumeFallbackPrefix() : ""; + const prefix = shouldPrefixDirectFollowupWithSessionResumeFailure(params) + ? buildSessionResumeFallbackPrefix() + : ""; await sendMessage({ channel: params.deliveryTarget.channel, to: params.deliveryTarget.to ?? "",