skills/cache-expert/references/filesync.md
Filesync transfers host files between client and engine. It powers host.directory / host.file imports and local exports.
This doc focuses on protocol flow, engine sync behavior, and cache interactions relevant to correctness/performance.
engine/client/filesync.go)Client exposes two gRPC services per session:
FileSync (source)FileSend (target)internal/fsutil)Wire protocol uses packetized stat/data/request frames:
engine/filesync)FileSyncer.Snapshot)High-level flow:
getRef)remoteFS (engine/filesync/remotefs.go)remoteFS reads from client stream:
Walk and ReadFilelocalFS (engine/filesync/localfs.go)localFS applies diff from remote stream into per-client mirror:
Filesync now uses a dedicated in-package typed cache:
engine/filesync/change_cache.goThis cache is intentionally narrow:
*ChangeWithStatlocalFS.Sync uses change-cache entries to:
This cache is shared across syncs for the same client mirror via localFSSharedState.
Applied changes are validated against expected remote stats (verifyExpectedChange).
If a cached/applied change does not match expected change, sync fails with conflict instead of silently producing mixed-state snapshot.
With gitignore-enabled import:
After sync operations:
This is separate from dagql call cache; it is snapshot-content reuse at filesync layer.
Exports use client FileSend service:
engine/client/filesync.gointernal/fsutil/send.go, internal/fsutil/receive.goengine/filesync/filesyncer.go, engine/filesync/localfs.go, engine/filesync/remotefs.goengine/filesync/change_cache.gocore/schema/host.go, core/host.go