Skip to content

fix(runtime): separate durable directory identity from mount identity - #6815

Merged
M4n5ter merged 3 commits into
rust-previewfrom
codex/stable-macos-directory-identity
Nov 12, 2026
Merged

M4n5ter merged 3 commits into
rust-previewfrom
codex/stable-macos-directory-identity

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Root admission, directory grants, workspace checkpoints, and directory-backed execution evidence use the same persistent directory identity. A device number is used only to compare handles within the current mount and is never part of the durable proof.

  • macOS reads the filesystem UUID from the opened directory. Windows uses the filesystem volume serial and file index it already obtains from handle metadata.
  • Linux uses UUID-derived filesystem IDs for ext and the lifetime UUID for tmpfs. Btrfs uses the metadata UUID and on-disk subvolume tree ID; its statfs ID can mix in the device number on a clone. XFS exposes its on-disk UUID through filesystem geometry because its statfs ID is a device number. Other Linux filesystems must expose a UUID through FS_IOC_GETFSUUID.
  • Workbench releases the pending-control notice for a recovered Stop and allows a new Stop of the same Run while retaining the original receipt.

Preview upgrade

The runtime accepts only Root marker schema 2. The previous runtime remount repair and legacy-grant matching paths are removed. Existing Roots must be migrated offline before starting this version. There is no SQLite schema change.

Download the one-time Python migration. Quit Maka and stop the Root's Host. Run python3 maka-migrate-directory-identity.py --root DIRECTORY to inspect the proposed changes, then add --apply. If the mount device already changed, verify the original directory and pass --confirm-remount ROOT_ID. The script takes the Root lease, verifies saved directory proofs, and makes backups before replacing them. It covers ordinary workspace bindings and their pending completion routes. Managed worktree bindings, missing directories, and other grants whose old proof cannot be verified require explicit re-establishment. Historical run and checkpoint records are preserved.

Verification

  • Migrated a legacy Root and workspace binding on a disposable APFS image after its device number changed. Remounted the same image again with a different device number and verified the same schema 2 Root opened. A second migration plan reported no changes.
  • Passed the focused macOS directory grant, Root lease, copied-marker rejection, and checkpoint restoration tests. Built and opened the schema 2 release desktop. Verified that a recovered Stop notice cleared and that its original receipt was retained in the client journal.
  • Cross-checked the identity implementation for x86_64-unknown-linux-gnu and aarch64-pc-windows-msvc. Native Linux and Windows CI are pending. The offline script has been exercised on macOS.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Codex implemented the changes and offline migration and ran the checks above.

Checklist

  • Tests cover the directory identity change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes
  • No

@M4n5ter M4n5ter changed the title fix(runtime): preserve macOS directory identity across remounts fix(runtime): separate durable directory identity from mount identity Nov 12, 2026
@M4n5ter
M4n5ter merged commit 51e2453 into rust-preview Nov 12, 2026
3 checks passed
@M4n5ter
M4n5ter deleted the codex/stable-macos-directory-identity branch November 12, 2026 02:25
@Astro-Han

Copy link
Copy Markdown
Contributor

@M4n5ter I hit the Root marker schema 2 bump and Folder unavailable on existing conversations after pulling rust-preview today, and read through this PR and the workspace identity checks. Before rust-preview replaces main, I want to check whether persistent DirectoryIdentity and .maka-workspace.json are still earning their keep for workspaces.

Since #6632 switched workspace selection to paths, the Host already resolves a canonical path inside workspace_roots, and cap-std handles plus sandbox rules keep operations inside the opened directory. Any local process that can replace the workspace root directory or remount its parent already runs as the same OS user. Meanwhile, persisting (volume, ino, birth) and .maka-workspace.json has a few real costs:

  • Common Linux setups without FS_IOC_GETFSUUID (WSL /mnt/c on 9p/drvfs, container overlayfs, VM virtiofs, ZFS, NFS) cannot open a folder at all (platform/sandbox/src/workspace/directory/linux.rs).
  • Deleting a repo and cloning it back to the same path changes its inode, which permanently breaks existing conversations bound to that path with agent_workspace_unavailable.
  • Every workspace operation currently checks three overlapping things (path under workspace_roots, DirectoryIdentity, and .maka-workspace.json), and non-Git folders get an unignored .maka-workspace.json marker file.

Would it make sense to persist only the canonical workspace path, keep cap-std::fs::Dir and in-memory (dev, ino) checks for single-operation races, and let the existing flock lease guard the State Root? Happy to put up a PR if you agree with that direction, or hear what threat boundary I might be missing.

中文版

@M4n5ter 今天拉了最新的 rust-preview 后遇到了 Root marker schema 2 升级和已有会话报“文件夹不可用”的问题,顺着把本 PR 和工作区身份校验读了一遍。趁 rust-preview 替换 main 之前,想和你对齐一下:工作区是否还有必要保留跨重启持久化的 DirectoryIdentity 和 .maka-workspace.json?

#6632 改成按路径选择工作区后,Host 已经在 workspace_roots 范围内解析规范化路径,打开目录后的子路径访问也由 cap-std 句柄和沙箱规则限制在目录内。能在本地把整个工作区根目录替换掉或重挂父目录的进程,本来就已经跑在同一个系统用户权限下了。同时,把 (volume, ino, birth) 和 .maka-workspace.json 持久化下来有几处实际代价:

  • 不支持 FS_IOC_GETFSUUID 的常见 Linux 环境(WSL /mnt/c 的 9p/drvfs、容器 overlayfs、虚拟机 virtiofs、ZFS、NFS)会直接打不开目录(platform/sandbox/src/workspace/directory/linux.rs)。
  • 用户删掉仓库重新 clone 回同一路径后 inode 会变,绑定在该路径上的已有对话会因为 agent_workspace_unavailable 永久失效。
  • 现在每次工作区操作都要重复验三层(workspace_roots 下的 path、DirectoryIdentity、.maka-workspace.json),非 Git 目录还会留下一个没法被忽略的 .maka-workspace.json 标记文件。

是不是可以工作区只持久化规范化后的 path,单次操作防并发竞态保留 cap-std::fs::Dir 和内存里的 (dev, ino) 检查,State Root 互斥继续交给现有的 flock 租约?如果你同意这个方向我可以提个 PR 收掉,或者看看有没有我漏掉的威胁边界。

@M4n5ter

M4n5ter commented Nov 13, 2026

Copy link
Copy Markdown
Member Author
English

I agree with this direction. I explicitly asked to retain Host-persisted directory_identity in #6632, but that premise deserves revisiting given the costs you’ve identified.

We’re comfortable making a clean architectural cut here. If a concept can be removed while the supported workflows and meaningful safety guarantees continue to work, it should be removed. Existing consumers alone don’t justify keeping it.

For ordinary workspaces, let’s use the canonical path as the persisted location and remove the persistent filesystem identity and .maka-workspace.json marker. Re-cloning a repository at the same path should not permanently strand its conversations. Keep containment checks, private-state exclusions, captured directory handles, and the live checks needed to prevent operations from switching targets during execution.

Please follow the removal through its consumers, including workspace grouping, authorization, managed worktrees, and recovery. Simplify or delete the assumptions that depend on the old model, and reuse the existing Host binding and permission mechanisms where needed. We don’t need compatibility wrappers for the internal formats; a one-time migration is fine.

The same reasoning applies to State Root: retain the lease for exclusive ownership, and assess any additional persistent identity against a concrete correctness requirement. Recovery must not silently redirect an already admitted operation to a replacement directory. If that requires a durable proof in a particular workflow, scope it to that workflow rather than making every workspace depend on a universal persistent directory identity.

Please go ahead with the PR along these lines. We’re happy to remove the abstraction and its supporting machinery completely wherever they no longer serve a concrete requirement.

简体中文

我同意这个方向。#6632 里是我明确要求保留 Host 持久化的 directory_identity,但结合你指出的这些实际成本,这个前提值得重新审视。

这里可以做一次彻底的架构删减。如果一个概念删掉以后,受支持的工作流和真正需要的安全保证仍然成立,那它就应该被删除。现有代码里有消费者,本身不足以证明这个概念应该继续存在。

对于普通工作区,我们就用规范化后的路径作为持久化位置,移除持久化的文件系统身份和 .maka-workspace.json 标记。同一路径重新 clone 仓库,不应该让原有会话永久失效。保留路径范围校验、私有状态目录排除、已捕获的目录句柄,以及防止操作在执行过程中切换目标所需的实时检查。

请把删除贯彻到相关消费者,包括工作区分组、授权、托管 worktree 和恢复逻辑。依赖旧模型的假设,该简化就简化,该删除就删除;需要时复用现有的 Host binding 和权限机制。内部存储格式不需要保留兼容 wrapper,一次性迁移即可。

State Root 也按同样的原则判断:保留用于独占所有权的 lease,额外的持久化身份则必须有具体的正确性需求支撑。恢复过程不能把已经接纳的操作静默转向同名的新目录。如果某个工作流确实需要持久化证明,就把证明限定在那个工作流里,不必让所有工作区都依赖一套通用的持久目录身份。

可以按这个方向提 PR。只要没有具体需求支撑,我们接受把这层抽象连同它的配套机制一起彻底删除。

@M4n5ter

M4n5ter commented Nov 13, 2026

Copy link
Copy Markdown
Member Author
English

Following up on my earlier reply, here is a concrete deletion plan after tracing the current workspace, authorization, worktree and State Root consumers.

The proposed end state is: Host records own logical identity; paths locate directories; filesystem-object observations serve the lifetime of the operations that need them. We should remove the general assumption that every workspace and State Root needs a permanent physical directory identity.

  1. Delete the workspace marker and its supporting machinery. Remove WorkspaceIdentity, .maka-workspace.json, marker preparation/read/validation/publication, temporary-file and hard-link publication, and the repository-local info/exclude writer. Remove the associated sandbox rule, file-browser/watch exclusions, checkpoint exemptions, clean-worktree exceptions and tracked-marker rejection. Keep the Git metadata resolution that sandbox policy actually uses. Selecting a folder should become a read-only operation.

  2. Make ordinary workspace bindings path-based. Remove Workspace.identity and Workspace.directory_identity; retain path, optional project membership and managed-worktree binding. Reuse existing BindingRef, BindingStamp and permission/metadata epochs without introducing another workspace UUID. Group workspace conversations by canonical path within the owning namespace, and project conversations by project ID; binding ID is not automatically the right grouping key for every consumer. Update skills, MCP, files, processes, browser uploads and other consumers together. Resolve and authorize a path, open it, and pass that actual directory handle into the operation. Re-cloning at the same path should leave existing conversations usable for new operations.

  3. Remove State Root's persistent physical binding and redundant format markers. Delete root_identity, the fixed kind=interactive field and .maka-rust-runtime.json; retain one versioned Root marker containing rootId. Keep the existing exclusive lease outside disposable cache state, lock-file stability checks, live Root/control-directory checks, and hostEpoch fencing. Treat a complete offline Root relocation or backup restore as the same logical Root, with stored locators updated through migration. Copies retaining the same rootId contend for the same account-local lease; an independent new Root is initialized with a new ID. This deliberately replaces the current blanket copied-marker rejection contract.

  4. Remove the source inode's lifetime coupling from published worktrees. Drop source_identity from the long-lived worktree binding and keep any necessary original source observation with the pending allocation. Published worktrees should be checked through allocation ownership, Git admin/common-directory relationships, base refs and retirement state. Keep the allocation owner documents, allocation lock and retirement tombstone: they still prevent foreign adoption, conflicting mutations and stale-binding resurrection. A source inode change alone should no longer invalidate an owned checkout; broken Git relationships must still fail explicitly. Migrate the allocation record and both owner documents together.

  5. Scope physical proofs to actual recovery needs. Existing admitted operations recover through their original receipts and contracts; resolving today's path must not become a way to replay an old effect against a replacement directory. Checkpoint restore currently persists parent/destination proofs across a crash, and captured directory facts also participate in provider execution_basis. Audit those consumers explicitly. Do not collapse provider equivalence to path equality or remove its captured facts indiscriminately. File-list cursors need only a short-lived directory observation. We cannot yet count the entire filesystem-UUID/Btrfs/XFS backend as removable: its remaining recovery consumers must first be discharged. Moving or renaming that abstraction alone would not be a simplification.

  6. Use one offline migration, with no dual-format runtime readers. Cover workspace bindings, persisted authorization/scheduler targets, pending completion routes, Root metadata and worktree owner documents. Preserve binding IDs, permission histories and original receipts; do not automatically merge distinct authority histories at the same path or regenerate historical proofs from the current filesystem. Clean up recorded legacy markers through migration rather than adding runtime repair or repository-scanning cleanup.

Suggested sequence: close out the marker and path-binding consumers first, then simplify State Root, then remove the long-lived worktree source fingerprint. Each change should preserve the original operation/recovery boundary.

Focused acceptance should cover same-path re-clone with existing conversations; folder selection without filesystem writes; directory replacement during an admitted operation; Root relocation plus competing-Host lease rejection; checkpoint crash recovery and original-receipt lookup; and worktree retirement without recreation. Reuse existing behavior tests and remove tests dedicated to deleted mechanisms.

简体中文

接着上面的回复,沿着当前 workspace、授权、worktree 和 State Root 的消费者核对了一遍,可以把删除方案具体化为下面这些改动。

目标模型是:逻辑身份由 Host 记录持有,路径负责定位目录,文件系统对象观察只服务于需要它的操作生命周期。 删除“所有工作区和 State Root 都必须拥有永久物理目录身份”这个通用前提。

  1. 删除 workspace marker 及整套配套机制。 移除 WorkspaceIdentity、.maka-workspace.json、marker 的准备/读取/校验/发布、临时文件和 hard-link 发布,以及 Git info/exclude 的写入逻辑。同步删除 sandbox 特殊规则、文件浏览/watch 排除、checkpoint 豁免、clean-worktree 特殊放行和 tracked-marker 拒绝分支。保留 sandbox 确实使用的 Git metadata 解析。选择文件夹应当变回只读操作。

  2. 普通 workspace binding 改为路径语义。 删除 Workspace.identity 和 Workspace.directory_identity,保留 path、可选 project 归属和托管 worktree binding。复用已有的 BindingRef、BindingStamp 和权限/metadata epoch,不再引入另一份 workspace UUID。workspace 会话按 owner namespace 内的 canonical path 分组,project 会话按 project ID 分组;不能把所有分组键机械替换成 binding ID。skills、MCP、文件、进程、浏览器上传等消费者一起更新。解析并授权路径后打开目录,把这个实际句柄交给操作。同路径重新 clone 后,已有会话仍能发起新操作。

  3. 删除 State Root 的持久物理绑定和重复格式标记。 移除 root_identity、固定的 kind=interactive 字段和 .maka-rust-runtime.json,保留一份包含 rootId 的版本化 Root marker。继续保留缓存目录之外的独占 lease、锁文件稳定性检查、live Root/control-directory 检查和 hostEpoch 隔离。完整的离线 Root 迁移或备份恢复视为同一个逻辑 Root,保存的位置由迁移同步更新。保留同一 rootId 的副本竞争同一账号下的 lease;独立的新 Root 通过初始化获得新 ID。这会有意识地替换当前“一律拒绝复制 marker”的契约。

  4. 解除已发布 worktree 对原 source inode 的终身依赖。 从长期 worktree binding 删除 source_identity,尚未完成的 allocation 如果需要原始 source 观察,就把它留在该次分配记录中。已发布 worktree 通过 allocation 所有权、Git admin/common-directory 关系、base ref 和退休状态核对。保留 allocation owner 文档、allocation lock 和 retirement tombstone,它们仍然防止接管他人的分配、并发冲突和旧 binding 复活。source inode 变化不再单独判死已拥有的 checkout;真实 Git 关系损坏仍显式失败。allocation 记录和两处 owner 文档需要一起迁移。

  5. 把物理证明限定到真实的恢复需求。 已接纳的操作按原回执和原恢复契约处理,不能通过重新解析当前路径,把旧 effect 重放到替换后的目录。checkpoint restore 目前确实跨崩溃持久化父目录/目标目录证明,已捕获的目录事实也参与 provider 的 execution_basis,这些消费者需要单独闭合。不能把 provider 等价性退化为路径字符串相等,也不能无差别抹掉捕获事实。文件列表 cursor 只需要短期目录观察。目前不能把整个文件系统 UUID/Btrfs/XFS 后端算进“确定可删”的收益:要先消除它剩余的恢复消费者。单纯搬模块或改名不算简化。

  6. 一次离线迁移,不保留双格式运行时 reader。 覆盖 workspace binding、持久化授权/调度目标、待完成路由、Root metadata 和 worktree owner 文档。保留 binding ID、权限历史和原始回执;不自动合并同路径下不同的授权历史,也不拿当前文件系统重新生成历史证明。已记录的旧 marker 交给迁移清理,不再添加运行时修复或扫描仓库的清理机制。

建议顺序是先闭合 marker 和路径绑定的消费者,再简化 State Root,最后移除 worktree 的长期 source fingerprint。每刀都保住原 operation/recovery 边界。

定向验收覆盖:同路径重新 clone 后旧会话可用;选择目录不写文件;已接纳操作期间替换目录不会切换目标;Root 迁移后可打开且第二个 Host 仍被 lease 拒绝;checkpoint 崩溃恢复和原回执查询正确;退休 worktree 不会被旧 binding 重建。复用现有行为测试,删除只保护废弃机制的测试。


Prepared with Maka (OpenAI Codex), based on a read-only source audit at c142a04c48340b746c0bea2eb06911e577e19b03. This is an implementation proposal; no code changes or new runtime validation were performed for this follow-up.

本方案由 Maka(OpenAI Codex)辅助整理,依据上述提交的只读源码审计;本次补充未修改代码,也未新增运行时验证。

@M4n5ter

M4n5ter commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

@Astro-Han

M4n5ter pushed a commit that referenced this pull request Nov 15, 2026
…-up (#6910)

Preserve workspace directory grants when Linux overlayfs copies a lower-layer directory to the writable upper layer so creating `.maka-workspace.json` does not invalidate the grant used by ACP `session/new` and subsequent tools.

- Omit `birth` from `DirectoryIdentity` only on `OVERLAYFS_SUPER_MAGIC`, where directory copy-up updates birth time while preserving the origin directory inode.
- Keep overlayfs on the `FS_IOC_GETFSUUID` path rather than `f_fsid` so mounts with `uuid=on`/`uuid=auto` bind to their persistent overlay instance UUID and `uuid=off`/`uuid=null` mounts (which expose the shared backing filesystem `f_fsid`) fail closed with `Unsupported`.

Refs #6667 and #6815.

Generated-by: Google Antigravity
Generated-by: OpenAI Codex
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