[PR #2681] [MERGED] fix(agents): await tool-loop result so a tool failure can't corrupt co-grouped agents #5716

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2681
Author: @kolacheee
Created: 6/20/2026
Status: ✅ Merged
Merged: 6/21/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/issue-2680-agent-tool-rethrow-group


📝 Commits (1)

  • 1ac51f2 fix(agents): await tool-loop result so a tool failure can't corrupt co-grouped agents (#2680)

📊 Changes

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

View changed files

📝 packages/server/src/services/agents/agent-executor.ts (+6 -2)

📄 Description

Linked issue

Closes #2680

Why this change

A tool-using agent whose tool call throws should fail only itself — but today it corrupts every other agent that shares its provider+model job group:

  • executeAgent returned the tool path with return executeAgentWithTools(...) and no await (agent-executor.ts). Without the await, a rethrow from the tool loop (executeToolCall throwing → throw err) escaped this function's own try/catch — the catch that would have produced a failed AgentResult via makeError — and surfaced as a rejected promise.
  • In agent-pipeline.ts, executeGroup joins batch + tool agents for the same provider+model group with Promise.all([...]). One tool agent's rejection rejected that Promise.all, rejecting the whole group.
  • executePhase then caught the rejected group via Promise.allSettled and overwrote every agent in the group — including co-grouped batch agents (e.g. tracker, expression) and sibling tool agents that already succeeded — with success: false error results, discarding their real output.

This is reachable with a realistic config: a custom tool-using agent sharing the default-for-agents connection with the built-in batch agents.

What changed

  • Added await to the tool-loop call in executeAgent (return await executeAgentWithTools(...)), so a rethrow is caught by the function's existing catch and converted into a failed AgentResult for only the failing agent — restoring per-agent isolation.
  • Added an explanatory comment at the call site so the await isn't "optimized away" by a future reader.

Minimal, behavior-preserving for the success path: the no-tools path already returned a failed AgentResult on error, and this makes the tool path do the same.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

pnpm check (TypeScript + ESLint + build) passed in the automated run that produced this change. A human should still confirm:

  • Manually verify isolation: configure a custom tool-using agent that shares the default-for-agents connection (same provider + model) with the built-in batch agents (tracker, expression). Force its tool call to throw (e.g. a tool whose executeToolCall raises). Confirm that only the failing tool agent is reported success: false, and the co-grouped batch agents keep their real output (no [agent-pipeline] Group REJECTED log for the whole group).
  • Manually verify sibling tool agents: if another tool agent in the same group succeeds, confirm it is no longer overwritten as failed.
  • Manually verify the main turn: confirm the main user generation turn is unaffected by the failing agent.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

n/a — server-side agent pipeline change, no UI surface.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling in agent execution to ensure tool-related failures are properly captured and converted to failed results, improving overall reliability and error reporting.

🔄 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/2681 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 6/20/2026 **Status:** ✅ Merged **Merged:** 6/21/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/issue-2680-agent-tool-rethrow-group` --- ### 📝 Commits (1) - [`1ac51f2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1ac51f222c44d62bc65ed449b694a94e6f964ac9) fix(agents): await tool-loop result so a tool failure can't corrupt co-grouped agents (#2680) ### 📊 Changes **1 file changed** (+6 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/agents/agent-executor.ts` (+6 -2) </details> ### 📄 Description ## Linked issue Closes #2680 ## Why this change A tool-using agent whose tool call throws should fail **only itself** — but today it corrupts every other agent that shares its provider+model job group: - `executeAgent` returned the tool path with `return executeAgentWithTools(...)` and **no `await`** (`agent-executor.ts`). Without the `await`, a rethrow from the tool loop (`executeToolCall` throwing → `throw err`) escaped this function's own `try/catch` — the catch that would have produced a failed `AgentResult` via `makeError` — and surfaced as a **rejected promise**. - In `agent-pipeline.ts`, `executeGroup` joins batch + tool agents for the same provider+model group with `Promise.all([...])`. One tool agent's rejection rejected that `Promise.all`, rejecting the whole group. - `executePhase` then caught the rejected group via `Promise.allSettled` and overwrote **every** agent in the group — including co-grouped batch agents (e.g. `tracker`, `expression`) and sibling tool agents that already **succeeded** — with `success: false` error results, discarding their real output. This is reachable with a realistic config: a custom tool-using agent sharing the default-for-agents connection with the built-in batch agents. ## What changed - Added `await` to the tool-loop call in `executeAgent` (`return await executeAgentWithTools(...)`), so a rethrow is caught by the function's existing `catch` and converted into a failed `AgentResult` for **only** the failing agent — restoring per-agent isolation. - Added an explanatory comment at the call site so the `await` isn't "optimized away" by a future reader. Minimal, behavior-preserving for the success path: the no-tools path already returned a failed `AgentResult` on error, and this makes the tool path do the same. ## Validation <!-- Boxes intentionally left UNCHECKED — this PR was prepared with an AI agent. Treat them as a TO-DO list and verify each yourself before ticking. --> - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes `pnpm check` (TypeScript + ESLint + build) passed in the automated run that produced this change. A human should still confirm: - **Manually verify isolation:** configure a custom tool-using agent that shares the default-for-agents connection (same provider + model) with the built-in batch agents (`tracker`, `expression`). Force its tool call to throw (e.g. a tool whose `executeToolCall` raises). Confirm that **only** the failing tool agent is reported `success: false`, and the co-grouped batch agents keep their real output (no `[agent-pipeline] Group REJECTED` log for the whole group). - **Manually verify sibling tool agents:** if another tool agent in the same group succeeds, confirm it is no longer overwritten as failed. - **Manually verify the main turn:** confirm the main user generation turn is unaffected by the failing agent. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) n/a — server-side agent pipeline change, no UI surface. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced error handling in agent execution to ensure tool-related failures are properly captured and converted to failed results, improving overall reliability and error reporting. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:18:48 +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#5716
No description provided.