refactor(ocap-kernel): close database in Kernel.stop()#845
Merged
Conversation
Kernel.stop() now owns full shutdown by closing the KernelDatabase at the end of the stop sequence, eliminating a resource leak. The database is stored as a private field on the Kernel class. E2E tests are updated to remove explicit database close calls (now handled by stop()). Tests that restart kernels with the same database are switched to file-based temp databases (in-memory databases are destroyed on close). The restartKernel/restartKernelAndReloadVat helpers accept a dbFilename string instead of a KernelDatabase object. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sirtimid
previously approved these changes
Feb 19, 2026
In 'remote relationships should survive kernel restart', restarted kernels were assigned to local serverKernel/clientKernel variables while afterEach only stopped the outer-scope kernel1/kernel2 (the old already-stopped kernels). Update kernel1/kernel2 at the end of the test body so afterEach picks up the restarted kernels and closes their database connections. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests in the kernel-test package were reusing the same KernelDatabase object after kernel.stop() closed it. Each test that restarts a kernel now opens a fresh database connection for the second kernel. Also adds afterEach to remote-comms.test.ts to stop kernel1/kernel2 properly, and refactors the restart test to use temp file-based databases (in-memory databases cannot persist state across close/reopen). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
sirtimid
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Kernel.stop()gracefully shuts down all kernel subsystems but previously did not close the database, leaving a resource leak. Since there's no realistic scenario where you'd stop the kernel but keep the database open (a restart in production means a new process with a new connection),stop()should own the full shutdown lifecycle.#kernelDatabase: KernelDatabaseprivate field toKernel; store it in the constructor and call.close()at the end ofstop()close()to the mockmakeMapKernelDatabase()inocap-kernel/test/storage.tsto satisfy theKernelDatabasetypekernelDatabase.close()calls from all e2e tests — these are now handled bykernel.stop():memory:to temp file paths (in-memory databases are destroyed onclose(), making persistence across restarts impossible)restartKernelandrestartKernelAndReloadVathelpers to accept adbFilename: stringinstead of aKernelDatabaseobject, opening a fresh connection internally on each callTesting
Covered by the existing e2e test suites (
system-subcluster,bip39-identity-recovery,remote-comms). The persistence tests in particular exercise the stop → close → reopen cycle that this change introduces, verifying that the database is properly closed and can be re-opened for the next kernel incarnation.🤖 Generated with Claude Code
Note
Medium Risk
Changes core shutdown behavior by closing the database automatically; risk is primarily around callers/tests that previously assumed the DB connection could outlive
Kernel.stop()or be reused after stopping.Overview
Kernel.stop()now closes the underlyingKernelDatabaseas part of shutdown, making the kernel responsible for fully releasing persistent-state resources.To accommodate this lifecycle change, persistence/remote-comms/system-subcluster e2e tests are refactored to reopen fresh DB connections on restart (often using temp file-backed SQLite DBs) and to remove manual
kernelDatabase.close()calls; remote-comms restart helpers now take adbFilenameand open the database internally each time.Written by Cursor Bugbot for commit 9bbc6e6. This will update automatically on new commits. Configure here.