fix(core): break filesystem search import cycle - #50439
Merged
Merged
Conversation
search.ts imported the FileSystem namespace from ../filesystem to reach Entry.make / Match.make, which filesystem.ts only re-exports from @opencode-ai/schema/filesystem. That is a runtime cycle with filesystem.ts, which imports FileSystemSearch back. With code splitting the bundler can evaluate filesystem.ts first, leaving FileSystemSearch.node undefined in its deps array, so the first prompt dies in SystemPrompt.environment with TypeError: undefined is not an object (evaluating 'a.name'). Import the schema constructors directly and make the remaining FileSystem import type-only so no runtime edge points back at filesystem.ts. Co-authored-by: kernel-oops <300539221+kernel-oops@users.noreply.github.com>
joe-ieta
added a commit
to joe-ieta/opencode
that referenced
this pull request
Sep 22, 2026
Upstream merged our filesystem search import cycle fix via anomalyco#50439: drop the local patch, update KG upstream/architecture/history, and refresh doc version baselines to 1.18.32.
difro
added a commit
to difro/dotfiles
that referenced
this pull request
Sep 23, 2026
nixpkgs now builds opencode with `splitting: false` to work around the Bun 1.4 code splitting regression (NixOS/nixpkgs#564101), so opencode 1.18.31 built with bun 1.4.2 no longer fails every prompt in SystemPrompt.environment. Upstream also broke the filesystem import cycle in 1.18.32 (anomalyco/opencode#50439). Drop the nixpkgs-bun input and build opencode with the default bun again. The glibc 2.40 interpreter patch is a separate issue and stays.
rldona
pushed a commit
to rldona/FlupCode
that referenced
this pull request
Sep 24, 2026
Co-authored-by: frank <48937772+joe-ieta@users.noreply.github.com> Co-authored-by: kernel-oops <300539221+kernel-oops@users.noreply.github.com>
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 #49685
Closes #48372
Closes #48811
Closes #49158
Closes #48645
Closes #48803
Supersedes #49683 and the
search.tschange in #48397. Unblocks #48818.Type of change
What does this PR do?
Every prompt in a compiled build can fail with:
a.nameis the minifiednode.nameinpackages/core/src/effect/layer-node.ts, walking adepsarray that containsundefined.Cause.
packages/core/src/filesystem/search.tsimported theFileSystemnamespace from../filesystemonly to callFileSystem.Entry.make/FileSystem.Match.make. Those two are re-exports of@opencode-ai/schema/filesystem. Meanwhilefilesystem.tsimportsFileSystemSearchfrom./filesystem/searchand listsFileSystemSearch.nodein itsdeps. That is a runtime import cycle:From source, evaluation order happens to work. With
splitting: trueinscript/build.tsthe bundler chooses chunk order, and whenfilesystem.tsevaluates first,FileSystemSearch.nodeis stillundefinedwhen thedepsarray is built. Any unrelated code change can reshuffle chunks and flip this on or off, which is why 1.18.30 broke, 1.18.31 "fixed" it without touching any of these files (git log v1.18.30..v1.18.31has no changes tofilesystem*,layer-node.ts, or the build script), Homebrew patched it by disabling splitting, and the snap is still broken.Fix.
search.tstakesEntryandMatchfrom@opencode-ai/schema/filesystemdirectly and makes the remaining../filesystemimport type-only, which is erased at compile time. No runtime edge points back atfilesystem.ts. Same objects, no behaviour change.This is how the neighbouring module already does it:
packages/core/src/ripgrep.tshasimport { Entry, Match } from "@opencode-ai/schema/filesystem".search.tswas the outlier, and the change follows the Schema → Core dependency direction fromAGENTS.md.Credit
The commit is cherry-picked from @joe-ieta's #49683 (they remain the git author). @kernel-oops found the root cause first in #48372 / #48397 and is co-author. #48397 also adds a Python compiled-prompt harness and a CI workflow; this PR deliberately carries only the one-file fix so it can land now. #48818 (@vidit19sharma) adds a layer-node guard that turns this class of bug into a named error at startup; it should land after this.
Verification
Reproduced on current
dev, not just the release. Built the single native binary (script/build.ts --single) twice on macOS arm64, once fromdevand once with this change, then ran each withservein an isolatedHOME/XDG_*against a local mock OpenAI-compatible provider and sent one prompt:devUnexpected server error, assistant message empty. Server log:TypeError: undefined is not an object (evaluating 'a.name') at resolve (chunk-…) … at SystemPrompt.environment … at SessionPrompt.runPONG, no errorSo the tip of
devcurrently ships this crash in compiled builds; the next release would regress without this.Static check. A cycle scan over
packages/core/srcusingBun.Transpiler.scanImports(which dropsimport typelike the bundler does):dev:filesystem.ts -> filesystem/search.ts -> filesystem.tsfilesystem.tsis its ownexport * as FileSystem from "./filesystem"self-reexport, which every core module has by design.The scan also finds cycles in the
plugin/internal.tsregistry pattern. Those are a different shape (nodepsarray built from a half-initialised module) and are out of scope here; #48818's guard is the right tool for catching any that do bite.Tests.
bun typecheckinpackages/corepasses.packages/core:test/filesystem,location-filesystem,ripgrep,tool-read-filesystemall pass.packages/opencode:tool/glob,tool/greppass.Checklist
devand from this branch