feat(vault-agent): scheduled background sync#16
Merged
Conversation
New `sync.interval_secs` config key: while unlocked, the agent re-pulls `/sync` on that cadence (server::scheduled_sync_loop, a tokio interval task mirroring idle_lock_loop), refreshing the in-memory vault and the encrypted on-disk cache so it never drifts and a later offline/PIN unlock reads fresh data — no manual `vault sync`. `0`/unset disables. - Reuses AgentState::resync wholesale; best-effort (Locked/Offline/network logged + skipped) and deliberately does NOT touch(), so background syncs never defer the idle-lock countdown. - Flows config -> --sync-interval-secs auto-spawn flag like idle_lock_secs; applies on the next agent spawn. last_sync (already in `vault status`) surfaces freshness — no protocol change. - Tests: vault-config get/set/unset + agent_args flag emission; an agent invariant test that a locked resync is a clean Locked no-op and leaves last_activity untouched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
New
sync.interval_secsconfig key. While the agent is unlocked, it re-pulls/syncon that cadence, refreshing the in-memory vault and the encryptedon-disk cache — so a long-running session never drifts from the server, and an
offline/PIN unlock later reads fresh data, with no manual
vault sync.0/unset disables.How
server::scheduled_sync_loop— atokiointerval task modeled on theexisting
idle_lock_loop; spawned frommain.rsonly when--sync-interval-secs > 0. Each tick, if unlocked, it callsAgentState::resync(the same pathvault syncuses:ensure_online→/sync→ replace ciphers/folders/last_sync→ re-persist cache).Locked/Offline/ network result is logged andskipped — a failed background sync never disturbs the session.
touch()— a background sync must not reset the idle-lockcountdown, so idle-lock still fires on schedule; once locked, the loop skips.
idle_lock_secs:sync.interval_secs→--sync-interval-secs, applied on the next agent (auto-)spawn.last_sync(already invault status) surfaces freshness — no protocolchange.
Tests
vault-config:sync.interval_secsget/set/unset round-trip +agent_argsemits
--sync-interval-secs <n>only when set.vault-agent: an invariant test that a lockedresyncreturnsLocked(clean skip) and leaves
last_activityuntouched (background sync doesn'tdefer idle-lock).
Local CI-exact gates all green:
fmt, fresh isolatedclippy -D warnings,cargo test --workspace --all-targetsunderRUSTFLAGS=-D warnings,cargo deny check(no new deps), both headless builds.🤖 Generated with Claude Code