Skip to content

perf: shorten native scan claim transactions - #3698

Merged
Patrick-Erichsen merged 1 commit into
mainfrom
codex/clawscan-claim-contention
Sep 14, 2026
Merged

Patrick-Erichsen merged 1 commit into
mainfrom
codex/clawscan-claim-contention

Conversation

@Patrick-Erichsen

Copy link
Copy Markdown
Collaborator

Concurrent scan workers can exhaust Convex transaction retries while claiming the same queue head. Production request IDs matched claimQueuedJobsInternal OCC failures. Native claims now read each source directly within the mutation, removing nested-query dispatch overhead; blocked legacy GitHub records retain the existing paginated fallback. Priority ordering, rollout gates, catalog admission, leases and scan settings are unchanged.

Paired proof on a disposable local Convex backend at http://127.0.0.1:3318, seeded with 600 fake queued bulk jobs: eight callers making 32 paced requests went from 22 successful claims / 10 OCC failures in 20.41 seconds to 32 successful claims / zero failures in 9.90 seconds. Every claimed ID was unique; read budgets for limits 1, 4 and 16 passed. An unpaced saturation test still had conflicts (15 failures before, 12 after), so higher production capacity requires fresh measurement. Temporary local seed functions are excluded from this PR.

Validation: 117 scanner tests pass; the three direct-read regression cases fail on the old implementation. bun run ci:static, bun run ci:unit (6,690 tests), bun run ci:types-build, and schema/CLI/Convex TypeScript checks passed. Independent autoreview passed with no actionable findings.

@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@vercel

vercel Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clawhub Ready Ready Preview Sep 14, 2026 11:28pm UTC

Request Review

@clawsweeper

clawsweeper Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 14, 2026, 7:28 PM ET / 23:28 UTC.

ClawSweeper review

What this changes

Read ordinary security-scan queues directly inside the claim transaction while retaining paginated fallback for blocked legacy jobs.

Merge readiness

⛔ Blocked before merge - 1 item remains

No blocking findings. This remains a useful, focused contention mitigation: current main bounds queue reads but still performs nested query calls. The collaborator-authored PR should remain open.

Priority: P2
Reviewed head: c12ef388479abe94f39de8267c168a83c85de1a7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable mitigation with relevant regression assertions and reported real-Convex measurements; no blocking defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor proof gate is exempt for this collaborator-authored PR, and authority is unchanged. Its reported paired local Convex claim run supports reduced contention, but no raw runtime transcript was supplied for independent inspection.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor proof gate is exempt for this collaborator-authored PR, and authority is unchanged. Its reported paired local Convex claim run supports reduced contention, but no raw runtime transcript was supplied for independent inspection.
Evidence reviewed 9 items Pinned scope and current-main necessity: The verified introduced delta contains only the claim implementation and its regression assertions. Current main still uses nested source queries; the proposed direct-read branch is additional work.
Selection and lease safeguards: Both read paths share the queued/source/time index, rollout filter, and ascending order. The direct path checks legacy eligibility; final selection rechecks job state and rollout eligibility before writing leases. Catalog admission remains on its existing path.
Runtime caller and authorization boundary: The worker calls claimCodexScanJobLeases, which validates the worker token before invoking the internal mutation. Artifact hydration separately verifies worker identity and lease token. This optimization changes neither authorization nor persisted lease format.
Findings None None.
Security None None.

How this fits together

ClawHub scan workers request queued security jobs from the Convex backend. The claim transaction selects eligible jobs and issues exclusive leases before workers retrieve artifacts and scan them.

flowchart TD
  A[Scan worker request] --> B[Worker token check]
  B --> C[Select ready queue jobs]
  C --> D[Direct native read]
  C --> E[Legacy or catalog pagination]
  D --> F[Recheck eligibility and issue lease]
  E --> F
  F --> G[Worker retrieves scan artifacts]
Loading

Before merge

  • Resolve merge risk (P1) - The reported local improvement does not establish safe production concurrency; unpaced saturation still produces transaction conflicts.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Diff size +38/-8 across 2 files The change stays within scanner claims and their existing tests.
Production versus test delta Production +36/-6; tests +2/-2 Production growth provides a shared query builder and a direct-read fast path with retained fallback.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep queue selection and leasing atomic, and qualify higher worker concurrency with production measurements.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep queue selection and leasing atomic, and qualify higher worker concurrency with production measurements.

Do we have a high-confidence way to reproduce the issue?

No reviewer-established reproduction: the body supplies a concrete concurrent local-Convex scenario, but OCC failure rates are workload-dependent and were not rerun.

Is this the best way to solve the issue?

Yes, as a bounded mitigation: removing nested-call overhead targets the implicated transaction. Worker retries already exist; queue sharding would be a broader change unsupported by the current measurements.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 595afc09a183.

Labels

Label changes:

  • add P2: This is a bounded scanner-throughput improvement with reported claim failures, without evidence of a broader service outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded scanner-throughput improvement with reported claim failures, without evidence of a broader service outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

  • Pinned scope and current-main necessity: The verified introduced delta contains only the claim implementation and its regression assertions. Current main still uses nested source queries; the proposed direct-read branch is additional work. (convex/securityScan.ts:3213, 595afc09a183)
  • Selection and lease safeguards: Both read paths share the queued/source/time index, rollout filter, and ascending order. The direct path checks legacy eligibility; final selection rechecks job state and rollout eligibility before writing leases. Catalog admission remains on its existing path. (convex/securityScan.ts:3099, c12ef388479a)
  • Runtime caller and authorization boundary: The worker calls claimCodexScanJobLeases, which validates the worker token before invoking the internal mutation. Artifact hydration separately verifies worker identity and lease token. This optimization changes neither authorization nor persisted lease format. (convex/securityScan.ts:4038, c12ef388479a)
  • Regression coverage and established contract: Three parameterized cases assert no nested queries for native claim limits 1, 4, and 16. Existing tests cover priority lanes, exact Test-only claims, a 513-blocked-job fallback, catalog gates, and the 512-job cap. The security specification requires capacity-sized native reads and reserves broader pagination for legacy or catalog work. (convex/securityScan.test.ts:4263, c12ef388479a)
  • Captured local runtime results: The supplied complete PR body, matching the live REST response, reports a disposable local Convex backend with 600 queued jobs and eight concurrent callers: 32 paced requests improved from 22 successes/10 OCC failures in 20.41 seconds to 32 successes/zero failures in 9.90 seconds, with unique claimed IDs. Unpaced saturation still failed 12 requests after the change. These are author-reported measurements, not a reviewer-executed run. (c12ef388479a)
  • Merged adjacent fix is not a replacement: GitHub confirms fix: bound native scan claim queue reads #3662 merged at the pinned main SHA. Its body explicitly distinguishes reduced read amplification from an unproven throughput improvement, supporting this PR's distinct remaining purpose. (595afc09a183)

Likely related people:

  • Patrick-Erichsen: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@Patrick-Erichsen
Patrick-Erichsen merged commit 5ba76f2 into main Sep 14, 2026
29 checks passed
@Patrick-Erichsen
Patrick-Erichsen deleted the codex/clawscan-claim-contention branch September 14, 2026 23:30

This branch was successfully deployed

1 active deployment
Preview – clawhub — c12ef388 Deployed Sep 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant