Skip to content

fix(telemetry): flush terminal events immediately so error telemetry is delivered#41

Open
mgar wants to merge 2 commits into
telemetry-proxyfrom
miguel/fix/flush-terminal-telemetry-events
Open

fix(telemetry): flush terminal events immediately so error telemetry is delivered#41
mgar wants to merge 2 commits into
telemetry-proxyfrom
miguel/fix/flush-terminal-telemetry-events

Conversation

@mgar

@mgar mgar commented Jun 9, 2026

Copy link
Copy Markdown

Description

command-error / command-not-found telemetry was buffered and silently dropped: the batched flush only ran on postrun, which oclif doesn't run after an error or a not-found command. This restores delivery of error telemetry.

Changes

  • Flush on any terminal event (postrun, command-error, command-not-found) instead of only postrun.
  • De-dupe the typo path: a not-found fires command-not-found and then the host rethrows it as command-error; drop that one rethrow. Scoped narrowly (and cleared on prerun) so nested
    config.runCommand and "Did you mean…? Yes" don't get masked.
  • command-not-found is now commandSuccess: false (a missing command didn't succeed).

Related Issue

Flagged in code review on PR #39 (src/telemetry-lib.js)

How Has This Been Tested?

  • Unit tests, 100% coverage, lint clean (one pre-existing test fails only inside an AI-agent shell — passes in CI).

  • Verified end-to-end against the prod proxy / New Relic: real errors and typos each deliver a single correct event; nested commands each flush (no masking).

    Screenshots (if appropriate):

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

github-actions[bot]
github-actions Bot previously approved these changes Jun 9, 2026

@github-actions github-actions 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.

🤖 PR Reviewer

This diff correctly refactors telemetry flushing to trigger on terminal events (postrun, command-error, command-not-found) rather than only on postrun, ensuring error telemetry is actually delivered. The code changes are clean, well-commented, and the tests are updated to match the new behavior. No security, performance, or correctness issues found.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

@mgar mgar mentioned this pull request Jun 9, 2026
10 tasks

@pru55e11 pru55e11 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.

awesome, thank you!

@mgar mgar requested a review from purplecabbage June 9, 2026 18:06
github-actions[bot]
github-actions Bot previously approved these changes Jun 9, 2026

@github-actions github-actions 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.

🤖 PR Reviewer

The changes correctly extend flush behavior to terminal events (command-error, command-not-found) and add a flush-once guard per process. The logic is well-documented, tests cover the new behavior including the double-fire edge case, and the README is updated to match. No significant issues found.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

@github-actions github-actions Bot dismissed their stale review June 9, 2026 18:24

Superseded by new review

github-actions[bot]
github-actions Bot previously approved these changes Jun 9, 2026

@github-actions github-actions 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.

🤖 PR Reviewer

The diff is well-structured and the logic is sound. The de-duplication of the command-not-found/command-error typo path is clear and intentional, the module-level commandNotFoundFired flag is reset in init to avoid cross-command leakage, and the tests cover all the meaningful new paths. One minor concern: the commandNotFoundFired flag is never reset after the de-dupe drop, meaning a second unrelated command-error in the same process (e.g., from a nested config.runCommand) would also be silently dropped — but this is an edge-case given the existing process model. No blocking issues.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

Comment thread src/telemetry-lib.js
@github-actions github-actions Bot dismissed their stale review June 9, 2026 19:12

Superseded by new review

@mgar mgar removed the request for review from purplecabbage June 9, 2026 19:21
@github-actions github-actions Bot dismissed their stale review June 9, 2026 19:22

Superseded by new review

github-actions[bot]
github-actions Bot previously approved these changes Jun 9, 2026

@github-actions github-actions 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.

🤖 PR Reviewer

The previously raised issue about commandNotFoundFired not being reset after suppressing the follow-up command-error has been addressed — the flag is now cleared in the else-if branch, and a dedicated test (only the first command-error after a not-found is suppressed) verifies the fix. The diff is clean: logic, documentation, and tests are all consistent, and init also resets the flag for new sessions.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

The batched-flush design only spawned the flush worker on the postrun hook.
But postrun does not run after a command fails or is not found, so those
metrics were buffered in memory and silently dropped on exit — error/not-found
telemetry was never delivered.

Lifecycle (verified against @oclif/core 4.11.4 and @adobe/aio-cli 11.1.0):
oclif runs postrun only after command.run() returns; on a throw the error
propagates first, and on a not-found oclif throws before postrun. command_error
is not an oclif hook — the host CLI fires it from its top-level catch. So no
postrun follows an error or not-found.

Flush on any terminal event (postrun, command-error, command-not-found),
merging buffered non-terminal metrics into the batch. Update the hook tests to
exercise the real lifecycle (the error/not-found hook flushes on its own, no
manufactured postrun) and the README "Flush architecture" section.
@mgar mgar force-pushed the miguel/fix/flush-terminal-telemetry-events branch from d7c55c0 to 9933eb6 Compare June 9, 2026 19:25
@github-actions github-actions Bot dismissed their stale review June 9, 2026 19:25

Superseded by new review

github-actions[bot]
github-actions Bot previously approved these changes Jun 9, 2026

@github-actions github-actions 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.

🤖 PR Reviewer

The diff is well-structured and the logic is sound. The de-duplication of the command-not-found/command-error pair is clearly explained and correctly scoped. Tests are thorough and cover the edge cases (nested commands, flag reset). No security, performance, or significant correctness issues found.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

@mgar mgar force-pushed the miguel/fix/flush-terminal-telemetry-events branch from 9933eb6 to 3dfa389 Compare June 9, 2026 19:32
@github-actions github-actions Bot dismissed their stale review June 9, 2026 19:32

Superseded by new review

github-actions[bot]
github-actions Bot previously approved these changes Jun 9, 2026

@github-actions github-actions 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.

🤖 PR Reviewer

The diff is well-structured and clearly documented. The de-duplication logic for the command-not-found/command-error typo path is sound, and the test coverage is thorough for the new terminal-event flushing behavior. No security, performance, or significant correctness issues found.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

…telemetry

A mistyped command fires command-not-found (from oclif) and then command-error
(the host CLI rethrowing the same typo, exit 127), recording a typo twice. Track
a per-process commandNotFoundFired flag (reset in init) and drop only the single
command-error that follows a command-not-found, then clear the flag so a later,
unrelated command-error still flushes.

Scoped to the typo on purpose: init fires once per process while nested
config.runCommand calls re-fire prerun/postrun (e.g. app:undeploy -> app:clean),
so a blunt "first terminal event wins" flag would mask real command-errors and
misattribute commands. Also clear the flag in trackPrerun so plugin-not-found's
"Did you mean ...? Yes" (which runs the suggestion) doesn't mask its errors.

Mark command-not-found as commandSuccess: false (a missing command did not
succeed). Add tests for the single-typo entry, flag reset, both "Did you mean?"
answers, and nested commands.
@mgar mgar force-pushed the miguel/fix/flush-terminal-telemetry-events branch from 3dfa389 to a7ca31f Compare June 9, 2026 19:45

@github-actions github-actions 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.

🤖 PR Reviewer

The diff is a well-structured change that promotes command-error and command-not-found to terminal (flush-triggering) events, adds a deduplication guard for the oclif typo rethrow, and backs everything with thorough tests. The logic is clear, the state machine is small and easy to follow, and the README is updated to match. No security, performance, or error-handling issues were found.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

@github-actions github-actions Bot dismissed their stale review June 9, 2026 19:45

Superseded by new review

@mgar mgar requested a review from purplecabbage June 9, 2026 19:52
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.

2 participants