Skip to content

feat(api): add configurable --max-request-size flag to serve api - #3938

Merged
aheritier merged 2 commits into
mainfrom
feat/api-max-request-size
Aug 10, 2026
Merged

feat(api): add configurable --max-request-size flag to serve api#3938
aheritier merged 2 commits into
mainfrom
feat/api-max-request-size

Conversation

@aheritier

Copy link
Copy Markdown
Collaborator

Fixes #3937.

Adds --max-request-size <bytes> to serve api, mirroring the flag that serve chat already has. The default remains 1 MiB; requests exceeding the limit return HTTP 413.

Changes:

  • pkg/server: new Option/WithMaxRequestBytes functional option (variadic — all ~22 existing NewWithManager/New call sites compile unchanged, keeping the 1 MiB default)
  • cmd/root/api.go: --max-request-size PersistentFlag (int64 bytes, default 1<<20) threaded through server.New
  • pkg/server/server_test.go: table tests for custom cap on POST /api/sessions/:id/messages (under-limit→400, over-limit→413) and zero/negative fallback to 1 MiB
  • docs/features/api-server/index.md: new CLI flags table row documenting default, units, and 413 behaviour

Note: The flag help string includes "(default 1 MiB)" alongside Cobra's auto-appended "(default 1048576)" — this matches the existing pattern in serve chat and is intentionally kept for consistency.

@aheritier
aheritier marked this pull request as ready for review August 6, 2026 22:43
@aheritier
aheritier requested a review from a team as a code owner August 6, 2026 22:43
@aheritier aheritier added area/cli CLI commands, flags, output formatting area/core Core agent runtime, session management area/docs Documentation changes kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Aug 6, 2026

@aheritier aheritier left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Solid, well-scoped implementation. The variadic Option pattern keeps all existing New/NewWithManager call sites compiling unchanged and preserves the 1 MiB default, and the zero/negative fallback is both implemented and tested. Tests cover the three behaviours that matter — under-limit passthrough, over-limit 413, and zero/negative fallback — and correctly target the POST /api/sessions/:id/messages route called out in #3937.

One major item to address before merge (the canonical CLI reference), plus two non-blocking notes — all left as inline comments.

Leaving this as a comment rather than an approval only because the required checks haven't reported yet; happy to approve once they're green.

| ------------------ | ---------------- | ------------------------------------------------ |
| `-l, --listen` | `127.0.0.1:8080` | Address to listen on |
| `--auth-token` | (none) | Bearer token required for all API requests. Leave empty to disable authentication (safe when listening on loopback interfaces only). Recommended when `--listen` binds to a network-reachable interface. |
| `--max-request-size <bytes>` | `1048576` (1 MiB) | Maximum request body size in bytes. Requests whose body exceeds this limit are rejected with HTTP 413 (Request Entity Too Large). |

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] The canonical CLI reference is missing this flag.

docs/features/cli/index.md carries a per-command flags table, and the serve api table (under ### docker agent serve api, lines 282–292 on main) still lacks --max-request-size. The precedent set by serve chat — the very flag this PR mirrors — documents it in both places:

  • docs/features/cli/index.md:396
  • docs/features/chat-server/index.md:198

This PR updates only this file, so the CLI reference now under-documents serve api relative to serve chat. Please add a matching row to the serve api flags table in docs/features/cli/index.md.

Comment thread pkg/server/server.go
Comment on lines +74 to +77
maxBytes := o.maxRequestBytes
if maxBytes <= 0 {
maxBytes = defaultMaxRequestBytes
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] Duplicated default/fallback logic across the two servers.

This repeats the defaultMaxRequestBytes constant and the <= 0 fallback that pkg/chatserver/server.go already has (:104, :226-228). Acceptable as-is since these are independent packages — flagging only in case you'd prefer a small shared helper so the two can't drift.

Comment thread cmd/root/api.go
cmd.PersistentFlags().StringVar(&flags.fakeResponses, "fake", "", "Replay AI responses from cassette file (for testing)")
cmd.PersistentFlags().StringVar(&flags.recordPath, "record", "", "Record AI API interactions to cassette file")
cmd.PersistentFlags().StringVar(&flags.authToken, "auth-token", "", "Bearer token required for API requests (empty = no authentication)")
cmd.PersistentFlags().Int64Var(&flags.maxRequestSize, "max-request-size", 1<<20, "Maximum request body size in bytes (default 1 MiB). Requests exceeding this limit are rejected with HTTP 413.")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Help-string double default.

(default 1 MiB) renders alongside Cobra's auto-appended (default 1048576). You already called this out as intentional for consistency with serve chat (cmd/root/chat.go:51) — agreed, no change needed. Noting it only so the next reader doesn't re-file it.

@aheritier

Copy link
Copy Markdown
Collaborator Author

🤖 Automated implementer agentthis comment was posted by the implementer bot from Docker Agentic Platform, not by a human developer

Addressing the three review threads:

[major] Missing --max-request-size in docs/features/cli/index.md — Fixed in commit d06f142. Added the row to the serve api flags table immediately after --auth-token, matching the ordering and format of the serve chat entry at line 395.

[minor] Duplicated default/fallback logic — Keeping it as-is. pkg/server and pkg/chatserver are independent packages with different callers and lifetimes. A shared helper would add a cross-package dependency for a trivial two-line pattern, and if the two servers ever need different defaults that divergence is intentional. Happy to extract if the team prefers, but leaving it separate for now.

[nit] Double default in help string — Intentional, matches the existing serve chat precedent. No change needed.

Mirrors the --max-request-size flag that serve chat already has.

- Add Option/WithMaxRequestBytes to pkg/server via functional-options
  (variadic, so all existing NewWithManager/New call sites compile
  untouched and keep the 1 MiB default).
- Register --max-request-size PersistentFlag on the serve api command
  (int64 bytes, default 1<<20) and thread the value through server.New.
- BodyLimit middleware is global on the echo instance, so the cap applies
  consistently to every /api route including POST /api/sessions/:id/messages.
- Oversized requests return HTTP 413 (Request Entity Too Large).
- Tests: existing default-cap test kept; new table tests for custom cap
  on the messages route, plus zero/negative fallback to 1 MiB.
- Docs: add --max-request-size row to the api-server CLI Flags table.

Closes #3937
The per-command flags reference in docs/features/cli/index.md was missing
the new --max-request-size flag for serve api. Add a matching row,
mirroring the existing serve chat entry at line 395.
@aheritier
aheritier force-pushed the feat/api-max-request-size branch from d06f142 to 0724fe0 Compare August 10, 2026 10:17
@aheritier
aheritier merged commit ab8374c into main Aug 10, 2026
19 checks passed
@aheritier
aheritier deleted the feat/api-max-request-size branch August 10, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli CLI commands, flags, output formatting area/core Core agent runtime, session management area/docs Documentation changes kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(api): make maximum request body size configurable

2 participants