fix(admin): batch param is unclamped and batch=0 spins 50 no-op batches in all=true mode
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
apps/web/app/routes/api.admin.recompute.ts の parseIntSafe、batchSize の代入、all=true ループから始め、検証処理を recompute-all-skills.ts:177 に記載された挙動と比較します。必要な D1 および KV bindings を指定した、提供されている ADMIN_SECRET curl 再現手順を使用し、その後 batch の値に上限が設定され、batch=0 が 50 個の no-op batch を生成しなくなっていることを確認します。
索引モデルが issue の本文から書いたものです。
説明
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 #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.
- 主要言語
- TypeScript
- スター
- 189
- フォーク
- 40
- 平均マージ
- 6時間 54分
- マージ済み PR(30日)
- 24
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nextlevelbuilder/skillx のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
nextlevelbuilder/skillx#49 ·
メンテナーはふだん 1 日以内に返信
-
refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
nextlevelbuilder/skillx#27 ·
メンテナーはふだん 1 日以内に返信
-
Harden personal kit proposal scanning before enabling the API flag対応中かも @mrgoonie が 1 日前に担当しました。 オープン
nextlevelbuilder/skillx#86 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 18/100
nextlevelbuilder/skillx#84 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 12/100
nextlevelbuilder/skillx#81 ·
メンテナーはふだん 1 日以内に返信
nextlevelbuilder/skillx の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
juice-shop/juice-shop#3686 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dsh-market/dsh-market#877 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
ScottKirvan/GOMAC#61 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
stellar/stellar-dev-skill#151 ·
メンテナーはふだん 1 日以内に返信