Skip to content

fix(gain): suggest repair for missing tracking tables - #5300

Open
remote-controlled-man wants to merge 2 commits into
rtk-ai:developfrom
remote-controlled-man:codex/prflow-7890947c3811
Open

remote-controlled-man wants to merge 2 commits into
rtk-ai:developfrom
remote-controlled-man:codex/prflow-7890947c3811

Conversation

@remote-controlled-man

@remote-controlled-man remote-controlled-man commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3685

Summary

  • Show the existing rtk init recovery hint when a fatal tracking query in a static gain report fails because a table is missing, preserving the SQLite error and exit status.
  • Cover summaries, history, period/JSON exports and attribution views at source-known tracking query results. Telemetry stays silent, discover keeps its existing warnings, and recall errors keep their own database label.
  • Preserve migration-failure explanations and the existing fallback for optional reads and interactive dashboard refreshes.

Test plan

  • cargo fmt --all --check and cargo fmt --manifest-path proxy/Cargo.toml --all --check.
  • cargo clippy --workspace --all-targets.
  • cargo test --all: 5905 passed, 0 failed, 9 ignored. The telemetry subprocess fixture is explicitly executed by its passing parent test.
  • Real CLI regressions and existing migration/hook controls: 32 passed. With engine_attribution missing, rtk gain --by-layer --format json exits 1 with exactly one repair hint and plain rtk gain succeeds without the hint.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 16:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@TechWizard9999 TechWizard9999 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. The root cause in #3685 is right: warn_if_missing_table was only wired into the write paths, so a dropped table made rtk gain fail with a bare no such table error. Wrapping the report reads with inspect_err keeps the error and the exit status, and on a real build rtk gain, --history, --format json and -p with commands dropped now print the hint once and exit 1.

Two things before merge. Both are test gaps: a mutation survives the suite.

  1. The --by-layer --format json hint is untested (src/analytics/gain.rs:111). It is the first read in attribution_json when only --by-layer is set, so removing that wrap brings back the bare error for rtk gain --by-layer --format json with engine_attribution dropped, and every test still passes. The loop in gain_explains_missing_attribution_data_in_each_report covers --by-layer as text and --by-method --format json only. Fix: add &["--by-layer", "--format", "json"] to it.
  2. The kept fallback is unpinned. The description says optional reads keep their fallback. On this head, rtk gain with engine_attribution dropped is silent and exits 0, because print_efficiency_ledger (gain.rs:1224) still uses unwrap_or_default(). Making that read print the hint (it then prints it three times) passes every test. Fix: one row with engine_attribution dropped asserting that plain rtk gain succeeds with no Run \rtk init`` on stderr.

Smaller, optional (not every suggestion needs acting on):

  • 15 of the wraps can never fire, because an earlier wrapped read of the same table always fails first:

    • :323, :346, :366, :395 (after :290);
    • :461, :474 (after :458);
    • :1146, :1640, :1647, :1654 (after :763);
    • :1706, :1722, :1727, :1732 (after :1698);
    • :1709 (after :1703).

    Plain ? there is enough. Each of them is a mutation no test can kill. For the same reason, the --history / --daily / --weekly / --monthly rows in the first loop all stop at the summary read (:763).

  • missing_tracking_tables_keep_telemetry_reads_silent and its fixture (telemetry.rs:898-942) pass with every production line of this PR reverted, since no telemetry code changed. Dropping them saves the subprocess re-run and 46 lines.

cc @KuSh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tracking: warn_if_missing_table's self-heal hint isn't wired into rtk gain's read paths

3 participants