mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2332] [Issue]: Invoke command rate-limit headers are overwritten by the coarse pre-extraction bucket in the middleware (server runtime) #1158
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#1158
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?
Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2332
Originally assigned to: @Xelvanis on GitHub.
Summary
Severity: Low — Correctness (server runtime, advisory headers). For
/api/invoke, the handler sets correct command-specific rate-limit headers, but afternext.run(request)returns the middleware re-applies the coarseinvoke-pre-extractionoutcome withheaders.insert, overwritingratelimit-limit/ratelimit-remaining. Clients always see the coarse 6000 limit for invoke commands, breaking client-side backoff that readsratelimit-remaining. Enforcement (429 + retry-after) is still correct; only the advisory headers are wrong.Expected behavior
The advisory
ratelimit-*headers on an/api/invokeresponse should reflect the command-specific bucket the handler enforced (e.g.update_apply=5,backup_*=30), not the coarse pre-extraction bucket.Actual behavior
src-tauri/src/http_server.rs:1378-1381:/api/invokepasses throughapi_controls_middleware, which computes the coarseinvoke-pre-extractionoutcome (limitINVOKE_PRE_EXTRACTION_API_RATE_LIMIT = 6000). The invoke handler then computes the command-specific outcome and sets correct headers. But the middleware re-applies the coarse outcome viaapply_rate_limit_headers, which usesheaders.insert(1905/1908/1911) — overwriting the handler's headers on every invoke response (success and 429). Enforcement survives because the coarse outcome isallowed(retry_afterNone), so the 429 status + retry-after are not clobbered. The testapi_invoke_enforces_command_specific_rate_limit_at_dispatch_boundarycallsinvoke()directly, bypassing the middleware, so it never catches the overwrite.Steps to reproduce
/api/invokerequest through the production router.ratelimit-*headers (most visible when a command-specific limit likeupdate_apply/backup_*is exceeded): they report the coarse 6000 bucket, not the command limit.Impact area
Environment
b0e5561dLogs, screenshots, or video
Static source audit; cited to file:line above.
Regression notes
Found via static audit of the refactor branch; not verified against main. Advisory-only — server enforcement is correct; impact limited to a client doing adaptive backoff off
ratelimit-remaining, hence low.Additional context
Suggested fix: do not blindly re-apply the coarse outcome over the handler's headers. Simplest: after
next.run, only callapply_rate_limit_headerswhen!response.headers().contains_key("ratelimit-limit")(insert-if-absent), or make the invoke handler the sole header authority for that route.Template check
Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: