Skip to content

fix(miner): policy-doc-cache.js missing from doctor's storeIntegrityChecks and migrate's STORES lists #7238

Description

@JSONbored

Context

packages/loopover-miner/lib/status.js's storeIntegrityChecks function carries this comment directly
above its store list:

/** Per-store `PRAGMA integrity_check` sweep for `doctor` (#4834) — flags a corrupted store instead of probing
 *  only one with `SELECT 1`. A store file that does not exist yet is healthy by absence. Keep in sync with
 *  migrate-cli.js's `STORES` list (#6768): every durable local SQLite store using resolveLocalStoreDbPath. */
function storeIntegrityChecks(env) {
  const stores = [
    ["event-ledger", resolveEventLedgerDbPath(env)],
    ["governor-ledger", resolveGovernorLedgerDbPath(env)],
    ["prediction-ledger", resolvePredictionLedgerDbPath(env)],
    ["portfolio-queue", resolvePortfolioQueueDbPath(env)],
    ["claim-ledger", resolveClaimLedgerDbPath(env)],
    ["run-state", resolveRunStateDbPath(env)],
    ["plan-store", resolvePlanStoreDbPath(env)],
    ["governor-state", resolveGovernorStateDbPath(env)],
    ["attempt-log", resolveAttemptLogDbPath(env)],
    ["replay-snapshot", resolveReplaySnapshotDbPath(env)],
    ["worktree-allocator", resolveWorktreeAllocatorDbPath(env)],
    ["contribution-profile", resolveContributionProfileCacheDbPath(env)],
    ["policy-verdict-cache", resolvePolicyVerdictCacheDbPath(env)],
  ];
  ...

packages/loopover-miner/lib/migrate-cli.js's STORES array (its #6768-referenced counterpart, required
to stay "in sync") lists the exact same 13 stores.

packages/loopover-miner/lib/policy-doc-cache.js (#4842, the local ETag cache for
AI-USAGE.md/CONTRIBUTING.md policy-doc fetches, distinct from policy-verdict-cache.js) is not in
either list
, despite matching the stated inclusion criterion exactly:

// lib/policy-doc-cache.js
import { normalizeLocalStoreDbPath, openLocalStoreDb, resolveLocalStoreDbPath } from "./local-store.js";
...
export function resolvePolicyDocCacheDbPath(env = process.env) {
  return resolveLocalStoreDbPath(defaultDbFileName, "LOOPOVER_MINER_POLICY_DOC_CACHE_DB", env);
}
...
export function initPolicyDocCacheStore(dbPath = resolvePolicyDocCacheDbPath()) {
  const resolvedPath = normalizeDbPath(dbPath);
  const db = openLocalStoreDb(resolvedPath);
  ...

It is a real, durable, per-machine SQLite file (policy-doc-cache.sqlite3) created via the same
resolveLocalStoreDbPath/openLocalStoreDb helpers from local-store.js that every listed store uses, and
it is opened for real by discover-cli.js's runDiscover in the exact same way the other listed stores are.

This is not a re-tread of #6987 ("policy_verdict_cache missing from purge/status/migrate 'known local
stores' lists", closed) — that issue was about the separate policy-verdict-cache.js store (#4843), which
is already present in both lists (see "policy-verdict-cache" above). policy-doc-cache.js is a
different file/store that #6987's fix never added, and it was also not one of the "four real local stores"
#6768 originally added.

Practical effect: loopover-miner doctor's per-store PRAGMA integrity_check sweep never checks
policy-doc-cache.sqlite3 for corruption, and loopover-miner migrate's proactive sweep never brings an
existing policy-doc-cache.sqlite3 file's schema up to date — an operator relying on either command to
cover "every durable local store" silently misses this one.

Requirements

  • In packages/loopover-miner/lib/status.js: import resolvePolicyDocCacheDbPath from
    ./policy-doc-cache.js (alongside the existing import { resolvePolicyVerdictCacheDbPath } from "./policy-verdict-cache.js"), and add ["policy-doc-cache", resolvePolicyDocCacheDbPath(env)] to the
    stores array inside storeIntegrityChecks.
  • In packages/loopover-miner/lib/migrate-cli.js: import initPolicyDocCacheStore, resolvePolicyDocCacheDbPath from ./policy-doc-cache.js (alongside the existing policy-verdict-cache.js
    import), and add { name: "policy-doc-cache", resolveDbPath: resolvePolicyDocCacheDbPath, open: initPolicyDocCacheStore } to the STORES array.
  • Do not reorder or modify any of the existing 13 entries in either list — this is strictly an addition.
  • The entry's name string must be exactly "policy-doc-cache" (matching the existing naming convention of
    hyphenated, lowercase store names already used for every other entry, and distinct from the existing
    "policy-verdict-cache" entry so the two are never conflated in doctor/migrate output).

Deliverables

  • packages/loopover-miner/lib/status.js's storeIntegrityChecks includes a "policy-doc-cache" entry
    pointing at resolvePolicyDocCacheDbPath(env).
  • packages/loopover-miner/lib/migrate-cli.js's STORES includes a "policy-doc-cache" entry using
    resolvePolicyDocCacheDbPath/initPolicyDocCacheStore.
  • A regression test asserting loopover-miner doctor --json's output contains a
    store-integrity:policy-doc-cache check result, and a regression test asserting loopover-miner migrate --json's output contains a "policy-doc-cache" entry in stores (both mirroring this
    package's existing tests for the "policy-verdict-cache" entry policy_verdict_cache missing from purge/status/migrate 'known local stores' lists #6987 added).

Test Coverage Requirements

This repo's Codecov patch gate (codecov/patch) enforces target: 99%, threshold: 0%, branch-counted, on
every changed line/branch under src/**/packages/** — both changed files are inside packages/** and are
gated. Add the two regression tests described above (one for doctor, one for migrate) so both new list
entries are exercised, not just visually present. Measure locally with npm run test:coverage (unsharded).

Expected Outcome

loopover-miner doctor and loopover-miner migrate both cover policy-doc-cache.sqlite3 the same way they
already cover the other 13 known local stores — a corrupted policy-doc-cache.sqlite3 file is flagged by
doctor's integrity sweep, and an existing one is proactively brought up to date by migrate, closing the
gap #6768's "keep in sync" comment intends to prevent.

Links & Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions