mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #8585] [MERGED] fix(llm): retell tool history for endpoints that refuse the tool role #8686
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#8686
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8585
Author: @ylli-selmani
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ylli-selmani
Base:
staging← Head:fix/provider-tool-history📝 Commits (6)
24d93abfix(llm): retell tool history for endpoints that refuse the tool role061f9d1fix(llm): log the shaped request and cover Anthropic's tool-role wording838246afix(llm): refusal-anchored tool-role detector, alternated retold historya9abf67fix(llm): require the verdict to follow the quoted tool role39f7297fix(llm): make the tool-role verdict a refusal, not a permissiona868f95fix(llm): require a stated refusal, not a conditional complaint📊 Changes
2 files changed (+369 additions, -16 deletions)
View changed files
📝
packages/server/src/services/llm/providers/openai.provider.ts(+114 -16)➕
scripts/regressions/provider-tool-history-shape.regression.ts(+255 -0)📄 Description
Why
A reporter runs Professor Mari on a LinkAPI connection typed OpenAI. LinkAPI serves Claude, so it translates
Chat Completions into Anthropic's Messages API. Mari's first tool round works —
toolsgo out, the model returnstool_calls, she reads the lorebook — and the next round dies:Anthropic's Messages API has only
userandassistant; tool results must be content inside a user turn. So thereplayed
{role: "tool"}row is refused. Because the proxy reports it as HTTP 429, it is also treated as a ratelimit and retried with backoff (two different
request ids in the banner, "Worked for 24s") before the run fails.This is the second, distinct half of #8564. #8576 fixed tools being dropped for uncatalogued models; tools are
now sent, which is exactly what exposes the history shape. Same connection type, so it is not Mari-specific: game
mode tools and agent tools fail on the same second round.
Related: #8584.
What changed
packages/server/src/services/llm/providers/openai.provider.tsisToolRoleRejectionmatches the role/tool wording LinkAPI and Anthropic use. It onlyfires when the request that failed actually carried a
toolrow, so a plain rate limit is never reshaped.anthropicSafeWireMessagesgainsretellToolRounds, which retells every tool round astext — calls folded into the assistant turn (its words are kept when it has them), results folded into one user
message.
toolRoleSafeWireMessagesis the always-retell entry point. Nativetoolsstay in the body.refusedToolHistories, per gateway and model, an hour on the monotonic clock, bounded — laterrounds send the retold shape immediately instead of losing one request to the refusal every round. The existing
reasoning-effort refusal store now shares the same read/write helpers.
postChatCompletionsbeside the role-alternation and Anthropic-shape retries,but is not gated on status 400 (the proxy's status is 429).
scripts/regressions/provider-tool-history-shape.regression.tstools, returnstool_calls, and refuses any{role: "tool"}with that exact 429 body.a Claude-looking and a plain proxy-alias model id, the remembered endpoint skipping the refusal on the next
round, the memory being scoped per model, and a plain 429 that must still surface as a typed error after exactly
one request.
Verification
provider-tool-history-shape.regression.ts: passes (pre-fix the same round was refused, proven with a throwawayfixture against unmodified
stagingbefore the change).--filter provider-): 8/8 passed, includingprovider-unknown-model-tools(#8576) andprovider-compat.pnpm check: exit 0.24d93ab80: three findings. One taken (debug log of the shaped request), one partly taken(the regression now also feeds Anthropic's own wording), two declined with code reasons:
and textless rounds, so it does not prove this endpoint refuses the tool role; the new branch already remembers
when the body names the tool role.
400-gated retries never fire. The fixture keeps it.
Manual verification
lorebook entry, confirm the first round works and the second round no longer fails with
Unexpected role.role: "tool"and is not reshaped (debug logshould show no tool-role retry).
Known limit
The retold history loses
tool_use/tool_resultpairing, so a model may repeat a read. That is what this endpointcan take, and it matches the path the provider already used for tool rounds with no words.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.