[PR #4025] [MERGED] fix(agents): configurable AGENT_CALL_TIMEOUT_MS so slow local models aren't cancelled mid-stream (#3958) #6209

Closed
opened 2026-10-23 04:08:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4025
Author: @SpicyMarinara
Created: 7/24/2026
Status: ✅ Merged
Merged: 7/24/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/3958-agent-call-timeout-env


📝 Commits (4)

  • 9ba3a89 feat(agents): make the agent LLM call timeout configurable via AGENT_CALL_TIMEOUT_MS
  • a4db679 fix: address CodeRabbit review on AGENT_CALL_TIMEOUT_MS PR
  • 3e4f462 Merge branch 'staging' into fix/3958-agent-call-timeout-env
  • df77ce6 docs(env): order AGENT_CALL_TIMEOUT_MS first in the timeouts group

📊 Changes

5 files changed (+56 additions, -7 deletions)

View changed files

📝 .env.example (+5 -0)
📝 CHANGELOG.md (+2 -0)
📝 docs/CONFIGURATION.md (+2 -1)
📝 packages/server/src/config/runtime-config.ts (+35 -0)
📝 packages/server/src/services/agents/agent-executor.ts (+12 -6)

📄 Description

Why

Fixes the root cause reported in #3958 (and its follow-up comment): local LLMs running as agents are cancelled mid-generation and then fail JSON validation on truncated output, even when actively streaming.

The reporter set CHAT_GENERATION_TIMEOUT_MS=3600000 and still saw failures. That's because agent LLM calls never consulted that setting. Every agent call (trackers, HTML reformatter, etc.) was bounded by a hardcoded constant:

const DEFAULT_AGENT_CALL_TIMEOUT_MS = 5 * 60_000; // 300s, hardcoded

turned into AbortSignal.timeout(300_000) in agentCallSignal(). Two consequences:

  1. It's a total-duration cap, not an idle cap — a healthy model streaming at 10–15 tk/s is still killed at exactly 300s. That's the "even when streaming" symptom and matches the llama.cpp cancel task log in the issue.
  2. It ignores every configured timeout. Only the illustrator got a special 30-minute constant.

This also explains the reporter's "mysterious 600s second pass": when the first agent pass is cut at 300s, the truncated output fails JSON validation and the executor automatically retries once with a fresh 300s signal — so from the wall clock the second cancel lands at ~600s. It was 300 + 300, not a different timeout.

What changed

  • runtime-config.ts: new getAgentCallTimeoutMs() reading AGENT_CALL_TIMEOUT_MS (valid range 10000–3600000, default 300000), hot-reloaded per run and validated/warned exactly like CHAT_GENERATION_TIMEOUT_MS.
  • agent-executor.ts: agentCallSignal() now uses the configured value; the illustrator keeps at least its built-in 30-minute budget via Math.max. The hardcoded DEFAULT_AGENT_CALL_TIMEOUT_MS constant is removed (the default now lives in runtime-config).
  • .env.example and docs/CONFIGURATION.md: document the new knob next to CHAT_GENERATION_TIMEOUT_MS, noting it is a total-duration cap applied even while streaming.
  • CHANGELOG.md: Unreleased → Added.

The automatic invalid-JSON retry behavior is unchanged — but with a correctly-sized budget the first pass should now complete, so the double-timeout stops happening.

Test plan

  • With a slow local endpoint (e.g. llama.cpp), enable an agent (HTML reformatter) and a task needing >5 min of generation; confirm it is cancelled at 300s with the default, and completes after setting AGENT_CALL_TIMEOUT_MS=1800000.
  • Confirm an invalid AGENT_CALL_TIMEOUT_MS (e.g. abc, 5, 99999999) logs the range warning once and falls back to 300000.
  • Confirm the value hot-reloads from .env without a server restart (like CHAT_GENERATION_TIMEOUT_MS).
  • Confirm the Illustrator agent still gets at least its 30-minute budget.
  • pnpm check passes. (It passed in the authoring session; re-verify locally.)

Closes #3958.

Summary by CodeRabbit

  • New Features

    • Added the configurable AGENT_CALL_TIMEOUT_MS setting for controlling the maximum duration of individual agent calls, including streaming.
    • Supports values from 10 seconds to 1 hour and applies to the next agent run without restarting.
  • Documentation

    • Documented the new timeout setting in the example environment configuration, configuration reference, and changelog.
  • Bug Fixes

    • Improved support for slow local models by replacing the previous fixed timeout with a configurable limit.

🔄 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/4025 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 7/24/2026 **Status:** ✅ Merged **Merged:** 7/24/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/3958-agent-call-timeout-env` --- ### 📝 Commits (4) - [`9ba3a89`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9ba3a89d1ced506d17c777d77f6baee11adff671) feat(agents): make the agent LLM call timeout configurable via AGENT_CALL_TIMEOUT_MS - [`a4db679`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a4db6799612052b6d05a94ddf89156482a09a7f5) fix: address CodeRabbit review on AGENT_CALL_TIMEOUT_MS PR - [`3e4f462`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3e4f462d6a338499552e048f80c8770cc45984e7) Merge branch 'staging' into fix/3958-agent-call-timeout-env - [`df77ce6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/df77ce6831dc954e921100c59825ca8031406b00) docs(env): order AGENT_CALL_TIMEOUT_MS first in the timeouts group ### 📊 Changes **5 files changed** (+56 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+5 -0) 📝 `CHANGELOG.md` (+2 -0) 📝 `docs/CONFIGURATION.md` (+2 -1) 📝 `packages/server/src/config/runtime-config.ts` (+35 -0) 📝 `packages/server/src/services/agents/agent-executor.ts` (+12 -6) </details> ### 📄 Description ## Why Fixes the root cause reported in #3958 (and its follow-up comment): local LLMs running as agents are cancelled mid-generation and then fail JSON validation on truncated output, even when actively streaming. The reporter set `CHAT_GENERATION_TIMEOUT_MS=3600000` and still saw failures. That's because **agent LLM calls never consulted that setting.** Every agent call (trackers, HTML reformatter, etc.) was bounded by a hardcoded constant: ```ts const DEFAULT_AGENT_CALL_TIMEOUT_MS = 5 * 60_000; // 300s, hardcoded ``` turned into `AbortSignal.timeout(300_000)` in `agentCallSignal()`. Two consequences: 1. It's a **total-duration** cap, not an idle cap — a healthy model streaming at 10–15 tk/s is still killed at exactly 300s. That's the "even when streaming" symptom and matches the llama.cpp `cancel task` log in the issue. 2. It ignores every configured timeout. Only the illustrator got a special 30-minute constant. This also explains the reporter's "mysterious 600s second pass": when the first agent pass is cut at 300s, the truncated output fails JSON validation and the executor automatically retries once with a **fresh** 300s signal — so from the wall clock the second cancel lands at ~600s. It was 300 + 300, not a different timeout. ## What changed - **`runtime-config.ts`**: new `getAgentCallTimeoutMs()` reading `AGENT_CALL_TIMEOUT_MS` (valid range 10000–3600000, default 300000), hot-reloaded per run and validated/warned exactly like `CHAT_GENERATION_TIMEOUT_MS`. - **`agent-executor.ts`**: `agentCallSignal()` now uses the configured value; the illustrator keeps at least its built-in 30-minute budget via `Math.max`. The hardcoded `DEFAULT_AGENT_CALL_TIMEOUT_MS` constant is removed (the default now lives in runtime-config). - **`.env.example`** and **`docs/CONFIGURATION.md`**: document the new knob next to `CHAT_GENERATION_TIMEOUT_MS`, noting it is a total-duration cap applied even while streaming. - **`CHANGELOG.md`**: Unreleased → Added. The automatic invalid-JSON retry behavior is unchanged — but with a correctly-sized budget the first pass should now complete, so the double-timeout stops happening. ## Test plan - [ ] With a slow local endpoint (e.g. llama.cpp), enable an agent (HTML reformatter) and a task needing >5 min of generation; confirm it is cancelled at 300s with the default, and completes after setting `AGENT_CALL_TIMEOUT_MS=1800000`. - [ ] Confirm an invalid `AGENT_CALL_TIMEOUT_MS` (e.g. `abc`, `5`, `99999999`) logs the range warning once and falls back to 300000. - [ ] Confirm the value hot-reloads from `.env` without a server restart (like `CHAT_GENERATION_TIMEOUT_MS`). - [ ] Confirm the Illustrator agent still gets at least its 30-minute budget. - [ ] `pnpm check` passes. (It passed in the authoring session; re-verify locally.) Closes #3958. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added the configurable `AGENT_CALL_TIMEOUT_MS` setting for controlling the maximum duration of individual agent calls, including streaming. * Supports values from 10 seconds to 1 hour and applies to the next agent run without restarting. * **Documentation** * Documented the new timeout setting in the example environment configuration, configuration reference, and changelog. * **Bug Fixes** * Improved support for slow local models by replacing the previous fixed timeout with a configurable limit. <!-- 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-23 04:08:11 +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#6209
No description provided.