You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every launch fails immediately with only this client-side error:
Error: Standalone server exited before reporting readiness
The real cause is visible solely in the server log
(~/.local/share/opencode/log/opencode.log).
Server log
timestamp=... level=ERROR message="database migration failed"
migration=20260812213948_worktree ... error="... SQLiteError:
FOREIGN KEY constraint failed" role=server
(followed by the CLI-side "cli process failed ... Standalone server
exited before reporting readiness")
Root cause
The migration bulk-inserts project_directory rows into the new
worktree table with no orphan guard. Any project_directory row whose
project_id has no parent project row (mine: 2 stale rows under
/tmp/opencode/difftest-*, project long deleted, 0 sessions and
0 messages referencing them) violates worktree.project_id's foreign
key, aborting the entire migration — and with it every server boot,
deterministically. Fresh databases never hit this, which is why it
survives CI.
Repro
On a working install, insert one orphan row:
INSERT INTO project_directory(project_id, directory, time_created)
VALUES ('deadbeef','/tmp/gone', <now_ms>);
(Backup opencode.db + wal/shm first.)
Start opencode → immediate readiness error; server log shows the
migration FK failure above.
Suggested fix
Guard the migration INSERT with a parent check, e.g.
WHERE EXISTS (SELECT 1 FROM project WHERE project.id = ...),
and/or consider surfacing migration failures distinctly instead of
the generic "exited before reporting readiness", which sent me
chasing container/network causes for a database-content problem.
Workaround (verified)
Back up opencode.db + -wal + -shm, then:
DELETE FROM project_directory WHERE project_id NOT IN (SELECT id FROM project);
Server boots and the migration completes.
Plugins
No response
OpenCode version
2.0.29
Steps to reproduce
On a working install, insert one orphan row:
INSERT INTO project_directory(project_id, directory, time_created)
VALUES ('deadbeef','/tmp/gone', <now_ms>);
(Backup opencode.db + wal/shm first.)
Start opencode → immediate readiness error; server log shows the
migration FK failure above.
Thanks for the detailed report and the workaround. I reproduced this on 2.0.29, and it still happens on the latest dev (328f74c).
Steps:
Let OpenCode create a fresh database.
Roll it back to just before migration 20260812213948_worktree and insert one project_directory row whose project_id has no project row ('deadbeef', /tmp/gone).
Start OpenCode again.
The CLI only prints Error: Standalone server exited before reporting readiness. The server log shows database migration failed migration=20260812213948_worktree ... SQLiteError: FOREIGN KEY constraint failed. The migration copies every project_directory row into worktree and doesn't check that the project still exists. The script below reproduces it in separate data directories.
Until this is fixed, your workaround is the way around it: back up the database first, then run DELETE FROM project_directory WHERE project_id NOT IN (SELECT id FROM project);.
Reproduction script (repro.sh)
#!/usr/bin/env bash# Reproduces #55583: migration 20260812213948_worktree aborts on an orphaned# project_directory row (FOREIGN KEY constraint failed), so the server never boots.# Usage: ./repro.sh -> uses `opencode` from PATH# OC_DEV=/path/to/repo ./repro.sh -> runs the CLI from a checkoutset -u
ROOT=$(mktemp -d /tmp/opencode/repro55583.XXXX)export XDG_DATA_HOME=$ROOT/data XDG_CONFIG_HOME=$ROOT/cfg XDG_STATE_HOME=$ROOT/state XDG_CACHE_HOME=$ROOT/cache
if [ -n"${OC_DEV:-}" ];then# BUN_OPTIONS so the spawned standalone server gets the same flagsexport BUN_OPTIONS="--conditions=browser --preload=$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js"
OC=(bun "$OC_DEV/packages/cli/src/index.ts")
else
OC=(opencode)
fiecho"== version: $("${OC[@]}" --version)"echo"== 1. first boot creates a fresh database"
timeout 90 "${OC[@]}" models --standalone >/dev/null 2>&1||true
DB=$(ls $XDG_DATA_HOME/opencode/opencode*.db 2>/dev/null | head -1)# opencode-local.db when run from source
[ -n"$DB" ] && [ -f"$DB" ] || { echo"no database created";exit 2; }
echo"== 2. roll the DB back to just before the worktree migration and add an orphan project_directory row"
python3 - "$DB"<<'EOF'import sqlite3, sys, timec = sqlite3.connect(sys.argv[1])c.execute("PRAGMA foreign_keys = OFF") # how such orphans can exist in older DBsc.execute("DROP TABLE worktree")c.execute("DELETE FROM migration WHERE id = '20260812213948_worktree'")c.execute("INSERT INTO project_directory(project_id, directory, time_created) VALUES ('deadbeef', '/tmp/gone', ?)", (int(time.time()*1000),))c.commit()print("orphans:", c.execute("SELECT count(*) FROM project_directory WHERE project_id NOT IN (SELECT id FROM project)").fetchone()[0])EOFecho"== 3. boot again"
timeout 90 "${OC[@]}" models --standalone --print-logs >"$ROOT/out.txt"2>&1echo"exit code: $?"
grep -E "Standalone server exited|database migration failed|FOREIGN KEY""$ROOT/out.txt"| cut -c1-400
grep -rhE "database migration failed|FOREIGN KEY""$XDG_DATA_HOME/opencode/log"2>/dev/null | cut -c1-400 | head -3
Activity
opencode-agent commentedon Oct 15, 2026
Thanks for the detailed report and the workaround. I reproduced this on 2.0.29, and it still happens on the latest
dev(328f74c).Steps:
20260812213948_worktreeand insert oneproject_directoryrow whoseproject_idhas noprojectrow ('deadbeef',/tmp/gone).The CLI only prints
Error: Standalone server exited before reporting readiness. The server log showsdatabase migration failed migration=20260812213948_worktree ... SQLiteError: FOREIGN KEY constraint failed. The migration copies everyproject_directoryrow intoworktreeand doesn't check that the project still exists. The script below reproduces it in separate data directories.Until this is fixed, your workaround is the way around it: back up the database first, then run
DELETE FROM project_directory WHERE project_id NOT IN (SELECT id FROM project);.Reproduction script (repro.sh)
Run it:
bash repro.shfariello commentedon Nov 12, 2026
Just happened to me on two of three different servers. Still not fixed in the latest update.