Skip to content

fix(agent-memory-sync): watch push is base-snapshot-aware, stop mirror-deleting unpulled peer files#65

Merged
LanNguyenSi merged 4 commits into
masterfrom
fix/memory-sync-watch-mirror-delete
Jul 23, 2026
Merged

fix(agent-memory-sync): watch push is base-snapshot-aware, stop mirror-deleting unpulled peer files#65
LanNguyenSi merged 4 commits into
masterfrom
fix/memory-sync-watch-mirror-delete

Conversation

@LanNguyenSi

Copy link
Copy Markdown
Owner

Summary

watch pushed the local tree as a full mirror of repositorySubdir: any remote path missing locally (e.g. a peer machine's file this workspace never pulled) was deleted, and concurrently changed remote files were overwritten without a merge. Empirically reproduced in the 2026-07-22 review (task ff75687e follow-up): a watch tick from machine B deterministically deleted machine-state/mac-mini.json from the bare remote.

This PR routes the watch tick through the existing base-snapshot-aware performPush machinery (the run --mode sync/push path) instead of the removed commitAndPushSnapshot mirror:

  • Remote-only (unpulled peer) files are never enumerated as delete targets: the 3-way merge only considers localFiles and baseFiles.
  • Concurrent remote edits get the configured conflict strategy (inline markers by default), identical to run --mode sync.
  • An unreachable remote or failed push queues the snapshot locally and replays it on the next tick, instead of hard-exiting. Documented contract change: config/data errors stay fail-loud (non-zero exit); see README watch section and docs/machine-setup.md.
  • performPush gains two backward-compatible optional fields (commitMessage, tempDirLabel); watch keeps its human-readable commit messages and an isolated working copy.
  • docs/machine-setup.md mirror-delete warnings rolled back to describe the fixed behavior; the periodic run --mode sync job remains required (watch still never pulls).

Verification

  • Red-test first: 3 new integration tests pinned the hazard against the old code (peer-file delete, blind overwrite, negative control), then went green after the fix.
  • Reviewer mutation test: reverting src to master turned all 3 new tests red; tests are not inert.
  • Review follow-up tests: offline-queue-then-replay lifecycle through watch itself, plus a direct stateDir/base post-merge assertion.
  • Full package suite 95/95, typecheck clean.

Risks

  • watch now shares StateStore/queue/base snapshots with a periodic run --mode sync on the same profile (pre-existing race class, consciously out of scope; the working-copy race is avoided via tempDirLabel: "watch").
  • watch tick log wording changed; external log scrapers matching the old phrasing need updating.

Refs: agent-tasks a2bb475d (toolchain-parity-2026-07-22:followup-watch-mirror)

Lan Nguyen Si and others added 2 commits July 23, 2026 12:08
…r-deleting unpulled peer files

watch's pushSnapshot() now routes through the same performPush machinery as
run --mode sync/push (3-way merge over localFiles and baseFiles) instead of
the whole-subtree mirror commitAndPushSnapshot: remote-only peer files are
never delete targets, concurrent remote edits get the configured conflict
strategy, and an unreachable remote queues locally instead of hard-exiting
(documented contract change; config/data errors stay fail-loud). Red-test
first: 3 new integration tests pinned the hazard against the old code before
the fix.

Refs: agent-tasks a2bb475d (toolchain-parity-2026-07-22:followup-watch-mirror)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…apshot refresh; clarify --max-runs tick semantics

Review follow-up: the queued-instead-of-fail-loud watch path and the
stateDir/base refresh were untested (a regression to the old mirror-push
contract would have passed the suite). --max-runs keeps counting ticks
(applied or queued), consistent with run.ts and required as termination
for the offline test; help text and README now say so.

Refs: agent-tasks a2bb475d

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@LanNguyenSi LanNguyenSi added review:tests-pass merge-approval gate prerequisite review:checklist-complete merge-approval gate prerequisite review:comments-resolved merge-approval gate prerequisite review:scope-matches-task merge-approval gate prerequisite review:evidence-logged merge-approval gate prerequisite labels Jul 23, 2026
Lan Nguyen Si and others added 2 commits July 23, 2026 12:27
…ady; deterministic test arming + tick deadlines

The new watch integration tests armed their trigger edit after a fixed
sleep; on Linux/inotify the edit can land before chokidar finishes its
initial scan, the event is lost, watch never ticks, and CI hangs until
the job timeout. The 'watching N path(s)' line now fires in the 'ready'
handler (it previously claimed watching before the watcher was armed),
tests wait for that line before editing, and every spawned watch child
is bounded by a 20s deadline with a kill, so a regression fails in
seconds instead of orphaning the job.

Refs: agent-tasks a2bb475d

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…rt watch-restore tests off fixed-sleep arming

watch-restore.test.ts used the same sleep-then-edit arming that hung the
new tests on Linux; under the higher parallel suite load it now hangs CI
too. Both watch test files use one helper (chokidar-ready wait, 20s tick
deadline with kill, --verbose for the ready line); no assertion changes.

Refs: agent-tasks a2bb475d

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@LanNguyenSi
LanNguyenSi merged commit f819092 into master Jul 23, 2026
5 checks passed
@LanNguyenSi
LanNguyenSi deleted the fix/memory-sync-watch-mirror-delete branch July 23, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:checklist-complete merge-approval gate prerequisite review:comments-resolved merge-approval gate prerequisite review:evidence-logged merge-approval gate prerequisite review:scope-matches-task merge-approval gate prerequisite review:tests-pass merge-approval gate prerequisite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant