anomalyco / anomalyco/opencode
session.create can use a deleted project ID and fail with a SQLite foreign-key error
@neriousy is already working on this.
Since Aug 15, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
session.create returned 500 UnknownError while creating a session from the OpenChamber web UI. It first appeared in a worktree, but the same failure occurred immediately afterward for the repository root, so it is not worktree-specific.
The OpenCode server tried to insert a session with a stale project_id that no longer existed in the SQLite project table. session.project_id is the only foreign key on the session table, so the insert was rejected. The client only surfaced the returned UnknownError.
Restarting OpenCode rebuilt the project record with a different ID and cleared the stale in-memory mapping. PRAGMA foreign_key_check was clean afterward.
Plugins
OpenChamber was the client for the managed OpenCode server. No OpenCode plugin inventory was collected.
OpenCode version
1.18.16
Steps to reproduce
I do not yet have a minimal deterministic reproduction for the stale project mapping. Observed sequence:
- Start an OpenCode server and open a Git project.
- Create a session in a worktree from the OpenChamber UI.
- The client receives
500withUnknownErrorand anerr_*reference. - Create a session in the repository root before restarting the server. It fails identically.
- Restart OpenCode. The project receives a new database ID and session creation recovers.
Sanitized server error
The server did not emit JavaScript stack frames for this request. This is the complete sanitized Drizzle/Effect error chain logged for err_093e9a17:
EffectDrizzleQueryError: Failed query: insert into "session" ("id", "project_id", "workspace_id", "parent_id", "slug", "directory", "path", "title", "version", "share_url", "summary_additions", "summary_deletions", "summary_files", "summary_diffs", "metadata", "cost", "tokens_input", "tokens_output", "tokens_reasoning", "tokens_cache_read", "tokens_cache_write", "revert", "permission", "agent", "model", "time_created", "time_updated", "time_compacting", "time_archived") values (?, ?, ?, null, ?, ?, ?, ?, ?, null, null, null, null, null, null, ?, ?, ?, ?, ?, ?, ?, null, null, null, ?, ?, null, null) on conflict do nothing returning "id"
params: <session-id>,<stale-project-id>,,<slug>,<worktree-path>,,New session - <timestamp>,1.18.16,0,0,0,0,0,0,,<timestamp>,<timestamp>
(cause: Cause([Fail(effect/sql/SqlError: Failed to execute statement (cause: effect/sql/SqlError/ConstraintError: Failed to execute statement (cause: SQLiteError: FOREIGN KEY constraint failed)))]))
The same stale project ID was used for both the worktree and the repository-root requests.
Screenshot and/or share link
N/A
Operating System
macOS 26.6.1
Terminal
N/A; reproduced through the OpenChamber web UI.
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.