[GH-ISSUE #3000] [Issue]: GET /agents/runs/:chatId/custom?limit=<non-numeric> returns an empty list instead of the default 50 #1574

Closed
opened 2026-10-21 05:39:28 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3000

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
The custom-runs route parses limit with Number.parseInt guarded only by truthiness of the raw string. For a non-numeric value like ?limit=abc, the raw string is truthy so Number.parseInt yields NaN, which is forwarded (not undefined), so the default of 50 does not apply. Inside the storage function Math.max(1, Math.min(NaN, 200)) is NaN and rows.slice(0, NaN) returns []. So a malformed limit query yields zero custom runs instead of the intended default.

How to reproduce (try it yourself)
GET /api/agents/runs//custom?limit=abc

You'll see: [] even when the chat has custom-agent runs.
Expected: up to 50 custom runs (the default), exactly as GET .../custom with no limit returns.

Where it is
packages/server/src/routes/agents.routes.ts:155-156 together with packages/server/src/services/storage/agents.storage.ts:368-380.

What's happening
NaN from Number.parseInt is forwarded as the limit and is not normalized to the default; Math.min/Math.max propagate NaN, and Array.prototype.slice(0, NaN) coerces the end index to 0, yielding an empty array.

Suggested fix
Guard the parse so non-finite values fall back to the default-parameter path, matching the codebase's established Number.isFinite idiom. In agents.routes.ts:155:

const parsed = req.query.limit ? Number.parseInt(req.query.limit, 10) : undefined;
const parsedLimit = Number.isFinite(parsed) ? parsed : undefined;
return storage.listCustomRunsForChat(req.params.chatId, parsedLimit);

With parsedLimit undefined, the storage default of 50 applies. No regression: the only real-world caller (the client hook) passes no limit param, so the happy path is unchanged; ?limit=0 and valid numeric limits are unaffected. Optional defense-in-depth: also harden agents.storage.ts:369 to Math.max(1, Math.min(Number.isFinite(limit) ? limit : 50, 200)). Either guard alone fully resolves the bug; the route guard is the more surgical single-touch fix.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3000 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The custom-runs route parses `limit` with `Number.parseInt` guarded only by truthiness of the raw string. For a non-numeric value like `?limit=abc`, the raw string is truthy so `Number.parseInt` yields NaN, which is forwarded (not undefined), so the default of 50 does not apply. Inside the storage function `Math.max(1, Math.min(NaN, 200))` is NaN and `rows.slice(0, NaN)` returns `[]`. So a malformed limit query yields zero custom runs instead of the intended default. **How to reproduce (try it yourself)** GET /api/agents/runs/<chatId>/custom?limit=abc You'll see: `[]` even when the chat has custom-agent runs. Expected: up to 50 custom runs (the default), exactly as GET .../custom with no limit returns. **Where it is** `packages/server/src/routes/agents.routes.ts:155-156` together with `packages/server/src/services/storage/agents.storage.ts:368-380`. **What's happening** NaN from `Number.parseInt` is forwarded as the limit and is not normalized to the default; `Math.min`/`Math.max` propagate NaN, and `Array.prototype.slice(0, NaN)` coerces the end index to 0, yielding an empty array. **Suggested fix** Guard the parse so non-finite values fall back to the default-parameter path, matching the codebase's established `Number.isFinite` idiom. In agents.routes.ts:155: ```ts const parsed = req.query.limit ? Number.parseInt(req.query.limit, 10) : undefined; const parsedLimit = Number.isFinite(parsed) ? parsed : undefined; return storage.listCustomRunsForChat(req.params.chatId, parsedLimit); ``` With `parsedLimit` undefined, the storage default of 50 applies. No regression: the only real-world caller (the client hook) passes no limit param, so the happy path is unchanged; `?limit=0` and valid numeric limits are unaffected. Optional defense-in-depth: also harden agents.storage.ts:369 to `Math.max(1, Math.min(Number.isFinite(limit) ? limit : 50, 200))`. Either guard alone fully resolves the bug; the route guard is the more surgical single-touch fix. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in merged staging PR #3004.

<!-- gh-comment-id:4832283659 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3004.
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#1574
No description provided.