Skip to content

Limit API request size without relying on a proxy - #364

Merged
dipeshbabu merged 1 commit into
mainfrom
feat/request-size-limit
Nov 20, 2026
Merged

dipeshbabu merged 1 commit into
mainfrom
feat/request-size-limit

Conversation

@dipeshbabu

Copy link
Copy Markdown
Owner

The API read request bodies of any size into memory. The Caddy stack limits uploads at the proxy, but managed platforms (Cloud Run, App Runner, ...) and a direct `agentloop server` had no limit.

  • New `agentloop/request_limits.py` ASGI middleware, innermost around the routes (CORS still wraps it):
    • declared `Content-Length` over the limit → `413` before reading (the HTTP server already refuses bodies longer than declared);
    • no declared length (chunked): the body is read here only up to the limit, then replayed to the app; over the limit → `413`. (Raising from `receive` instead was turned into a generic 400 by FastAPI; a test covers this.)
  • `AGENTLOOP_MAX_REQUEST_BYTES`: default 16 MiB (matches the client response cap and the Caddy stack), `0` disables, invalid or negative values fail at startup.
  • Cloud stack passes the setting to the API and documents raising it with the proxy limit.

Behaviour change: uploads over 16 MiB to a server without a proxy now get 413 unless the limit is raised (changelog "Changed").

Tests: within limit, declared oversize, chunked oversize through FastAPI, disabled limit, setting parsing, and a 17 MiB upload to the real API app. Docs: PRODUCTION, CLOUD_DEPLOY, `.env.example`, changelog.

🤖 Generated with Claude Code

Deployments without a reverse proxy, such as managed container
platforms or a direct agentloop server, read request bodies of any size
into memory. The API now refuses bodies over AGENTLOOP_MAX_REQUEST_BYTES
(default 16 MiB, 0 disables) with 413: declared lengths are checked
before reading, and bodies without one are buffered only up to the
limit before being replayed to the application. Invalid settings stop
the server at startup. The cloud stack passes the setting through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown

AgentLoop replay self-test

This required repository check evaluates generated synthetic demo traces. It tests the replay and CI machinery; it does not show that this PR improves application performance.

AgentLoop CI Report

  • Status: passed
  • Replay: Replay passed: latency improvement 69.67%, cost improvement 78.82%, retry delta -1.
  • Merge recommendation: synthetic self-test only; assess application traces before merge
  • Findings: 1 total, 0 high severity, 1 patchable

Performance Gates

Gate Status Detail
latency_regression pass 0.00% regression <= 0.00% allowed
cost_regression pass 0.00% regression <= 0.00% allowed
latency_improvement pass 69.67% improvement >= 20.00% required
cost_improvement pass 78.82% improvement >= 5.00% required
retry_non_increase pass 0 candidate retries <= 1 baseline retries

Trace inputs

This comparison includes synthetic data. It does not establish application performance gains from a pull request.

Side Run ID Path Synthetic marker Source
baseline run_7dbc600b783344eb runs/research_agent_baseline.json yes agentloop_demo
candidate run_51470237fb9e46bb runs/research_agent_optimized.json yes agentloop_demo

Metric Impact

Metric Impact
Latency improvement 69.67%
Cost improvement 78.82%
Retry delta -1
Candidate schema validity not provided
Candidate quality score not provided

Top Findings

Finding Severity Type Rewrite
al_cache_context_f3c3574594e5: Cache repeated prompt/context prefix medium cache_context Move stable instructions into cached prefixes, summaries, or framework-level memory instead of resending full text.

@dipeshbabu
dipeshbabu merged commit 7979ad6 into main Nov 20, 2026
27 checks passed
@dipeshbabu
dipeshbabu deleted the feat/request-size-limit branch November 20, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant