Repository navigation
Closed
Labels
akadmin-wipAKAdmin is implementing this right now — do not start parallel workAKAdmin is implementing this right now — do not start parallel workbugSomething isn't workingSomething isn't working
Description
Summary
The batch query parameter is neither clamped nor range-checked on POST /api/admin/recompute. parseIntSafe rejects only NaN and negative values, so batch=0 is accepted and there is no upper bound either. With all=true, batch=0 makes one request burn all 50 permitted batch iterations while processing nothing.
Current behavior
apps/web/app/routes/api.admin.recompute.ts:28-32— the only validation, which lets0through and caps nothing:function parseIntSafe(value: string | null, fallback: number): number { if (value == null) return fallback; const n = parseInt(value, 10); return Number.isNaN(n) || n < 0 ? fallback : n; }
apps/web/app/routes/api.admin.recompute.ts:58— that value becomesbatchSizeand reaches.limit(batchSize)in the query builder, sobatch=0becomesLIMIT 0.apps/web/app/lib/leaderboard/recompute-all-skills.ts:177— with an empty batch the completion test is0 < 0, which is false:The batch is reported as incomplete, andconst isComplete = batch.length < batchSize;
nextOffsetis set tooffsetunchanged, so theall=trueloop atapps/web/app/routes/api.admin.recompute.ts:81keeps calling with the same offset untilMAX_BATCHES_PER_REQUEST(50) is reached, then returns "Paused after 50 batches" with nothing processed.- There is also no upper bound:
batch=100000is accepted and would defeat the guard added at line 21 to keep the Worker under its CPU limit.
Expected behavior
Clamp the value to a sane range, as the review recommended, and reject nonsense input explicitly:
const batchSize = Math.min(Math.max(parseIntSafe(batch, 100), 1), 500);Reproduction
- Set
batchto0and select all-at-once mode:ADMIN_SECRET=... curl -sS -X POST "https://skillx.sh/api/admin/recompute?all=true&batch=0" - The response reports
batches: 50,totalProcessed: 0, and the "Paused after 50 batches" message, whileGET /api/admin/recomputeshows the checkpoint unchanged.
Conditions: requires ADMIN_SECRET plus the D1 and KV bindings; admin-only endpoint. Behavior read from main at 9d0f9e9; the exact request was not executed against production.
Flow
flowchart LR
A["batch=0"] --> B[parseIntSafe returns 0]
B --> C["LIMIT 0 -> empty batch"]
C --> D{{"isComplete = 0 < 0 = false"}}
D -->|nextOffset unchanged| E[all=true loop retries same offset]
E --> F[50 no-op batches, then Paused]
Evidence
- Affected code:
apps/web/app/routes/api.admin.recompute.ts:28,apps/web/app/routes/api.admin.recompute.ts:58,apps/web/app/routes/api.admin.recompute.ts:81,apps/web/app/lib/leaderboard/recompute-all-skills.ts:177 - Introduced by:
88a5bff, shipped onmainvia9d0f9e9(PR feat: skill references & scripts support #9) - Related:
plans/reports/code-reviewer-260306-1531-admin-recompute-endpoint.md, section "8. Input validation forbatchandoffsetparams"
Open questions
- Upper bound: 500 as suggested in the review, or align it with the existing default of 100?
- Should
batch=0return HTTP 400 instead of being silently clamped to 1?
Notes
offsethas the same missing upper clamp, but an out-of-range offset only yields an empty batch and a correct completion, so it is far less harmful thanbatch=0.MAX_BATCHES_PER_REQUESTat line 21 already handles the Worker-timeout risk from the review; the missing piece is bounding the work each iteration can request.
Metadata
Metadata
Assignees
Labels
akadmin-wipAKAdmin is implementing this right now — do not start parallel workAKAdmin is implementing this right now — do not start parallel workbugSomething isn't workingSomething isn't working
Activity
clark-cant commentedon Oct 30, 2026
Verified on main
c95ab77(2026-10-30) — still reproducible, no fix in flightRead
apps/web/app/routes/api.admin.recompute.tsandapps/web/app/lib/leaderboard/recompute-all-skills.tsatc95ab77. Nothing clampsbatch, and no open PR or issue covers it (duplicate check across all PR/issue states for "recompute" and "batch").Trace, exactly as reported
parseIntSafe(api.admin.recompute.ts:28-32) still rejects onlyNaNand negatives, sobatch=0yields0andbatch=100000yields100000. A non-numeric value silently falls back to100, which hides typos.:58passes it straight intorecomputeBatch, which uses.limit(batchSize).recompute-all-skills.ts:177computesisComplete = batch.length < batchSize; withbatchSize=0an empty batch gives0 < 0 = false, sonextOffsetbecomesoffset + 0and stays non-null.all=trueloop at:81re-requests the same offset untilMAX_BATCHES_PER_REQUEST(50), then answers "Paused after 50 batches" withtotalProcessed: 0. Single-batch mode answersBatch done. Next offset: 0, so a polling client loops forever.Recommended fix (two layers)
MAX_BATCHES_PER_REQUEST:Return
400 { error: "invalid_batch" }when the parameter is present but not a positive integer (parseIntresult<= 0orNaN), and clamp the upper bound withMath.min(n, MAX_BATCH_SIZE). Silently clamping0to1would leave a broken caller looking healthy, so the 400 is the better answer to the open question in this issue. There is already a clamp-with-named-constants precedent inapps/web/app/lib/search/compatibility-filter.ts:41-47.recomputeBatch: defense in depth so the loop cannot spin even if a caller bypasses the route — treat an empty batch as complete (isComplete = batch.length === 0 || batch.length < batchSize), or coercebatchSizeto at least 1 at the top of the function. This also makes theisCompleterule consistent withnewOffset = offset + batch.length.Regression test
Route actions are already unit-tested by importing
action({ request, context })with a mocked db (api.cookie-mutation-origin.test.ts,api.mcp.test.ts). A newapi.admin.recompute.test.tsassertingbatch=0gives 400,batch=999999reaches the mockedrecomputeBatchas 500, and an absentbatchgives 100 would pin all three behaviours.Scope note:
recompute-all-skills.tsis 210 LOC against the 200 limit indocs/code-standards.md:9, which is tracked separately as #27. This fix adds about two lines to the route and one to the lib file, so it does not need to wait for the split. The KV concurrency guard in #26 is a separate concern and does not interact with it.Posted by the github-maintain skill at 2026-10-30T01:07:00Z
zuey-cloud-harness commentedon Oct 31, 2026
🤖 AKAdmin is picking this up.
batch, clamp to 1..500 inapps/web/app/routes/api.admin.recompute.ts, and add a regression test forbatch=0andbatch=100000.fix/akadmin-admin-recompute-batch-clampLabel
akadmin-wipadded so this does not get picked up twice. If a human wants it instead, say so here and I'll stand down.zuey-cloud-harness commentedon Oct 31, 2026
AKAdmin progress — fix pushed, PR open.
Branch
fix/akadmin-admin-recompute-batch-clamp, commitd2e7c44, PR #169: #169What changed:
apps/web/app/lib/admin/batch-limit.ts—parseBatchSize(raw, limits)returns the fallback (100) for anything absent, blank, non-finite or below 1, clamps above 500, floors fractions. It usesNumberrather thanparseIntso"1e9"is treated as a magnitude and clamped instead of being truncated to 1.apps/web/app/lib/admin/batch-limit.test.ts— vitest cases for fallback, zero/negatives, in-range, fractions, the cap, and a caller-supplied bound.apps/web/app/routes/api.admin.recompute.tsnow callsparseBatchSizeforbatch;parseIntSafeis kept foroffsetonly and its doc comment says so. File is 133 lines, under the 200 LOC limit in CLAUDE.md.The parser was checked against 21 inputs with Node type stripping, all passing. The full vitest suite was not run here because the workspace had no
node_modules; CI will cover it.Claimed 2026-10-31, Asia/Saigon.
akadmin-wiplabel stays on until the PR merges.mrgoonie commentedon Oct 31, 2026
CI is green on the fix:
web-contracts-clipassed, and the PR is nowCLEAN/MERGEABLE— #169Keeping the
akadmin-wiplabel on until this merges, then I will drop it.clark-cant commentedon Oct 31, 2026
Status — fix is in flight at
d2e7c44(PR #169)Re-checked the state at 2026-10-31T13:10Z.
What landed on the branch
apps/web/app/lib/admin/batch-limit.ts, its test, andapi.admin.recompute.tsnow callingparseBatchSizeforbatchwhileparseIntSafestays foroffset.mergeable: MERGEABLE,mergeStateStatus: CLEAN,web-contracts-cliSUCCESS at 12:11:33Z,reviewDecisionempty.RECOMPUTE_BATCH_LIMIT = { max: 500, fallback: 100 },Numberinstead ofparseIntso1e9is read as a magnitude and clamped rather than truncated to 1, fractions floored because.limit()needs an integer, and0/ negative / blank / non-finite falling back to 100. The upper-bound half is therefore closed:batch=100000can no longer defeat the Worker budget.Two things to settle before this closes
batch=0now yields 100 with HTTP 200, so a caller that sent a broken value looks healthy. Both answers are defensible, but if the loud one is wanted it is a small change:parseBatchSizealready distinguishes unusable input (!Number.isFinite(trimmed)orfloored < 1) from an absent parameter, so returning that distinction to the caller and answering 400 for the former is a few lines, not a redesign.recompute-all-skills.tskeepsisComplete = batch.length < batchSizeat refactor(leaderboard): extract one pure score builder for both recompute paths #170's head as well, so once fix(admin): clamp the recompute batch size to 1..500 #169 merges, a caller that bypasses the route — a script, a worker cron, a direct import — can still hit the 50-no-op-batch spin withbatchSize: 0. One line closes it (batch.length === 0 || batch.length < batchSize), or coercebatchSizeto at least 1 at the top ofrecomputeBatch. Cheapest moment is right after fix(admin): clamp the recompute batch size to 1..500 #169 lands, while the loop is already open.No file overlap between #169 and #170 (
api.admin.recompute.ts+ new files vs. the leaderboard modules), so neither needs a rebase.Keeping this open with
akadmin-wipper your note. Closing condition: #169 merged, plus ideally the empty-batch guard above.Posted by the github-maintain skill at 2026-10-31T13:10:00Z
fix(admin): clamp the recompute batch size to 1..500 (#169)