fix(core): watch new config files and directories - #46925
Open
opencode-agent[bot] wants to merge 3 commits into
Open
fix(core): watch new config files and directories#46925opencode-agent[bot] wants to merge 3 commits into
opencode-agent[bot] wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Reported by nexxel; no separate issue.
Type of change
What does this PR do?
Creating a project's first
opencode.json(c)or.opencode/directory could require/restart. Files written after discovery but before a new native watch attached could also be missed.ConfigDiscovery.discoverreturns source paths;ConfigWatch.planis a pure grouped-watch planner. No mutable watch targets are hidden inside discovery..opencoderoots non-recursively through their parents. Keep recursive watches limited to existing config roots.FiberMapfor running watch consumers and teardown, including deleting/recreating config directories.There are no added runtime sleeps or startup-delay workarounds. The old 10/50 ms startup sleeps were removed from the config-creation tests. Existing precedence, global/project exclusions and
{file:...}refresh behavior remain intact.How did you verify your code works?
bun test test/config test/filesystem/watcher.test.ts test/instruction-discovery.test.ts test/session-activation.test.tsfrompackages/core: 178 passed.bun typecheck, Prettier andgit diff --check: passed. Scoped lint: no errors; existing warnings only.Benchmark
script/benchmark-config-watch.tssnapshots Config, discovery, watch planning and watcher sources. Compare--ref 02f8009b47(before readiness/refactor) with--ref working, frompackages/core.Linux, Bun 1.3.14; warm Config-only construction, not full app startup. Fixtures contain one root config and an empty
.opencode, with discovery clamped to the fixture root. Depth is below that root (two additional scanned directories). Retained heap includes one change observer per location. RSS is too noisy to interpret. Construction is one directional sample; reload is the median of three and includes the existing 100 ms debounce.Before → after this readiness refactor:
These fixtures performed two initial scans per location: the first load plus a readiness rescan. Startup CPU/call counts and memory include settling that work. At the 100-location/60-level extreme, process CPU through settling increased from 6.31 to 7.37 seconds. Native/kernel watch counts were unchanged (163 at that extreme), and every subscription was released after closure.
Normal one/few-location overhead remains small. Many deeply nested live locations, especially with churn inside
.opencode, remain the expensive case. Unrelated project-file bursts triggered zero discoveries. Config-root changes still rescan to preserve file substitutions; no dependency cache or filename-only reload filter was added.Existing native atomic-rename behavior, directory replacement entirely within the debounce window, and replay of missed Markdown/domain-file events are outside this JSON-config fix.
Screenshots / recordings
Not a UI change.
Checklist
Requested by: @nexxeln (nexxel via Slack)