Skip to content

fix(dev-server): cap request bodies and retain at most 10k debug events - #846

Merged
ld-ahartmann merged 2 commits into
mainfrom
devin/1791049530-dev-server-body-limits
Oct 7, 2026
Merged

ld-ahartmann merged 2 commits into
mainfrom
devin/1791049530-dev-server-body-limits

Conversation

@wchieng

@wchieng wchieng commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This caps dev-server request bodies and caps how many debug events are kept on disk.

Before this change, any caller could send unlimited data:

  • /bulk and /mobile/events/bulk read the whole body into memory with io.ReadAll.
  • POST /dev/backup copied the whole body into a temp file.
  • The generated /dev handlers decoded JSON without any size limit.
  • While /events/tee is open, every event is written to debug_events, which never deleted old rows.

A web page can POST text/plain to /bulk without a CORS preflight. Together, that meant a page could fill the developer's disk.

Changes:

  • limitRequestBody router middleware applies http.MaxBytesReader to every route: 10 MiB by default, 256 MiB for POST /dev/backup.
  • SdkEventsReceiveHandler returns 413 when the body is too large. Before, it returned an implicit 200.
  • Sqlite.WriteEvent deletes rows older than the newest 10,000 after each insert:
    DELETE FROM debug_events WHERE id <= :lastInsertId - 10000

Where the limits come from:

  • 10 MiB matches event-recorder's request body limit.
  • 256 MiB for backup restore is new. Dev-server databases hold flag state for a few projects, so this leaves plenty of headroom.
  • 10,000 debug events is new.

Related: #845 changes the default bind address to 127.0.0.1.

Testing

  • Added TestLimitRequestBody, which checks requests at and just over each limit, and TestWriteEventRetention.
  • go test ./internal/dev_server/... passes.
  • Pre-commit hooks pass, including golangci-lint.

Link to Devin session: https://app.devin.ai/sessions/33518e0108ac4ea3aaec26dd594dbd62
Open in Devin Desktop: https://app.devin.ai/desktop/session/33518e0108ac4ea3aaec26dd594dbd62?variant=devin
Requested by: @wchieng


Note

Overview
Adds global request body limits on the dev server via limitRequestBody middleware: 10 MiB by default and 256 MiB for POST /dev/backup, with backup restore requiring application/vnd.sqlite3 so simple cross-origin POSTs cannot hit restore without a preflight.

SDK bulk event ingestion now responds with 413 when the capped body is exceeded instead of failing silently.

Debug event persistence trims debug_events after each insert: at most 10,000 rows and 64 MiB of stored event payload (whichever bound bites first), with tests for count- and byte-based retention.

Failed SQLite restores delete their temp file in RestoreToFile, with a test that TMPDIR stays empty after invalid input.

Reviewed by Cursor Bugbot for commit 5afc430. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: wchieng@launchdarkly.com <williamchieng1991@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Comment thread internal/dev_server/events_db/sqlite.go Outdated
Comment on lines +13 to +15
// maxDebugEvents bounds the debug_events table; older rows are deleted as new ones arrive.
const maxDebugEvents = 10000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm surprised we have a 'debug events' table honestly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The table is used by the dev server's event debugger. When someone opens the event view (/dev/events/tee), sdkEventObserver in api/events/events_stream.go creates a debug_session and writes every SDK event the dev server receives to debug_events. The UI can then page through events per session, and debug_session rows are cleaned up when they no longer have any events.

Before this PR, nothing ever deleted rows from it. While the debugger was open, a noisy SDK, or anything else posting to /bulk, could grow the SQLite file without limit. The 10k cap deletes the oldest rows on insert. It applies across all sessions combined, not per session.

If you think the feature isn't worth keeping, removing it would be a separate PR. This one only puts a bound on it.

@ld-ahartmann

Copy link
Copy Markdown
Contributor

@BugBot review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit ff01b3a. Configure here.

@ld-ahartmann

Copy link
Copy Markdown
Contributor

got some complaints about this one:

'POST /dev/backup still fills the disk. RestoreToFile copies the body into a new temp file and does not remove it when the copy or the validation fails, so each request leaves another file of up to 256 MiB. The same request shape as /bulk (text/plain, no preflight) can do this in a loop.

The debug-event cap only bounds the row count. Each row can be as large as the 10 MiB body limit, and the delete is global across sessions, so 10,000 rows is still on the order of 100 GiB.'

…stores, require sqlite content type for restore

Co-Authored-By: wchieng@launchdarkly.com <williamchieng1991@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Both complaints were valid. Fixed in 5afc430:

POST /dev/backup leaving temp files. RestoreToFile now closes the temp file and deletes it whenever the copy, the connection or the validation fails. Before, the file was never closed either. The restore route also now requires the documented Content-Type: application/vnd.sqlite3 and returns 415 otherwise. That rules out a text/plain request with no preflight, so a web page can no longer send restore requests at all, looped or not. This does change behavior for anyone calling it with curl --data-binary and no -H 'Content-Type: application/vnd.sqlite3'. No in-repo client calls the endpoint.

Debug event row cap doesn't bound size. debug_events now has a byte budget as well as the row cap: maxDebugEventBytes = 64 MiB of total length(data), alongside the 10,000-row limit. After each insert, the oldest rows are deleted until the newest rows fit within both limits. With 10 MiB bodies, that's at most about 64 MiB on disk instead of about 100 GiB. The budget is still shared across all sessions, which seemed fine for a local debugging tool. 64 MiB is a new number we're introducing; I didn't find an existing standard for it.

Tests added: restore with an invalid database leaves TMPDIR empty; restore requests with text/plain or no content type get 415; byte-based retention keeps only the newest events that fit the budget.

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review October 5, 2026 19:18
@devin-ai-integration
devin-ai-integration Bot requested a review from a team as a code owner October 5, 2026 19:18
@ld-ahartmann
ld-ahartmann merged commit e381109 into main Oct 7, 2026
10 checks passed
@ld-ahartmann
ld-ahartmann deleted the devin/1791049530-dev-server-body-limits branch October 7, 2026 14:21
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.

2 participants