fix(core): break filesystem/search import cycle - #48877
Open
benrfairless wants to merge 1 commit into
Open
benrfairless wants to merge 1 commit into
benrfairless wants to merge 1 commit into
Conversation
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Found potentially related PRs:
These PRs may be addressing the same or overlapping issues around the filesystem import cycle and undefined dependencies that occur with certain bundler configurations (Bun 1.4.2). |
filesystem.ts and filesystem/search.ts import each other, and filesystem.ts dereferences the other module at evaluation time in a top-level deps array. search.ts never needs it that early: its only runtime uses are FileSystem.Entry.make and FileSystem.Match.make, and its three remaining uses are type positions. Entry and Match already live in @opencode-ai/schema/filesystem, which filesystem.ts imports them from and re-exports. Import them from there directly, and make the remaining FileSystem import type-only so it is erased. That removes the runtime edge back to filesystem.ts, so the cycle is gone and module evaluation order no longer matters. With the cycle present, a bundler that emits search.ts after filesystem.ts leaves FileSystemSearch.node undefined in that deps array, and the layer graph then fails on first use with "TypeError: undefined is not an object (evaluating 'a.name')". Bun 1.4.2 does exactly that, reported as oven-sh/bun#42664. Closes anomalyco#48876 Assisted-by: Claude Code:claude-opus-5
benrfairless
force-pushed
the
fix/filesystem-search-import-cycle
branch
from
September 14, 2026 00:09
a0cfbf2 to
7f392ba
Compare
attilaolah
added a commit
to attilaolah/os
that referenced
this pull request
Sep 14, 2026
Adds a fetchpatch to pull anomalyco/opencode#48877.
attilaolah
added a commit
to attilaolah/os
that referenced
this pull request
Sep 15, 2026
* Update dependency anomalyco/opencode to v1.18.30 * chore(opencode): update flake lock * fix: patch model-router for opencode 1.18.29+ support * fix: opencode npm deps hash * fix: patch opencode, remove model-router patch Adds a fetchpatch to pull anomalyco/opencode#48877. * fix: patch hash * fix: make hashes platform dependent --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Attila Oláh <attila@dorn.haus>
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
Closes #48876
Type of change
What does this PR do?
core/src/filesystem.tsandcore/src/filesystem/search.tsimport each other, andfilesystem.ts:117dereferences the other module at evaluation time:search.tsnever needs it that early. Its only runtime uses areFileSystem.Entry.makeandFileSystem.Match.make; the other three are type positions.EntryandMatchalready live in@opencode-ai/schema/filesystem, whichfilesystem.tsimports them from and re-exports. So this imports them from there directly insearch.tsand makes the remainingFileSystemimportimport type, which is erased. The runtime edge back tofilesystem.tsis gone, so there is no cycle and evaluation order stops mattering.Why it matters: with the cycle present, a bundler that emits
search.ts's body afterfilesystem.ts's body leavesFileSystemSearch.nodeundefined in that array, and the layer graph carries an undefined dependency until something walks it. Bun 1.4.2 does exactly that, so 1.18.30 built with it fails on every prompt withTypeError: undefined is not an object (evaluating 'a.name'). I have reported the ordering behaviour separately as oven-sh/bun#42664, but the cycle is worth removing either way, since it makes us rely on the bundler picking the one order that works.No behaviour change: same schema classes, same
.makecalls, imported from where they are defined.How did you verify your code works?
On this branch, with Bun 1.4.2 on macOS 27:
bun run typecheckinpackages/core- exit 0bun test test/filesystem/search.test.ts- 2 pass, 0 failbun --bun ./script/build.ts --single --skip-install- builds, smoke test passesdevfails on every prompt with the TypeError above, so this is the change that fixes it.I also reduced the bundler behaviour to a three-file repro (in oven-sh/bun#42664): unbundled, Bun raises
ReferenceError: Cannot access 'node' before initialization, which is the correct answer; bundled, it silently yieldsundefined.Screenshots / recordings
n/a, not a UI change.
Checklist
AI disclosure: I used Claude Code (model
claude-opus-5) to investigate the crash and prepare this change. I reviewed the diff and ran the verification above myself.