Skip to content

fix(selfhost): reconcile a stale AMS reporting export's schema on preserve-last-good - #5757

Merged
JSONbored merged 1 commit into
mainfrom
fix/ams-reporting-schema-drift-reconcile
Jul 14, 2026
Merged

fix(selfhost): reconcile a stale AMS reporting export's schema on preserve-last-good#5757
JSONbored merged 1 commit into
mainfrom
fix/ams-reporting-schema-drift-reconcile

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • Root-caused why the miner-usage Grafana dashboard hard-fails with "no such column: provider" on an engine-only self-host instance (no co-located miner): a genuine migration-drift bug in scripts/export-ams-reporting-db.sh, confirmed via git history -- PR fix(observability): avoid exposing live AMS ledgers #5471 first shipped this script with attempt_log_events' DDL missing provider/cost_usd/tokens_used; PR feat(miner): persist coding-agent provider + real cost on the attempt log #5637 added those columns to the DDL one day later.
  • An instance whose ledger source has never existed creates its one-and-only export under whichever DDL was current at that moment. export_ledger's "source missing, output already exists" fail-open path then preserves that output forever -- the fingerprint/SCRIPT_VERSION rebuild check is unreachable while the source stays absent, so the later DDL widening was invisible to such an instance permanently.
  • Fixed by reconciling the preserved output's schema against the current DDL's declared columns (ALTER TABLE ... ADD COLUMN) whenever a preserve-last-good path fires, mirroring packages/gittensory-miner/lib/attempt-log.js's own ensureOutcomeColumns pattern. Additive only -- existing rows and data are never touched; a genuinely-never-collected column is simply NULL for pre-existing rows.

Test plan

  • npx tsc --noEmit
  • npx tsx scripts/check-docs-drift.mjs
  • shellcheck scripts/export-ams-reporting-db.sh
  • New regression test: seeds a pre-feat(miner): persist coding-agent provider + real cost on the attempt log #5637-schema output file, runs the exporter with the source still missing, asserts the output's schema gets upgraded (columns added, NULL for the pre-existing row) rather than staying frozen -- verified this test fails without the fix (reverted the fix locally, confirmed the exact failure), and passes with it
  • Full existing selfhost-ams-reporting.test.ts suite green (10/10)

…serve-last-good

An instance whose ams-attempt-log source has never existed (an engine-only
deployment with no co-located miner) creates its one-and-only export under
whichever DDL was current at that moment, then export_ledger's "source
missing, output already exists" fail-open path preserves it forever --
the fingerprint/SCRIPT_VERSION rebuild check is unreachable while the
source stays absent, so a later DDL widening (PR #5637 added
provider/cost_usd/tokens_used to attempt_log_events a day after PR #5471
first shipped this script) was previously invisible to such an instance
permanently. Every miner-usage.json panel selecting those columns then
hard-fails with "no such column" instead of just showing empty. Fixed by
reconciling the preserved output's schema against the current DDL's
declared columns (ALTER TABLE ADD COLUMN, mirroring
packages/gittensory-miner/lib/attempt-log.js's own ensureOutcomeColumns
pattern) whenever a preserve-last-good path fires -- additive only, so
existing rows and their data are never touched.
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.07%. Comparing base (12958f4) to head (6ece872).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5757   +/-   ##
=======================================
  Coverage   95.07%   95.07%           
=======================================
  Files         581      581           
  Lines       46181    46181           
  Branches    14811    14811           
=======================================
  Hits        43905    43905           
  Misses       1516     1516           
  Partials      760      760           
Flag Coverage Δ
shard-1 43.96% <ø> (ø)
shard-2 35.71% <ø> (ø)
shard-3 32.27% <ø> (ø)
shard-4 33.56% <ø> (ø)
shard-5 31.18% <ø> (+<0.01%) ⬆️
shard-6 44.64% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored JSONbored self-assigned this Jul 14, 2026
@JSONbored
JSONbored merged commit c3d07a3 into main Jul 14, 2026
17 checks passed
@JSONbored
JSONbored deleted the fix/ams-reporting-schema-drift-reconcile branch July 14, 2026 11:53
@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant