From b949049dcb2c19d7d1755c8298468180dfe896a7 Mon Sep 17 00:00:00 2001 From: Bryan Morgan Date: Thu, 12 Mar 2026 15:16:50 -0400 Subject: [PATCH] feat(core): add error recovery guidance to non-interactive system prompt The autonomous system prompt did not guide the agent on error recovery, causing fallback loops. Adds a non-interactive error recovery section to renderOperationalGuidelines() gated behind !options.interactive. Covers: analyze before retrying, two-strike rule for trying alternatives, avoid alternating-approach loops, verify fixes incrementally. --- .../src/core/__snapshots__/prompts.test.ts.snap | 16 ++++++++++++++-- packages/core/src/prompts/snippets.ts | 10 ++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/core/src/core/__snapshots__/prompts.test.ts.snap b/packages/core/src/core/__snapshots__/prompts.test.ts.snap index f11af69e7b..41af3e6024 100644 --- a/packages/core/src/core/__snapshots__/prompts.test.ts.snap +++ b/packages/core/src/core/__snapshots__/prompts.test.ts.snap @@ -918,7 +918,13 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi ## Interaction Details - **Help Command:** The user can use '/help' to display help information. -- **Feedback:** To report a bug or provide feedback, please use the /bug command." +- **Feedback:** To report a bug or provide feedback, please use the /bug command. + +## Error Recovery (Non-Interactive) +- **Analyze before retrying:** When a command or tool call fails, read the error message carefully. Identify the root cause before attempting a fix. Do not blindly retry the same command. +- **Two-strike rule:** If the same approach fails twice, try a fundamentally different approach. Do not repeat a failing strategy more than twice. +- **Avoid loops:** If you find yourself alternating between two approaches that both fail, stop and reassess. Consider whether the task requirements need to be adjusted or a completely different tool/method is needed. +- **Incremental progress:** After recovering from an error, verify the fix worked before moving on. Do not assume success." `; exports[`Core System Prompt (prompts.ts) > should handle CodebaseInvestigator with tools=grep_search,glob 1`] = ` @@ -1040,7 +1046,13 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi ## Interaction Details - **Help Command:** The user can use '/help' to display help information. -- **Feedback:** To report a bug or provide feedback, please use the /bug command." +- **Feedback:** To report a bug or provide feedback, please use the /bug command. + +## Error Recovery (Non-Interactive) +- **Analyze before retrying:** When a command or tool call fails, read the error message carefully. Identify the root cause before attempting a fix. Do not blindly retry the same command. +- **Two-strike rule:** If the same approach fails twice, try a fundamentally different approach. Do not repeat a failing strategy more than twice. +- **Avoid loops:** If you find yourself alternating between two approaches that both fail, stop and reassess. Consider whether the task requirements need to be adjusted or a completely different tool/method is needed. +- **Incremental progress:** After recovering from an error, verify the fix worked before moving on. Do not assume success." `; exports[`Core System Prompt (prompts.ts) > should handle git instructions when isGitRepository=false 1`] = ` diff --git a/packages/core/src/prompts/snippets.ts b/packages/core/src/prompts/snippets.ts index bad6827ae7..adfe89738c 100644 --- a/packages/core/src/prompts/snippets.ts +++ b/packages/core/src/prompts/snippets.ts @@ -365,9 +365,19 @@ export function renderOperationalGuidelines( ## Interaction Details - **Help Command:** The user can use '/help' to display help information. - **Feedback:** To report a bug or provide feedback, please use the /bug command. +${!options.interactive ? nonInteractiveErrorRecovery() : ''} `.trim(); } +function nonInteractiveErrorRecovery(): string { + return ` +## Error Recovery (Non-Interactive) +- **Analyze before retrying:** When a command or tool call fails, read the error message carefully. Identify the root cause before attempting a fix. Do not blindly retry the same command. +- **Two-strike rule:** If the same approach fails twice, try a fundamentally different approach. Do not repeat a failing strategy more than twice. +- **Avoid loops:** If you find yourself alternating between two approaches that both fail, stop and reassess. Consider whether the task requirements need to be adjusted or a completely different tool/method is needed. +- **Incremental progress:** After recovering from an error, verify the fix worked before moving on. Do not assume success.`; +} + export function renderSandbox(mode?: SandboxMode): string { if (!mode) return ''; if (mode === 'macos-seatbelt') {