A rebuild that could not rebuild past a schema change - #779
Merged
Conversation
`rebuildIndex` clears rows and keeps the tables, and its `DELETE FROM meta` deliberately preserves `schema_version` -- so on a database written by an older release the stale state survives its own repair. The first insert then dies on a column the table does not have, and the message names a SQLite constraint rather than the situation. Measured on a worktree whose index came from v1.0.2: zero `signature_status` columns in `trailers`, and `--rebuild` reporting NOT NULL constraint failed: trailers.signature_status which is a constraint on a column that does not exist. Deleting the file made the identical command succeed; restoring it made it fail again, twice each. The condition was already detectable and already handled elsewhere: `healthProblem` returns "index was built by schema v<n>, this build expects v<m>", and `ensureIndex` resets the file on it. The command named *rebuild* was the one path that did not, because `index-cmd.ts` opens the index and calls `rebuildIndex` directly rather than going through that branch. So the reset belongs to the rebuild, not to one of its callers. I fixed the `force` branch of `ensureIndex` first; it changed nothing, because `--rebuild` never reaches it. That is the second time today a first fix landed on a path that does not fire -- the other was the empty-payload return in `inject.ts`. Limit: this recreates the file whenever the recorded version differs, so a downgrade discards an index a newer build wrote rather than reading what it can from it Blast: module Undo: easy Certainty: firm Record-Id: r-rebuildschema Provenance: authored Verified: against the real v1.0.2 database, which failed before and rebuilds 652 commits after; the test writes that schema rather than depending on the artefact, and a first version of it omitted `id INTEGER PRIMARY KEY` and failed on `no such column: id` -- a fixture defect wearing the costume of the bug CommitLore-Version: 2.0.0
CommitLore — record lintTrailers: clean — 2 commits in Trailer violations fail this check. Active constraints are informational — they are what the repository already decided, not a verdict on this PR. |
# Conflicts: # dist/commitlore.mjs # installer/canonical-artifact.json
This was referenced Aug 18, 2026
Merged
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.
Fixes #774.
rebuildIndexclears rows and keeps the tables, and itsDELETE FROM metadeliberately preservesschema_version— so on a database written by an older release the stale state survives its own repair. The first insert then dies on a column the table does not have.Measured
A worktree whose index came from v1.0.2:
A constraint on a column that does not exist. Deleting the file made the identical command succeed; restoring it made it fail again. Twice each.
The same database later reported
table trailers has no column named signature_status— two SQLite symptoms of one cause, and the first is the more misleading.The condition was already handled, one branch over
healthProblemreturns "index was built by schema v3, this build expects v4", andensureIndexresets the file on it. The command namedrebuildwas the one path that did not, becauseindex-cmd.tsopens the index and callsrebuildIndexdirectly rather than going through that branch.So the reset belongs to the rebuild, not to one of its callers.
I fixed the
forcebranch ofensureIndexfirst. It changed nothing —--rebuildnever reaches it. That is the second time today a first fix landed on a path that does not fire; the other was the empty-payload return ininject.ts(#778).What this corrects on the issue
The reproduction I originally filed — "a worktree detached a few hundred commits back" — does not reproduce. A fresh worktree at the same old commit rebuilds cleanly. The notes-outside-the-range correlation was real and coincidental. The actual trigger is an index written by an older schema, which is every repository a user upgrades.
Verified
Against the real v1.0.2 database: fails before, rebuilds 652 commits after.
The test writes that schema itself rather than depending on the artefact, so it keeps testing once every such file is gone. A first version of it omitted
id INTEGER PRIMARY KEYand failed onno such column: id— a fixture defect wearing the costume of the bug, caught because the error was the wrong one.75 tests pass across the index and init suites;
artifact:verifypasses against the regenerated manifest.Still open on #774
The message. It names a SQLite column rather than the situation, and advises
commitlore init— which runs the command that was failing. Both are the shape #746 fixed elsewhere, and neither is addressed here.Limit (on the commit): this recreates the file whenever the recorded version differs, so a downgrade discards an index a newer build wrote rather than reading what it can from it.