Repository navigation
fix(security-scan): plan queue claims so concurrent shards stop conflicting - #4805
Conversation
…icting Since 2026-11-15, Production security workers got "[Request ID] Server Error" bursts from claimCodexScanJobLeases. Production logs show they are OCC retry exhaustion in claimQueuedJobsInternal: "Documents read from or written to the securityScanJobs table changed ... on every subsequent retry". Each claim read the shared queue-head index ranges and leased rows out of them, so every concurrent claim conflicted with every other. Fast shard refills (fast-failing backfill jobs) pushed claims to ~95/min. Shared and priority claims now plan candidates in a read-only query over a bounded head window (legacy tier order kept), shuffle within each tier in the action, and lease them in a new mutation that uses point reads only and skips stale rows. The action replans a short claim that saw stale rows, and returns committed leases even if a later round fails. The catalog lane, assigned/targeted claims, the Test catalog source, and deep blocked legacy rows keep the existing claim. Local backend race (10 workers, tight claim loop): main failed 224/420 claim calls (125 OCC, 99 timeouts); this change failed 1/503, with every job leased exactly once.
Pass the planner's clock from the action (queries must not read the clock) with a small forward allowance, and let admission skip rows that are not ready yet without counting them as contention. Hand the remaining limit to the legacy claim when a replan needs it instead of stopping short. Correct the comment and spec about how the worker reads a short claim. Cover retired automatic plugin scans through the planned action.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Codex review: needs changes before merge. What this changesThis PR separates security-scan queue discovery from lease admission to reduce conflicts between concurrent workers. Example: Ten workers concurrently claim batches from 1,200 queued backfill jobs.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this maintainer-authored PR addresses contention still present on main, but its new planner can incorrectly report an empty queue. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherSecurity workers submit authenticated claim requests to Convex and receive token-bearing job leases, which they hydrate and process through the existing scanner pipeline. flowchart TD
A[Security workers] --> B[Authenticated claim action]
B --> C[Read only candidate planner]
C --> D[Tier preserving shuffle]
D --> E[Point read admission]
E --> F[Job leases]
B --> G[Existing specialized claim paths]
G --> F
Technical reviewBest possible solution: Keep query planning and point-read admission, but prevent future candidates from hiding ready jobs in lower tiers. Do we have a high-confidence way to reproduce the issue? Current main supports the reported shared-range conflict mechanism, and the introduced readiness failure follows from the planner, admission check and worker drain rule; no target code was executed during this read-only review. Is this the best way to solve the issue? The fix uses the right boundary and an established planning pattern; additional retries retain the conflicting read set, while existing assigned-job claims cover coordinated bulk work rather than general queue discovery. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a83aceea4249. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 16, 2026, 1:47 AM ET / 06:47 UTC. |
Co-authored-by: Patrick-Erichsen <20157849+Patrick-Erichsen@users.noreply.github.com>
The claim planner looked one second ahead for clock skew and counted those not-yet-due rows toward its head window. A tier with a window's worth of rows due inside that second filled the plan, admission skipped every one as not yet due, and ready work in lower tiers was never planned. The worker read the empty claim as a drained queue and stopped refilling. Only rows due on the action's clock now fill the window. Each tier still plans up to one claim's worth of rows due within the allowance, so a trailing action clock cannot hide a job that was just enqueued. Co-authored-by: Patrick-Erichsen <20157849+Patrick-Erichsen@users.noreply.github.com>
|
Maintainer fixup pushed at Patrick's request to land this: e8954dc (plus a merge of current What it fixes. The ClawSweeper P2 is real. The planner looked one second ahead and counted those not-yet-due rows toward its head window. With a window's worth of rows due inside that second in one tier, admission skipped all of them, a ready job in a lower tier was never planned, and the action returned The change. Only rows due on the action's clock fill the window. Each tier still plans up to one claim's worth of rows due within the allowance, so a trailing action clock cannot hide a job that was just enqueued. The action now passes Proof on a real local Convex backend (full app pushed to
The backfill rows were still 260 to 320 ms from due when each call returned. Concurrent drain, 8 workers on 400 ready jobs: both builds leased 400 unique jobs in 185 calls, with no failed calls, no duplicate leases, and no job above one attempt. Tests. Three fixed-clock runtime tests in Not covered. The proof ran on one machine with a local backend, not Production. It does not measure the OCC failure rate under production load; that still rests on the numbers in the PR description. |
Summary
Since 2026-11-15 (around 18:14 UTC), Production Security Scan Codex Worker shards have hit bursts of
[Request ID: …] Server Errorwhen they callclaimCodexScanJobLeases. A read-onlybunx convex logs --prodcapture caught a live burst (05:38–05:45 UTC on 11-16). Every failed claim had the same cause, OCC retry exhaustion inclaimQueuedJobsInternal:Hundreds more conflicts in that window were retried successfully inside Convex. Claim rate reached about 95 per minute during the burst, which fits shards refilling fast after fast-failing jobs.
Cause. Each claim mutation reads the shared queue-head index ranges (manual, malicious signal, then each source) and leases rows out of those same ranges. Every concurrent claim therefore conflicts with every other one. At high refill rates, Convex exhausts its retries.
Fix. Shared and priority claims now follow the plan-then-admit pattern already used by Skill Card claims (
convex/lib/skillCardClaims.ts):planCodexScanClaimsInternalis a read-only query. It plans candidates over a bounded queue-head window (at least 128 rows), in the existing tier order: manual, then malicious signal, thenCLAIM_SOURCE_ORDER. The priority lane still stops after publish.claimPlannedJobsInternalleases candidates using point reads only. For each row it re-checks status,nextRunAt, lane eligibility and rollout claimability, and it skips a row another worker already leased. Two claims now conflict only when they pick the same row, and Convex's retry then skips that row.specs/security-moderation.md.Proof: real local Convex backend
I pushed the full app to an anonymous local deployment for
mainand for this branch. Then 10 concurrent workers claimed 1–4 jobs at a time in a tight loop against a seededbackfillqueue. Because the machine was heavily loaded (load average 100+), the numbers that matter come from runs under the same load:mainEvery run leased every job exactly once: no duplicate leases and no job with more than one attempt. The remaining failures are 1 s function timeouts caused by host load, and
maingets them too. An earlier run on a less loaded machine had 1 failure in 503 calls on this branch. With 20 workers on 400 jobs, 5 of 232 calls failed.The race scripts and fixture were proof-only and are not committed.
Notes for rollout
claim_failedlogs drop, and look for any claim that falls back to the existing path.take(limit). These are cheap reads in a query, not in the conflicting mutation.Tests
bunx tsc -p convex/tsconfig.json --noEmit,bunx tsc -p packages/schema/tsconfig.json --noEmit,bunx tsc -p packages/clawhub/tsconfig.json --noEmit: clean.VITE_CONVEX_URL=https://example.invalid bunx vitest run convex/securityScan.claimPlan.runtime.test.ts convex/securityScan.test.ts convex/packageSecurityScan.runtime.test.ts convex/securityScan.retiredQueue.runtime.test.ts convex/skills.moderationBackfill.runtime.test.ts: 154 passed. The new runtime tests cover tier order, priority-lane exclusion, stale-row skipping, lane refusal, and retired plugin scans through the action. The orchestration tests cover replanning and committed-lease return.bun run ci:static: passed.bun run coveragelocally: the Convex suites pass. 21 script tests failed on this overloaded machine: Python 3.15 and Docker subprocess timeouts inscripts/security/*, none of which import the changed code. CI is the gate for those.