[PR #2073] [MERGED] Fix hostable remote API controls #5418

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2073
Author: @cha1latte
Created: 6/3/2026
Status: ✅ Merged
Merged: 6/3/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/issue-2059-remote-api-controls


📝 Commits (4)

  • 08b8830 Fix remote API control parity
  • dde9ff1 Apply command-aware remote API limits
  • 43069e4 Rate limit malformed remote invokes
  • cd36b38 Keep invoke pre-extraction limit nonrestrictive

📊 Changes

1 file changed (+616 additions, -14 deletions)

View changed files

📝 src-tauri/src/http_server.rs (+616 -14)

📄 Description

Linked issue

Closes #2059

Why this change

  • The hostable Rust Remote Runtime was missing legacy-equivalent API abuse, request body, and no-store cache controls that the legacy Fastify server applied to API traffic.
  • Remote clients already preserve Retry-After metadata, but the hostable runtime did not have an app-owned source for 429 throttling, explicit upload/body limits, or default API JSON no-store policy.

What changed

  • Added hostable API control middleware in src-tauri/src/http_server.rs.
  • Restored legacy-sized explicit request body policy with a 256 MiB Axum body limit plus an early Content-Length rejection for oversized unsafe API requests.
  • Added per-IP API rate buckets with legacy-shaped default and route-specific limits, including RateLimit-* headers and Retry-After on 429.
  • Added command-aware /api/invoke buckets for sensitive dispatch commands, so backup/update/bulk-import/haptic commands are limited at the real mounted runtime boundary.
  • Kept the coarse /api/invoke middleware bucket so malformed invoke requests are still throttled before JSON extraction succeeds, while making it non-restrictive relative to parsed command budgets.
  • Split /api/llm/stream/:stream_id/cancel into its own control-plane bucket so cancel requests are not blocked by exhausted stream creation traffic.
  • Added default Cache-Control: no-store for /api/ responses while preserving existing explicit cache headers on managed assets.
  • Added focused Rust tests for the positive rows and negative controls.

Refactor impact

Primary owner:

  • Remote runtime / hostable HTTP dispatch in src-tauri.

Impact areas reviewed:

  • Hostable /api/invoke
  • Dedicated hostable API routes: /api/import/st-bulk/run, /api/sidecar/v1/embeddings, /api/llm/stream, /api/backup, /api/updates/apply
  • Managed asset cache headers
  • Existing hostable auth, CSRF, IP allowlist, and security header tests

Boundary notes:

  • The fix stays in the Rust HTTP runtime owner. No React UI, engine, or shared API wrapper behavior changed.
  • The explicit remote HTTP pipeline remains intact: shared clients still call existing routes, and hostable runtime controls are enforced at the HTTP boundary.

Pressure points touched:

  • src-tauri/src/http_server.rs middleware and route-level tests.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • Codex ran cargo test --manifest-path src-tauri\Cargo.toml http_server::tests::api_ --lib: 9 passed.
  • Codex ran cargo test --manifest-path src-tauri\Cargo.toml http_server --lib: 35 passed.
  • Codex ran cargo check --manifest-path src-tauri\Cargo.toml: passed.
  • Codex ran pnpm check:architecture: passed.
  • Codex ran node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json: passed.
  • Codex ran pnpm check: passed.
  • Bunny pre-PR review: pass before opening. Bunny found route-limit placement issues on the draft; Codex repaired them, including malformed invoke throttling and the coarse invoke bucket undercut, then reran focused Rust tests, proof gate, and pnpm check successfully.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Internal remote-runtime bugfix only; no user-discoverable surface is added.

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

UI evidence

N/A. This is a backend/hostable HTTP runtime control fix with command and Rust test proof rather than visible UI behavior.


🔄 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/2073 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/3/2026 **Status:** ✅ Merged **Merged:** 6/3/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/issue-2059-remote-api-controls` --- ### 📝 Commits (4) - [`08b8830`](https://github.com/Pasta-Devs/Marinara-Engine/commit/08b8830f70ccc534596413d05502a75ce625a938) Fix remote API control parity - [`dde9ff1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dde9ff163fd152f99a42087bd3abaf6c3671f96d) Apply command-aware remote API limits - [`43069e4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/43069e4ad7d0995604d0465cc541a707cb322239) Rate limit malformed remote invokes - [`cd36b38`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cd36b3892e569aed86eaa5ca130fd7cedc48e61a) Keep invoke pre-extraction limit nonrestrictive ### 📊 Changes **1 file changed** (+616 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/http_server.rs` (+616 -14) </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 #2059 ## Why this change - The hostable Rust Remote Runtime was missing legacy-equivalent API abuse, request body, and no-store cache controls that the legacy Fastify server applied to API traffic. - Remote clients already preserve `Retry-After` metadata, but the hostable runtime did not have an app-owned source for `429` throttling, explicit upload/body limits, or default API JSON no-store policy. ## What changed - Added hostable API control middleware in `src-tauri/src/http_server.rs`. - Restored legacy-sized explicit request body policy with a 256 MiB Axum body limit plus an early `Content-Length` rejection for oversized unsafe API requests. - Added per-IP API rate buckets with legacy-shaped default and route-specific limits, including `RateLimit-*` headers and `Retry-After` on `429`. - Added command-aware `/api/invoke` buckets for sensitive dispatch commands, so backup/update/bulk-import/haptic commands are limited at the real mounted runtime boundary. - Kept the coarse `/api/invoke` middleware bucket so malformed invoke requests are still throttled before JSON extraction succeeds, while making it non-restrictive relative to parsed command budgets. - Split `/api/llm/stream/:stream_id/cancel` into its own control-plane bucket so cancel requests are not blocked by exhausted stream creation traffic. - Added default `Cache-Control: no-store` for `/api/` responses while preserving existing explicit cache headers on managed assets. - Added focused Rust tests for the positive rows and negative controls. ## Refactor impact Primary owner: - Remote runtime / hostable HTTP dispatch in `src-tauri`. Impact areas reviewed: - Hostable `/api/invoke` - Dedicated hostable API routes: `/api/import/st-bulk/run`, `/api/sidecar/v1/embeddings`, `/api/llm/stream`, `/api/backup`, `/api/updates/apply` - Managed asset cache headers - Existing hostable auth, CSRF, IP allowlist, and security header tests Boundary notes: - The fix stays in the Rust HTTP runtime owner. No React UI, engine, or shared API wrapper behavior changed. - The explicit remote HTTP pipeline remains intact: shared clients still call existing routes, and hostable runtime controls are enforced at the HTTP boundary. Pressure points touched: - `src-tauri/src/http_server.rs` middleware and route-level tests. ## Validation <!-- Check only what you personally ran or manually verified. Treat unchecked items as explicit TODOs. --> <!-- Do not submit *.test.ts or *.test.tsx files as PR proof; cite existing checks, command output, app/browser/Tauri verification, or manual notes instead. --> - [ ] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - Codex ran `cargo test --manifest-path src-tauri\Cargo.toml http_server::tests::api_ --lib`: 9 passed. - Codex ran `cargo test --manifest-path src-tauri\Cargo.toml http_server --lib`: 35 passed. - Codex ran `cargo check --manifest-path src-tauri\Cargo.toml`: passed. - Codex ran `pnpm check:architecture`: passed. - Codex ran `node C:\Users\celia\.codex\tools\marinara-proof-gate.mjs scratch\bugfix-verification.json`: passed. - Codex ran `pnpm check`: passed. - Bunny pre-PR review: pass before opening. Bunny found route-limit placement issues on the draft; Codex repaired them, including malformed invoke throttling and the coarse invoke bucket undercut, then reran focused Rust tests, proof gate, and `pnpm check` successfully. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [ ] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Internal remote-runtime bugfix only; no user-discoverable surface is added. ## 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 ## UI evidence N/A. This is a backend/hostable HTTP runtime control fix with command and Rust test proof rather than visible UI behavior. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:16:08 +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#5418
No description provided.