Skip to content

feat(tracking): record project_path on parse failures - #3227

Open
bharvey42 wants to merge 1 commit into
rtk-ai:developfrom
bharvey42:feat/telemetry-parse-failure-project-path
Open

bharvey42 wants to merge 1 commit into
rtk-ai:developfrom
bharvey42:feat/telemetry-parse-failure-project-path

Conversation

@bharvey42

@bharvey42 bharvey42 commented Jul 26, 2026 •

Copy link
Copy Markdown

Problem

commands has been stamped with the cwd since project-scoped stats landed, but parse_failures was not. A failure could therefore only be related to other telemetry by bare timestamp, which is ambiguous on a machine running concurrent sessions in different projects — so "which project do rtk's filters keep breaking in?" was not answerable from the data.

Changes

  • Add parse_failures.project_path TEXT DEFAULT '', stamped by record_parse_failure via the same current_project_path_string() helper record uses. Call sites are unchanged.
  • Add get_parse_failure_summary_filtered() and wire --project through rtk gain --failures, using the same exact-or-subdirectory GLOB scoping as the commands queries. The unscoped failure log now labels each recent row with its project directory, since that view spans several projects.
  • Index (project_path, timestamp) to match idx_project_path_timestamp.

Migration handling

The column is added in run_schema_migrations(), and SCHEMA_VERSION goes from 2 to 3. v1.0.0 already stamps databases with user_version 2, so without the bump Tracker::new()'s version gate would skip the new statement on every machine that has run 1.0. test_gated_open_migrates_v2_db_to_parse_failures_project_path opens a v2-stamped DB through the gated path to pin that (it fails with the version left at 2).

Existing rows take the column DEFAULT rather than NULL, so readers never have to tell "old row" from "unknown project".

Privacy

No new field is reported upstream: telemetry sends parse_failures_24h and projects_count, both counts, and no raw path leaves the machine.

Verification

Rebased onto develop 8157d4d (v1.0.0). cargo test --all --no-fail-fast on Windows: every target passes except two known Windows-environment failures in files this PR doesn't touch (find_cmd::run_from_args_propagates_find_exit_status and stream::test_read_lines_lossy_preserves_lines_after_invalid_utf8. Clippy is clean.

On a copy of a production history.db reshaped to v1.0's schema (user_version 2, no parse_failures.project_path): all 17653 existing rows migrate to '', user_version becomes 3, the index is created and 1.0's own tables are untouched.

@CLAassistant

CLAassistant commented Jul 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@bharvey42
bharvey42 force-pushed the feat/telemetry-parse-failure-project-path branch from 9a47b56 to 66690ca Compare September 1, 2026 09:13
@bharvey42
bharvey42 force-pushed the feat/telemetry-parse-failure-project-path branch from 66690ca to 62b4476 Compare September 15, 2026 04:01
@bharvey42

Copy link
Copy Markdown
Author

Rebased onto current develop (5e0f92c) — conflict-free again, and simplified in the process.

develop has since done the schema unification this PR originally carried: Tracker::new() and new_in_memory() both run one run_schema_migrations(), gated by SCHEMA_VERSION in Tracker::new(). So this branch no longer ships its own migrate_schema() helper. Instead:

  • the parse_failures.project_path column + idx_pf_project_path_timestamp index are added inside run_schema_migrations(), and
  • SCHEMA_VERSION is bumped 1 → 2 so existing databases actually pick the migration up on their next open (with the gate, a new ALTER TABLE without a bump would never run against an already-stamped DB).

Recording (record_parse_failure stamps cwd), the --project filter for rtk gain --failures, the ParseFailureRecord.project_path field, and the README are as before. The legacy-schema migration test now drives run_schema_migrations() directly (renamed to test_schema_migration_adds_parse_failures_project_path).

Full gate on Windows 11: fmt clean, clippy zero warnings, 3599 passed / 0 failed. The 3 remaining failures (find_cmd, stream, hook_cmd) reproduce identically on pristine develop under Windows — pre-existing, unrelated.

@bharvey42

Copy link
Copy Markdown
Author

Friendly ping: this one is still waiting on workflow approval. The fork-PR CI run for 8ec0ecb is sitting at action_required, so no checks have run yet.

Re-checked today against develop c356374:

  • Merges with no conflicts.
  • cargo fmt --all -- --check and cargo clippy --all-targets are clean.
  • cargo test --all: 3946 passed, 2 failed. The two failures are find_cmd::run_from_args_propagates_find_exit_status and stream::test_read_lines_lossy_preserves_lines_after_invalid_utf8. Both also fail on develop without this PR on Windows. (This was on the GNU toolchain, with fix(build): use the GNU linker's stack flag on *-pc-windows-gnu #3239's build.rs applied so the test binaries link.)
  • develop's SCHEMA_VERSION is still 1, so the bump to 2 here still lines up.

Happy to rebase onto current develop if a fresh head is easier to review.

@bharvey42
bharvey42 force-pushed the feat/telemetry-parse-failure-project-path branch 2 times, most recently from 5a306cd to b1a2d72 Compare October 14, 2026 02:47
@bharvey42

Copy link
Copy Markdown
Author

@KuSh, a gentle nudge on this one when you have a moment. It's small and self-contained (3 files, one commit), and it still merges cleanly onto today's develop (e05c7bd).

Re-checked today with this branch merged onto e05c7bd, on Windows x86_64-pc-windows-gnu: cargo test --all --no-fail-fast gives 4942 passed / 2 failed. The 2 failures are the known Windows baselines: #4610 (find_cmd) and #3730 (stream). Neither touches tracking. Both schema tests pass: test_schema_migration_adds_parse_failures_project_path and test_gated_open_migrates_v2_db_to_parse_failures_project_path.

One thing to watch whenever this is rebased: v1.0 took SCHEMA_VERSION = 2 for itself (classifier_cache + engine_attribution), so this PR's migration is 3. Git merges two sides' = 2 without a conflict. If the bump is lost in a rebase, a 1.0 database silently skips the migration. test_gated_open_migrates_v2_db_to_parse_failures_project_path covers that case: it fails at 2 and passes at 3.

The fork-PR CI run for b1a2d72 has been waiting on workflow approval since 10-14. Could someone approve it and take a look? If you'd rather it be sliced differently, or folded into something you already have open around tracking, I'm happy to do that.

@KuSh KuSh self-assigned this Nov 1, 2026
@bharvey42
bharvey42 force-pushed the feat/telemetry-parse-failure-project-path branch 2 times, most recently from 6bfebf8 to 0c46285 Compare November 15, 2026 11:00

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Round 1 — CHANGES REQUESTED

Claim: parse failures are stamped with the cwd, rtk gain --failures --project scopes them like rtk gain --project scopes savings, and existing DBs gain the column through a schema migration.
Scope: accept (round 1, frozen).
Ran:

  • Matrix: rtk's own fallback (rtk echo … recovered, rtk <missing> failed), recording into a scratch RTK_DB_PATH. 8 cwd cases: project root, subdirectory, sibling, symlink to the root, proj[1], proj1/sub, a project with no failures, a deleted cwd. Builds: merge-base 8157d4d, head b1a2d72, and that head merged onto develop 6c2313a. Also a DB upgraded from 1.0 and then written by 1.0 again, 12 failures under the 10-row window, and the first upgrading open with another connection holding the write lock for 3, 8 and 14 s.
  • On 0c46285 (the same patch, rebased): the 8 s lock run, the surviving mutations, and fmt/clippy/tests. It no longer applies to develop 3ab08be (tracking.rs), so there is no merge gate this time. The lock run was also made on this patch ported locally onto develop's step engine.
  • Invariants: non-default targets; over-cap + accounting (12 total, 10 shown under "last 10"); under the hook (rtk rewrite leaves rtk gain --failures --project unchanged); every decision. No filter, so no savings figure applies.

Pins: 18 decisions, 19 mutations. 8 survive the suite, and still do on 0c46285 against 91 core::tracking/analytics::gain tests:

  • succeeded unscoped and top_commands unscoped;
  • in show_failures: scope not passed, empty-message branches swapped, title branches swapped, Scope: line removed, label guard dropped, label removed.

One more is equivalent (the is_empty() guard in project_dir_name).
Matrix: executed this round; pin check: executed this round.
CI @0c4628578: not run. The run waits for approval, and the branch no longer merges into develop; it runs after the rebase. (@b1a2d72b9: all green.)

Blocks merge (3)

  1. src/core/tracking.rs:506: the migration has to move onto develop's step engine, and on this branch it can stamp the version without the column.
    • Why the port: since #4894, develop versions the tracking schema with SchemaVersion and applies each step in its own transaction. SCHEMA_VERSION 3 is now InitialRecheck's stamp, so this migration is version 4. A DB develop already stamped 3 would never run it.

    • The port:

      • a ParseFailuresProject = 4 variant directly above Next;
      • its step appended to MIGRATIONS, adding the column with db::add_column_if_missing and the index with ? (a let _ would hide a failed ALTER that the engine otherwise rolls back and retries);
      • an upgrade test from a DB seeded at InitialRecheck (seed_schema + upgrade_through_tracker), as the enum's doc asks.

      migrate_initial stays as it is: a released step never changes the schema it produces.

    • Rows it must pass:

      • a fresh DB has parse_failures.project_path;
      • a DB stamped 3 gains it on the first rtk <cmd>, and its existing rows read '';
      • rtk init replays every step without error;
      • rtk gain --failures exits 0.
    • Evidence on this branch: v2 DB, another connection holding BEGIN EXCLUSIVE for 8 s during the first open.

      • The ALTER error is discarded and user_version = 3 is written once the lock is free, so the DB ends at version 3 without the column.
      • The run under the lock and every run after it record no parse failure, with no warning.
      • Plain rtk gain --failures exits 1 with no such column: project_path.
      • Reproduced twice on b1a2d72, once on that head merged onto develop 6c2313a, and once on 0c46285.
    • The port closes it, with no lock-specific test needed: ported locally onto the step engine, the same patch comes out of that run at version 4 with the column, and it records failures.

  2. src/analytics/gain.rs:1815: the row label does not identify the project, and none of show_failures's decisions is pinned.
    • Label: it is the cwd's last component. Failures recorded in projA/sub, proj[1]/sub and proj1/sub all print as (sub) in rtk gain --failures.

    • Scoped view: the label is suppressed even for rows from a subdirectory of the scope. From projA, the failure recorded in projA/sub prints exactly like the ones recorded at the root.

    • A correct label: tells those three apart in the unscoped view. In the scoped view, a row recorded below the scope carries its subdirectory, and a row at the scope root carries nothing.

    • Evidence (pins): each of these passes all 91 core::tracking/analytics::gain tests:

      • show_failures(&tracker, None) at :632;
      • swapping the empty-message branch;
      • swapping the title branch;
      • removing the Scope: line;
      • dropping if project_scope.is_none() from the label arm;
      • removing the label.
    • Test must record failures in <root>/a, <root>/a/sub and <root>/b/sub (through common::rtk_command(), or a renderer that returns the text), then assert that:

      • the unscoped labels are distinct;
      • --project from a prints RTK Parse Failures (Project Scope), the Scope: line and the sub row's label, and leaves out b/sub;
      • --project from an empty directory prints No parse failures recorded for this project.

      Each of the six mutations must turn it red.

  3. src/core/tracking.rs:1200, :1215: two of the four scoped queries are unpinned.
    • Evidence: removing the project filter from the succeeded count, or from the top_commands query, passes the suite. test_parse_failure_summary_filtered_by_project's only recovered row is in scope, and it never reads top_commands.
    • Test must put recovered failures and a repeated command in the sibling project (for example two recovered cmd_other rows in beta), then assert that the scoped recovery_rate is still 50.0 and that top_commands has no cmd_other. Each mutation must turn it red.

Optional

  • In the scoped view, a project whose only failures predate the column prints No parse failures recorded for this project. followed by This means all commands parsed successfully, though rtk gain --failures lists the failure. Rows recorded before the upgrade carry '' and are correctly out of scope; only the second line's claim is wrong there.
  • get_parse_failure_summary has no production caller left and needs #[allow(dead_code)]. Its tests can call get_parse_failure_summary_filtered(None) directly.
  • The // added / // changed: … markers on new lines describe the edit, not the code; they read as noise once merged.

Follow-ups

  • #5173 rtk gain --project mis-scopes project paths containing [, * or ?. It is pre-existing (project_filter_params, unchanged since v1.0.1 and in v1.2.0, not in this PR's hunks), and this PR's scoped failure view inherits it.

Checked and correct — no need to re-verify

  • Rows are stamped with the canonical cwd. Through a symlink they get the target's path. A deleted cwd records '', and --project there fails with the existing cwd error.
  • --project scoping on head (root plus subdirectories, sibling excluded) replaces the merge-base behaviour, where --failures ignored --project and listed every project.
  • 1.0 → 3 upgrade: existing rows read '' and get no label, the index is created, and 1.0's tables are untouched. 1.0 writing into a v3 DB inserts '', and both binaries read it back.
  • 12 failures in one project: total 12, 10 rows under "last 10".
  • These are pinned (their mutations fail the suite): the project_path write, the ALTER, the total and recent filters, the project_path read-back, and project_dir_name's separators.
  • Telemetry still sends only counts. parse_failures_since, the cleanup DELETE and reset_all don't depend on the new column.
  • 0c46285: fmt and clippy are clean, and cargo test --all passes 5563 tests. b1a2d72 merged onto develop 6c2313a: 5326 passed, with 1 local failure (go_test_help_is_not_replayed_through_the_injected_json, a toolchain shim on this machine, unrelated; green in CI).

Your questions

  • "If you'd rather it be sliced differently, or folded into something you already have open around tracking, I'm happy to do that." → No change of shape: the scope is accepted as it stands, and nothing open on our side touches parse_failures.
  • "this PR's migration is 3" (10-25) → since #4894 it is version 4, through the step engine (item 1). A lost bump now fails the build: MIGRATIONS has to list every variant in order.

Next

Items 1–3: the port onto the step engine, a label that names the project with show_failures pinned, and the two scoped queries pinned. After those, this merges.
Rounds: 1. Threads: 3 open (waiting on the author), 0 resolved this round.

Comment thread src/core/tracking.rs Outdated
// concurrent sessions. Non-fatal: `ADD COLUMN` errors harmlessly once the
// column exists, and SQLite backfills existing rows with the DEFAULT.
let _ = conn.execute(
"ALTER TABLE parse_failures ADD COLUMN project_path TEXT DEFAULT ''",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This migration needs to move onto develop's step engine (#4894). It becomes a SchemaVersion variant and its step, instead of a statement inside run_schema_migrations behind SCHEMA_VERSION = 3, which develop already uses for InitialRecheck. On this branch, the ALTER error is discarded and the version is stamped anyway. With another connection holding the write lock for 8 s during the first open, the DB ends at version 3 without parse_failures.project_path. From then on no parse failure is recorded, and rtk gain --failures exits 1. Item 1 in the review body has the transcript, the port and the rows it must pass.

Comment thread src/analytics/gain.rs Outdated
// added: name the project when the view spans several of them —
// already-scoped output would just repeat the header
let where_display = match project_dir_name(&rec.project_path) {
Some(name) if project_scope.is_none() => format!(" ({})", name),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

project_dir_name keeps only the cwd's last component, so failures from projA/sub, proj[1]/sub and proj1/sub all print as (sub). The guard drops the label in the scoped view even for rows recorded below the scope. None of show_failures's six decisions is pinned: each mutation listed in item 2 passes the suite.

Comment thread src/core/tracking.rs Outdated
[],
"SELECT COUNT(*) FROM parse_failures
WHERE fallback_succeeded = 1
AND (?1 IS NULL OR project_path = ?1 OR project_path GLOB ?2)", // added: project filter

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Removing the project filter from this succeeded count, or from the top_commands query below, passes the suite: the test's only recovered row is in scope, and it never reads top_commands. The rows a test must assert are in item 3.

`commands` has been stamped with the cwd since project-scoped stats landed,
but `parse_failures` was not. A failure could therefore only be related to
other telemetry by bare timestamp, which is ambiguous on a machine running
concurrent sessions in different projects, so "which project do rtk's
filters keep breaking in?" was not answerable from the data.

- Add `parse_failures.project_path TEXT DEFAULT ''`, stamped by
  `record_parse_failure` via the same `current_project_path_string()` helper
  `record` uses. Call sites are unchanged.
- The column and its `(project_path, timestamp)` index arrive as schema step
  4 (`SchemaVersion::ParseFailuresProject`), through `db::add_column_if_missing`
  so a failed ALTER rolls back and is retried instead of being stamped over.
  `migrate_initial` is untouched. A test upgrades a database stamped at
  `InitialRecheck` and a second one checks a fresh database and a replay.
- Add `get_parse_failure_summary_filtered()` and wire `--project` through
  `rtk gain --failures`, using the same exact-or-subdirectory GLOB scoping as
  the `commands` queries.
- Label each recent failure by where it happened: the full project path in
  the unscoped view (the last component alone cannot tell `a/sub` from
  `b/sub`), the subdirectory below the scope in the scoped view, nothing for
  a row at the scope root. `show_failures` now renders through
  `render_failures`, so the output is testable.
- Drop the unscoped `get_parse_failure_summary` wrapper, which had no caller
  left.

Tests pin the scoped `recovery_rate` and `top_commands` against a sibling
project's recovered rows, the unscoped labels, the scoped header, `Scope:`
line and labels, and both empty-state messages.

No new field is reported upstream: telemetry sends `parse_failures_24h` and
`projects_count`, both counts, and no raw path leaves the machine.
@bharvey42
bharvey42 force-pushed the feat/telemetry-parse-failure-project-path branch from 0c46285 to 4346455 Compare November 23, 2026 01:20
@bharvey42

Copy link
Copy Markdown
Author

@KuSh, I've force-pushed a port of this onto develop's SchemaVersion step engine (single commit, 4346455).

  • The migration is now SchemaVersion::ParseFailuresProject (step 4), using add_column_if_missing. The stray inline ALTER TABLE block is gone, so there is one migration path.
  • show_failures is split into render_failures plus a small failure_location helper, so the output can be tested without touching the database.
  • The scoped empty-state message is fixed, and the unused get_parse_failure_summary wrapper is dropped.
  • README is updated alongside tracking.rs and gain.rs.

I mutation-checked the new tests: removing the succeeded filter, the top_commands filter or the label each turns them red, and removing the Scope line fails to compile. cargo fmt and clippy are clean. The full suite passes except the known core::stream baseline failure.

No path data leaves the machine; only counts are sent.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants