fix(admin): use cursor-based pagination for API request log download#2259
Merged
chrarnoldus merged 8 commits intomainfrom Apr 13, 2026
Merged
fix(admin): use cursor-based pagination for API request log download#2259chrarnoldus merged 8 commits intomainfrom
chrarnoldus merged 8 commits intomainfrom
Conversation
The download endpoint loaded all rows into memory at once, causing Vercel OOM kills for users with many API requests. Switch to cursor-based pagination (batches of 100) with backpressure-aware stream draining so only one batch is in memory at a time.
Contributor
Author
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by gpt-5.4-20260305 · 311,613 tokens |
Address review comment: if a batch query or archive.finalize() fails, destroy the passthrough stream so the error surfaces to the client instead of hanging until timeout.
Adds an optional 'model' query parameter to filter the download by a specific model. When not set, all models are included (existing behavior).
Replace / and : in the model name so the ZIP filename is safe for all filesystems.
markijbema
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
/admin/api/api-request-log/downloadendpoint loaded all matching rows into memory before archiving them into a ZIP. For users with many API requests, this caused Vercel to kill the instance with an OOM error (Vercel Runtime Error: instance was killed because it ran out of available memory).PassThroughstream to drain before fetching the next batch, preventing archiver from buffering unbounded data.COUNT(*)query to preserve the existing 404 behavior when no records match.Verification
pnpm typecheck— passes with no errorspnpm lint— passes (via pre-push hook)pnpm format:check— passes (via pre-push hook)Visual Changes
N/A
Reviewer Notes
BATCH_SIZEof 100 is conservative. Each row'srequest(jsonb) andresponse(text) columns can be large, so keeping batches small limits peak memory. This can be tuned up if the count query + extra round-trips become a bottleneck.created_attoidfor cursor pagination correctness (timestamps can have duplicates;idis a monotonically increasing bigserial).