anomalyco / anomalyco/opencode

session.create can use a deleted project ID and fail with a SQLite foreign-key error

Open
#42,734 1 comment 0 reactions 1 assignee View on GitHub

@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:

  1. Start an OpenCode server and open a Git project.
  2. Create a session in a worktree from the OpenChamber UI.
  3. The client receives 500 with UnknownError and an err_* reference.
  4. Create a session in the repository root before restarting the server. It fails identically.
  5. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.