You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(sweep): dedup the re-gate fan-out so a burst collapses to one effective sweep
The ~2-min cron enqueues a fan-out job each tick, but fanOutAgentRegateSweepJobs
had no global dedup. When a burst of fan-out jobs ran at once — a deploy-restart
cron catch-up, or fan-out jobs that queued behind a heavy per-PR re-review
backlog and then drained together — EACH one enqueued a per-repo sweep before the
per-repo dispatch-stamp in-flight guard could engage, producing redundant
overlapping sweeps (observed ~3x on the metagraphed dry-run). Those redundant
sweeps tripled the per-PR load, which delayed the next fan-out, which then burst
in turn — a self-sustaining cascade.
Add an atomic fan-out dedup: claimRegateFanoutSlot does a conditional UPDATE on
the global_agent_controls singleton (new last_regate_fanout_at column, migration
0063) that matches only when the last fan-out is unset or older than the dedup
window. D1 serializes writes, so a burst collapses to exactly ONE winner per
window; the rest get 0 changes and skip (audited deduped). One effective fan-out
per window keeps the per-PR load bounded, which stops the backlog that was
delaying subsequent fan-outs — breaking the cascade at its source. Fail-open on a
driver error so the fleet never stalls.
"UPDATE global_agent_controls SET last_regate_fanout_at = ?1 WHERE id = 'singleton' AND (last_regate_fanout_at IS NULL OR last_regate_fanout_at < ?2)",
1962
+
)
1963
+
.bind(now,threshold)
1964
+
.run();
1965
+
/* v8 ignore next -- D1 update metadata normally includes changes; the ?? 0 fallback protects driver anomalies. */
1966
+
returnNumber(result.meta.changes??0)===1;
1967
+
}catch{
1968
+
returntrue;
1969
+
}
1970
+
}
1971
+
1951
1972
/** Flip the DB-backed global kill-switch (operator emergency brake; no redeploy required). */
awaitprocessJob(env,{type: "agent-regate-sweep",requestedBy: "schedule"});// burst sibling in the same window → deduped
908
+
expect(sent.filter((m)=>m.type==="agent-regate-sweep")).toEqual([]);// enqueues no redundant sweep
909
+
constdenied=awaitenv.DB.prepare("select count(*) as n from audit_events where event_type='agent.sweep.fanout' and outcome='denied'").first<{n: number}>();
910
+
expect(denied?.n).toBe(1);
911
+
});
912
+
894
913
it("the sweep stamps the marker INLINE when the repo has no installation (audit-only, still converges) (#audit-sweep-fanout)",async()=>{
0 commit comments