feat(telemetry): first-run health — startup_ready, event_loop_stall, registration timing - #1294
Merged
Merged
Conversation
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.
Why
The 0.11.0 first-run freeze (#1292: an in-process
@npmcli/arboristinstall blocking Bun's event loop for 2.5 to 5 minutes) shipped in six releases without a trace in telemetry. Three reasons, all structural:session_start; the next is agenerationafter the model answers. A freeze between them produced no number anywhere.setIntervalon the same loop that was blocked. A frozen-then-killed process died with its buffer and left onlysession_start+task_classified(a "dead session": 0 to 2 s span, no generation, no error, no end).What
startup_readyservelistening, TUI transport resolved,runabout to send its first promptcommand,duration_ms(process uptime),fresh_installevent_loop_stallblocked_ms,since_start_ms,thread,commandaltimate_base_registrationregisterAfterConsentoutcome, so the TUI dialog and the HTTP consent route both countresult,duration_ms,statusPlus: anchor events (
first_launch,startup_ready,event_loop_stall,altimate_base_registration,session_start) flush immediately instead of waiting for the interval, and the CLI middleware records the top-level command viaTelemetry.setCommand.The stall monitor reports when the loop resumes, so a stall that ends in a killed process is still lost, but every stall a user waited through is now a number, and it is flushed before anything else can go wrong.
docs/internal/first-run-telemetry.mdcarries the rationale, the event table, and KQL for startup time, stalls, registration, and the fresh-versus-returning dead-session rate (the last one works on historical data).Verification
bun test: 8 new tests (startup_ready once per process; pure lag check; monitor detects a synchronous 250 ms block and stays quiet otherwise; idempotent start/stop; registration success, HTTP 429 with status, misconfigured gateway URL, network failure) plus the existing telemetry, Altimate Base, TUI and provider-API suites, all green.tsgo --noEmitclean. Upstream marker guard clean.servein a fresh isolated HOME withAPPLICATIONINSIGHTS_CONNECTION_STRINGpointed at a local sink receivedstartup_ready command=servewithin the anchor flush, from both the dev build (2048 ms) and abun build --compilesingle-target binary (1561 ms), so the monitor andisMainThreadbehave in the compiled form.startup_readynow fires forrun --commandas well as plain prompts, and aConfigurationErrorfrom the gateway URL is reported asresult: configurationinstead of escaping before the timer starts.Known limit
Telemetry is initialised and shut down per prompt by
session/prompt.ts, so in a long-livedserveprocess the stall monitor, like every other event, is dark between prompts. That is pre-existing lifecycle behaviour, noted here so nobody reads an absence of stalls outside a prompt window as proof of health.🤖 Generated with Claude Code
https://claude.ai/code/session_01WrT7MEUL5CYvpjf9cJbeQR
Note
Medium Risk
Touches telemetry flush timing and runs instrumentation on CLI main thread and TUI worker at startup; low user-facing risk but changes when events ship and adds process-lifetime monitors tied to telemetry init/shutdown.
Overview
Adds first-run health telemetry so long startup freezes and silent “dead sessions” show up in App Insights instead of only
session_startwith no follow-up.New events:
startup_ready(once per process whentui/serve/runcan work, with uptime andfresh_install),event_loop_stall(250 ms monitor, >1 s late tick, capped at 20, main vs worker), andaltimate_base_registration(everyregisterAfterConsentoutcome with duration and HTTP status when relevant).Behavior: Selected anchor events (
first_launch,startup_ready,event_loop_stall,altimate_base_registration,session_start) flush immediately instead of waiting on the 5 s interval. CLI middleware records the top-level command viaTelemetry.setCommand; the TUI worker starts the stall monitor and callsTelemetry.init()at boot so pre-prompt blocking is observable.Altimate Base: Registration paths report telemetry for expired consent, bad gateway URL (
configuration), success/failure; caller aborts are classified ascancelledrather thannetwork.Docs/tests:
docs/internal/first-run-telemetry.mdwith KQL for startup, stalls, registration, and dead-session rate; new unit tests plus an existing flush-retry test adjusted to avoid anchor auto-flush.Reviewed by Cursor Bugbot for commit f6343e2. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Adds first-run health telemetry so the 2.5–5 minute freeze from the 0.11.0 first-run
@npmcli/arboristinstall shows up in telemetry instead of a "dead session" that reports onlysession_start.startup_readyonce per process whenserve,tui, orruncan start work, with command, duration, and fresh-install flag.event_loop_stallwhen a 250 ms monitor tick is over 1 s late, capped at 20 per process, on main and worker threads; the TUI worker starts the monitor at boot.altimate_base_registrationfor every registration outcome on both TUI and HTTP consent paths; a caller abort reportscancelledand a bad gateway URL reportsconfiguration.first_launch,startup_ready,event_loop_stall,altimate_base_registration,session_start) flush immediately instead of waiting for the 5 s interval.Telemetry.setCommand, and documentation with KQL queries lives indocs/internal/first-run-telemetry.md.Written for commit f6343e2. Summary will update on new commits.
Summary by CodeRabbit
New Features
Documentation