perf(queue): parallelize regate-sweep per-repo settings resolution#3928
Conversation
fanOutAgentRegateSweepJobs resolved every repo's settings + drain-state one at a time in a sequential for-loop, even though the actual dispatch below it already runs in parallel. Each repo costs 4 D1/KV round-trips (resolveRepositorySettings's own 3 plus getLatestRegatedAt), so this prefix scaled linearly with repo count on every 2-minute cron tick. Reuses the bounded-concurrency worker pool loadRepoFocusManifests already relies on for the same per-repo fan-out shape. Closes #3899
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review result - approve/merge recommendedReview updated: 2026-07-07 07:04:47 UTC
✅ Suggested Action - Approve/Merge
Review summary Nits — 4 non-blocking
Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3928 +/- ##
=======================================
Coverage 93.58% 93.58%
=======================================
Files 358 358
Lines 34342 34345 +3
Branches 12570 12573 +3
=======================================
+ Hits 32138 32141 +3
Misses 1580 1580
Partials 624 624
🚀 New features to boost your workflow:
|
Summary
fanOutAgentRegateSweepJobs(armed every 2 minutes for every registered+configured repo) resolved each repo's settings and drain-state one at a time in a sequentialforloop, with both awaits inside the loop body — while the actual per-repo dispatch right below it already correctly usesPromise.all.resolveRepositorySettings's own 3 parallel round-trips plus a 4thgetLatestRegatedAtD1 query, so this prefix scaled linearly with repo count (~4 x round-trip-latency x repoCount), entirely serialized, before dispatch even started. As a self-host maintainer onboards more repos, this risks colliding with the Workers CPU-time budget for the cron-triggered invocation.mapWithConcurrencyLimit, concurrency 4), reusing the exact worker-pool helperloadRepoFocusManifestsalready relies on for the same "many small per-repo D1/KV reads" shape — exported it fromfocus-manifest-loader.tsrather than duplicating it.ineligible/draining/configured/errored) instead of mutating shared counters directly, preserving the exact existing behavior: per-repo try/catch isolation, theskippedDraining/skippedErroredaudit counters, and the silent skip for ineligible repos.Found via a fresh performance/scalability/accuracy hardening audit of the self-host ORB stack. Tracked under #1667.
Scope
src/signals/focus-manifest-loader.ts— exportmapWithConcurrencyLimitsrc/queue/processors.ts— bounded-concurrency resolution + newSWEEP_FANOUT_RESOLUTION_CONCURRENCYconstanttest/unit/queue.test.ts— new regression test proving real overlap (maxInFlight > 1) AND boundedness (maxInFlight <= 4)Validation
npm run typechecknpm run test:coverage(full unsharded) — 546 files / 10825 tests passed; changed lines inprocessors.tsfully covered perlcov.info(cross-checked against the diff hunks — zero overlap with the 51 pre-existing uncovered lines elsewhere in the file)git diff --checkcleanSafety
delaySeconds) still applies — its exact repo-to-delay assignment can now vary run-to-run since worker completion order isn't guaranteed, which doesn't affect correctness (the stagger only needs some spread, not a specific repo-to-delay mapping).Closes #3899