Repository navigation
fix: reopen snapshot ref for no-op withChanges - #13820
Merged
Merged
Conversation
Applying an empty changeset with Directory.withChanges stores the parent's snapshot ref instance on the derived directory. When the derived cache entry is later collected (session close plus cache prune), its OnRelease releases the shared handle, and the parent's still-cached snapshot becomes unusable: every later mount, from any session, fails with "invalid immutable ref" until the engine restarts. Reproduce with two sessions against a nested engine: one keeps the parent entry alive while the other applies an empty changeset and disconnects, then a prune loop re-mounts the parent. Signed-off-by: Alex Suraci <[email protected]>
Directory.withChanges with an empty changeset returned the parent's snapshot ref instance as the derived directory's snapshot. Every cached Directory owns its handle and releases it when its cache entry is collected, so the shared instance let a collected withChanges result invalidate the parent's still-cached snapshot engine-wide (introduced in dagger#13342). Reopen the snapshot by ID instead, matching how subdirectory and diff derive their handles. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to vito/dagger
that referenced
this pull request
Aug 1, 2026
Record the withChanges empty-changeset snapshot fix in the unreleased changelog so the next release notes mention the invalid-immutable-ref failure mode it removes. Signed-off-by: Alex Suraci <[email protected]>
vito
force-pushed
the
fix-withchanges-empty-changeset
branch
from
August 1, 2026 18:17
66b12e8 to
934a440
Compare
sipsma
approved these changes
Aug 3, 2026
vito
added a commit
that referenced
this pull request
Aug 4, 2026
* test: reproduce withChanges snapshot poisoning Applying an empty changeset with Directory.withChanges stores the parent's snapshot ref instance on the derived directory. When the derived cache entry is later collected (session close plus cache prune), its OnRelease releases the shared handle, and the parent's still-cached snapshot becomes unusable: every later mount, from any session, fails with "invalid immutable ref" until the engine restarts. Reproduce with two sessions against a nested engine: one keeps the parent entry alive while the other applies an empty changeset and disconnects, then a prune loop re-mounts the parent. Signed-off-by: Alex Suraci <[email protected]> * fix: reopen snapshot ref for no-op withChanges Directory.withChanges with an empty changeset returned the parent's snapshot ref instance as the derived directory's snapshot. Every cached Directory owns its handle and releases it when its cache entry is collected, so the shared instance let a collected withChanges result invalidate the parent's still-cached snapshot engine-wide (introduced in #13342). Reopen the snapshot by ID instead, matching how subdirectory and diff derive their handles. Signed-off-by: Alex Suraci <[email protected]> --------- Signed-off-by: Alex Suraci <[email protected]>
marcosnils
pushed a commit
to marcosnils/dagger
that referenced
this pull request
Aug 24, 2026
* test: reproduce withChanges snapshot poisoning Applying an empty changeset with Directory.withChanges stores the parent's snapshot ref instance on the derived directory. When the derived cache entry is later collected (session close plus cache prune), its OnRelease releases the shared handle, and the parent's still-cached snapshot becomes unusable: every later mount, from any session, fails with "invalid immutable ref" until the engine restarts. Reproduce with two sessions against a nested engine: one keeps the parent entry alive while the other applies an empty changeset and disconnects, then a prune loop re-mounts the parent. Signed-off-by: Alex Suraci <[email protected]> * fix: reopen snapshot ref for no-op withChanges Directory.withChanges with an empty changeset returned the parent's snapshot ref instance as the derived directory's snapshot. Every cached Directory owns its handle and releases it when its cache entry is collected, so the shared instance let a collected withChanges result invalidate the parent's still-cached snapshot engine-wide (introduced in dagger#13342). Reopen the snapshot by ID instead, matching how subdirectory and diff derive their handles. Signed-off-by: Alex Suraci <[email protected]> --------- Signed-off-by: Alex Suraci <[email protected]> (cherry picked from commit b1c2c81)
marcosnils
pushed a commit
to marcosnils/dagger
that referenced
this pull request
Aug 24, 2026
* test: reproduce withChanges snapshot poisoning Applying an empty changeset with Directory.withChanges stores the parent's snapshot ref instance on the derived directory. When the derived cache entry is later collected (session close plus cache prune), its OnRelease releases the shared handle, and the parent's still-cached snapshot becomes unusable: every later mount, from any session, fails with "invalid immutable ref" until the engine restarts. Reproduce with two sessions against a nested engine: one keeps the parent entry alive while the other applies an empty changeset and disconnects, then a prune loop re-mounts the parent. Signed-off-by: Alex Suraci <[email protected]> * fix: reopen snapshot ref for no-op withChanges Directory.withChanges with an empty changeset returned the parent's snapshot ref instance as the derived directory's snapshot. Every cached Directory owns its handle and releases it when its cache entry is collected, so the shared instance let a collected withChanges result invalidate the parent's still-cached snapshot engine-wide (introduced in dagger#13342). Reopen the snapshot by ID instead, matching how subdirectory and diff derive their handles. Signed-off-by: Alex Suraci <[email protected]> --------- Signed-off-by: Alex Suraci <[email protected]> (cherry picked from commit b1c2c81)
marcosnils
pushed a commit
to marcosnils/dagger
that referenced
this pull request
Aug 25, 2026
* test: reproduce withChanges snapshot poisoning Applying an empty changeset with Directory.withChanges stores the parent's snapshot ref instance on the derived directory. When the derived cache entry is later collected (session close plus cache prune), its OnRelease releases the shared handle, and the parent's still-cached snapshot becomes unusable: every later mount, from any session, fails with "invalid immutable ref" until the engine restarts. Reproduce with two sessions against a nested engine: one keeps the parent entry alive while the other applies an empty changeset and disconnects, then a prune loop re-mounts the parent. Signed-off-by: Alex Suraci <[email protected]> * fix: reopen snapshot ref for no-op withChanges Directory.withChanges with an empty changeset returned the parent's snapshot ref instance as the derived directory's snapshot. Every cached Directory owns its handle and releases it when its cache entry is collected, so the shared instance let a collected withChanges result invalidate the parent's still-cached snapshot engine-wide (introduced in dagger#13342). Reopen the snapshot by ID instead, matching how subdirectory and diff derive their handles. Signed-off-by: Alex Suraci <[email protected]> --------- Signed-off-by: Alex Suraci <[email protected]> (cherry picked from commit b1c2c81)
marcosnils
pushed a commit
that referenced
this pull request
Aug 25, 2026
* test: reproduce withChanges snapshot poisoning Applying an empty changeset with Directory.withChanges stores the parent's snapshot ref instance on the derived directory. When the derived cache entry is later collected (session close plus cache prune), its OnRelease releases the shared handle, and the parent's still-cached snapshot becomes unusable: every later mount, from any session, fails with "invalid immutable ref" until the engine restarts. Reproduce with two sessions against a nested engine: one keeps the parent entry alive while the other applies an empty changeset and disconnects, then a prune loop re-mounts the parent. Signed-off-by: Alex Suraci <[email protected]> * fix: reopen snapshot ref for no-op withChanges Directory.withChanges with an empty changeset returned the parent's snapshot ref instance as the derived directory's snapshot. Every cached Directory owns its handle and releases it when its cache entry is collected, so the shared instance let a collected withChanges result invalidate the parent's still-cached snapshot engine-wide (introduced in #13342). Reopen the snapshot by ID instead, matching how subdirectory and diff derive their handles. Signed-off-by: Alex Suraci <[email protected]> --------- Signed-off-by: Alex Suraci <[email protected]> (cherry picked from commit b1c2c81)
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.
Problem
Once an empty changeset is applied anywhere on an engine, the engine can enter a state where every use of the parent directory — from any session — fails with
invalid immutable ref 0x...: invaliduntil the engine restarts. In practice the poisoned parent is often the shared scratch directory (Query.directory), since SDK generators build outputs asdag.directory().withChanges(cs)and workspace staging overlays apply changesets onto the workspace root, both frequently with empty changesets. First observed asdagger generatefailing repeatedly, with even a baredagger core directory entriesfailing on the same engine.Root cause
Directory.WithChangeshas a fast path for an empty changeset that stored the parent's snapshot ref instance on the derived directory (dir.Snapshot.setValue(currentSnapshot)), introduced in #13342. Every cachedDirectoryvalue owns its snapshot handle and releases it inDirectory.OnReleasewhen its dagql cache entry is collected. Because the derived result shared the parent's handle, collecting the derived entry — e.g. disk-pressure GC pruning its persisted edge after its creating session closed — released the handle out from under the parent's still-cached, still-owned entry. Every subsequent mount of the parent then failed thereleasedcheck inimmutableRef.Mount.Instrumented runs showed the signature clearly: one real release of the shared handle from
gc → Prune → removePersistedEdge → collect → Directory.OnRelease, followed by dozens of no-op re-releases of the same pointer as other empty-withChangesderivatives of the same parent were collected. Before #13342 even no-op merges went throughSnapshotManager.Merge, which returns a fresh handle in all paths, so no sharing occurred.Fix
The empty-changeset path now reopens its own handle via
SnapshotManager().GetBySnapshotID(...), the same conventionsubdirectory,diff, and the container rootfs clone helper already follow. An audit of every otherSnapshot.setValuesite incore/found no other instance-sharing violation.Testing
New regression test
TestChangeset/TestWithChangesEmptyChangesetKeepsParentSnapshot: two sessions against a nested dev engine — one holds the parent entry, the other applies an empty changeset and disconnects — then a prune loop re-mounts the parent. Verified both ways: it fails withinvalid immutable refon the unfixed code and passes with the fix. Also validated end to end on a dev engine: repeateddagger generateruns across sessions plus explicit prunes no longer reproduce the failure.🤖 Generated with Claude Code