Skip to content

Move a mounted workspace onto a newer source in place - #166

Merged
lydakis merged 4 commits into
mainfrom
claude/project-thread-wdmsae
Oct 26, 2026
Merged

lydakis merged 4 commits into
mainfrom
claude/project-thread-wdmsae

Conversation

@lydakis

@lydakis lydakis commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

sandfs update NAME [SOURCE] used to refuse a mounted workspace. Now a mounted workspace moves in place, so a shell or agent working inside the folder carries on and reads the newer files from then on. Graft's sync needs this.

How it works

  • Finding the source. The command finds the newer source itself, so a relative path means what it says, and freezes a new copy for a fork of a plain folder. It then sends the result to the home's mount process over its socket: a new update field on the request, with Updated in the reply.

  • Moving the workspace. The mount process keeps a list of the mounts it serves (server.rs). For the named mount, Shared::replace:

    1. holds off requests;
    2. saves every change, buffers included;
    3. runs update::apply, the same on-disk move as for an unmounted workspace, now split out of move_onto;
    4. reopens the workspace and serves it, swapping the base lease too.
  • What the kernel forgets (Linux FUSE), worked out by Inner::replace:

    • Paths checked. For a commit, the paths the newer commit changed, the workspace's changes that went, and anything under .git. For a folder, everything the kernel knows.
    • Same kind as before. The path keeps its inode, and only its attributes, pages or listing are dropped.
    • Gone, or a different kind (file to folder). The name is removed as if unlinked, and an open handle still reads the old file. Its entry and its folder's listing are dropped, and the folder gets a new time.
    • Folders that stay. No dentry is dropped for a folder that stays, so a shell's working folder stays valid (checked through /proc/PID/cwd).
  • macOS (NFS). The NFS client can't be told to forget anything, and macOS doesn't revalidate even on open: nfs_vnop_open uses cached attributes, up to acregmax = 60 s. The first CI run showed stale reads, so on NFS (Inner::renumber_changed):

    • every known file or link that may have changed gets a new inode (file handle), and its folder gets a new time;
    • the mount now asks for folders' attributes again after 1 s (acdirmin/acdirmax/acrootdirmin/acrootdirmax=1);
    • update waits that second before returning.

    The client's next lookup sees the folder changed, drops its name cache and finds the new handle, which has nothing cached. Files keep the default attribute times.

    An NFS client never says when it is done with an inode, so sandfs normally drops a removed one at once. An inode that an update takes off its name now stays readable until the next update (Inner::moved_off), so a file left open across a sync still reads as it was, as on Linux.

  • Frozen folder copies. A mount that moves off a copy of a folder holds the old copy (a locked COPY.held file next to it) until the mount ends, so files of it left open still read. remove_unused_copies skips held copies, and the mount deletes them when it ends.

  • Mounts this can't move. A mount served by a process that can't move it, such as mount --foreground, still gets "unmount it first".

Tests

  • New mount test update_moves_a_mounted_workspace_in_place:
    • Setup: a shell sits in sub/, a file is held open, and the kernel has cached names, sizes, a missing name and listings.
    • Upstream changes a file's size, adds and removes files, and turns a folder into a file.
    • After update while mounted: everything reads as upstream, the workspace's own change stays, and git status and changes are right.
    • The shell's cwd is intact, the open file reads as it was, and later writes save and survive a remount.
  • Other mount tests:
    • New: update_moves_a_mounted_folder_workspace_onto_another_folder.
    • Extended: a_fork_of_a_plain_folder_keeps_it_as_it_was now does a mounted update with a file left open that the folder removed, and checks the old copy is held. This test runs only on a disk that clones files; I ran it on a btrfs loop.
  • Unit tests: a_newer_workspace_keeps_inodes_and_names_what_went_stale and a_newer_workspace_renumbers_files_that_may_have_changed_where_asked. The second also covers the NFS keep-until-next-update rule.
  • The tests catch a missing invalidation: with the kernel notifications turned off, both new mount tests fail.
  • CI: all green, macOS included.
  • Local runs: cargo fmt, clippy -D warnings (Linux and aarch64-apple-darwin) and the workspace tests pass on Linux. sandfs-bench's smoke test fails when its temp folder is on the btrfs loop and passes on ext4, so that failure isn't from this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CboUL9BU7nvDEZKfQBSkkq

sandfs update on a mounted workspace no longer asks for an unmount. The
command finds the newer source, then asks the process serving the mount to
move it: that process saves every change with requests held off, moves the
workspace on disk as when unmounted, serves the moved workspace from then on
and tells the kernel to forget the names, attributes, pages and listings that
changed. Inodes stay with their paths, so a shell in one of the mount's
folders and files left open carry on; a name that went or changed kind is
removed as if unlinked, still readable through handles left open.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CboUL9BU7nvDEZKfQBSkkq
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T02:55:05.565466Z d06d43b New commits
🔒 Security Review ✅ Completed 2026-10-26T02:57:43.685121Z d06d43b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 043b8a0735

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/sandfs-cli/src/fs.rs Resolved
Comment thread crates/sandfs-cli/src/fs.rs Resolved
… copy while it may be read

macOS's NFS client keeps a file's attributes and pages for up to a minute
without asking, opens included, so files an update changed kept reading as
before. On NFS, a file that may have changed now gets a new inode, its folder
a new time, and folders' attributes are asked for again after a second
(acdirmin/acdirmax 1): once the client looks the name up again it finds the
new inode, with nothing cached. update waits that second before returning.

A mount that moved off a copy of a folder holds the copy (a locked .held file
next to it) until the mount ends, so files of it left open still read; copies
are deleted only once nothing holds them.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CboUL9BU7nvDEZKfQBSkkq
An NFS client never says when it is done with an inode, so removed files
go at once there. A file left open across an in-place update (removed,
or renumbered because it may have changed) then failed to read. Inodes a
replace takes off their names now stay readable until the next one.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CboUL9BU7nvDEZKfQBSkkq

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aececcf621

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/sandfs-cli/src/fs.rs Resolved
Comment thread crates/sandfs-cli/src/update.rs Resolved
Comment thread crates/sandfs-cli/src/fs.rs Resolved
…hard link

- A served workspace's new saved state takes over the old one's objects
  (Saved::take_over), so a file left open across an in-place update
  keeps reading its object after later saves.
- Another name of an inode an update takes off its name stays on it when
  the newer workspace still links them, and is looked up anew when it
  doesn't, so writes never go to a removed inode.
- A mounted update holds the shared source lock until the mount has
  recorded the new source, so sandfs clean can't delete a copy frozen
  for it in between.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01CboUL9BU7nvDEZKfQBSkkq
@lydakis
lydakis merged commit 4400f70 into main Oct 26, 2026
23 checks passed
@lydakis lydakis mentioned this pull request Oct 26, 2026
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.

2 participants