workerd: let embedders prefix OpenCode's SQLite tables · Issue #53577 · anomalyco/opencode · GitHub
Skip to content

workerd: let embedders prefix OpenCode's SQLite tables #53577

Closed as not planned

Description

@mattzcarey

Problem

OpenCodeWorkerd.create({ storage }) puts OpenCode's tables in the Durable Object's SQLite database without a prefix: session_v2, session_message, event, kv, project, permission, workspace, and so on. That causes two problems when the object also stores its own data:

  1. Bootstrap fails. DatabaseMigration.apply stops with Database is not empty and has no session table if any table exists whose name doesn't start with _. Most objects create their tables before OpenCode boots. The Cloudflare Agents SDK, for example, keeps its scheduler and streams in cf_agents_* tables. So in practice, embedding OpenCode means it has to boot first, or the embedder has to hide its tables from OpenCode's discovery query.
  2. Names can collide. Names like session, message, event, kv and project are common, so an object's own tables can clash with OpenCode's.

Workerd is where this shows up most, because the database belongs to the Durable Object, not to OpenCode. The same applies to anyone sharing a database through database.path.

Proposal

Add a table prefix option to the database layer, and expose it from OpenCodeWorkerd.create and OpenCode.create:

OpenCodeWorkerd.create({ storage, database: { prefix: "opencode_" } })

When it is set:

  • every table and index in schema.gen.ts and the migrations is created as <prefix><name>
  • the bootstrap check only looks at tables that start with the prefix, so tables outside it are ignored, as underscore-prefixed tables are today
  • the migration journal is prefixed too

Drizzle table definitions already go through sqliteTable(name, ...), so a prefixed table builder plus prefixed DDL in the generated schema and migrations would cover most of it.

What we do for now

cloudflare/agents is adding an OpenCodeHarness built on @opencode/sdk/workerd. Until there is a prefix option, it hands OpenCode a view of DurableObjectStorage that rewrites the SQL OpenCode sends: table names get an opencode_ prefix, and the bootstrap discovery query only sees opencode_* tables. This relies on the shape of OpenCode's SQL, which is why we'd like to replace it with a supported option.

Related: #53221, the same bootstrap check failing on a shared database.

Activity

  1. github-actions commented on Oct 6, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • For a feature request, the title must start with [FEATURE]: and the issue must include the required verification checkbox.

    Please edit this issue to address the above within 72 hours, or it will be automatically closed.


    This issue might be a duplicate of existing issues. Please check:

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. github-actions commented on Oct 9, 2026

    @github-actions
    Contributor

    This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 72-hour window.

    Feel free to open a new issue that follows our issue templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions