fix(agents): hide successful resume fallback prefix

This commit is contained in:
Peter Steinberger
2026-04-28 11:37:24 +01:00
parent 6dec2e1852
commit 6559288d4a
2 changed files with 19 additions and 3 deletions

View File

@@ -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",
}),
);

View File

@@ -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 ?? "",