Skip to content

fix(core): reload symlinked config targets - #53932

Closed
ykai55 wants to merge 4 commits into
anomalyco:devfrom
ykai55:symlink-config-reload
Closed

ykai55 wants to merge 4 commits into
anomalyco:devfrom
ykai55:symlink-config-reload

Conversation

@ykai55

@ykai55 ykai55 commented Oct 8, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #53920

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Config watches cover the directory containing a symlink, but miss edits to its target outside that directory. Resolve file symlink targets when building the watch plan and include them in the existing parent-entry watches. Keep the original paths watched so retargeting the link reconciles the target watch, and retain the original document paths for relative config references.

Reading the link before resolving its target also keeps a watch when the target file is temporarily absent, allowing deletion/recreation and atomic saves to reload.

How did you verify your code works?

  • One real-watcher regression test checks two successive in-place edits to a symlinked global config, with no settle sleep. Removing target watches makes this test time out.
  • Watch-plan unit tests cover global, direct project, .opencode, and explicit config symlinks, including dangling targets and retargeting, without starting filesystem watchers.
  • bun test test/config/config.test.ts test/config/watch.test.ts test/filesystem/watcher.test.ts from packages/core: 63 passed.
  • bun run check from the repository root: passed, including all 36 typecheck tasks.
  • Tested on macOS arm64 with Bun 1.4.2.

Screenshots / recordings

Not applicable (filesystem/config change).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #54933, #55119

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced #53920 on the base: with ~/.config/opencode/opencode.json symlinked to a dotfiles file and serve running, edits to the target after the first one were ignored (1111/1111/1111). With this PR each edit is picked up (1111/2222/3333). The new test times out on the base and passes here. The core and watch tests pass and packages/core type-checks.

The approach looks right. The watch plan resolves each config symlink's target and adds a watch on the target's parent directory, alongside the existing directory watches. If the target is missing it is still watched, because resolve falls back to the plain path when the file isn't found. Retargeting the link triggers a reload, which rebuilds the plan with the new target.

My one request is about the new integration test (see inline comment): it is large and timing-sensitive for what it checks.

@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:37
@ykai55

ykai55 commented Oct 22, 2026

Copy link
Copy Markdown
Author

Merged the latest dev into this branch and resolved the config-watch conflicts in 409d654. The watch plan preserves system configuration discovery and shared ignore rules, with symlink target coverage extended to system configs.

Validated with Bun 1.4.4: the 57 config/watch tests pass across 10 repetitions (570 passes), and bun run check passes. The branch is conflict-free and ready for another review.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier test feedback is addressed. The live-watcher coverage is now one short test of two edits to a symlinked global config's target, and the other sources, dangling targets and retargeting are covered by watch-plan unit tests that start no watchers.

I re-ran the #53920 steps against serve from source. On the base, edits to the symlink target after the first were ignored (1111/1111/1111). With this PR each edit is picked up (1111/2222/3333). The new live test fails on the base and passes here. The config and watcher tests pass (72) and packages/core type-checks.

The public API is unchanged.

One small test-isolation point is inline: the new live test doesn't turn off system config discovery, which the neighbouring tests now do.

  • packages/core/test/config/config.test.ts:633: The neighbouring tests now add Config.node.replace(Config.configured({ system: false })) so they don't read a real /etc/opencode (or /Library/Application Support/opencode) on the machine running them. System config has the highest priority, so a shell value there would break this test's assertions. Could you add the same replacement here?

@ykai55

ykai55 commented Nov 4, 2026

Copy link
Copy Markdown
Author

Addressed the test-isolation feedback in fd56dd0. The symlink reload integration test now provides Config.node.replace(Config.configured({ system: false })), matching the neighbouring tests and preventing machine-level system configuration from affecting its assertions.

Validated with Bun 1.4.4: all 57 config/watch tests pass across 10 repetitions (570 passes), and bun run check passes. Ready for re-review.

@0xViva

0xViva commented Nov 7, 2026

Copy link
Copy Markdown

Verified on Linux.

Platform: Arch Linux, kernel 7.2.14, Bun 1.4.4.

cd packages/core
bun test test/config/config.test.ts test/config/watch.test.ts test/filesystem/watcher.test.ts
# 73 pass, 0 fail, 242 expect() calls

The real-watcher test reloads successive edits to a symlinked global config target passes. As a control, I removed the ...linked.filter(...) line from ConfigWatch.plan and ran only that test:

bun test test/config/config.test.ts -t "symlinked global config target"
# 1 fail after the 3s timeout

The test fails without the target watch on Linux, not only on macOS. The dangling-target cases also pass:

bun test test/config/watch.test.ts -t "watches the target"
# 5 pass, 0 fail

This matches a live failure on v2.2.5. A global opencode.json symlinked into a dotfiles repo did not reload after I edited its target. /api/config kept the old document and /api/model/default returned a free fallback model, so new sessions ignored the configured model. Touching an entry inside ~/.config/opencode triggered a reload and both calls returned the configured model. I can retest against a build of this branch if that helps.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: edits to symlinked global config target do not trigger hot reload

2 participants