aft icon indicating copy to clipboard operation
aft copied to clipboard

A project root at `/tmp` gets a recursive watch when `/tmp` is a bind mount, but AFT classes the home folder as too broad

Open iceteaSA opened this issue 3 weeks ago • 4 comments

Version: v0.64.0, Linux, subc mode. Standalone mode uses the same rule.

Summary

/tmp can be a bind mount of a subdirectory of a larger filesystem. Then a session with the working folder /tmp gets the full root treatment. AFT starts three tasks: a recursive file watch on all of /tmp, a data-layer index build and the language-server applicability walk. AFT classes the home folder and its ancestors as root_too_broad. They get none of these tasks. /tmp holds the files of other programs and services, frequently millions of entries. Thus it is as broad as the home folder, or broader.

Setup

  • /tmp is a bind mount of the subdirectory /tmp of a large ext4 filesystem. findmnt /tmp shows /dev/<disk>[/tmp] ext4. Some hosts do this to put /tmp on a large disk.
  • An OpenCode session starts with the working folder /tmp.

What occurs

  1. project root set: /tmp. No root_too_broad warning.
  2. The recursive watcher starts on /tmp. Its exclusion planning walks the tree for approximately 4 minutes. Then it stops with watcher exclusion plan unavailable: root=/tmp generation=1 reason=io_deadline. During those minutes one maintenance worker is busy: the oldest queued maintenance task waited 181 s in the perf tick lines. The walk reads a large quantity of ext4 directory and inode blocks. On our host, the block-device cache increased by approximately 7 GiB in those minutes. The page cache decreased by the same quantity.
  3. The data-layer build stops with cannot walk /tmp/systemd-private-<id>-<service>.service-<id>: Permission denied (os error 13) and retries with a backoff to 300 s. Health stays Degraded: 1 root(s) could not build or refresh their index store: /tmp (build_failed).
  4. After an idle stop, ensure_project_watcher installs the watcher again at the first request. Thus the walk can occur again while the session lives.

Cause (v0.64.0 source)

  • path_identity.rs:114-125 project_root_is_narrow: a narrow root is absolute and has a parent. It is not an ancestor of the home folder, and it is not its volume.
  • path_identity.rs:154-185 project_root_volume_with (the repair for #670): for a root that is the mount point of a subdirectory, AFT uses the volume of its parent. For a bind-mounted /tmp that volume is /, so /tmp counts as an ordinary first-level folder of / and is narrow.
  • directory_is_system_tree (/var, /usr, /etc and others) applies only to permission scopes (directory_scope_is_narrow), not to project roots. /tmp is in no list.
  • When /tmp is a tmpfs or the root of its own filesystem, the root equals its volume and is too broad. Thus the result changes with the mount layout.

Correct behavior

A project root at a shared temporary tree (/tmp, /var/tmp and the platform temporary folder) is too broad, as the home folder is, with all mount layouts. A subdirectory such as /tmp/my-scratch-project stays a usual root.

Possible changes

  • Add the shared temporary roots themselves to the too-broad cases in project_root_is_too_broad.
  • Or apply a system-tree list to project roots too, with the temporary roots in it.
  • Optional: a user setting that lists more too-broad roots, so an operator can add a host-specific folder without a release.

Related

#670 (the bind-mount repair that makes this case narrow), #1007 (the trigram walk of a large scratch folder in /tmp).

iceteaSA avatar Nov 11 '26 12:11 iceteaSA

Thanks, the diagnosis is right. For a root that is itself a mount point of a subdirectory, AFT judges it by its parent's volume (the #670 repair), so a bind-mounted /tmp counts as an ordinary folder under / and gets the watcher, the index build and the language-server walk, while a tmpfs /tmp is already too broad. The result shouldn't depend on the mount layout.

The fix we plan: the shared temporary folders themselves (/tmp, /var/tmp, their /private forms on macOS, and the platform temporary folder) are too broad on every layout, like the home folder. A project in a subfolder such as /tmp/my-scratch-project stays an ordinary root. We don't plan a setting for extra too-broad roots for now.

Your report also shows a second problem we'll fix with it: one unreadable folder (/tmp/systemd-private-…, permission denied) fails the whole index build and leaves health degraded. A build should skip a folder it can't read and name it as a gap.

aft-alfonso[bot] avatar Nov 11 '26 12:11 aft-alfonso[bot]

This occurred again on v0.64.0 (Linux, /tmp is an ext4 bind mount). Two facts are new.

1. An AFT tool call is not necessary for the problem. A session connected with /tmp as its host location. On the route attach, AFT set /tmp as a project root. Other sessions in that location attached to the same root during the next hour.

2. After a data-layer build failure, AFT walks /tmp again and again. The build stopped at a directory that the user cannot read (/tmp/systemd-private-*: Permission denied). AFT tried again after 5, 10, 20, 40 and 80 s, and then at 300 s intervals for approximately 55 minutes, until the sessions ended. Each try is a new walk of /tmp.

Sequence and cost:

  • The recursive watcher walked /tmp until the watcher exclusion plan stopped at io_deadline after approximately 4.5 minutes. Then the watcher stopped.
  • In those 4.5 minutes, the memory of the cgroup that contains the module increased by approximately 19 GiB, to a peak of approximately 35 GiB. The host had approximately 30,000 allocation stalls and wrote approximately 3 GiB to the swap device.
  • At the peak, the processes of the module used only approximately 4.4 GiB. The remainder was kernel memory (directory and inode caches, inotify marks). Thus a limit on process memory does not see it.

Workaround that I measured (10,000 files in 1,000 directories as the root, one directory that the user cannot read):

Root ignore file inotify marks Data-layer build getdents64 calls (22 s run; 8 s for /*)
none 1,003 failure, then a new try 15,156
.aftignore with /* 1 (no watcher) 0 files, no failure 2,249
.aftignore with * 1 (no watcher) 0 files, no failure 2,263
.ignore with * 1,003 failure, then a new try 6,255

With /*, a child root such as /tmp/<dir> continues to index its files. With *, a child root indexes 0 files. One directory walk when AFT sets the root stays.

Request:

  1. Classify /tmp and the temporary directory as too broad, also when they are a bind mount.
  2. Do not walk the full root again after a build failure that has a permanent cause. An alternative is a limit on the number of tries.

See also #1442: the plugin event hook can set the root of each open location, /tmp included, for a session of a different location.

iceteaSA avatar Nov 13 '26 09:11 iceteaSA

Thanks for measuring this. Both requests are already fixed on main and ship with the next release.

  1. /tmp, /var/tmp, their macOS /private forms and the platform temporary folder now count as too broad on every mount layout, bind mounts included, so a session located there gets no watcher, index build or language-server walk. A project in a subfolder such as /tmp/my-project stays an ordinary root.
  2. An unreadable folder no longer fails the index build. The build skips it, finishes, and names it as a gap in replies and in health, so there is no failure to retry.

Until the release, your .aftignore with /* at the /tmp root is a good workaround.

aft-alfonso[bot] avatar Nov 13 '26 09:11 aft-alfonso[bot]

Fixed in v0.65.0, released today: Shared temporary folders such as /tmp are never watched or indexed as projects, on any mount layout, and unreadable folders are reported as index gaps. Thanks for the report. If you still see it after updating, reply here and we'll reopen.

aft-alfonso[bot] avatar Nov 14 '26 10:11 aft-alfonso[bot]