[PR #7141] [MERGED] fix(agents): preserve Claude thinking and cap reasoning budgets #7496

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7141
Author: @SpicyMarinara
Created: 10/5/2026
Status: ✅ Merged
Merged: 10/5/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/agent-params-review-7131


📝 Commits (6)

  • 2588189 Merge remote-tracking branch 'origin/staging' into fix/agent-connection-params-7131
  • 04a8385 fix(agents): address #7131 review findings
  • c6d3e19 Merge remote-tracking branch 'origin/staging' into fix/agent-connection-params-7131
  • 4ddb906 Merge remote-tracking branch 'origin/staging' into fix/agent-connection-params-7131
  • 1717ba3 Merge remote-tracking branch 'origin/staging' into fix/agent-params-review-7131
  • 7711f0f fix(agents): reserve thinking within fallback context

📊 Changes

12 files changed (+641 additions, -108 deletions)

View changed files

📝 CHANGELOG.md (+3 -0)
📝 docs/prompts/generation-parameters.md (+4 -4)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+2 -1)
📝 packages/server/src/services/agents/agent-executor.ts (+30 -11)
📝 packages/server/src/services/generation/agent-generation-parameters.ts (+42 -20)
📝 packages/server/src/services/generation/illustrator-background-generation.ts (+3 -0)
📝 packages/server/src/services/generation/illustrator-manual-prompt-generation.ts (+7 -9)
📝 packages/server/src/services/llm/base-provider.ts (+10 -2)
📝 packages/server/src/services/llm/connection-fallback-provider.ts (+8 -2)
📝 packages/server/src/services/llm/providers/anthropic.provider.ts (+56 -12)
📝 packages/shared/src/constants/model-lists.ts (+2 -2)
📝 scripts/regressions/agent-connection-parameters.regression.ts (+474 -45)

📄 Description

Linked issue

Refs #7131. Follow-up to #7135, which merged before the review-fix commit 04a8385d2 was included.

Why this change

With reasoning enabled, Claude Opus 4/4.1 agent batches can exceed the model's output limit and receive a 400. Tool-using Claude agents also need to preserve the signed thinking returned by one round when sending the next round. These fixes restore both paths and finish the parameter-handling review fixes from #7135.

What changed

  • Cap manual Claude thinking requests at the model's output limit and preserve signed and redacted thinking through buffered and streamed tool rounds.
  • Size agent thinking headroom against available prompt context, including the Illustrator paths and smaller fallback connections, and correct the Sonnet 4 output limit.
  • Honor connection Send switches on shared-connection agents, retries and package calls; apply saved reasoning only where the model supports it.
  • Expand the existing request-body regression and update parameter documentation and the changelog.

Validation

  • pnpm install and a fresh pnpm check passed at 7711f0fce7519c5903ea98d4bc6cee8f7613dc3d after integrating staging and fixing the GitHub review finding.
  • node scripts/run-regressions.mjs --filter scripts/regressions/agent-connection-parameters.regression.ts passed. It exercises real request bodies with a controlled upstream, including the Opus batch cap, thinking replay, Send switches and context headroom. The added large-primary/small-fallback case failed before the fix and passes afterward with the complete prompt intact; known and unknown context limits are covered. provider-compat.regression.ts also passed.
  • Independent review of the Opus limits and thinking replay found no blocking issue.
  • Local CodeRabbit completed with one minor suggestion, which was traced and rejected: disabling thinking when the nominal visible budget reaches the model cap would override the user's selected reasoning. The final request already caps total output; Opus at the cap sends max_tokens=32000 and budget_tokens=1024, satisfying the strict budget-below-output requirement. Existing boundary regression coverage passes. GitHub CodeRabbit then identified the smaller-fallback context case; that finding is fixed in 7711f0fce, and the incremental local CodeRabbit review completed with zero findings.
  • Docker built and ran with the exact branch commit baked into the image. Health, frontend and multiplayer guest assets passed; production startup/reload passed in desktop Chromium, mobile Chromium and mobile WebKit (3/3).

Manual verification notes

  • Manually verify an Opus 4/4.1 agent batch with reasoning enabled completes without a 400.
  • Manually verify a Claude tool-using agent preserves thinking across rounds.
  • Manually verify connection Send switches and small-context Illustrator requests with your provider.

Docs and release impact

Updated docs/prompts/generation-parameters.md and the Unreleased changelog. No version or storage-format changes. Translation follow-up: #7142 covers the documentation changed by both #7135 and this PR.

UI evidence (if applicable)

No frontend changes in this follow-up.


🔄 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/7141 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/5/2026 **Status:** ✅ Merged **Merged:** 10/5/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/agent-params-review-7131` --- ### 📝 Commits (6) - [`2588189`](https://github.com/Pasta-Devs/Marinara-Engine/commit/25881890cae56c5338a616372d10a64b9cab756a) Merge remote-tracking branch 'origin/staging' into fix/agent-connection-params-7131 - [`04a8385`](https://github.com/Pasta-Devs/Marinara-Engine/commit/04a8385d2ea2ace55f68b390987701c9e3ce4f0a) fix(agents): address #7131 review findings - [`c6d3e19`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c6d3e19ff66d741f6e0ca3a62c5fe0e84073a6e7) Merge remote-tracking branch 'origin/staging' into fix/agent-connection-params-7131 - [`4ddb906`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4ddb906582f28cfc2c0b2c8cea9b503a9e8025a7) Merge remote-tracking branch 'origin/staging' into fix/agent-connection-params-7131 - [`1717ba3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1717ba3bb4df940c7cbe6f9a32a95b1016aaa45e) Merge remote-tracking branch 'origin/staging' into fix/agent-params-review-7131 - [`7711f0f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7711f0fce7519c5903ea98d4bc6cee8f7613dc3d) fix(agents): reserve thinking within fallback context ### 📊 Changes **12 files changed** (+641 additions, -108 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+3 -0) 📝 `docs/prompts/generation-parameters.md` (+4 -4) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+2 -1) 📝 `packages/server/src/services/agents/agent-executor.ts` (+30 -11) 📝 `packages/server/src/services/generation/agent-generation-parameters.ts` (+42 -20) 📝 `packages/server/src/services/generation/illustrator-background-generation.ts` (+3 -0) 📝 `packages/server/src/services/generation/illustrator-manual-prompt-generation.ts` (+7 -9) 📝 `packages/server/src/services/llm/base-provider.ts` (+10 -2) 📝 `packages/server/src/services/llm/connection-fallback-provider.ts` (+8 -2) 📝 `packages/server/src/services/llm/providers/anthropic.provider.ts` (+56 -12) 📝 `packages/shared/src/constants/model-lists.ts` (+2 -2) 📝 `scripts/regressions/agent-connection-parameters.regression.ts` (+474 -45) </details> ### 📄 Description ## Linked issue Refs #7131. Follow-up to #7135, which merged before the review-fix commit `04a8385d2` was included. ## Why this change With reasoning enabled, Claude Opus 4/4.1 agent batches can exceed the model's output limit and receive a 400. Tool-using Claude agents also need to preserve the signed thinking returned by one round when sending the next round. These fixes restore both paths and finish the parameter-handling review fixes from #7135. ## What changed - Cap manual Claude thinking requests at the model's output limit and preserve signed and redacted thinking through buffered and streamed tool rounds. - Size agent thinking headroom against available prompt context, including the Illustrator paths and smaller fallback connections, and correct the Sonnet 4 output limit. - Honor connection Send switches on shared-connection agents, retries and package calls; apply saved reasoning only where the model supports it. - Expand the existing request-body regression and update parameter documentation and the changelog. ## Validation - `pnpm install` and a fresh `pnpm check` passed at `7711f0fce7519c5903ea98d4bc6cee8f7613dc3d` after integrating staging and fixing the GitHub review finding. - `node scripts/run-regressions.mjs --filter scripts/regressions/agent-connection-parameters.regression.ts` passed. It exercises real request bodies with a controlled upstream, including the Opus batch cap, thinking replay, Send switches and context headroom. The added large-primary/small-fallback case failed before the fix and passes afterward with the complete prompt intact; known and unknown context limits are covered. `provider-compat.regression.ts` also passed. - Independent review of the Opus limits and thinking replay found no blocking issue. - Local CodeRabbit completed with one minor suggestion, which was traced and rejected: disabling thinking when the nominal visible budget reaches the model cap would override the user's selected reasoning. The final request already caps total output; Opus at the cap sends `max_tokens=32000` and `budget_tokens=1024`, satisfying the strict budget-below-output requirement. Existing boundary regression coverage passes. GitHub CodeRabbit then identified the smaller-fallback context case; that finding is fixed in `7711f0fce`, and the incremental local CodeRabbit review completed with zero findings. - Docker built and ran with the exact branch commit baked into the image. Health, frontend and multiplayer guest assets passed; production startup/reload passed in desktop Chromium, mobile Chromium and mobile WebKit (3/3). ### Manual verification notes - [ ] Manually verify an Opus 4/4.1 agent batch with reasoning enabled completes without a 400. - [ ] Manually verify a Claude tool-using agent preserves thinking across rounds. - [ ] Manually verify connection Send switches and small-context Illustrator requests with your provider. ## Docs and release impact Updated `docs/prompts/generation-parameters.md` and the Unreleased changelog. No version or storage-format changes. Translation follow-up: #7142 covers the documentation changed by both #7135 and this PR. ## UI evidence (if applicable) No frontend changes in this follow-up. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:20:22 +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#7496
No description provided.