Repository navigation
Back off idle collection ticks and keep active truncations progressing - #231
Merged
Shengyu Fu (shengyfu) merged 4 commits intoNov 30, 2026
Merged
Conversation
A collection continuation waiting out its retry interval (up to 64x the 5 s base) kept every full scheduler tick at 100 ms, so an otherwise idle namespace re-read the catalog and reopened its anchor files ten times a second. On Windows this showed up as steady CPU in tgrep and in Defender. Treat the wait as quiet so ticks back off to the idle tick, and record the continuation's due time as a pacer wake so it still starts on the first base tick after it falls due. A wake that is not after the tick is dropped so work that was due but did not start cannot hold the scheduler at the base tick. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are blocking approval of the retry-aware idle-backoff change.
No open issues 🎉
What changed in this PR
This PR reduces idle scheduler work in managed shared daemons by letting waiting collection continuations use the existing idle backoff, while preserving timely retries.
Changes:
- Tracks the continuation’s retry deadline so idle pacing does not delay eligible collection work.
- Drops stale wake deadlines and adds a simulated-clock regression test for backoff and retry timing.
- Documents that waiting collection continuations count as idle.
| File | Description |
|---|---|
tgrep-cli/src/serve/shared/managed.rs |
Adds retry-aware idle pacing, scheduler wiring, and regression coverage. |
SHARED_WORKTREE_INDEXES.md |
Documents idle backoff and wake timing for waiting collection continuations. |
Review effort: Balanced
A verified member can take many bounded collection passes to delete. Treat each credited truncation as activity on its retained proof, using the current pass policy without rereading the catalog. Keep native invalidation and genuine idle expiry unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
|
||
| [workspace.package] | ||
| version = "1.2.9" | ||
| version = "1.2.10" |
Shengyu Fu (shengyfu)
deleted the
shengyfu/idle-pacing-collection-cursor
branch
November 30, 2026 22:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
e90fe722594a5651a44276fe8abe11f75c724115↑ The exact CI dependency qualification now passes both locked graphs and all four fuzz targets after updating
fuzz/Cargo.lockto 1.2.10.↑ Collection and shared-daemon tests pass; the CLI prints
tgrep 1.2.10.↓ Workspace Clippy reported disallowed
std::env::current_diruses in unchanged files. The full workspace test command omittedmanaged-test-hooks; its affected test passed when rerun with the feature.↓ CI for the current head is still running; no production-sized backlog measurement.
↑ On the previous head, a real collection pass re-read 4,096 bytes and reclaimed zero after individually short idle gaps. Credited truncations had not renewed the completed proof's deadline.
↓ Neither the reported cache total nor the 15 s checkpoint cadence has been attributed on the reporter's machine. Branch-switch rebuild policy is separate.
Problem
Reports on Windows ARM64 and x64 describe an idle managed daemon (
tgrep serve --shared) that:owner.lock,activity.lockandcatalog.sqlite, which Defender then scans.The scheduler loop cleared
quietwhenever a collection continuation was waiting:A cursor waits out
collection_schedule, which isretry_ms × 2^exponentwith the exponent capped at 6. The Copilot runtime setsretry_ms = 5000, so one wait can last up to 320 s. For that whole time every 100 ms tick was a full tick, which reads the catalog and re-verifies the anchors. TheIdlePacerbackoff added in #210/#211 never engaged.There was also a distinct cause of slow reclamation. After tgrep finished verifying a large member, successive passes could safely truncate it in chunks, but only verification pages refreshed the proof's idle deadline. Once the original deadline elapsed, tgrep started verifying the remaining prefix from byte zero. The cursor stayed on that member, delaying cleanup of later objects even though every individual retry arrived on time.
Change
SCHEDULER_IDLE_TICKas they do for any idle namespace.RetrySchedule::next_duegives the continuation's due time.IdlePacerkeeps it as awake, andIdlePacer::dueruns a full tick oncenow >= wake. The continuation therefore still starts on the first 100 ms tick after it falls due, the same start latency as before.IdlePacer::completeddrops a wake that is not after the tick. Work that was due but did not start (for example, when collection was disabled while a cursor waited) costs at most one extra full tick and cannot hold the scheduler at the base tick.SHARED_WORKTREE_INDEXES.mddocuments both the idle pacing and the lifetime of a proof during deletion.fuzz/Cargo.lockis updated to matchtgrep-core.Full ticks per wait:
Validation
cargo fmt --all --check: passedcargo clippy --locked --workspace --all-targets --features tgrep-cli/managed-test-hooks --quiet -- -D warnings: failed on disallowedstd::env::current_diruses in unchanged files (tgrep-core/tests/case_insensitive_roundtrip.rs,tgrep-cli/tests/shared_daemon/managed.rs,tgrep-core/src/gitignore.rs,tgrep-cli/src/search.rs, andtgrep-core/src/shared.rs).cargo test --locked -p tgrep-cli --bin tgrep: passed (394 passed, 2 ignored)cargo test --locked -p tgrep-core --lib managed::collection::tests: passed (25 tests on Windows, including true idle expiry and policy/allocation invalidation)cargo test --locked -p tgrep-cli --features managed-test-hooks --test shared_daemon collection_: passed (7 tests on Windows, including crash recovery, cancellation and replay)cargo check --workspace --offline: passed with both packages at 1.2.10.cargo run --locked --offline -p tgrep-cli -- --version: printedtgrep 1.2.10.python -B scripts/qualification/qualify.py dependencies: passed; both locked dependency graphs and all four fuzz targets checked, with all lockfiles unchanged.cargo test --locked --workspace --offline: one daemon test failed because the command omitted its requiredmanaged-test-hooksfeature (unknown managed method: testing.reconcile-timer); 68 tests in that target passed and 1 was ignored. The exact test passed when rerun with--features managed-test-hooks.active_truncation_outlives_the_original_verification_deadlineuses a sealed four-block file, bounded passes and simulated gaps of two-thirds of an idle lifetime. On the old head, the pass after the second gap re-read 4,096 bytes and reclaimed zero. With the fix, the collector deletes the whole payload without re-reading any verified bytes after truncation begins.scheduling_tests::waiting_continuations_let_ticks_back_off_and_start_on_timesimulates 100 ms ticks against a 5 s retry. It checks that the full ticks fall at exactly[0, 200, 600, 1400, 3000, 4600]ms and that the continuation is due on the first tick at its due time. Removing either the wake check or the stale-wake filter makes the test fail.The loop wiring (
quiet/wakeinrun) is an inline closure with no unit seam, so it was checked by review rather than by a test.Known limits and follow-ups (not changed here)
collection.retry_msis lowered while a cursor waits, the earlier due time is noticed up to one idle tick (1.6 s) late. That is within the documented "noticed up to one idle tick later" lag.diagnostics.consecutive_failed_ticksandfailed_phasesin status.!failures.names().is_empty()in the quiet check is redundant withtick.is_ok(). It is left as is to keep this change small.