[PR #2397] [MERGED] Feed agent tool-call errors back to the model instead of aborting the run #5578

Closed
opened 2026-10-22 04:17:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2397
Author: @Romuromylus
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/agent-tool-error-feedback


📝 Commits (2)

  • 96cc39e Feed agent tool-call errors back to the model instead of aborting the run
  • e1c53fc Mark Spotify play as called only after it succeeds so the fallback still runs

📊 Changes

1 file changed (+26 additions, -6 deletions)

View changed files

📝 src/engine/agents-runtime/executor/agent-executor.ts (+26 -6)

📄 Description

Linked issue

Closes #2322

Why this change

  • Inside the agent tool-calling loop, any error thrown by a tool was re-thrown unconditionally and converted into a failed AgentResult, so a single recoverable tool failure aborted the entire agent turn. The success path already feeds tool results back to the model, and the main generation tool loop (start-generation.ts:3499-3521) already feeds errors back for self-correction — the agent loop was the lone inconsistency.

What changed

  • In executeAgentWithTools (src/engine/agents-runtime/executor/agent-executor.ts), a thrown tool error is now pushed back as a role: "tool" message { error } with the original tool_call_id, letting the model self-correct within the existing MAX_TOOL_ROUNDS. Cancellation still aborts: a new isAgentCancellation helper re-throws when signal.aborted or err.name === "AbortError".
  • No new imports — the error payload uses JSON.stringify({ error }) (byte-identical to stringifyToolResult({ error })) to avoid an agents-runtime → generation dependency.

Refactor impact

Primary owner: engine generation (agents-runtime)

Impact areas reviewed:

  • src/engine/agents-runtime/executor/agent-executor.ts (executeAgentWithTools tool loop + isAgentCancellation)

Boundary notes:

  • None. Single engine file; no new cross-module dependency. Spotify fallback path has its own try/catch and is untouched.

Pressure points touched:

  • None.

Validation

  • Matching validation command passes locally
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • pnpm vitest run src/engine/agents-runtime/executor/agent-executor.test.ts — 4 passed (2 new, run locally): a thrown tool error is fed back as a role: "tool" message containing the error and the turn still succeeds; a cancellation (AbortError + aborted signal) propagates instead of being swallowed.
  • pnpm exec tsc -b — clean. pnpm exec eslint …agent-executor.ts — clean.

Feature Discoverability

  • Updated src/features/shell/discovery/
  • N/A because this PR is a resilience bugfix in agent plumbing.

Reason:

  • No new discoverable surface.

Docs and release impact

  • No docs changes needed

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/2397 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/agent-tool-error-feedback` --- ### 📝 Commits (2) - [`96cc39e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/96cc39ecc86ab3937bb902f141512933beffd804) Feed agent tool-call errors back to the model instead of aborting the run - [`e1c53fc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e1c53fc3baebf23fb9472ba9f8084fdcd2bfbb21) Mark Spotify play as called only after it succeeds so the fallback still runs ### 📊 Changes **1 file changed** (+26 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/agents-runtime/executor/agent-executor.ts` (+26 -6) </details> ### 📄 Description ## Linked issue Closes #2322 ## Why this change - Inside the agent tool-calling loop, any error thrown by a tool was re-thrown unconditionally and converted into a failed `AgentResult`, so a single recoverable tool failure aborted the entire agent turn. The success path already feeds tool results back to the model, and the main generation tool loop (`start-generation.ts:3499-3521`) already feeds errors back for self-correction — the agent loop was the lone inconsistency. ## What changed - In `executeAgentWithTools` (`src/engine/agents-runtime/executor/agent-executor.ts`), a thrown tool error is now pushed back as a `role: "tool"` message `{ error }` with the original `tool_call_id`, letting the model self-correct within the existing `MAX_TOOL_ROUNDS`. Cancellation still aborts: a new `isAgentCancellation` helper re-throws when `signal.aborted` or `err.name === "AbortError"`. - No new imports — the error payload uses `JSON.stringify({ error })` (byte-identical to `stringifyToolResult({ error })`) to avoid an agents-runtime → generation dependency. ## Refactor impact Primary owner: engine generation (agents-runtime) Impact areas reviewed: - `src/engine/agents-runtime/executor/agent-executor.ts` (`executeAgentWithTools` tool loop + `isAgentCancellation`) Boundary notes: - None. Single engine file; no new cross-module dependency. Spotify fallback path has its own try/catch and is untouched. Pressure points touched: - None. ## Validation - [x] Matching validation command passes locally - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `pnpm vitest run src/engine/agents-runtime/executor/agent-executor.test.ts` — 4 passed (2 new, run locally): a thrown tool error is fed back as a `role: "tool"` message containing the error and the turn still succeeds; a cancellation (`AbortError` + aborted signal) propagates instead of being swallowed. - `pnpm exec tsc -b` — clean. `pnpm exec eslint …agent-executor.ts` — clean. ## Feature Discoverability - [ ] Updated `src/features/shell/discovery/` - [x] N/A because this PR is a resilience bugfix in agent plumbing. Reason: - No new discoverable surface. ## Docs and release impact - [x] No docs changes needed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:32 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5578
No description provided.