fix(leaderboard): bulk recompute has no concurrency guard, overlapping all=true runs race on the KV checkpoint
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- api, backend, distributed-systems
Hướng nghiên cứu
Read apps/web/app/routes/api.admin.recompute.ts and apps/web/app/lib/leaderboard/recompute-all-skills.ts, starting at the cited action, state load, and state write paths. Use the overlapping curl reproduction to verify that a second active run is rejected or coordinated atomically, and that the KV checkpoint remains consistent.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
POST /api/admin/recompute?all=true has no concurrency guard, so two simultaneous runs share one KV checkpoint. Both requests read and write the same state, offset can be advanced or reset by whichever write lands last, and every skill in the overlap window is scored twice or skipped. Both callers still get HTTP 200.
Current behavior
apps/web/app/routes/api.admin.recompute.ts:51—action()verifies the admin secret and starts batching immediately. There is no in-flight check and no 409 response path anywhere in the file.apps/web/app/lib/leaderboard/recompute-all-skills.ts:45-46— KV state is read only whenresumeis true, and only to choose a starting offset:savedState = await loadState(kv); offset = savedState?.status === "running" ? savedState.offset : 0;apps/web/app/lib/leaderboard/recompute-all-skills.ts:191-194— every batch then overwrites or clears that same state, with no compare-and-set:if (isComplete) { await clearState(kv); } else { await saveState(kv, state); }apps/web/app/routes/api.admin.recompute.ts:21caps one request atMAX_BATCHES_PER_REQUEST = 50, so a single call can run for many seconds — long enough for a second call to overlap.batchCountis per-request only, so it never coordinates across requests.
Expected behavior
A second run is rejected while a run is active — for example 409 Conflict when status === "running" and lastBatchAt is recent — or the runs coordinate through an atomic lock so the checkpoint advances monotonically.
Reproduction
- Send two overlapping requests with the admin secret in the header:
ADMIN_SECRET=... curl -sS -X POST "https://skillx.sh/api/admin/recompute?all=true&batch=100" & ADMIN_SECRET=... curl -sS -X POST "https://skillx.sh/api/admin/recompute?all=true&batch=100" & wait - Watch the returned
nextOffsetandstatefrom each response, thenGET /api/admin/recomputeto read the surviving checkpoint. - Interleaved responses show both runs advancing the same checkpoint.
Conditions: requires ADMIN_SECRET plus the D1 and KV bindings; admin-only endpoint. The code paths above are read directly from main at 9d0f9e9 — no live concurrent run against production was performed for this report.
Flow
flowchart LR
A[POST all=true] --> B[verifyAdmin]
B --> C[recomputeBatch: load KV offset]
D[POST all=true] --> E[verifyAdmin]
E --> F[recomputeBatch: load KV offset]
C --> G{{both write same KV checkpoint}}
F --> G
G --> H[offset / totalProcessed corrupted]
Evidence
- Affected code:
apps/web/app/routes/api.admin.recompute.ts:51,apps/web/app/routes/api.admin.recompute.ts:21,apps/web/app/lib/leaderboard/recompute-all-skills.ts:45,apps/web/app/lib/leaderboard/recompute-all-skills.ts:191 - Introduced by:
88a5bff("feat: add bulk recompute admin endpoint for leaderboard scores"), shipped onmainvia9d0f9e9(PR #9) - Related:
plans/reports/code-reviewer-260306-1531-admin-recompute-endpoint.md, section "4. No concurrency guard"
Open questions
- Preferred mechanism: a KV read-check-write optimistic lock, a Durable Object, or simply rejecting when
lastBatchAtis recent (under 5 minutes)? - Is this reachable in practice?
scripts/run-recompute.shsleepsDELAYseconds between batches but holds no lock, and it is currently untracked — see the runbook tooling issue.
Notes
- The other findings from the same review are already fixed on
main: the date/millisecond bug, the N+1 aggregation, theall=truebatch guard, the secret-in-query-param auth, and the redundant ternary. - A KV read-check-write is not atomic on its own, so if that route is chosen the check must tolerate the small race window (accepting a rare double-reject) rather than assume a real lock.
- Ngôn ngữ chính
- TypeScript
- Star
- 190
- Fork
- 42
- Merge trung bình
- 5 giờ 50 phút
- Pull request đã merge (30 ngày)
- 37
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nextlevelbuilder/skillx
-
ai-handle
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
nextlevelbuilder/skillx#105 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
nextlevelbuilder/skillx#28 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
nextlevelbuilder/skillx#27 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feat(compatibility): write declared compatibility_json on publish, sync and backfillCó thể đã có người làm @mrgoonie đã nhận 3 ngày trước. Đang mở
nextlevelbuilder/skillx#119 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-handle
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
nextlevelbuilder/skillx#113 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của nextlevelbuilder/skillx
Issue tương tự
-
[good first issue, hacktoberfest] 🏯 Hacktoberfest Task - Add new Japan Fact 898 (good-first-issue)Đang mởcommunity first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
lingdojo/kana-dojo#33145 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
code-yeongyu/senpi#4278 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Activity | The activity list ignores taskIds and returns the activities of every taskCó thể đã có người làm @NdekoCode đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ever-co/ever-gauzy#11469 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
griffinwork40/agent-afk#4408 ·
Maintainer thường phản hồi trong vòng 1 ngày