feat(opencode): add db doctor and repair commands#32093
Open
pascalandr wants to merge 12 commits into
Open
Conversation
Adds native db doctor and repair flows with JSON output, dry-run and apply modes, safe/aggressive repair planning, backup-before-apply safeguards, transactional preconditions, and targeted DB tests.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
# Conflicts: # packages/opencode/src/cli/cmd/db.ts # packages/opencode/src/index.ts
This was referenced Jun 13, 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.
Issue for this PR
Related issues (does not automatically close): #29908, #31204, #19191, #29581, #31597, #23594, #30157, #14970, #24780.
Type of change
What does this PR do?
Adds native database health commands for local OpenCode SQLite databases:
opencode db doctorandopencode db doctor --jsonopencode db repair --dry-runandopencode db repair --applyThe commands inspect local OpenCode SQLite databases directly. They diagnose/repair rows by comparing persisted data shapes against the invariants required by the OpenCode binary currently running the command.
The supported repair catalog is exported from
@opencode-ai/core/database/healthasSUPPORTED_REPAIRSand is included indoctor/repair --dry-runJSON output. Each catalog entry declares the target OpenCode version/invariant, known target migration when applicable, source evidence if known, repair behavior, and safety constraints. The report also includes acompatibilityblock with the current binary version, expected migrations for that binary, applied DB migrations, and observedsession.versiondistribution.Supported repair catalog (for now)
part_legacy_id_prefix: renamespart_<suffix>IDs toprt_<suffix>only when the target ID does not already exist. This fixes the observed load failure:Expected a string starting with "prt", got "part_..." at [0]["parts"][0]["id"].assistant_message_missing_agent: copies assistantsession_message.data.modetodata.agentwith original-JSON precondition checks.session_agent_missing: fillssession.agentonly when one unambiguous value can be derived from assistant or agent-switched messages.session_model_missing: fillssession.modelonly when one unambiguous model object can be derived from assistant or model-switched messages.session_path_missing: fillssession.pathfrom the same row's non-emptysession.directory.message_assistant_missing_parent: fills missing assistantparentIDfrom the immediately preceding message in the same session.message_user_missing_agent: fills missing useragentonly when one unambiguous agent is derivable.message_user_missing_model: fills missing usermodelonly when one unambiguous model is derivable.part_step_finish_missing_reason: fills missingstep-finish.reasonwithstop.part_compaction_missing_auto: fills missingcompaction.autowithfalse.part_tool_completed_missing_metadata: fills missing completed-toolstate.metadatawith{}.part_tool_completed_missing_title: fills missing completed-toolstate.titlefromdata.toolonly when present.part_tool_completed_missing_time: fills missing completed-toolstate.time.start/endfrom the part row timestamp while preserving any existing start/end value.How did you verify your code works?
I manually validated the tool against several real local user database and confirmed it repaired the targeted damaged session rows that caused session loading failures in Codenomad.
Screenshots / recordings
Not a UI change.
Checklist