Skip to content

fix: reinitialize database after reset to prevent connection errors#2826

Open
wwwillchen-bot wants to merge 1 commit intodyad-sh:mainfrom
wwwillchen-bot:agent-2767-1772234220
Open

fix: reinitialize database after reset to prevent connection errors#2826
wwwillchen-bot wants to merge 1 commit intodyad-sh:mainfrom
wwwillchen-bot:agent-2767-1772234220

Conversation

@wwwillchen-bot
Copy link
Collaborator

@wwwillchen-bot wwwillchen-bot commented Feb 27, 2026

Summary

  • Add closeDatabase() function to properly close the SQLite connection and reset internal state
  • After resetAll operation, reinitialize the database to prevent "The database connection is not open" errors
  • Fixes [bug] Database connection not open when loading model providers #2767 - users can now continue using the app after reset without seeing connection errors

Test plan

  • Run npm test - all 842 tests pass
  • Manual test: Open Settings → Reset Everything → Click around the app → No "database connection not open" errors should appear

🤖 Generated with Claude Code


Open with Devin

Fixes dyad-sh#2767

After calling resetAll, the database connection was closed but not
reinitialized. This caused "The database connection is not open" errors
when users interacted with the app before restarting.

Changes:
- Add closeDatabase() function to properly close connection and reset state
- Call initializeDatabase() after reset to ensure continued functionality

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@wwwillchen
Copy link
Collaborator

@BugBot run

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the application's database handling by introducing a dedicated function for closing database connections and ensuring the database is properly reinitialized after a full application reset. This change resolves critical connection errors that users previously encountered, allowing for seamless continued use of the application after a reset operation.

Highlights

  • Database Connection Management: Introduced a new closeDatabase() function to properly close the SQLite connection and reset the internal database state, ensuring clean disconnections.
  • Error Prevention: Implemented reinitialization of the database after a full application reset (resetAll operation) to prevent 'The database connection is not open' errors, addressing issue [bug] Database connection not open when loading model providers #2767.
  • Improved Reset Logic: Modified the application reset handler to utilize the new closeDatabase() function and subsequently call initializeDatabase() to ensure the application remains functional post-reset.
Changelog
  • src/db/index.ts
    • Added closeDatabase() function to encapsulate database connection closing logic.
    • Ensured the internal _db state is reset to null after closing the connection.
  • src/ipc/handlers/app_handlers.ts
    • Imported closeDatabase and initializeDatabase functions.
    • Replaced direct db.$client.close() call with the new closeDatabase() function during the reset process.
    • Added a call to initializeDatabase() after the reset operation to re-establish the database connection and prevent errors.
Activity
  • The pull request was generated with assistance from Claude Code.
  • A comprehensive test plan was provided, including npm test and manual verification steps to confirm the fix.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes an issue where the application would become unusable after a 'Reset All' operation due to database connection errors. It introduces a closeDatabase function for proper connection handling and ensures the database is re-initialized after being reset. The changes are logical and well-implemented. The suggestion to make the reset logic even more robust by unconditionally calling closeDatabase() is valid and aligns with best practices for resource management.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 27, 2026

Greptile Summary

Fixes issue #2767 where users encountered "The database connection is not open" errors after using the Reset Everything feature. The PR adds a new closeDatabase() function that properly closes the SQLite connection and resets the internal _db state, then calls initializeDatabase() after the reset operation completes to restore database functionality.

Key changes:

  • New closeDatabase() function with proper error handling in src/db/index.ts
  • Updated reset-all handler to use closeDatabase() instead of directly accessing db.$client.close()
  • Database is now reinitialized after reset, allowing the app to continue functioning without restart

The fix follows the correct IPC error handling patterns and properly manages the database lifecycle during the reset operation.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is focused, addresses the root cause correctly, and follows established patterns for database lifecycle management and IPC error handling. The changes are minimal and well-tested (842 tests passing)
  • No files require special attention

Important Files Changed

Filename Overview
src/db/index.ts Added closeDatabase() function to properly close SQLite connection and reset internal state
src/ipc/handlers/app_handlers.ts Updated reset-all handler to use closeDatabase() and reinitialize database after reset to prevent connection errors

Last reviewed commit: 549855f

@github-actions
Copy link
Contributor

🎭 Playwright Test Results

❌ Some tests failed

OS Passed Failed Flaky Skipped
🍎 macOS 234 2 9 6

Summary: 234 passed, 2 failed, 9 flaky, 6 skipped

Failed Tests

🍎 macOS

  • select_component.spec.ts > select component next.js
    • Error: expect(locator).toBeVisible() failed
  • template-create-nextjs.spec.ts > create next.js app
    • Error: expect(locator).toMatchAriaSnapshot(expected) failed

📋 Re-run Failing Tests (macOS)

Copy and paste to re-run all failing spec files locally:

npm run e2e \
  e2e-tests/select_component.spec.ts \
  e2e-tests/template-create-nextjs.spec.ts

⚠️ Flaky Tests

🍎 macOS

  • chat_mode.spec.ts > chat mode selector - ask mode (passed after 1 retry)
  • chat_tabs.spec.ts > tabs appear after navigating between chats (passed after 1 retry)
  • context_manage.spec.ts > manage context - smart context (passed after 1 retry)
  • context_manage.spec.ts > manage context - exclude paths with smart context (passed after 1 retry)
  • debugging_logs.spec.ts > network requests and responses should appear in the console (passed after 1 retry)
  • hmr_path.spec.ts > HMR after navigating back to root should stay on root (passed after 1 retry)
  • setup_flow.spec.ts > Setup Flow > setup banner shows correct state when node.js is installed (passed after 1 retry)
  • setup.spec.ts > setup ai provider (passed after 1 retry)
  • undo.spec.ts > undo with native git (passed after 1 retry)

📊 View full report

@github-actions
Copy link
Contributor

🤖 Claude Code Review Summary

PR Confidence: 4/5

All review comments addressed; the fix is straightforward and low-risk, but CI type-checking could not be verified due to a missing tsgo package in the environment.

Unresolved Threads

No unresolved threads

Resolved Threads

Issue Rationale Link
closeDatabase() conditionally skipped in resetAll (2 duplicate threads) Both gemini-code-assist and devin-ai-integration identified the same bug: closeDatabase() was inside the fs.existsSync() check, so _db could remain stale if the file was already deleted. Moved closeDatabase() before the check. View 1, View 2
Product Principle Suggestions

No suggestions — product principles were not needed for these purely technical review comments.


🤖 Generated by Claude Code

@github-actions
Copy link
Contributor

✅ Claude Code completed successfully

Summary

  • Fixed 2 review comments (both addressing the same bug: closeDatabase() conditionally skipped in resetAll)
  • No CI failures attributable to this PR (2 E2E timeouts are pre-existing flaky tests also seen on main)
Details

Review Comments Addressed

  • gemini-code-assist and devin-ai-integration both identified that closeDatabase() was inside the fs.existsSync(dbPath) check in the resetAll function. If the database file was already deleted externally, _db would remain non-null, causing initializeDatabase() to return a stale connection via the early return at src/db/index.ts:32.
  • Fix: Moved closeDatabase() before the file existence check so it's always called unconditionally.

CI Check Analysis

  • claude-review (fail): Claude PR Review bot process failure — not a code issue.
  • e2e-tests shard 2/2 (fail): 2 timeouts in Next.js template/preview tests (select_component.spec.ts:149, template-create-nextjs.spec.ts:4). These are pre-existing flaky tests — the main branch also shows E2E failures (setup_flow.spec.ts). Not related to the resetAll changes in this PR.
  • build, lint, CLA, and all other checks: passing.

Environment Notes

  • npm run ts (tsgo) not available in npm registry — pre-existing CI environment issue.
  • Local test suite could not run due to Node.js version mismatch (v20 vs required >=24).

Workflow run

@github-actions github-actions bot added cc:done needs-human:review-issue ai agent flagged an issue that requires human review and removed cc:pending labels Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc:done cc:request needs-human:review-issue ai agent flagged an issue that requires human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Database connection not open when loading model providers

2 participants