Skip to content

fix: reliable cli_audit telemetry + docs links → /introduction#461

Merged
NiveditJain merged 2 commits into
mainfrom
luv-459
Jun 26, 2026
Merged

fix: reliable cli_audit telemetry + docs links → /introduction#461
NiveditJain merged 2 commits into
mainfrom
luv-459

Conversation

@NiveditJain

@NiveditJain NiveditJain commented Jun 26, 2026

Copy link
Copy Markdown
Member

Separate PR from the merged 0.0.11 release (#460). Started as the cli_audit telemetry fix + docs links, then expanded to close all the gaps from a full telemetry audit of the repo.

Telemetry reliability + coverage

The core bug (delivery on exit). Several CLI events were emitted fire-and-forget (void trackHookEvent(...)) and then dropped by a following process.exit()/die():

  • failproofai audit (src/audit/cli.ts) — cli_audit_completed (empty-history path) and cli_audit_failed were lost. Now awaited; cli_audit_started stays fire-and-forget (the multi-second scan keeps the process alive).
  • failproofai auth (src/auth/cli.ts) — identical bug. audit_cli_auth_login_completed / audit_otp_verified / audit_user_identity_linked / audit_cli_auth_logout_completed / audit_cli_auth_whoami now awaited; the two mid-flow events stay fire-and-forget behind the interactive prompts.

The blind spot (server-side audit run). POST /api/audit/run ran runAudit() as a detached task with zero telemetry — the dashboard's actual audit work and its failures were invisible (only the client's audit_rerun_clicked / audit_rerun_failed existed). Now emits audit_run_started, audit_run_completed (duration, events + sessions scanned, findings, hits, persisted), audit_run_failed, and audit_run_rejected, mirroring the CLI funnel. The dashboard also now emits the previously-missing audit_rerun_succeeded.

Smaller gaps.

  • postinstall — track the build-missing failure (package_install_failed, awaited before exit(1)); failed installs were invisible.
  • captureClientEvent — add keepalive: true so events fired right before a navigation or unload aren't dropped.
  • login-verify — track validation-400s and add email + source for parity with login-request.
  • Property gapsnode_version on package_installed, drop the duplicate version on first_install, add subcommand + exit_code to cli_auth_invoked.
  • Deliberately not changed — the hook hot-path error events stay fire-and-forget: awaiting them would add telemetry latency to every tool call. (Event-name prefix renames were also skipped to preserve PostHog historical continuity.)

Docs links to /introduction

The "Docs" landing links pointed at a bare root that doesn't resolve to a Mintlify page. Pointed the CLI help banner, the launch banners, the dashboard "Reach Us" Documentation entry, and the README docs badge (English + 14 translations) at https://docs.befailproof.ai/introduction. Deep page links are unchanged.

Tests

New __tests__/auth/auth-cli-telemetry.test.ts (proves each path emits and awaits its event). Extended the audit-run-route, client-telemetry, and postinstall tests. The cli_audit fix is guarded by __tests__/audit/audit-cli-telemetry.test.ts.

Validation (all CI gates green locally)

lint (0 errors) · tsc · 1905 unit tests · build · validate:mdx (300 pages) · 298 e2e

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of analytics so key CLI, dashboard, and install events are less likely to be lost when the app exits or the page changes.
    • Added better tracking for audit runs, authentication flows, reruns, and install failures, including more complete event details and durations.
  • Documentation

    • Updated all documentation and help links to point directly to the introduction page for easier access.

Separate PR (the 0.0.11 release PR #460 is already merged). Two changes:

1. The `failproofai audit` CLI dropped its telemetry on exit. src/audit/cli.ts
   emitted cli_audit_started/completed/failed fire-and-forget (void
   trackHookEvent), then die()->process.exit(1) (failed path) and
   process.exit(0) (empty-history path) killed the in-flight fetch before it
   landed — those events never reached PostHog. Now await the two
   exit-adjacent events before exiting, matching bin/failproofai.mjs's track()
   helper; cli_audit_started stays fire-and-forget since the multi-second scan
   keeps the process alive. New __tests__/audit/audit-cli-telemetry.test.ts
   asserts each path emits its event and that the exit-adjacent events are
   awaited before process.exit.

2. "Docs" landing links pointed at a bare root that doesn't resolve to a page.
   Point the failproofai --help LINKS banner, the dev/start launch banner, the
   dashboard "Reach Us" Documentation entry, and the README docs badge (English
   + 14 translations) at https://docs.befailproof.ai/introduction. Deep page
   links (e.g. /built-in-policies) are unchanged.

All gates green locally: lint (0 errors), tsc, 1898 unit tests, build,
validate:mdx (300 pages), 298 e2e tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TD26MQ8M3gyaTLN2cwufTf
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Telemetry is initialized earlier or awaited before exit across audit and auth flows, dashboard reruns, client capture, and postinstall failure handling. Docs links in banners, badges, and locale READMEs now point to the documentation introduction page.

Changes

Telemetry Delivery Updates

Layer / File(s) Summary
Audit run telemetry
app/api/audit/run/route.ts, __tests__/api/audit-run-route.test.ts
The audit run route now initializes telemetry, emits rejected/start/completed/failed events, and the route tests assert the event names plus run-lock and cache outcomes.
Audit CLI exit telemetry
src/audit/cli.ts, __tests__/audit/audit-cli-telemetry.test.ts
runAuditCli now awaits terminal failed/completed telemetry before exit paths, and the CLI telemetry tests assert those events resolve before process.exit.
Auth CLI and entrypoint telemetry
bin/failproofai.mjs, src/auth/cli.ts, __tests__/auth/auth-cli-telemetry.test.ts
The auth entrypoint records invocation metadata, and the auth CLI awaits login/logout/whoami terminal telemetry; the auth telemetry tests assert the awaited exit-path events.
Auth OTP request and verify telemetry
app/api/auth/login-request/route.ts, app/api/auth/login-verify/route.ts
The OTP request and verify routes now emit validation-failure telemetry earlier and include dashboard source and normalized email fields in the payloads.
Audit rerun duration telemetry
app/audit/_components/audit-dashboard.tsx
startRerun stores one start timestamp and uses it to emit rerun success and failure events with duration_ms.
Client and install telemetry delivery
lib/client-telemetry.ts, scripts/postinstall.mjs, __tests__/lib/client-telemetry.test.ts, __tests__/scripts/postinstall.test.ts
captureClientEvent now uses keepalive, and postinstall.mjs awaits failure telemetry before exit while adjusting install payload fields; the tests cover both paths.

Documentation Link Updates

Layer / File(s) Summary
Changelog entries
CHANGELOG.md
The changelog adds telemetry-fix bullets and a docs-link bullet.
Docs landing links
README.md, bin/failproofai.mjs, scripts/launch.ts, components/reach-developers.tsx, docs/i18n/README.*
The README badge, CLI help banner, launch banner, dashboard docs link, and translated README badges now target the docs introduction page.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

I nibbled the logs and listened well,
for signals that should land, not melt.
From audit runs to docs in sight,
the little data hops just right.
Hooray! 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is informative but does not follow the required template sections or checklist structure. Reformat the PR description to match the template with Description, Type of Change, and Checklist sections, and fill in the required checkboxes.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed It concisely summarizes the two main changes: reliable cli_audit telemetry and docs links to /introduction.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

__tests__/api/audit-run-route.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

__tests__/audit/audit-cli-telemetry.test.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

__tests__/auth/auth-cli-telemetry.test.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 13 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@mintlify

mintlify Bot commented Jun 26, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
failproofai 🟢 Ready View Preview Jun 26, 2026, 9:29 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

…dit run, +)

Follow-up to the cli_audit fix, addressing the rest of the telemetry audit:

- Auth CLI (src/auth/cli.ts): same fire-and-forget bug as cli_audit — the
  terminal login/logout/whoami/otp events were dropped when the process exited.
  Now awaited (mid-flow events stay fire-and-forget behind interactive prompts).
- Server-side audit run (POST /api/audit/run): ran runAudit() detached with NO
  telemetry. Now emits audit_run_started/completed/failed/rejected mirroring the
  CLI funnel; dashboard now emits the missing audit_rerun_succeeded too.
- postinstall: track the build-missing failure (package_install_failed) awaited
  before exit(1) — previously invisible.
- captureClientEvent: add keepalive:true so unload-time events aren't dropped.
- login-verify: track validation-400s + add email/source for parity with
  login-request.
- Property gaps: node_version on package_installed, drop duplicate version on
  first_install, subcommand+exit_code on cli_auth_invoked.
- Deliberately left the hook hot-path error events fire-and-forget (awaiting
  them would add telemetry latency to every tool call).

Tests: new __tests__/auth/auth-cli-telemetry.test.ts; extended audit-run-route,
client-telemetry, and postinstall tests. All gates green: lint, tsc, 1905 unit,
build, validate:mdx (300), 298 e2e.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TD26MQ8M3gyaTLN2cwufTf

@coderabbitai coderabbitai Bot 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.

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__/auth/auth-cli-telemetry.test.ts`:
- Around line 1-145: The new auth CLI telemetry test is placed under the wrong
unit-test area relative to the stated repository guideline. Update the placement
of the `auth-cli-telemetry.test.ts` coverage so it follows the expected
unit-test layout used by the test suite (or, if the broader per-area convention
is intended, align the guideline and suite organization consistently); use the
`runAuthCli`-focused test in the auth telemetry file as the location reference
when relocating it.
🪄 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: CHILL

Plan: Pro

Run ID: bc6e428c-3bba-46f9-9e78-2e938bfc3ba3

📥 Commits

Reviewing files that changed from the base of the PR and between 2d3e16a and 9ffe45f.

📒 Files selected for processing (32)
  • CHANGELOG.md
  • README.md
  • __tests__/api/audit-run-route.test.ts
  • __tests__/audit/audit-cli-telemetry.test.ts
  • __tests__/auth/auth-cli-telemetry.test.ts
  • __tests__/lib/client-telemetry.test.ts
  • __tests__/scripts/postinstall.test.ts
  • app/api/audit/run/route.ts
  • app/api/auth/login-request/route.ts
  • app/api/auth/login-verify/route.ts
  • app/audit/_components/audit-dashboard.tsx
  • bin/failproofai.mjs
  • components/reach-developers.tsx
  • docs/i18n/README.ar.md
  • docs/i18n/README.de.md
  • docs/i18n/README.es.md
  • docs/i18n/README.fr.md
  • docs/i18n/README.he.md
  • docs/i18n/README.hi.md
  • docs/i18n/README.it.md
  • docs/i18n/README.ja.md
  • docs/i18n/README.ko.md
  • docs/i18n/README.pt-br.md
  • docs/i18n/README.ru.md
  • docs/i18n/README.tr.md
  • docs/i18n/README.vi.md
  • docs/i18n/README.zh.md
  • lib/client-telemetry.ts
  • scripts/launch.ts
  • scripts/postinstall.mjs
  • src/audit/cli.ts
  • src/auth/cli.ts

Comment thread __tests__/auth/auth-cli-telemetry.test.ts
@NiveditJain NiveditJain merged commit 60dbff1 into main Jun 26, 2026
13 checks passed
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.

1 participant