Skip to content

fix(server): return a clear "restart required" error on missing DB schema#897

Open
wideplain wants to merge 1 commit into
siteboon:mainfrom
wideplain:fix/fail-loud-on-missing-schema
Open

fix(server): return a clear "restart required" error on missing DB schema#897
wideplain wants to merge 1 commit into
siteboon:mainfrom
wideplain:fix/fail-loud-on-missing-schema

Conversation

@wideplain

@wideplain wideplain commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Problem

When a DB-backed request hits a SQLite no such table / no such column error, the global error handler in server/index.js returns a generic 500 INTERNAL_ERROR.

This occurs in a very common real-world situation: the package is updated on disk (new schema / migrations in initializeDatabase()), but the running server process is not restarted. Because the new schema is only applied at startup, the long-lived old process keeps running against a DB that lacks the new tables (projects, sessions, …). DB-backed actions — deleting/archiving/renaming a session or project — then throw no such table: sessions and fail silently from the user's point of view (the trash icon appears to do nothing).

Sidebar listings still work because they're read from disk (~/.claude/projects/*/*.jsonl), which makes the failure even more confusing: items are visible but can't be mutated.

Fix

In the global error handler, detect this specific class of error (SQLITE_ERROR / SqliteError with a no such table|column message) and return a 503 with code SCHEMA_NOT_INITIALIZED and an actionable message asking the user to restart the server, instead of burying it in a generic 500.

No behavior change for any other error.

Notes

  • This is a defensive, fail-loud safety net. A complementary change (detecting the running-server-vs-frontend version skew and showing a "restart required" banner) is a good follow-up.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for uninitialized database schemas. The server now detects schema-related failures and returns a clear HTTP 503 response with guidance to restart the server for proper initialization, replacing generic error messages.

…hema

When a DB-backed action hits a "no such table/column" SQLite error, the
global error handler previously returned a generic 500 INTERNAL_ERROR.
This happens in a very common real-world situation: the on-disk package
was updated (introducing new schema/migrations) but the running server
process was never restarted, so initializeDatabase() never created the
new tables for the running process. The result is that session/project
delete, archive and rename silently fail and look like nothing happened.

Map that specific failure to a 503 with code SCHEMA_NOT_INITIALIZED and
an actionable message telling the user to restart the server, instead of
hiding it behind a generic 500.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d963afc2-a942-4edb-a350-3f1ebba32824

📥 Commits

Reviewing files that changed from the base of the PR and between a12ca8e and cb49f4d.

📒 Files selected for processing (1)
  • server/index.js

📝 Walkthrough

Walkthrough

The global Express error handler in server/index.js gains a new branch that pattern-matches SQLite "no such table" and "no such column" error messages. When matched, it logs a specific message and returns HTTP 503 with error code SCHEMA_NOT_INITIALIZED and a restart-required message, bypassing the generic 500 response.

Changes

SQLite Schema Error Handling

Layer / File(s) Summary
SQLite schema error → 503 middleware branch
server/index.js
Adds a conditional in the global error middleware that detects SQLite missing-table/column errors and returns 503 with SCHEMA_NOT_INITIALIZED and a restart instruction instead of falling through to the generic 500 handler.

🐇 When tables go missing, don't panic or frown,
A 503 will gently set things down.
"Restart the server!" the rabbit suggests,
So initializeDatabase() handles the rest.
No more cryptic 500s—just clear guidance found! 🗄️✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: detecting SQLite schema errors and returning a clear 'restart required' error response instead of a generic error.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant