Repository navigation
Description
What the code does
FileStorage::register_root returns the index of an existing root whenever the requested path equals a path already registered, without reopening the directory or comparing what it points to (file_storage.rs#L298-L338); the same check runs again inside the blocking task that would otherwise open the handle (file_storage.rs#L329-L331). The method's own comment says root indices are append-only (file_storage.rs#L298-L299), and registered handles are dropped only when the storage closes (file_storage.rs#L710-L718).
A registered handle is a read-only O_DIRECTORY descriptor opened by walking the path from / (file_storage.rs#L2016-L2035). Access under that root is an openat relative to this descriptor, not a walk from / again (file_storage.rs#L1985-L2004), and a caller that passes an absolute path is routed to the root whose registered path is its longest prefix (file_storage.rs#L390-L408).
When a root is registered and released
SettingsService::authorize_project registers a session's working directory as a root (settings.rs#L278-L306), and it runs both when a session is created and when a stored session is restored (agents.rs#L1505-L1517, agents.rs#L995-L1002). The storage is a process plugin that the server does not reload at runtime (lib.rs#L819-L825, lib.rs#L403), so a root registered by an earlier session stays in use until the process shuts down; closing a session, detaching a client or unloading an idle session does not release it.
The stale-handle case
When the directory at a registered path is removed while the server keeps running, the stored descriptor still refers to the removed directory. If a directory is created again at the same absolute path and a session is opened there, authorize_project reaches register_root with a path string equal to the registered one, so the call returns the old index and the new directory is never opened. Reads through that root are then openat calls against the removed directory, and project-level configuration reads treat a missing entry as no document (settings.rs#L541-L553, hooks_settings.rs#L210-L243).
Reproduction conditions
- A server process that outlives the deletion, since the handle is released only at shutdown.
- A working directory that is removed and later created again at the same absolute path.
- A session created or restored at that path after the recreation, so
authorize_projectruns again.
I did not reproduce this. This report comes from reading the code at the linked commit; no test and no running server were exercised, so no failure output is claimed and no behavior below was observed.
Inferred effects
- Project-level settings, hooks, workflow files and MCP project sources for a session at that path read as absent, because every read under the stale root fails as not found.
- Writes of project-level configuration under that root fail the same way, so a change made from that session is not persisted.
- File tools and shell commands are not affected in the same way, because they resolve the path themselves instead of going through the root index.
Suggested check, not a plan
Compare the registered descriptor with the directory the path resolves to now, using device and inode, and reopen the root when they differ. The same crate already validates a directory handle that way (file_access.rs#L291-L299) and already has a device and inode helper (file_access.rs#L773-L777). This issue records the behavior only.
Related
Issues #2016 and #2080 cover the FileStorage owner scan and its target contract; neither reports this behavior. No open issue or pull request describing this defect was found before filing.
Activity
fix(fs): register an authorized root by the directory its path names
fix(app-server): release a project's root when its Session closes or …
test(fs): pin a registered path whose directory is gone