Skip to content

Commit 6079722

Browse files
authored
Clamp daemon push-sweep throttle to grace window (#83)
The onSaved retention sweep is meant to archive an aged-out previous generation as soon as a new capture in the same page family arrives. The fixed 5s push-sweep throttle added in #73 could swallow that sweep when a second push lands within 5s of the first, leaving the old generation in the listing past its grace window until the next 60m timer sweep. This regressed daemon/scripts/e2e-smoke.mjs (onSaved branch), which reproduced on main with retention.js unchanged. Bound the throttle by the grace window (throttle <= grace): within the grace window a rapid push cannot archive its predecessor anyway (it is grace-protected), so throttling is free; once grace has elapsed the predecessor becomes archivable and the throttle must not delay it. The default grace (30m) far exceeds 5s, so production keeps the 5s throttle unchanged; only an extremely short grace clamps it down. Verified: daemon npm test 123/123, e2e-smoke green x3 (stable).
1 parent 7c3fd67 commit 6079722

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

daemon/src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ function sweep(dir) {
6464
// 度に inbox 全体を同期スキャンし直す必要はなく、次の定期 timer sweep でも同じ stale entry を
6565
// 安全に退避できる。起動時 sweep / 定期 timer sweep / downloadsDir 採用時の sweep は対象外
6666
// (頻度が低く意図的なタイミングのため、スロットルせず常に実行する)。
67-
const PUSH_SWEEP_THROTTLE_MS = 5000;
67+
//
68+
// 不変条件 throttle ≤ grace: grace 窓内では rapid push の旧世代はどのみち保護されて archive されない
69+
// ので throttle は無害だが、grace を「抜けた直後」の push で旧世代を即退避するのが onSaved sweep の
70+
// 役割であり、throttle がそれを食ってはならない(grace より長い throttle は、grace 経過後に archive
71+
// 可能になった旧世代の即時退避を次の定期 sweep まで遅らせてしまう)。既定 grace(30分) ≫ 5秒なので
72+
// 通常はそのまま 5秒。grace を極端に短く設定した場合のみ grace に切り詰める。
73+
const PUSH_SWEEP_THROTTLE_MS = Math.min(5000, retentionPolicy.graceWindowMs);
6874
let lastPushSweepAt = 0;
6975
function sweepAfterPush(dir) {
7076
const now = Date.now();

0 commit comments

Comments
 (0)