Follow-up to the 2026-10-09 incident (a tenant's managed Gitea was OOM-killed; six scheduled scans failed with 502). Companion to #546 (retry on 5xx).
Finding
scheduler::scan_all_repos awaits run_target_scan one target at a time, so the scheduler tick itself never cloned a tenant's repos in parallel: the six failures were six sub-second 502s in a serial loop. The real concurrent Scheduled fan-outs are git_source::spawn_scan (targets the git sync creates) and lifecycle::resume_interrupted_scans (after a restart), plus webhooks/clicks across targets.
What changes
Jitter:scan_gate::start_delay(trigger): a random 0 to 30 s (SCHEDULED_SCAN_JITTER) for Scheduled, zero for Webhook/Manual/Support. run_target_scan waits it (tokio sleep) before taking the target and a scan slot, so the wait costs no slot. Covers all three Scheduled entry points. Cost: the serial scheduler loop adds a mean of 15 s per target per tick (6 h schedule).
Per-host clone limit:pipeline/clone_limit.rs: process-wide CLONE_SLOTS, a counting semaphore per git host (std Mutex + Condvar, 2 per host), taken at the top of GitOps::clone_or_fetch and held to its end, i.e. around the clone/fetch only, not the scan. This is the one function every path goes through (orchestrator, ingest, PR review, graph/chat builds); it is sync, so the wait runs under block_in_place on the multi-thread runtime. Hosts are keyed lower-case; a refused remote has no host and fails as before. The global SCAN_CONCURRENCY semaphore is unchanged.
Not limited: submodule fetches (kept small). Once #546 is in, the host slot is also held across its retry waits, which keeps a restarting host from being hammered.
Tests
clone_limit::tests::a_host_runs_at_most_two_while_another_host_proceeds: two permits on host A, a third waits (channel times out), host B is granted meanwhile, dropping one A permit lets the waiter through.
scan_gate::tests::a_scheduled_scan_waits_within_the_jitter (1000 samples within 0 to 30 s, not constant), scan_gate::tests::webhook_manual_and_support_scans_start_at_once
Follow-up to the 2026-10-09 incident (a tenant's managed Gitea was OOM-killed; six scheduled scans failed with 502). Companion to #546 (retry on 5xx).
## Finding
`scheduler::scan_all_repos` awaits `run_target_scan` one target at a time, so the scheduler tick itself never cloned a tenant's repos in parallel: the six failures were six sub-second 502s in a serial loop. The real concurrent `Scheduled` fan-outs are `git_source::spawn_scan` (targets the git sync creates) and `lifecycle::resume_interrupted_scans` (after a restart), plus webhooks/clicks across targets.
## What changes
- **Jitter:** `scan_gate::start_delay(trigger)`: a random 0 to 30 s (`SCHEDULED_SCAN_JITTER`) for `Scheduled`, zero for Webhook/Manual/Support. `run_target_scan` waits it (tokio sleep) before taking the target and a scan slot, so the wait costs no slot. Covers all three Scheduled entry points. Cost: the serial scheduler loop adds a mean of 15 s per target per tick (6 h schedule).
- **Per-host clone limit:** `pipeline/clone_limit.rs`: process-wide `CLONE_SLOTS`, a counting semaphore per git host (std Mutex + Condvar, 2 per host), taken at the top of `GitOps::clone_or_fetch` and held to its end, i.e. around the clone/fetch only, not the scan. This is the one function every path goes through (orchestrator, ingest, PR review, graph/chat builds); it is sync, so the wait runs under `block_in_place` on the multi-thread runtime. Hosts are keyed lower-case; a refused remote has no host and fails as before. The global `SCAN_CONCURRENCY` semaphore is unchanged.
- Not limited: submodule fetches (kept small). Once #546 is in, the host slot is also held across its retry waits, which keeps a restarting host from being hammered.
## Tests
- `clone_limit::tests::a_host_runs_at_most_two_while_another_host_proceeds`: two permits on host A, a third waits (channel times out), host B is granted meanwhile, dropping one A permit lets the waiter through.
- `clone_limit::tests::a_dropped_permit_frees_its_slot`
- `scan_gate::tests::a_scheduled_scan_waits_within_the_jitter` (1000 samples within 0 to 30 s, not constant), `scan_gate::tests::webhook_manual_and_support_scans_start_at_once`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
A scheduled scan now starts after a random delay of up to 30 s
(SCHEDULED_SCAN_JITTER), applied in run_target_scan before the target and
a scan slot are taken; webhook, manual and support scans start at once.
Every clone or fetch takes one of two slots of its git host
(pipeline/clone_limit.rs, process-wide), held only around clone_or_fetch,
so a tenant's scans no longer all hit one self-hosted Gitea together,
while another host's clones go ahead. The global scan semaphore stays.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Follow-up to the 2026-10-09 incident (a tenant's managed Gitea was OOM-killed; six scheduled scans failed with 502). Companion to #546 (retry on 5xx).
Finding
scheduler::scan_all_reposawaitsrun_target_scanone target at a time, so the scheduler tick itself never cloned a tenant's repos in parallel: the six failures were six sub-second 502s in a serial loop. The real concurrentScheduledfan-outs aregit_source::spawn_scan(targets the git sync creates) andlifecycle::resume_interrupted_scans(after a restart), plus webhooks/clicks across targets.What changes
scan_gate::start_delay(trigger): a random 0 to 30 s (SCHEDULED_SCAN_JITTER) forScheduled, zero for Webhook/Manual/Support.run_target_scanwaits it (tokio sleep) before taking the target and a scan slot, so the wait costs no slot. Covers all three Scheduled entry points. Cost: the serial scheduler loop adds a mean of 15 s per target per tick (6 h schedule).pipeline/clone_limit.rs: process-wideCLONE_SLOTS, a counting semaphore per git host (std Mutex + Condvar, 2 per host), taken at the top ofGitOps::clone_or_fetchand held to its end, i.e. around the clone/fetch only, not the scan. This is the one function every path goes through (orchestrator, ingest, PR review, graph/chat builds); it is sync, so the wait runs underblock_in_placeon the multi-thread runtime. Hosts are keyed lower-case; a refused remote has no host and fails as before. The globalSCAN_CONCURRENCYsemaphore is unchanged.Tests
clone_limit::tests::a_host_runs_at_most_two_while_another_host_proceeds: two permits on host A, a third waits (channel times out), host B is granted meanwhile, dropping one A permit lets the waiter through.clone_limit::tests::a_dropped_permit_frees_its_slotscan_gate::tests::a_scheduled_scan_waits_within_the_jitter(1000 samples within 0 to 30 s, not constant),scan_gate::tests::webhook_manual_and_support_scans_start_at_once🤖 Generated with Claude Code
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
0bf714d580toa5720f9fa3