[PR #5192] [MERGED] feat(mari): pause and resume Professor Mari requests on proxy rate limits (#5183) #6668

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5192
Author: @kolacheee
Created: 8/17/2026
Status: ✅ Merged
Merged: 8/17/2026
Merged by: @kolacheee

Base: staging ← Head: feat/5183-mari-rate-limit-pause-resume


📝 Commits (7)

  • 6dd2fc5 feat(mari): pause and resume Professor Mari requests on proxy rate limits (#5183)
  • b1b491c fix(llm): keep admission slot acquisition synchronous when a connection is unthrottled
  • df54eb7 Merge branch 'staging' of https://github.com/Pasta-Devs/Marinara-Engine into feat/5183-mari-rate-limit-pause-resume
  • 8d15237 style(mari-rate-limit): apply prettier formatting to touched files
  • 092e01d fix(mari-rate-limit): address CodeRabbit review
  • 77d79cf Merge branch 'staging' into feat/5183-mari-rate-limit-pause-resume
  • 4ab0f11 fix(mari-rate-limit): give the rate-limit input a programmatic aria-label (CodeRabbit)

📊 Changes

20 files changed (+651 additions, -48 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/client/src/components/connections/ConnectionEditor.tsx (+41 -0)
📝 packages/client/src/hooks/use-connections.ts (+1 -0)
📝 packages/client/src/lib/connection-transfer.ts (+9 -0)
📝 packages/client/src/localization/locales/en.json (+4 -0)
📝 packages/server/src/db/schema/connections.ts (+2 -0)
📝 packages/server/src/services/llm/base-provider.ts (+63 -1)
📝 packages/server/src/services/llm/connection-fallback-provider.ts (+26 -14)
➕ packages/server/src/services/llm/connection-rate-limit-registry.ts (+32 -0)
📝 packages/server/src/services/llm/provider-registry.ts (+5 -1)
📝 packages/server/src/services/llm/providers/anthropic.provider.ts (+9 -2)
📝 packages/server/src/services/llm/providers/google.provider.ts (+11 -4)
📝 packages/server/src/services/llm/providers/openai.provider.ts (+25 -6)
➕ packages/server/src/services/llm/rate-limit-aware-provider.ts (+179 -0)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+73 -8)
📝 packages/server/src/services/storage/connections.storage.ts (+38 -11)
📝 packages/shared/src/schemas/connection.schema.ts (+5 -0)
📝 packages/shared/src/types/connection.ts (+2 -0)
📝 packages/shared/src/types/professor-mari-workspace.ts (+1 -1)
➕ scripts/regressions/rate-limit-aware-provider.regression.ts (+124 -0)

📄 Description

Linked issue

Closes #5183.

Why this change

Professor Mari's agentic loop issues up to 13 back-to-back LLM requests per message (one per tool-call round, MAX_COMMAND_ROUNDS = 12) with no delay between them. On a rate-limited proxy — the issue reports OpenRouter at five messages per minute — that trips the limit mid-task. Worse, a rate-limit error propagated straight out of the loop and the error path discarded every completed round, so the user lost the work and had to re-ask. There was no 429 handling, retry, or backoff anywhere in the LLM layer.

What changed

Reactive pause & resume (always on, every connection). A new typed LLMHttpError{status, retryAfterMs} is thrown by the OpenAI (chat/completions and Responses API), Anthropic, and Google providers so a rate-limit response is distinguishable and Retry-After is captured. A new RateLimitAwareProvider decorator — installed in createLLMProvider for direct callers and around both connection-fallback legs for the main chat/agent path — catches a 429/529 (and 503 with Retry-After), pauses (honoring Retry-After, else capped exponential backoff, bounded to 6 tries, abort-aware), and retries the same request so the task completes.

Proactive per-connection throttle (opt-in). A new Max Requests Per Minute field (Settings → Connections; blank = unlimited) paces requests so a known proxy limit is never hit. It's keyed by a connection-rate-limit registry synced from the storage layer and from Professor Mari's own connection resolution, plumbed end to end (schema → type → DB column → storage create/update/clone/read/delete → client editor → import/export round-trip).

Professor Mari. Completed rounds are now persisted when a request ultimately fails (seeding a placeholder so the trace/thinking is saved even before any visible text), the pause is surfaced as a "paused, resuming in Ns…" status instead of a silent wait, and — for local-sidecar connections — the JSON command-protocol repair budget is larger (6 vs 2) and formatting-repair rounds no longer consume the command-round budget (bounded so repeated stumbles can't run unbounded). So a small local model can fumble the tool-call format a few times without starving the task.

On the separate-tool-call-model question (verify + document): Mari already resolves her connection independently (explicit picker → defaultForAgents role → local-sidecar sentinel → default), so you can already point her at a local sidecar or a different connection today to offload her off your main proxy model — and that sidecar now benefits from the larger repair budget above. A first-class per-tool-round model split remains a possible future enhancement (would need its own issue).

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 is green (TypeScript + ESLint + localization + production build across all packages) and the new scripts/regressions/rate-limit-aware-provider.regression.ts passes — it exercises the reactive retry end to end (retry-then-succeed, non-retryable-propagates, exhaust-after-6), Retry-After parsing, error classification, and the registry.
  • The full Node regression lane passes except runtime-integrity.regression.ts, which fails only on a local Windows checkout because packages/server/src/assets/mlx-runtime-requirements.lock gets CRLF-normalized by autocrlf (its SHA256 then differs from the LF manifest digest); it is unrelated to this change and passes on CI's Linux runner. provider-compat.regression.ts initially caught a real bug in an earlier revision — the decorator awaited before delegating, acquiring the admission slot a microtask late — which is fixed here (the slot is now reserved synchronously when unthrottled).
  • A 3-lens adversarial review ran against this diff; all confirmed findings are fixed in this PR (stream-generator slot leak, cold-registry no-op on Mari's resolve path, persist-no-op-without-visible-text, fallback-path coverage, typed errors on the other providers, absolute repair-refund cap, import clamp, throttle-slot rollback on abort, 503+Retry-After).
  • Please verify in the browser: set Max Requests Per Minute on a connection and confirm the field saves/reloads and round-trips through connection export/import; run Professor Mari against a rate-limited proxy and confirm she shows "paused, resuming" and completes instead of aborting; confirm normal chat generation on that connection is unaffected when the cap is blank.
  • No version bump; version:check not applicable.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG updated under [Unreleased] → Added. The new Max Requests Per Minute connection setting is user-facing config, so a docs/CONFIGURATION.md note (and its docs-i18n mirror) is likely warranted as a follow-up — flagging rather than checking the box.

Summary by CodeRabbit

  • New Features

    • Added configurable per-connection request pacing, with unlimited mode and limits up to 600 requests per minute.
    • Added pacing settings to connection import and export.
    • Added visible rate-limit pause status during workspace tasks.
  • Bug Fixes

    • Automatically retries rate-limited requests using server-provided or capped backoff delays.
    • Preserves workspace progress after failed requests.
    • Improved local-sidecar response repair capacity.
    • Prevents streamed responses from being duplicated during retries.

🔄 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/5192 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/17/2026 **Status:** ✅ Merged **Merged:** 8/17/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/5183-mari-rate-limit-pause-resume` --- ### 📝 Commits (7) - [`6dd2fc5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6dd2fc5425fe0c3395047d04019c39622dba8db7) feat(mari): pause and resume Professor Mari requests on proxy rate limits (#5183) - [`b1b491c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b1b491ccb6e31f285a705a9d594efa64050412b6) fix(llm): keep admission slot acquisition synchronous when a connection is unthrottled - [`df54eb7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/df54eb780afe99acef0af11d31ae315a7bae1086) Merge branch 'staging' of https://github.com/Pasta-Devs/Marinara-Engine into feat/5183-mari-rate-limit-pause-resume - [`8d15237`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8d15237b2d99055adb212d5686cc7b7f551e09de) style(mari-rate-limit): apply prettier formatting to touched files - [`092e01d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/092e01d8aa4a744394452da825e2beb58768e1b6) fix(mari-rate-limit): address CodeRabbit review - [`77d79cf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/77d79cf632cb8f1655d4b64247acd103a5c5349f) Merge branch 'staging' into feat/5183-mari-rate-limit-pause-resume - [`4ab0f11`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4ab0f1141673c9b645873aed881f968db47eeb1f) fix(mari-rate-limit): give the rate-limit input a programmatic aria-label (CodeRabbit) ### 📊 Changes **20 files changed** (+651 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/client/src/components/connections/ConnectionEditor.tsx` (+41 -0) 📝 `packages/client/src/hooks/use-connections.ts` (+1 -0) 📝 `packages/client/src/lib/connection-transfer.ts` (+9 -0) 📝 `packages/client/src/localization/locales/en.json` (+4 -0) 📝 `packages/server/src/db/schema/connections.ts` (+2 -0) 📝 `packages/server/src/services/llm/base-provider.ts` (+63 -1) 📝 `packages/server/src/services/llm/connection-fallback-provider.ts` (+26 -14) ➕ `packages/server/src/services/llm/connection-rate-limit-registry.ts` (+32 -0) 📝 `packages/server/src/services/llm/provider-registry.ts` (+5 -1) 📝 `packages/server/src/services/llm/providers/anthropic.provider.ts` (+9 -2) 📝 `packages/server/src/services/llm/providers/google.provider.ts` (+11 -4) 📝 `packages/server/src/services/llm/providers/openai.provider.ts` (+25 -6) ➕ `packages/server/src/services/llm/rate-limit-aware-provider.ts` (+179 -0) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+73 -8) 📝 `packages/server/src/services/storage/connections.storage.ts` (+38 -11) 📝 `packages/shared/src/schemas/connection.schema.ts` (+5 -0) 📝 `packages/shared/src/types/connection.ts` (+2 -0) 📝 `packages/shared/src/types/professor-mari-workspace.ts` (+1 -1) ➕ `scripts/regressions/rate-limit-aware-provider.regression.ts` (+124 -0) </details> ### 📄 Description ## Linked issue Closes #5183. ## Why this change Professor Mari's agentic loop issues **up to 13 back-to-back LLM requests per message** (one per tool-call round, `MAX_COMMAND_ROUNDS = 12`) with no delay between them. On a rate-limited proxy — the issue reports OpenRouter at five messages per minute — that trips the limit mid-task. Worse, a rate-limit error propagated straight out of the loop and the error path discarded **every completed round**, so the user lost the work and had to re-ask. There was no 429 handling, retry, or backoff anywhere in the LLM layer. ## What changed **Reactive pause & resume (always on, every connection).** A new typed `LLMHttpError{status, retryAfterMs}` is thrown by the OpenAI (chat/completions **and** Responses API), Anthropic, and Google providers so a rate-limit response is distinguishable and `Retry-After` is captured. A new `RateLimitAwareProvider` decorator — installed in `createLLMProvider` for direct callers and around both `connection-fallback` legs for the main chat/agent path — catches a 429/529 (and 503 **with** `Retry-After`), pauses (honoring `Retry-After`, else capped exponential backoff, bounded to 6 tries, abort-aware), and retries the **same** request so the task completes. **Proactive per-connection throttle (opt-in).** A new **Max Requests Per Minute** field (Settings → Connections; blank = unlimited) paces requests so a known proxy limit is never hit. It's keyed by a connection-rate-limit registry synced from the storage layer *and* from Professor Mari's own connection resolution, plumbed end to end (schema → type → DB column → storage create/update/clone/read/delete → client editor → import/export round-trip). **Professor Mari.** Completed rounds are now persisted when a request ultimately fails (seeding a placeholder so the trace/thinking is saved even before any visible text), the pause is surfaced as a **"paused, resuming in Ns…"** status instead of a silent wait, and — for **local-sidecar** connections — the JSON command-protocol repair budget is larger (6 vs 2) and formatting-repair rounds **no longer consume the command-round budget** (bounded so repeated stumbles can't run unbounded). So a small local model can fumble the tool-call format a few times without starving the task. **On the separate-tool-call-model question (verify + document):** Mari already resolves her connection independently (explicit picker → `defaultForAgents` role → local-sidecar sentinel → default), so you can **already point her at a local sidecar or a different connection today** to offload her off your main proxy model — and that sidecar now benefits from the larger repair budget above. A first-class per-tool-round model split remains a possible future enhancement (would need its own issue). ## Validation - [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` is green** (TypeScript + ESLint + localization + production build across all packages) and the new `scripts/regressions/rate-limit-aware-provider.regression.ts` passes — it exercises the reactive retry end to end (retry-then-succeed, non-retryable-propagates, exhaust-after-6), `Retry-After` parsing, error classification, and the registry. - The full Node regression lane passes **except** `runtime-integrity.regression.ts`, which fails only on a local Windows checkout because `packages/server/src/assets/mlx-runtime-requirements.lock` gets CRLF-normalized by autocrlf (its SHA256 then differs from the LF manifest digest); it is unrelated to this change and passes on CI's Linux runner. `provider-compat.regression.ts` initially caught a real bug in an earlier revision — the decorator awaited before delegating, acquiring the admission slot a microtask late — which is fixed here (the slot is now reserved synchronously when unthrottled). - A **3-lens adversarial review** ran against this diff; all confirmed findings are fixed in this PR (stream-generator slot leak, cold-registry no-op on Mari's resolve path, persist-no-op-without-visible-text, fallback-path coverage, typed errors on the other providers, absolute repair-refund cap, import clamp, throttle-slot rollback on abort, 503+Retry-After). - **Please verify in the browser:** set **Max Requests Per Minute** on a connection and confirm the field saves/reloads and round-trips through connection export/import; run Professor Mari against a rate-limited proxy and confirm she shows "paused, resuming" and completes instead of aborting; confirm normal chat generation on that connection is unaffected when the cap is blank. - No version bump; `version:check` not applicable. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) CHANGELOG updated under **[Unreleased] → Added**. The new **Max Requests Per Minute** connection setting is user-facing config, so a `docs/CONFIGURATION.md` note (and its `docs-i18n` mirror) is likely warranted as a follow-up — flagging rather than checking the box. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added configurable per-connection request pacing, with unlimited mode and limits up to 600 requests per minute. - Added pacing settings to connection import and export. - Added visible rate-limit pause status during workspace tasks. - **Bug Fixes** - Automatically retries rate-limited requests using server-provided or capped backoff delays. - Preserves workspace progress after failed requests. - Improved local-sidecar response repair capacity. - Prevents streamed responses from being duplicated during retries. <!-- 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:12:34 +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#6668
No description provided.