-
Notifications
You must be signed in to change notification settings - Fork 3
DB grounding verdict + db-doctor/db-sync (#94) #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| description: "In a checkout, the resolved ros-help.db is untrusted until verified; the latest CI release DB is the grounding source of truth." | ||
| applyTo: "src/paths.ts, src/setup.ts, src/mcp.ts, scripts/db-doctor.ts, Makefile, MANUAL.md, VALIDATION.md" | ||
| --- | ||
| # Local DB grounding | ||
|
|
||
| Dev mode (`resolveDbPath` → project root) serves the repo-root `ros-help.db` — a | ||
| git-ignored file whose contents are arbitrary local state. **It is not trusted by | ||
| default.** Before grounding any claim about shipped data on it, verify it. | ||
|
|
||
| ## The rule | ||
|
|
||
| - **The latest CI-built release DB is the source of truth for grounding claims.** | ||
| It is what `bunx @tikoci/rosetta` consumers actually get. `make db-sync` | ||
| (`scripts/db-sync.ts`) fetches it into the resolved path (atomic replace — safe | ||
| while an MCP server holds the old file open). | ||
| - It does **not** use `--refresh`: that pins the URL to `package.json`'s | ||
| version, which in a checkout is a CI-rewritten placeholder (`v0.11.0-rc.0`) | ||
| with no release, and falls back to `/releases/latest` — the newest *stable*, | ||
| which lags the prerelease schema. `db-sync` instead uses `gh` to find the | ||
| newest release (prereleases **included**) that actually ships | ||
| `ros-help.db.gz`, then reuses the hardened `downloadDb()` (schema/content | ||
| validation + stale-sidecar cleanup + atomic swap) via its `urlsOverride` | ||
| param. Requires the `gh` CLI. Keep it this way. | ||
| - **`make extract` produces an *unstamped* local working DB** — for extraction | ||
| and pipeline work, not for claims about shipped data. `db-doctor` reports it as | ||
| `unstamped`; that is expected, not a failure to "fix" by re-extracting. | ||
| - **Verify before trusting.** `make db-doctor` (or `bun run db:doctor`) prints the | ||
| resolved path + `db_meta` provenance + a grounding verdict and exits non-zero | ||
| when not `ok`. In-session, one `routeros_stats` call returns the same | ||
| `provenance.grounding` block — prefer it over shelling into sqlite. | ||
|
|
||
| ## The verdict (`classifyDbGrounding`, `src/paths.ts`) | ||
|
|
||
| Pure function, shared by `routeros_stats` (`getDbStats`), MCP startup, and | ||
| `db-doctor`. Status precedence: | ||
|
|
||
| | status | meaning | typical fix | | ||
| |---|---|---| | ||
| | `schema_mismatch` | `PRAGMA user_version` ≠ code `SCHEMA_VERSION` | `make db-sync` | | ||
| | `internal_inconsistent` | `db_meta.schema_version` ≠ pragma — a corpus bumped in place by `initDb()`; provenance no longer describes the bytes (the #94 "Frankenstein") | `make db-sync` | | ||
| | `unstamped` | neither `release_tag` nor `source_commit` — a local `make extract` build | fine for extraction; `make db-sync` to ground | | ||
| | `provenance_incomplete` | claims release identity but is missing one of the four CI stamps (`release_tag`/`source_commit`/`built_at`/`schema_version`), or a stamped version that won't parse — fail closed | `make db-sync` | | ||
| | `tag_behind` | `release_tag` base version behind the checkout | `make db-sync` | | ||
| | `ok` | all four stamps present, schema coherent, tag current | — | | ||
|
|
||
| `ok` means the DB is **schema/release-compatible** with this build (coherent schema, complete provenance, release not behind) — not proof it was built from the exact checked-out commit. A release DB is legitimately built from an ancestor commit; `db-doctor` reports that source commit for inspection. | ||
|
|
||
| The rc/beta counter is intentionally ignored — a dev checkout's `package.json` | ||
| routinely reads `-rc.0` while the correct published DB is a much higher rc. Only | ||
| the `MAJOR.MINOR.PATCH` base is a staleness axis. | ||
|
|
||
| ## Startup behavior | ||
|
|
||
| In dev mode, MCP startup emits a **loud but non-fatal** banner when the verdict | ||
| is not `ok` (never fetches — a contributor's local build must not be clobbered). | ||
| `checkDbFreshness` still hard-fails a genuine schema mismatch and auto-redownloads | ||
| in package/compiled mode; this warning is purely additive surfacing. | ||
|
|
||
| Keep the classifier, its three consumers, and this file in sync when the verdict | ||
| shape or `db_meta` key set changes. Cross-reference: `db-meta-stamping.instructions.md`. | ||
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/usr/bin/env bun | ||
|
|
||
| /** | ||
| * db-doctor.ts — report whether the resolved ros-help.db can be trusted to | ||
| * ground claims about this checkout (#94). | ||
| * | ||
| * Resolves the DB exactly as the MCP server would (DB_PATH / --db / auto-detect), | ||
| * reads its db_meta provenance, and prints a grounding verdict. Exits non-zero | ||
| * when the verdict is not "ok", so it doubles as a CI/pre-commit gate. | ||
| * | ||
| * Usage: | ||
| * bun run scripts/db-doctor.ts # resolved DB (dev: repo-root ros-help.db) | ||
| * DB_PATH=/path/to/ros-help.db bun run scripts/db-doctor.ts | ||
| * | ||
| * Fix a stale/mismatched DB with `make db-sync` (fetches the latest CI release DB). | ||
| */ | ||
|
|
||
| import { classifyDbGrounding, detectMode, resolveDbPath, resolveVersion, SCHEMA_VERSION } from "../src/paths.ts"; | ||
| import { probeDb } from "../src/setup.ts"; | ||
|
|
||
| const dbPath = resolveDbPath(import.meta.dirname); | ||
| const mode = detectMode(import.meta.dirname); | ||
| const codeVersion = resolveVersion(import.meta.dirname); | ||
|
|
||
| console.log(`rosetta db-doctor`); | ||
| console.log(` code : v${codeVersion} (schema v${SCHEMA_VERSION}, mode ${mode})`); | ||
| console.log(` resolved DB : ${dbPath}`); | ||
|
|
||
| const p = probeDb(dbPath); | ||
| if (!p) { | ||
| console.log(` status : NO_DB — no readable SQLite database at the resolved path.`); | ||
| console.log(` fix : run 'make db-sync' to fetch the latest CI release DB.`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const verdict = classifyDbGrounding({ | ||
| pragmaSchema: p.schemaVersion, | ||
| metaSchema: p.metaSchemaVersion, | ||
| releaseTag: p.releaseTag, | ||
| builtAt: p.builtAt, | ||
| sourceCommit: p.sourceCommit, | ||
| codeSchema: SCHEMA_VERSION, | ||
| codeVersion, | ||
| mode, | ||
| }); | ||
|
|
||
| console.log(` release_tag : ${p.releaseTag ?? "(unstamped)"}`); | ||
| console.log(` source_commit: ${p.sourceCommit ?? "(unstamped)"}`); | ||
| console.log(` built_at : ${p.builtAt ?? "(unstamped)"}`); | ||
| console.log(` schema : pragma=${p.schemaVersion} meta=${p.metaSchemaVersion ?? "—"} code=${SCHEMA_VERSION}`); | ||
| console.log(` pages : ${p.pages} commands: ${p.commands}`); | ||
| console.log(` status : ${verdict.status.toUpperCase()}`); | ||
| console.log(` detail : ${verdict.detail}`); | ||
|
|
||
| if (!verdict.ok) { | ||
| console.log(` fix : run 'make db-sync' to fetch the latest CI release DB for grounding.`); | ||
| process.exit(1); | ||
| } | ||
| process.exit(0); |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.