feat: use FSEvents for the UI live publisher on macOS

Open
#233 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
go, macos
Domain
tooling

Research direction

Start with armWatches in internal/uiserver/livepublish.go (around line 495) and newLivePublisher (around line 562), where the fsnotify watcher is created, then compare with the FSEvents backend in internal/watch/watcher_darwin.go. The main open question is the mapping from FSEvents flags to re-arm decisions, which the issue leaves undefined, so settle the design before coding. Done means the macOS publisher holds a fixed descriptor count regardless of files in .codegraph/store, and re-arming on Create, Remove and Rename still works.

Written by the indexing model from the issue text.

Description

area:ui enhancement priority:low
What exists today?

The UI live publisher in internal/uiserver/livepublish.go watches the store with fsnotify. newLivePublisher (line 562) creates the watcher at line 568. armWatches (line 495) adds the watches on the deepest existing path of the chain [repoRoot, .codegraph, .codegraph/store] and on its parent. In a normal index, those paths are .codegraph/store and .codegraph.

How does it behave now?

On macOS, fsnotify uses kqueue. kqueue holds one file descriptor for every file in each watched directory. Each codegraph ui process therefore holds one descriptor per file in .codegraph/store and one per file in .codegraph. On 2026-10-31, this repository's index had 10 store files, and a larger index had about 95 store files.

The publisher needs only the signal that the store changed. It re-runs its change detector on any event, so the per-file watches add cost without adding information.

PR #229 moved the indexing watcher in internal/watch to FSEvents on macOS. The live publisher does not use that backend. Related: #227 (closed, the FSEvents change for the indexing watcher).

How should it behave?

On macOS, the live publisher must hold a fixed number of descriptors, independent of the file count in .codegraph/store. One non-recursive FSEvents stream on .codegraph meets that requirement.

The arming state machine in armWatches must keep working. It re-arms on Create, Remove and Rename, so a store replaced by rename is still seen. FSEvents watches by path and survives a replaced directory, but the mapping from FSEvents flags to re-arm decisions is not defined yet.

Two options are open. The first option reuses the darwin backend in internal/watch/watcher_darwin.go. That backend runs one recursive stream over the repo root, so it needs a non-recursive or filtered variant for .codegraph. The second option adds a small FSEvents stream in internal/uiserver, behind the same build tag as the watch backend.

What kind of improvement?

Performance

Would this change existing behavior?

No. The UI output does not change. The publisher still reacts to store changes and runs the same change detector.

Before submitting
  • I searched existing issues and this is not a duplicate
  • I checked that the current behavior is not a deliberate decision in openspec/specs/
Dominant language
Go
Stars
0
Forks
0
Avg merge
5h 16m
Merged PRs (30d)
107

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from seanb4t/codegraph-go

All issues in seanb4t/codegraph-go

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.