Repository navigation
fix(devkitd): discard stale sweep commits (#493) - #505
Open
codeaholicguy wants to merge 2 commits into
Open
codeaholicguy wants to merge 2 commits into
codeaholicguy wants to merge 2 commits into
Conversation
Serialize sweep commits with a monotonic id so a timer sweep that started before agent.start cannot overwrite a fresher post-start snapshot. Timer ticks use try_apply_sweep to skip while another sweep is in flight. Closes #493
Use per-daemon commit pause hooks, sync_channel(1), and release sweep_commit_pause before blocking. Drive the fresh sweep through real apply_sweep with discover_override for deterministic ps. Co-authored-by: Hoang Nguyen <codeaholicguy@users.noreply.github.com>
This branch has not been deployed
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.
Closes #493
Root cause
The 2s timer and RPC handlers all call
apply_sweep()with no ordering on the commit step. A timer sweep can run discovery before a new agent exists, spend time on enrichment without holding any sweep-wide lock, then commit afteragent.starthas already applied a fresh snapshot. That stale commit tombstones the live row indaemon.db, replaces the enriched cache, and emits a phantomagent.disappearedevent. TLC counterexample on branchfeature-tla-analysis(Inv_NoPhantomDisappeared).Fix
Each
apply_sweeptakes a monotonic sequence number at entry. The commit phase (enriched cache,apply_agent_snapshot, lifecycle events) runs undersweep_mutexand is skipped whenmy_seq < sweep_applied, so an older sweep cannot land after a newer one. The 2s timer usestry_apply_sweep()and bails out whensweep_in_flightis already non-zero, so timer sweeps do not queue up behind slow RPC-triggered passes. Enrichment still happens outside the enrichedRwLock;start_mutexis untouched. No changes to daemon startup or autostart (#495).Regression test
stale_sweep_commit_does_not_tombstone_live_registrationuses aSweepCommitPausestored on the targetDaemononly (not a process-global flag). A stale timer-shapedapply_sweeppauses at commit; the test registers the agent and runs a full secondapply_sweep()whose seq comes fromsweep_seq, usingdiscover_overrideto fake ps seeing the pid (no codex fixture in this crate). When overrides are used, the sweep skips durable reconcile and session file resolution and builds minimal enriched rows so the test stays fast.Guard check: Removing the stale discard block in
commit_sweepmakes this test fail (tombstone assertion). The same test also failed on the first commit before the production fix landed.Test plan
cargo test -p devkitd stale_sweepcargo test --workspacecargo clippy --workspace --all-targets -- -D warningscargo fmt -- --checkRisks
Stale commit drops are quiet aside from a trace log. A skipped timer tick defers discovery by up to one 2s interval when another sweep is still running. Expect a small merge conflict with #503 if both touch
serve()/test_daemon()inserver.rs; this branch does not rebase onto #503.Behavior changes
For Hoang: the periodic discovery tick may skip one 2s cycle when a sweep is already running. No CLI, RPC, or event schema changes.
Overlap with open PRs
No overlap with #489 (
durable.rsonly). #481 editslisted_agent()and theagent.lookup/agent.unregisterdispatch arm; this PR only touchesapply_sweep, the timer spawn, and adjacent tests.AI DevKit skills used
dev-lifecycle, tdd, humanizer
Tooling friction
Long-running or stuck
devkitdtest binaries from earlier harness iterations can hold locks;pkillthe test binary if a sweep test hangs. Pre-commit failed once on flakystop_and_restart_adoption_do_not_double_launchon the first commit; retry passed.