fix(telemetry): cap cli_error per kind per day, flush app_close on quit#746
Merged
Merged
Conversation
Two robustness fixes from the getagentseal#741 telemetry audit: - cli_error had no rate limit: one install emitted 804 timeout events in a single day (56% of all events ever received). track() now caps cli_error at 20 per kind per calendar day. The day and per-kind counts persist in the telemetry state file (defensively loaded), so app relaunches within the same day cannot reset the budget; other event names are unaffected. - app_close almost never fired (1 close vs 48 opens): the quit path raced the outbound POST. before-quit now defers quit once, tracks the close and flushes with a bounded wait (1500ms race), then quits. Every step of the handler is independently guarded so a synchronous failure can neither skip the flush nor wedge quitting, and a full queue evicts its oldest event rather than dropping app_close. Disabled or not-onboarded telemetry quits instantly.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #741 (the cli_error rate-limit and app_close race items). Together with #745 this covers the three remaining items of the ticket (the skills/MCP verification result is in the #741 thread).
cli_error rate limit
One 0.9.15 install emitted 804
timeoutcli_error events in a single day, 56% of all events ever received.track()now capscli_errorat 20 perkindper calendar day. The day and per-kind counts persist in the existing telemetry state file (same mechanism aslastSnapshotDay), defensively loaded so malformed or pre-upgrade state files fall back clean, which means app relaunches inside the same day cannot reset the budget (a crash-looping install stays capped). Other event names are unaffected, and the counter never reaches the POST body.app_close flush race
app_close almost never fired (1 close vs 48 opens): before-quit queued the event and started an async POST that Electron never waited for. The quit path now defers quit exactly once, tracks the close, flushes with a bounded wait (1500ms
Promise.race), then quits for real. Hardened after adversarial review:Validation
npx tsc --noEmitclean; both Electron suites green (includes new tests for the cap, day rollover, restart persistence over the same state dir, malformed persisted state, full-queue eviction, hung-endpoint quit bound, no-consent instant quit, and synchronous-failure quit paths).