Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: no automatic retry after a declined approval

Samrat Talukdar608f7617bbaf
diff --git a/apps/app/src/app/lib/good-session.ts b/apps/app/src/app/lib/good-session.ts
index f855cfc9..d66a5015 100644
--- a/apps/app/src/app/lib/good-session.ts
+++ b/apps/app/src/app/lib/good-session.ts
@@ -860,6 +860,9 @@ function lastTurnEnd(messages: readonly UIMessage[]): TurnEnding {
return compaction ? { ...ending, retryable: false } : ending;
}
+/** A tool call the user declined in the approval card (the engine's RejectedError / CorrectedError text). */
+const DECLINED_TOOL = "The user rejected permission to use this specific tool call";
+
function turnEndOf(turn: readonly UIMessage[], last: UIMessage): TurnEnding {
const completed = messageOpencode(last).completed;
const endedAt = typeof completed === "number" ? completed : null;
@@ -868,6 +871,7 @@ function turnEndOf(turn: readonly UIMessage[], last: UIMessage): TurnEnding {
let finalText = "";
let afterLastTool = true;
let unfinished = false;
+ let declined = false;
let finish = "";
for (const message of turn) {
const reason = messageOpencode(message).finish;
@@ -878,6 +882,7 @@ function turnEndOf(turn: readonly UIMessage[], last: UIMessage): TurnEnding {
afterLastTool = false;
finalText = "";
if (value.state === "input-streaming" || value.state === "input-available") unfinished = true;
+ else if (value.state === "output-error" && str(value.errorText).startsWith(DECLINED_TOOL)) declined = true;
} else if (part.type === "text" && str(value.text).trim()) {
afterLastTool = true;
finalText = str(value.text);
@@ -885,6 +890,8 @@ function turnEndOf(turn: readonly UIMessage[], last: UIMessage): TurnEnding {
}
}
const reason = finish.toLowerCase();
+ // A turn that ended on a declined approval is the user's stop: no automatic "continue" (as the CLI).
+ if (declined && !unfinished && !(afterLastTool && finalText.trim())) return { ended: "stopped", endedAt, retryable: false };
if (unfinished || BAD_FINISH.has(reason) || !finalText.trim() || !afterLastTool) {
// A tool chain cut mid-call, or a stream that ended on an error or between tool calls.
return { ended: "cut", endedAt, retryable: unfinished || reason === "tool-calls" || reason === "error" };
diff --git a/apps/app/tests/good-session.test.tsx b/apps/app/tests/good-session.test.tsx
index f73bbade..49340111 100644
--- a/apps/app/tests/good-session.test.tsx
+++ b/apps/app/tests/good-session.test.tsx
@@ -719,6 +719,16 @@ describe("the server's auto-retry and one-more-turn nudge", () => {
expect(autoRetryMessage({ ...base, ended: busy.ended, retryable: busy.retryable })).toBe("Continue.");
});
+ test("never after a declined approval: the turn ended on the user's stop", () => {
+ const declined = tool("bash", { command: "npm publish" }, "output-error", "The user rejected permission to use this specific tool call.");
+ const facts = messageFacts([prompt(), assistant("a1", [declined], { finish: "tool-calls" })]);
+ expect(facts.ended).toBe("stopped");
+ expect(autoRetryMessage({ ...base, ended: facts.ended, retryable: facts.retryable })).toBeNull();
+ // Any other failed tool call that cut the chain is still retried once.
+ const failed = messageFacts([prompt(), assistant("a2", [tool("bash", { command: "make" }, "output-error", "exit 2")], { finish: "tool-calls" })]);
+ expect(autoRetryMessage({ ...base, ended: failed.ended, retryable: failed.retryable })).toBe("Continue.");
+ });
+
test("never after the Stop button or on a refusal", () => {
expect(autoRetryMessage({ ...base, userStopped: true })).toBeNull();
expect(autoRetryMessage({ ...base, ended: "stopped", retryable: false })).toBeNull();