Skip to content

fix(stats): filter legacy download_fail logs#2323

Merged
riderx merged 4 commits into
mainfrom
codex/filter-legacy-download-fail-stats
May 21, 2026
Merged

fix(stats): filter legacy download_fail logs#2323
riderx merged 4 commits into
mainfrom
codex/filter-legacy-download-fail-stats

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 21, 2026

Summary (AI generated)

  • Filters legacy download_fail events from updater plugins below 7.17.0 and 6.14.25 before writing user logs.
  • Reuses the same filter for fail aggregates so raw logs, update charts, and saved stats stay aligned.
  • Adds coverage for ignored and accepted download_fail plugin versions.

Motivation (AI generated)

Old updater plugins could report download_fail when there was no update to download. The aggregate fail counter already avoided this in one path, but raw user logs still saved the false failure, which could make chart drilldowns disagree with chart totals.

Business Impact (AI generated)

Users see cleaner update failure reporting and fewer false alarms from old clients. This improves trust in Capgo update analytics and avoids wasting debugging time on non-actionable failures.

Test Plan (AI generated)

  • bunx eslint supabase/functions/_backend/plugins/stats.ts tests/stats.test.ts
  • bun run lint:backend
  • bunx vitest run tests/stats.test.ts

Generated with AI

Summary by CodeRabbit

  • Bug Fixes

    • Refined stats collection so download-failure events are only recorded for supported plugin versions, with special handling to exclude legacy v6 and other older versions.
  • Tests

    • Added concurrent, table-driven tests to verify download-failure events are suppressed for legacy plugin versions and recorded for supported versions.

Review Change Stack

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: cb4f13e8-45ba-4ec9-ba92-da84fdb5711a

📥 Commits

Reviewing files that changed from the base of the PR and between eb8528d and 2c44660.

📒 Files selected for processing (1)
  • tests/stats.test.ts

📝 Walkthrough

Walkthrough

Adds semver-based gating for download_fail stats: a helper decides if an action (especially download_fail) should be recorded based on plugin version; post() uses it to conditionally persist fail stats; tests exercise multiple plugin-version cases to verify the gating.

Changes

Plugin Stats Version Gating

Layer / File(s) Summary
Version gating constants and helper function
supabase/functions/_backend/plugins/stats.ts
Import tryParse from @std/semver, define DOWNLOAD_FAIL_FIXED_PLUGIN_VERSION and DOWNLOAD_FAIL_FIXED_PLUGIN_VERSION_V6, and implement shouldRecordStatsAction() that validates plugin versions and gates download_fail while allowing other actions.
Version gating applied to post handler
supabase/functions/_backend/plugins/stats.ts
Compute shouldRecordAction via the new helper in post() and conditionally write fail stats and append to statsActions for failure actions, replacing prior inline download_fail logic.
Version filtering validation tests
tests/stats.test.ts
Set baseline plugin_version to 7.17.0 for download_fail within the per-action loop and add concurrent test filters legacy download_fail before saved stats and logs that posts download_fail with several plugin versions and asserts whether stats and version_usage rows are persisted per expectation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • jihadMo

Suggested labels

codex

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: filtering legacy download_fail logs based on plugin version thresholds.
Description check ✅ Passed The description is largely complete with a summary of changes, motivation, business impact, and detailed test plan, though it lacks traditional sections and doesn't fully match the template structure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added the codex label May 21, 2026
@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented May 21, 2026

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing codex/filter-legacy-download-fail-stats (2c44660) with main (f1090d7)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@tests/stats.test.ts`:
- Line 432: The test declared with it('filters legacy download_fail before saved
stats and logs', ...) should be changed to run concurrently by replacing it(...)
with it.concurrent(...); locate the test function with that exact description in
stats.test.ts and update the test declaration to it.concurrent('filters legacy
download_fail before saved stats and logs', async () => { ... }) so the test
runs in parallel with other tests (no other code changes required since
device_id and version_build are already unique).
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 246f2e3d-1472-445f-9b7b-1890945255bf

📥 Commits

Reviewing files that changed from the base of the PR and between ec0bb65 and bd92880.

📒 Files selected for processing (2)
  • supabase/functions/_backend/plugins/stats.ts
  • tests/stats.test.ts

Comment thread tests/stats.test.ts Outdated
Copy link
Copy Markdown

@hadessunxy-code hadessunxy-code left a comment

Choose a reason for hiding this comment

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

Reviewed the legacy download_fail filter. The shared helper is a good direction: it keeps saved logs and fail aggregates aligned, and the threshold tests cover both v7 and v6 boundaries.

One edge case worth checking before merge: the filter currently runs after the version lookup, so legacy download_fail events can still fail with version_not_found before they are suppressed if the noisy report references a missing/unknown target version. If old clients only ever send an existing/current version_name, this is fine. If not, moving the download_fail suppression ahead of getAppVersionPostgres would make the ignore behavior complete and avoid batch items turning into errors for the same legacy noise this PR is trying to drop.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/stats.test.ts (1)

434-450: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add a malformed/missing plugin_version case to this matrix.

shouldRecordStatsAction() also treats unparseable or absent plugin_version as legacy, but these cases only cover valid semver inputs. That leaves the "parse failed => suppress download_fail" branch untested, so a regression there could slip through without failing this suite.

As per coding guidelines: "Use version detection based on plugin_version to enable backward-compatible behavior changes; assume old versions for safety when version parsing fails"

🤖 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 `@tests/stats.test.ts` around lines 434 - 450, Add a test case to the cases
matrix that simulates a malformed/missing plugin_version so the "parse failed =>
suppress download_fail" branch is exercised: insert an object like {
pluginVersion: 'not-a-version', shouldRecord: false, createVersion: true } (or {
pluginVersion: '', shouldRecord: false, createVersion: true } if empty-string is
preferred) into the cases array used in tests/stats.test.ts; this ensures
shouldRecordStatsAction() behavior for unparseable/missing plugin_version is
validated without changing the surrounding test logic that sets
baseData.plugin_version and version_build.
🤖 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.

Outside diff comments:
In `@tests/stats.test.ts`:
- Around line 434-450: Add a test case to the cases matrix that simulates a
malformed/missing plugin_version so the "parse failed => suppress download_fail"
branch is exercised: insert an object like { pluginVersion: 'not-a-version',
shouldRecord: false, createVersion: true } (or { pluginVersion: '',
shouldRecord: false, createVersion: true } if empty-string is preferred) into
the cases array used in tests/stats.test.ts; this ensures
shouldRecordStatsAction() behavior for unparseable/missing plugin_version is
validated without changing the surrounding test logic that sets
baseData.plugin_version and version_build.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d2514404-2165-4802-b967-2034beef18ca

📥 Commits

Reviewing files that changed from the base of the PR and between 96ecba7 and eb8528d.

📒 Files selected for processing (2)
  • supabase/functions/_backend/plugins/stats.ts
  • tests/stats.test.ts

@sonarqubecloud
Copy link
Copy Markdown

@riderx riderx merged commit fb9f85b into main May 21, 2026
42 checks passed
@riderx riderx deleted the codex/filter-legacy-download-fail-stats branch May 21, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants