fix(cli): prevent tests from deleting session database - #11316
Merged
Conversation
marius-kilocode
enabled auto-merge
June 16, 2026 17:04
catrielmuller
approved these changes
Jun 16, 2026
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Reviewed by deepseek-v4-pro-20260423 · 400,736 tokens Review guidance: REVIEW.md from base branch |
marius-kilocode
disabled auto-merge
June 16, 2026 17:10
marius-kilocode
enabled auto-merge
June 16, 2026 17:14
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
fix(cli): prevent tests from deleting session database
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.
The shared database reset fixture could delete the real local Kilo session database when a test was launched without the package test preload. This is destructive because the fixture removed the resolved SQLite database together with its WAL and SHM files, while treating test-runner configuration as its only safety boundary. A missed preload could therefore permanently remove every conversation stored only in the shared database.
The complete failure requires all of these conditions:
packages/opencode/test/server/httpapi-sdk.test.tsin the observed incident, is run from a directory where Bun does not discoverpackages/opencode/bunfig.toml.packages/opencode/test/preload.tsis not applied andKILO_DB=:memory:is never set.KILO_DISABLE_CHANNEL_DB=true. The managed VS Code backend adds that variable inpackages/kilo-vscode/src/services/cli-backend/server-manager.tsso extension contexts use one shared session database.KILO_DBoverride,Database.getPath()inpackages/opencode/src/storage/db.tshonors the inherited channel setting and resolves to~/.local/share/kilo/kilo.db.resetDatabase()inpackages/opencode/test/fixture/db.tscloses the client and unlinks that resolved path,kilo.db-wal, andkilo.db-shm. The helper runs from both theafterEachcleanup and the default-versus-raw server parity reset inhttpapi-sdk.test.ts.parentandchildsessions, leaving a valid but nearly empty replacement database.At that point, conversations stored only in the previous SQLite database are gone. Agent Manager worktrees, git branches, and
.kilo/agent-manager.jsonremain because they are stored separately, which makes the UI look as though its sessions disappeared while the worktree metadata still exists.The unsafe helper originated in upstream OpenCode PR #15120, where tests used a temporary disk-backed XDG data directory and deleting the database was intended to reset state. Upstream PRs #24836 and #24853 expanded the SDK route and parity coverage that invokes this reset, including the
parentandchildlifecycle scenario. Kilo later switched package tests to an in-memory database, so filesystem deletion was no longer required.Kilo PR #11031 adapted the fixture from the former static database path to
Database.getPath(). Kilo PR #11087 intentionally addedKILO_DISABLE_CHANNEL_DB=trueto the managed VS Code server environment to restore one shared session database across extension contexts. Each change was reasonable in isolation, but together they allowed a test process that missed its preload to resolve the cleanup target to the real shared database.This change removes every filesystem deletion from
resetDatabase(). The fixture now accepts only the exact:memory:database, then disposes shared instances and closes the in-memory SQLite connection. Closing that connection clears its contents and resets the lazy client, so the next test still receives a clean database. Any disk-backed path fails before disposal or closure, regardless of the current directory or inherited environment.A Kilo-owned regression test documents the incident and enforces both safety boundaries. It points
KILO_DBat a disposable sentinel file and proves the reset is rejected without changing the file. It also scans the test tree for direct deletion code combined withDatabase.getPath(),Database.Path, or akilo.dbpath, so the removed database, WAL, and SHM cleanup cannot be reintroduced elsewhere. The existing HTTP API SDK coverage remains unchanged.