Skip to content

fix(core): watch the target of a symlinked AGENTS.md - #63754

Open
rafaetri wants to merge 1 commit into
anomalyco:devfrom
rafaetri:symlinked-agents-watch
Open

rafaetri wants to merge 1 commit into
anomalyco:devfrom
rafaetri:symlinked-agents-watch

Conversation

@rafaetri

@rafaetri rafaetri commented Nov 13, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #51936

Type of change

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

What does this PR do?

When the project AGENTS.md is a symlink, OpenCode watches the link path but reads the file it points to. Editing that file never triggers a rescan, so new sessions keep the old instructions until restart.

The fix also watches each resolved target that is not already watched as a candidate path. A target stays watched once seen, so one that is deleted and recreated is still picked up.

How did you verify your code works?

  • New test in instruction-discovery.test.ts: edits the symlink target, deletes and recreates it, then repoints the link and edits the new target. It fails on dev and passes with the fix.
  • A throwaway test with the real file watcher instead of the test one: on dev the edit is never picked up; with the fix the edit, delete and recreate all are.
  • bun run test and bun run typecheck:tsc in packages/core.

Screenshots / recordings

Not a UI 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

@opencodejr opencodejr 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 fix works. I ran the #51936 reproduction with OpenCode built from source: after editing the target of a symlinked AGENTS.md, a new session on the base still got the old instructions, and with this pull request it gets the new ones. The new test fails on the base and passes here, the instruction-discovery tests pass, and typecheck:tsc is clean.

Public API: unchanged.

No blocking concerns. Targets are never unwatched after a link is repointed, but that only costs an occasional extra rescan, and the number of watches is limited to the targets actually seen.

Related: #54933

Before

After

Project AGENTS.md files were watched at their link path but read through the resolved path, so editing the target of a symlinked AGENTS.md never refreshed the instructions. Also watch each resolved target that is not a candidate path. A target stays watched once seen, so one that is deleted and recreated is still picked up.
@rafaetri
rafaetri force-pushed the symlinked-agents-watch branch from f30ba5a to 722e0bc Compare December 1, 2026 09:24

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: new sessions reuse stale AGENTS.md from the per-location instruction cache

1 participant