fix(skill): pre-scan circular/broken symlinks to prevent ENAMETOOLONG crash#27639
Open
litown wants to merge 2 commits into
Open
fix(skill): pre-scan circular/broken symlinks to prevent ENAMETOOLONG crash#27639litown wants to merge 2 commits into
litown wants to merge 2 commits into
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Found a potentially related PR: PR #18670: fix(opencode): avoid symlink-loop recursion during skill discovery This PR appears to address a similar issue - preventing symlink loops/recursion during skill discovery. While it's a historical PR, it's worth reviewing to ensure the current fix (PR #27639) doesn't duplicate or conflict with the approach taken there. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
6 tasks
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
Fixes #27638
Type of change
What does this PR do?
On Bun runtime, opencode crashes with
ENAMETOOLONGduring skill scanning when external skill directories (~/.claude/skills/,~/.agents/skills/) contain circular or broken symlinks. Thegloblibrary withfollow: trueenters infinite recursion on circular symlinks, and Bun'sreaddirthrowsENAMETOOLONGwhen path strings exceedPATH_MAX. Node.js handles this gracefully, but Bun does not.This PR adds a pre-scan step (
findBrokenSymlinks) that recursively detects circular symlinks (viareadlink+ path resolution +realpathvisited set) and broken symlinks (viastatENOENT/ELOOP), then passes detected paths as globignorepatterns. Asubdirsoption limits the pre-scan to only directories glob would traverse (e.g., onlyskills/under~/.claude/), reducing pre-scan time from ~1.3s to ~19ms.Related work: PR #18670 addresses the same root cause with a more fundamental approach (replacing glob with a custom cycle-safe walker). However, #18670 targets an older codebase (pre-Effect-TS, zod-based) and likely needs significant rework to merge. This PR is adapted to the current Effect-TS codebase and provides an immediate fix.
Changes:
packages/core/src/util/glob.ts: Exposeignoreoption inGlob.Optionspackages/opencode/src/skill/index.ts: AddfindBrokenSymlinks()with recursive symlink detection,SCAN_IGNORE_PATTERNSfor standard deep directories, and pass results as glob ignore in all scan call sitesHow did you verify your code works?
~/.claude/skills/with 5 broken symlinks and 3 circular symlinkssubdirsfilter: 19ms (vs 1283ms without filter)tsc --noEmit)Screenshots / recordings
N/A
Checklist
🤖 Generated with Claude Code