Skip to content

Fix initial watch sync for existing files - #14031

Open
ousamabenyounes wants to merge 1 commit into
docker:mainfrom
ousamabenyounes:13725-fix-initial-sync
Open

Fix initial watch sync for existing files#14031
ousamabenyounes wants to merge 1 commit into
docker:mainfrom
ousamabenyounes:13725-fix-initial-sync

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Aug 11, 2026

Copy link
Copy Markdown

What I did

Fixes #13725.

develop.watch initial sync filtered host files by the service image's creation time. Existing files older than the image were therefore omitted at startup, even though later filesystem events synced them normally.

Initial sync now copies every eligible watched file, while preserving ignore and bind-mount filtering. The obsolete image-time lookup is removed, and with it the project argument that only fed it.

Rebased onto current main after 68ab763 flattened the watch trigger preparation; the fix applies to initialSyncFiles/initialSyncDirectory in their new shape.

Test verification

RED on main (3ee4b5c79), with only the new test applied:

=== RUN   TestInitialSyncFilesIncludesFilesOlderThanImage
    assertion failed:
        --- paths
        +++ →
          []*sync.PathMapping(
        - 	nil,
        + 	{
        + 		&{
        + 			HostPath:      ".../test.txt",
        + 			ContainerPath: "/app/src/test.txt",
        + 		},
        + 	},
          )
--- FAIL: TestInitialSyncFilesIncludesFilesOlderThanImage (0.00s)

GREEN with this change:

--- PASS: TestInitialSyncFilesIncludesFilesOlderThanImage
--- PASS: TestInitialSyncIncludesSingleFileOlderThanImage
--- PASS: TestWatchTriggerPathsRunsInitialSyncAndSkipsBindMounts

When the PR was opened I also checked this against a live Engine: reading /app/src/test.txt at watch startup went from No such file or directory to hello.

Validation

  • golangci-lint run --build-tags e2e ./... — 0 issues
  • go test -tags e2e over ./... minus e2e — every package passes, same set as main; pkg/compose coverage 43.9% → 44.8%
  • go build ./..., go vet ./..., and a go mod tidy diff check are clean

@ousamabenyounes
ousamabenyounes requested review from a team as code owners August 11, 2026 23:53
ndeloof
ndeloof previously approved these changes Aug 12, 2026

@ndeloof ndeloof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally, end to end: with a watched file antedated to 2020 (older than the service image) and initial_sync: true, a main build never syncs it at watch startup (/app/src: No such file or directory) while this branch does. New unit tests pass, the full pkg/compose suite and lint are green.

History check on the removed filter: the image-created-time condition was born with the feature itself (#12047, second commit) as a heuristic assuming watched files are baked into the image at build time — no later commit ever relied on or fixed it, so nothing regresses by removing it. It contradicted the pulled-image half of the original #11102 use case, and the removed imageCreatedTime helper was itself fragile (required an existing container, failed the whole initial sync otherwise). Same approach as #13728, which only got cosmetic review feedback before going stale.

Note: TestWatch/debian fails identically on main and on this branch in my environment (Docker Desktop restricted host mount on /var/folders) — pre-existing, unrelated.

Trade-off acknowledged: initial sync now copies the whole watched tree at watch start; acceptable since initial_sync is opt-in.

@ndeloof
ndeloof enabled auto-merge (rebase) August 12, 2026 14:11
@ndeloof
ndeloof disabled auto-merge August 12, 2026 14:11
@ndeloof

ndeloof commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

One request before this can merge: the PR includes AI_AGENT_DISCLOSURE.md, which states the change "may not have been independently reviewed or tested" by its human submitter. That file is meant as a checkpoint, not something to merge: please review the code your agent produced yourself, then remove the file from the commit (amend/rebase) to confirm that manual review took place. The fix itself looks good — see the approval review — so this is the only thing left. (A CI check blocking merges while this file is present is being added.)

@ousamabenyounes

Copy link
Copy Markdown
Author

Thanks for the approval @ndeloof. Removed AI_AGENT_DISCLOSURE.md from the commit and rebased onto the latest main. I reviewed the change myself before dropping the marker file.

Force-pushed the branch (3c8906f9be4979a7b0).

develop.watch initial sync filtered host files by the service image's
creation time, so files older than the image were never copied at watch
startup even though later filesystem events synced them normally.

Initial sync now copies every eligible watched file, keeping the ignore
and bind-mount filtering. The imageCreatedTime helper it relied on is
gone, and with it the project argument that only fed it.

Fixes docker#13725

Signed-off-by: Ben Younes <2910651+ousamabenyounes@users.noreply.github.com>
@ousamabenyounes

ousamabenyounes commented Aug 20, 2026

Copy link
Copy Markdown
Author

Rebased onto current main in a515d44 — this had gone conflicting since 68ab763 flattened the watch trigger preparation. The fix itself is unchanged: it now drops the image-time filter from initialSyncFiles/initialSyncDirectory in their new shape, and project falls out of watchTriggerPaths along with it. I added one test for that rewired path, covering both that the initial sync still runs and that bind-mounted watch paths are still skipped.

ndeloof pushed a commit that referenced this pull request Aug 20, 2026
initialSyncFiles and initialSyncDirectory filtered out any host file
whose mtime predated the image creation time — which is exactly the
files that initial_sync is meant to copy. The imageCreatedTime lookup
(ContainerList + ImageInspect) was also a silent failure point when the
container list returned nothing. Remove the filter and the helper
entirely: sync all files that are not ignored or bind-mounted.

Fixes #13725
Supersedes #14031

Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] develop.watch initial_sync: true does not fire at container start

2 participants