[PR #1318] [MERGED] Fix 429 query retry storm #5038

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1318
Author: @cha1latte
Created: 5/26/2026
Status: ✅ Merged
Merged: 5/26/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/issue-1277-rate-limit-backoff


📝 Commits (2)

  • cf735b3 Fix 429 query retry storm
  • 69a868c Merge remote-tracking branch 'upstream/refactor' into fix/issue-1277-rate-limit-backoff

📊 Changes

7 files changed (+159 additions, -17 deletions)

View changed files

📝 src/app/main.tsx (+3 -1)
📝 src/features/catalog/chats/hooks/use-chats.ts (+5 -12)
📝 src/shared/api/api-errors.ts (+25 -1)
➕ src/shared/api/query-retry.test.ts (+58 -0)
➕ src/shared/api/query-retry.ts (+43 -0)
📝 src/shared/api/remote-runtime.ts (+8 -3)
📝 src/shared/api/tauri-client.test.ts (+17 -0)

📄 Description

Linked issue

Closes #1277

Why this change

  • useChats and useChatSummaries treated 429 responses as retryable up to 10 times, so multiple tabs could keep hammering a self-hosted backend that was already rate limiting.
  • The app-level query defaults also retried without checking API status, so shared API calls had no common rate-limit policy.

What changed

  • Added a shared API query retry helper that blocks 429 retries unless the error carries Retry-After metadata.
  • Preserved normal transient retry behavior: chat queries still keep their existing retry budget for server/network-style failures, and unretryable 4xx errors still stop immediately.
  • Parsed Retry-After from remote runtime HTTP errors into ApiError details so React Query can honor one delayed retry when the backend explicitly asks for it.
  • Added QueryClient and remote-runtime tests for the 429/no-header, 429/Retry-After, 400, and 5xx rows.

Refactor impact

Primary owner:

shared API

Impact areas reviewed:

  • App-level React Query defaults
  • Chat catalog list/summary query hooks
  • Remote runtime HTTP error normalization

Boundary notes:

  • The fix stays in src/shared/api and app/feature query configuration.
  • Engine code remains React-free and does not import shared API adapters.
  • No Rust/server rate-limit policy changes are included.

Pressure points touched:

  • None of the large mode surfaces or Rust command registration paths were touched.

Validation

  • pnpm check passes locally
  • pnpm typecheck passes locally
  • pnpm build passes locally
  • pnpm check:architecture passes locally
  • pnpm check:docs passes locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace passes locally
  • Rust clippy/tests were run for Rust behavior changes
  • Browser or Tauri app manual verification completed
  • Playwright, screenshot, or recording evidence added for UI changes
  • Remote runtime smoke checked when relevant

Manual verification notes

  • Codex reproduced the pre-fix retry behavior with a QueryClient harness: 429 without Retry-After produced 11 attempts while 400 produced 1 attempt.
  • Codex verified the fixed behavior with scratch/issue-1277-repro.test.ts: 429 without Retry-After now produces 1 attempt, 429 with retryAfterMs produces 2 attempts, and 400 still produces 1 attempt.
  • Codex ran pnpm exec vitest run src\shared\api\query-retry.test.ts --reporter=verbose.
  • Codex ran pnpm exec vitest run src\shared\api\tauri-client.test.ts --reporter=verbose.
  • Codex ran pnpm check; it passed architecture, frontend typecheck, Rust cargo check, and docs checks.
  • Codex ran Bunny review before commit/PR; no blocking findings.
  • Human manual browser/Tauri verification is still welcome, but the core retry policy is covered by the automated QueryClient and remote-runtime tests.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

No docs or release metadata changes are included.

UI evidence

N/A - this is a non-visual retry policy fix. The proof is the QueryClient retry harness and shared API tests listed above.


🔄 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/1318 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/26/2026 **Status:** ✅ Merged **Merged:** 5/26/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/issue-1277-rate-limit-backoff` --- ### 📝 Commits (2) - [`cf735b3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cf735b3c0ba04cc3a07d6cdf094216def739a09d) Fix 429 query retry storm - [`69a868c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/69a868cdd6a3ffd4023be283faa5615aa9935815) Merge remote-tracking branch 'upstream/refactor' into fix/issue-1277-rate-limit-backoff ### 📊 Changes **7 files changed** (+159 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `src/app/main.tsx` (+3 -1) 📝 `src/features/catalog/chats/hooks/use-chats.ts` (+5 -12) 📝 `src/shared/api/api-errors.ts` (+25 -1) ➕ `src/shared/api/query-retry.test.ts` (+58 -0) ➕ `src/shared/api/query-retry.ts` (+43 -0) 📝 `src/shared/api/remote-runtime.ts` (+8 -3) 📝 `src/shared/api/tauri-client.test.ts` (+17 -0) </details> ### 📄 Description <!-- Target branch: `refactor`. Change the base to `refactor` before submitting unless a maintainer explicitly asked for another base. --> <!-- Keep all checkboxes unchecked until a human has actually verified them. --> ## Linked issue Closes #1277 ## Why this change - `useChats` and `useChatSummaries` treated 429 responses as retryable up to 10 times, so multiple tabs could keep hammering a self-hosted backend that was already rate limiting. - The app-level query defaults also retried without checking API status, so shared API calls had no common rate-limit policy. ## What changed - Added a shared API query retry helper that blocks 429 retries unless the error carries `Retry-After` metadata. - Preserved normal transient retry behavior: chat queries still keep their existing retry budget for server/network-style failures, and unretryable 4xx errors still stop immediately. - Parsed `Retry-After` from remote runtime HTTP errors into `ApiError` details so React Query can honor one delayed retry when the backend explicitly asks for it. - Added QueryClient and remote-runtime tests for the 429/no-header, 429/Retry-After, 400, and 5xx rows. ## Refactor impact Primary owner: shared API Impact areas reviewed: - App-level React Query defaults - Chat catalog list/summary query hooks - Remote runtime HTTP error normalization Boundary notes: - The fix stays in `src/shared/api` and app/feature query configuration. - Engine code remains React-free and does not import shared API adapters. - No Rust/server rate-limit policy changes are included. Pressure points touched: - None of the large mode surfaces or Rust command registration paths were touched. ## Validation <!-- Check only what you personally ran or manually verified. Treat unchecked items as explicit TODOs. --> - [ ] `pnpm check` passes locally - [ ] `pnpm typecheck` passes locally - [ ] `pnpm build` passes locally - [ ] `pnpm check:architecture` passes locally - [ ] `pnpm check:docs` passes locally - [ ] `cargo check --manifest-path src-tauri/Cargo.toml --workspace` passes locally - [ ] Rust clippy/tests were run for Rust behavior changes - [ ] Browser or Tauri app manual verification completed - [ ] Playwright, screenshot, or recording evidence added for UI changes - [ ] Remote runtime smoke checked when relevant ### Manual verification notes - Codex reproduced the pre-fix retry behavior with a QueryClient harness: 429 without `Retry-After` produced 11 attempts while 400 produced 1 attempt. - Codex verified the fixed behavior with `scratch/issue-1277-repro.test.ts`: 429 without `Retry-After` now produces 1 attempt, 429 with `retryAfterMs` produces 2 attempts, and 400 still produces 1 attempt. - Codex ran `pnpm exec vitest run src\shared\api\query-retry.test.ts --reporter=verbose`. - Codex ran `pnpm exec vitest run src\shared\api\tauri-client.test.ts --reporter=verbose`. - Codex ran `pnpm check`; it passed architecture, frontend typecheck, Rust cargo check, and docs checks. - Codex ran Bunny review before commit/PR; no blocking findings. - Human manual browser/Tauri verification is still welcome, but the core retry policy is covered by the automated QueryClient and remote-runtime tests. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims No docs or release metadata changes are included. ## UI evidence N/A - this is a non-visual retry policy fix. The proof is the QueryClient retry harness and shared API tests listed above. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:41 +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#5038
No description provided.