Skip to content

fix: skip JSON to SQLite migration on opencode serve#13612

Closed
remorses wants to merge 10 commits into
anomalyco:devfrom
remorses:skip-migration-on-serve
Closed

fix: skip JSON to SQLite migration on opencode serve#13612
remorses wants to merge 10 commits into
anomalyco:devfrom
remorses:skip-migration-on-serve

Conversation

@remorses

@remorses remorses commented Feb 14, 2026

Copy link
Copy Markdown
Contributor

Closes #13611

Problem: The JSON to SQLite migration can take several minutes for large databases. Commands like serve are designed for programmatic usage where the caller expects opencode to start quickly.

Fix: Only run migration when process.stdout.isTTY is true - if there's no TTY, the user can't see the progress anyway.

Marker change: Uses a dedicated migration.json marker file instead of checking for opencode.db existence. This prevents the issue where a non-TTY invocation creates the db via Database.Client(), which would permanently block migration from running on future interactive commands.

The migration can take several minutes for large databases. Commands like
`serve` are designed for programmatic usage where the caller expects
opencode to start quickly. The migration should only run for interactive
commands where the user can see the terminal progress.

Uses yargs' `opts._[0]` to check the command name in middleware.
Copilot AI review requested due to automatic review settings February 14, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts CLI startup behavior to avoid the potentially long JSON→SQLite session migration when running opencode serve, since serve is intended to start quickly for programmatic usage.

Changes:

  • Skip the one-time JSON→SQLite migration in the yargs middleware when the invoked command is serve.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/opencode/src/index.ts Outdated
Addresses review feedback: using opencode.db as marker was unsafe since
programmatic commands could create the db via Database.Client(), preventing
migration from ever running on interactive commands.

Now uses migration.json as a dedicated marker, written only after migration
completes successfully.
Simpler and more robust - if stdout is not a TTY, the user can't see
the migration progress anyway.
@remorses remorses closed this Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode should not run session JSON to sqlite migration when started with opencode serve

2 participants