Every 15 s Sessions poll listed every Codex day folder and Claude Code
project again (~18k files in a few hundred folders on a real history),
and those getattrlistbulk calls were ~63% of the poll's CPU while
nothing had changed. dirent now keeps an FSEvents watch on the Codex
and Claude Code homes, and Stats of a folder under one gives its last
listing back unless the system said something in it changed since.
What makes the word trustworthy:
- FSEvents is a moment late, so each Watch (once per read) writes in a
new folder of its own under the watch and waits for that write to be
heard; events come in order, so every earlier change is heard by
then. An earlier write's late word can't end a later wait: each wait
has its own folder (an earlier version shared one, and the test went
red 4 of 30 at load 73 on mica).
- A write to a file held open is heard only when it closes, and Codex
holds its rollout open. So a folder with a file written in the last
15 min is listed every time, a change in a home's own folder
(history.jsonl, at each prompt) relists everything under it, and no
listing is trusted past 2 min.
- Dropped events, a moved root, a mount, a wait over 1 s, another
volume, or no Watch in the last 2 s: the folder is listed.
Linux and Windows have no watcher, so they list as before.
Run:
- mica: go test -count=30 of the dirent watch tests at load 73, green;
with the shared probe folder put back by hand, 4 of 30 red.
- mica: go test -count=1 -timeout 45m ./internal/dirent ./internal/sessions
./internal/gui, ok (sessions 253s, gui 159s), one change before the
per-wait probe folder; dirent and the real-account checks after it.
- go vet: darwin, GOOS=linux -tags nogui, GOOS=windows, CGO_ENABLED=0.
- mote, real Codex + Claude Code account (sandbox HOME copy), 40
unchanged /api/sessions polls: 3.54 s CPU sampled on the base
binary, 2.28 s with this; getattrlistbulk gone from the top.
What is left is GC and os.Stat in claudeFiles.
- Same account: an event with a new timestamp appended to the newest
rollout changes the sessions tag on the next poll, as on the base.
Not tried: Linux and Windows (no change there); a rollout held open by
a real running Codex for more than 15 min without a prompt.