anomalyco / anomalyco/opencode
serve: InstanceStore.boot eagerly initializes every registered project directory - startup is O(projects), minute-scale
@nexxeln is already working on this.
Since Sep 14, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
opencode serve runs InstanceStore.boot at listen time, which eagerly initializes an instance for every row in project/project_directory. Each instance pays full init cost (project config load, plugin init, remote MCP client connects, LSP enumeration) — measured ~2–20s per directory. With ~19 projects / ~80 registered directories, the server isn't ready for several minutes. Downstream supervisors that spawn opencode serve and wait for readiness (e.g., Paseo) time out and kill it.
Environment
- opencode-ai 1.18.30 (npm), Windows 11
~/.local/share/opencode/opencode.db(~3.3GB) accumulated over months of worktree-based sessions
Evidence
Log excerpt from a single run= of opencode serve — creating instance/fromDirectory/bootstrapping repeating per directory, each followed by config loads, plugin init, MCP connects, and the ~35-entry "enabled LSP servers" enumeration:
message="creating instance" directory="C:\\Docker\\regmais"
message=fromDirectory directory="C:\\Docker\\regmais"
message=bootstrapping directory="C:\\Docker\\project-bulldog\\placeholder-folder"
message=bootstrapping directory="C:\\Docker\\fns-inteligencia-operacional"
message=bootstrapping directory="C:\\Docker\\project-bulldog"
message=bootstrapping directory="C:\\Docker\\dispensamais"
message="enabled LSP servers" serverIds="zls, yaml-ls, vue, typescript, ..." (per instance)
message=init (per instance)
Directories bootstrapped include long-dead paths (%TEMP% dirs, removed worktrees) — those rows are never skipped or pruned, they just add boot cost.
In my case the server was still bootstrapping minutes after listen, while a supervisor's readiness probe timed out and SIGTERM'd it.
Suggestions
- Lazy instance creation: initialize an instance on first request for that directory, not at listen time.
- Or parallelize
InstanceStore.bootand skip directories that no longer exist on disk. - Related: #36840 reports the same eager bootstrap deadlocking under concurrent triggers on WSL2 — lazy init would help there too.
Also encountered on the same install
- #42170 —
SQLiteError: no such column: project_idfromProject.migrateProjectIdinside this same boot path; resolved manually with theworkspacetable drop/recreate posted in that thread.
Repro
- Accumulate projects/dirs in opencode.db (or insert
project_directoryrows directly). opencode serve --port <port>and watchlog/opencode.log— onecreating instance/bootstrapping/initcycle per registered directory before the server is fully ready.- Time to readiness scales roughly linearly with registered directory count.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.