DB grounding verdict + db-doctor/db-sync (#94)#113
Conversation
In a checkout, nothing told a session whether the resolved ros-help.db matched the code querying it. Dev mode serves the git-ignored repo-root DB, and checkDbFreshness intentionally ignores release-tag drift in dev mode — so a schema-matching, wrong-corpus DB (a corpus whose PRAGMA user_version was bumped in place over stale data) started up silently and invalidated grounded work. Add a pure classifier (classifyDbGrounding, paths.ts) shared by three surfaces: - routeros_stats gains a `provenance` block + grounding verdict (ok / schema_mismatch / internal_inconsistent / tag_behind / unstamped); the TUI stats screen inherits it via shared getDbStats. - MCP dev-mode startup emits a loud, non-fatal banner on a non-ok verdict (never fetches — a contributor's local build is never clobbered). - `make db-doctor` / `bun run db:doctor` prints the verdict, non-zero on drift (CI/pre-commit ready). The load-bearing new signal is `internal_inconsistent` (db_meta.schema_version != PRAGMA user_version), which every prior check missed. `make db-sync` / `bun run db:sync` fetches the grounding source of truth — the newest CI release DB that matches this checkout's schema. It uses `gh` to find the newest release shipping the DB asset, prereleases included, rather than `--refresh` (which pins to package.json's CI-placeholder version, then falls back to /releases/latest — the newest *stable*, an older schema). Reuses the hardened downloadDb() via a new urlsOverride param (lock + schema/content validation + stale-sidecar cleanup + atomic swap). Also fixes same-class stale hardcodes (doc_export, the "317 pages / Confluence" text in the routeros_stats description). Durable guidance in .github/instructions/local-db-grounding.instructions.md; V-db-grounding row in VALIDATION.md. Closes #94 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds database provenance and grounding classification, exposes verdicts through runtime stats and MCP warnings, and introduces ChangesDatabase grounding
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)Database synchronizationsequenceDiagram
participant db-sync
participant GitHub
participant downloadDb
participant ros-help.db
db-sync->>GitHub: Query newest release asset
GitHub-->>db-sync: Return ros-help.db.gz URL
db-sync->>downloadDb: Download with urlsOverride
downloadDb->>ros-help.db: Validate and atomically replace
MCP grounding verificationsequenceDiagram
participant MCP
participant probeDb
participant classifyDbGrounding
MCP->>probeDb: Read database metadata
MCP->>classifyDbGrounding: Evaluate schema and provenance
classifyDbGrounding-->>MCP: Return grounding verdict
MCP-->>MCP: Log warning when verdict is not ok
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR adds a shared “DB grounding” classifier and surfaces DB provenance/grounding status across the MCP server, TUI stats, and new local tooling (db-doctor, db-sync) to prevent silently grounding work on a schema-coherent but wrong-corpus ros-help.db in dev checkouts.
Changes:
- Introduces
classifyDbGrounding(pure) and threads its verdict intogetDbStats/routeros_stats, plus a dev-only MCP startup warning banner. - Adds
make db-doctor/bun run db:doctor(verdict + non-zero exit on drift) andmake db-sync/bun run db:sync(fetch newest release DB asset viagh, prereleases included) with supporting docs/tests. - Updates documentation and validation/CI anchors (VALIDATION row, MANUAL/CLAUDE pointers, CHANGELOG entry, new instruction file).
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| VALIDATION.md | Adds V-db-grounding coverage and where it’s validated. |
| src/setup.ts | Extends DB probing to read additional db_meta provenance and adds downloadDb URL override. |
| src/setup.test.ts | Adapts checkDbFreshness tests to the expanded probe shape. |
| src/release.test.ts | Asserts package/Makefile wiring for db:doctor/db:sync and db-sync’s intended behavior. |
| src/query.test.ts | Verifies getDbStats() exposes provenance + grounding verdict. |
| src/paths.ts | Adds grounding classifier + version-base comparison helpers and isDevInvocation. |
| src/paths.test.ts | New unit tests for grounding verdict precedence and edge cases. |
| src/mcp.ts | Emits a dev-only grounding warning banner; updates routeros_stats description to reference provenance instead of hardcoded corpus facts. |
| src/db.ts | Adds provenance block to stats; derives doc_export display from provenance instead of hardcoding. |
| scripts/db-sync.ts | New script to discover newest release DB asset via gh and install it via downloadDb(urlsOverride). |
| scripts/db-doctor.ts | New script to print provenance + grounding verdict and exit non-zero when not ok. |
| package.json | Adds db:doctor and db:sync scripts. |
| MANUAL.md | Documents dev-checkout grounding rules and the new commands. |
| Makefile | Adds db-doctor and db-sync targets. |
| CLAUDE.md | Adds a quick pointer for grounding verification. |
| CHANGELOG.md | Adds an Unreleased entry describing the new grounding/provenance/tooling behavior. |
| .github/instructions/local-db-grounding.instructions.md | New durable rule doc for local DB grounding expectations and invariants. |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/setup.ts (1)
422-458: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winPreserve the explicit sync target during lock contention.
When
urlsOverrideis supplied, Lines 429-442 can return an arbitrary usable database before the override is evaluated.db-synccan therefore report success without installing its selected release. In override mode, reacquire the lock and perform the requested download, or verify that the reused probe matches the expected release.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/setup.ts` around lines 422 - 458, Update downloadDb so urlsOverride takes precedence over reuse paths after lock contention: do not return an arbitrary usable database from waitForUsableDb or the fallback probe when an override is supplied. Reacquire the lock and continue to the requested download, or only reuse a probe after verifying it matches the explicit target; preserve existing reuse behavior when urlsOverride is absent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/instructions/local-db-grounding.instructions.md:
- Around line 1-4: Update the frontmatter applyTo field in
local-db-grounding.instructions.md from a comma-separated string to a YAML array
containing each target path pattern, preserving all existing entries.
In `@src/db.ts`:
- Around line 1115-1119: Update the doc_export fallback derived from provenance
so artifacts identified by release_tag/source_commit or is_ci_artifact are
labeled as having an unknown build time rather than “(unstamped local build)”;
retain the existing stamped format when built_at exists and reserve the
local-build fallback for genuinely unstamped metadata.
In `@src/paths.ts`:
- Around line 241-249: Update the version-validation branch around
compareBaseVersion in the release-tag verdict flow so a null comparison returns
an appropriate non-OK verdict instead of falling through to "ok"; preserve the
existing tag_behind behavior for parsed older versions, and add a regression
test covering malformed release_tag or unknown codeVersion inputs.
---
Outside diff comments:
In `@src/setup.ts`:
- Around line 422-458: Update downloadDb so urlsOverride takes precedence over
reuse paths after lock contention: do not return an arbitrary usable database
from waitForUsableDb or the fallback probe when an override is supplied.
Reacquire the lock and continue to the requested download, or only reuse a probe
after verifying it matches the explicit target; preserve existing reuse behavior
when urlsOverride is absent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 77e3033d-a72e-496e-abda-8063b9271320
📒 Files selected for processing (17)
.github/instructions/local-db-grounding.instructions.mdCHANGELOG.mdCLAUDE.mdMANUAL.mdMakefileVALIDATION.mdpackage.jsonscripts/db-doctor.tsscripts/db-sync.tssrc/db.tssrc/mcp.tssrc/paths.test.tssrc/paths.tssrc/query.test.tssrc/release.test.tssrc/setup.test.tssrc/setup.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
- GitHub Check: copilot-pull-request-reviewer
🧰 Additional context used
📓 Path-based instructions (7)
*
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Keep this Copilot instructions file short; put substantive rules in narrow instruction files under
.github/instructions/*.instructions.md.
Files:
VALIDATION.mdCLAUDE.mdpackage.jsonMANUAL.mdMakefileCHANGELOG.md
*.md
📄 CodeRabbit inference engine (CLAUDE.md)
*.md: Keep each project document in its canonical location and role; do not invent new top-level Markdown files or duplicate content across documents.
Record durable project rationale inDESIGN.md, operator or release procedures inMANUAL.md, user-visible shipped changes inCHANGELOG.md, and load-bearing invariants plus their proofs inVALIDATION.md.
Avoid ticket sprawl: treat an issue as discussion initially, and apply theagent-readylabel only after acceptance criteria are settled rather than by default.
Files:
VALIDATION.mdCLAUDE.mdMANUAL.mdCHANGELOG.md
CLAUDE.md
📄 CodeRabbit inference engine (AGENTS.md)
Read
CLAUDE.mdbefore non-trivial work; it is the repository routing index.
Files:
CLAUDE.md
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use Bun and TypeScript, including Bun-native runtime APIs such as
bun:sqlite,Bun.serve, andbunx.Rosetta uses Bun and TypeScript; prefer
bunandbun testrather than Node/npm-oriented substitutes.
Files:
src/paths.test.tsscripts/db-doctor.tssrc/release.test.tssrc/query.test.tssrc/db.tssrc/setup.test.tsscripts/db-sync.tssrc/paths.tssrc/mcp.tssrc/setup.ts
{README.md,src/setup.ts,MANUAL.md}
📄 CodeRabbit inference engine (AGENTS.md)
Keep public client setup snippets aligned across
README.md,src/setup.ts, andMANUAL.md, including the Codex commandcodex mcp add rosetta -- bunx@tikoci/rosetta``.
Files:
MANUAL.mdsrc/setup.ts
.github/instructions/*.instructions.md
📄 CodeRabbit inference engine (AGENTS.md)
Manually read the matching
.github/instructions/*.instructions.mdfiles because Codex does not automatically apply Copilot’sapplyToselection.Keep narrow normative coding rules in
.github/instructions/*.instructions.md, and route them using theirapplyToscopes.
Files:
.github/instructions/local-db-grounding.instructions.md
src/{query,mcp,browse}.ts
📄 CodeRabbit inference engine (AGENTS.md)
Route MCP, query, classifier, TUI, and canonicalizer behavior through shared core code, usually
src/query.ts; keepsrc/mcp.tsandsrc/browse.tsthin adapters.
Files:
src/mcp.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
Repo: tikoci/rosetta
Timestamp: 2026-07-17T17:56:42.525Z
Learning: Committed codebase work belongs in a GitHub issue, grounded research and decision support in a briefing, durable rationale in `DESIGN.md`, procedures in `MANUAL.md`, shipped behavior in `CHANGELOG.md`, and invariants with proof in `VALIDATION.md`.
Learnt from: CR
Repo: tikoci/rosetta
Timestamp: 2026-07-17T17:56:42.525Z
Learning: Before changing extraction, MCP, or TUI search in response to the MikroTik manual-site migration, read `DESIGN.md` and `briefings/B-0012-docusaurus-manual-migration.md`.
Learnt from: CR
Repo: tikoci/rosetta
Timestamp: 2026-07-17T17:56:42.525Z
Learning: Before claiming a PR is mergeable or Ready for Review, run the `pr-review-gate` skill; green checks and `reviewDecision` do not override unresolved bot threads blocking `main`.
Learnt from: CR
Repo: tikoci/rosetta
Timestamp: 2026-07-17T17:56:42.525Z
Learning: Do not trust the checkout's root `ros-help.db` for grounding claims until it is verified with `make db-doctor`; use `make db-sync` to fetch the latest CI release database when needed.
🪛 LanguageTool
CLAUDE.md
[uncategorized] ~64-~64: The official name of this software platform is spelled with a capital “H”.
Context: ...DB (the grounding source of truth). See `.github/instructions/local-db-grounding.instruc...
(GITHUB)
MANUAL.md
[uncategorized] ~126-~126: The official name of this software platform is spelled with a capital “H”.
Context: ...'s local build is never clobbered). See `.github/instructions/local-db-grounding.instruc...
(GITHUB)
🔇 Additional comments (17)
scripts/db-doctor.ts (1)
1-60: LGTM!scripts/db-sync.ts (1)
1-71: LGTM!package.json (1)
25-27: LGTM!Makefile (1)
14-14: LGTM!Also applies to: 25-40
src/release.test.ts (1)
106-137: LGTM!src/setup.test.ts (1)
269-307: LGTM!.github/instructions/local-db-grounding.instructions.md (1)
5-59: LGTM!CHANGELOG.md (1)
27-28: LGTM!CLAUDE.md (1)
64-64: LGTM!MANUAL.md (1)
118-127: LGTM!VALIDATION.md (1)
30-30: LGTM!src/paths.ts (1)
83-88: LGTM!src/paths.test.ts (1)
1-112: LGTM!src/setup.ts (1)
45-54: LGTM!Also applies to: 166-199
src/db.ts (1)
41-41: LGTM!Also applies to: 1033-1069
src/mcp.ts (1)
74-74: LGTM!Also applies to: 168-191, 941-956
src/query.test.ts (1)
2160-2173: LGTM!
…describing doc_export Addresses PR #113 bot review threads: - setup.ts: probeDb reads db_meta via a parameterized statement (? bind) instead of interpolating the key into SQL (Copilot). - paths.ts: classifyDbGrounding no longer falls through to "ok" when compareBaseVersion returns null (unparseable release_tag / unknown code version) — an unverifiable version is not a grounded one. Adds regression tests (CodeRabbit, Major). - db.ts + browse.ts: doc_export is now self-describing ("DB built <ts>"), distinguishes a stamped artifact missing only built_at ("DB build time unknown") from a genuinely unstamped local build, and the TUI label is "Provenance:" not "Export:" (Copilot + CodeRabbit). - mcp.ts: dev-mode banner points to MANUAL.md's "Local DB grounding" section instead of a bare instructions filename (Copilot). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codex review/POVI’d request changes before merging PR #113. The core direction is strong, but the trust verdict and sync path still have false-success cases—exactly the kind Findings
The strongest parts are the internal_inconsistent detection, the routeros_stats provenance block, agent-readable tool description, dev startup warning, and Validation: 418 targeted tests passed, typecheck and Biome passed, all review threads are resolved, and GitHub currently reports mergeStateStatus: CLEAN. Those |
Addresses the Codex POV review on PR #113: P1 #1 — db-sync could report success without installing its selected release. downloadDb's lock-contention path reused any schema-compatible DB before honoring urlsOverride. When an explicit override is passed (db-sync), it now skips the reuse shortcut, waits for the lock to release, re-acquires it, and downloads the requested release. P1 #2 — "newest release matching this checkout's schema" is now actually implemented. db-sync passes the whole ordered candidate list (newest first) to downloadDb, which validates each schema and walks down to the newest release that matches — so an older checkout still resolves a compatible DB below a newer, higher-schema release. P1 #3 — incomplete provenance no longer produces grounding ok. New `provenance_incomplete` status: a DB claiming release identity but missing any of the four CI stamps (release_tag/source_commit/built_at/ schema_version), or a stamped-but-unparseable version, now fails closed. built_at is thus load-bearing, not informational. P2 #4 — "ok" is described as schema/release-compatible, not "matches the code": softened the routeros_stats description + verdict docs; noted a release DB is built from an ancestor commit. P2 #5 — the TUI stats screen now renders the grounding verdict line, so the "TUI inherits the verdict" claim holds. Tests: paths.test.ts gains provenance_incomplete cases; db-sync anchor asserts the ordered-list handoff; query.test.ts provenance test is now db_meta-deterministic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks — this was a sharp review; all five addressed in d5e9bd9. P1 #1 — db-sync false success under lock contention. P1 #2 — "newest matching this checkout's schema" now implemented. P1 #3 — incomplete provenance no longer grounds. New P2 #4 — "ok" wording. Reframed as schema/release-compatible with this build (coherent schema, complete provenance, release not behind) — explicitly not proof the DB was built from the exact checked-out commit (a release DB is built from an ancestor; db-doctor reports that commit for inspection). Updated in the P2 #5 — TUI verdict. The browse Gate after the fix: |
Codex re-reviewYes—I agree with the fixes. I found no remaining blocking issue on head d5e9bd9. All five findings are addressed:
Validation is clean:
One non-blocking test gap remains: the lock-contention override and multi-candidate schema fallback are asserted structurally, not exercised as behavioral CodeRabbit skipped an incremental rereview because that feature is disabled, but the existing threads are resolved and I independently checked the new diff. |
Problem
In a checkout, nothing told a session whether the resolved
ros-help.dbmatched the code querying it (#94). Dev mode serves the git-ignored repo-root DB, andcheckDbFreshnessintentionally ignores release-tag drift in dev mode (so it never clobbers a contributor's local build) — which means a schema-matching but wrong-corpus DB starts up silently and invalidates grounded work.Confirmed live: the repo-root DB was a "Frankenstein" —
db_metasaidv0.10.0/schema 5/321 Confluence pages, butPRAGMA user_version=10(an in-placeinitDbbumped it). Nothing flagged it.What this adds
A pure classifier —
classifyDbGrounding(src/paths.ts) — shared by three surfaces so they stay in lockstep:routeros_statsgains aprovenanceblock + grounding verdict (ok/schema_mismatch/internal_inconsistent/tag_behind/unstamped). One call self-checks the DB against the checkout. The browse TUIstatsscreen inherits it via sharedgetDbStats.okverdict — never fetches, so a contributor's local build is never clobbered.make db-doctor/bun run db:doctorprints the verdict and exits non-zero on drift (CI / pre-commit ready).The load-bearing new signal is
internal_inconsistent(db_meta.schema_version≠PRAGMA user_version) — the "Frankenstein" tell that every prior check missed.make db-sync(the grounding source of truth)make db-sync/bun run db:syncfetches the newest CI release DB that matches this checkout's schema. It usesghto find the newest release shippingros-help.db.gz— prereleases included — rather than--refresh, which pins the URL topackage.json's CI-placeholder version (v0.11.0-rc.0, no such release) and falls back to/releases/latest(the newest stable, an older schema). Reuses the hardeneddownloadDb()(lock + schema/content validation + stale-sidecar cleanup + atomic swap) via a new backward-compatibleurlsOverrideparam, so it's safe to run while an MCP server holds the old file open.Also
doc_exportand the "317 pages / March 2026 Confluence" text baked into therouteros_statsdescription now defer to the liveprovenanceblock..github/instructions/local-db-grounding.instructions.md;V-db-groundingrow inVALIDATION.md; CLAUDE.md pointer, MANUAL.md section, CHANGELOG entry.Verification
db-doctorflags the pre-sync Frankenstein asinternal_inconsistent(exit 1) and the synced CI artifact asok(exit 0). ✅ ran livemake db-syncinstallsv0.11.0-rc.102(schema 10, 363 pages) into the repo-root path. ✅ ran livebun test(914 pass, +new classifier / provenance / tooling-anchor tests),bun run typecheck,bun run lint, markdownlint, cspell — all green. ✅Closes #94
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
Tests