fix(telemetry): keep telemetry inert during shell completion (BE-4274)#586
fix(telemetry): keep telemetry inert during shell completion (BE-4274)#586mattmillerai wants to merge 2 commits into
Conversation
Add an explicit shell-completion guard to the telemetry provider gateway so no PostHog/Mixpanel client is stood up while fish/bash/zsh resolve tab completion (GitHub #506). The lazy provider construction from #535 already made completion inert as a side effect (providers build only on dispatch, which never runs during completion); this makes the guarantee explicit and independent of when providers get built, and adds the regression test the ticket asks for.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 22 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
🔍 Cursor Review — Consolidated panel
Triggered by @mattmillerai.
Found 2 finding(s).
| Severity | Count |
|---|---|
| 🟢 Low | 2 |
Panel: 6/8 reviewers contributed findings.
Reviewers that did not contribute: kimi-k2.5:adversarial (empty), kimi-k2.5:edge-case (empty)
…E-4274) - Set COMP_WORDS/COMP_CWORD in the end-to-end completion test so Typer's bash arg-resolution path (which reads them directly, unlike zsh/fish's _TYPER_COMPLETE_ARGS) no longer raises KeyError — fixes the red `build` job. - _in_shell_completion(): require a recognized completion instruction token in the _*_COMPLETE value so a stray/empty user-exported _FOO_COMPLETE can't silently suppress telemetry on a real run, and snapshot os.environ keys with list() to avoid RuntimeError under concurrent env mutation (cursor-review). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ELI-5
When you press Tab to autocomplete a
comfy ...command, the CLI runs a tiny hidden invocation just to list the possible completions. It should do nothing else — but a fish user reported (GitHub #506) that this hidden run was still spinning up the PostHog analytics client (a background thread + network setup). This PR makes sure telemetry stays completely asleep during tab-completion, and adds a test so it never wakes up there again.What changed
comfy_cli/tracking.py: added_in_shell_completion()(detects the_<PROG>_COMPLETEenv var Click/Typer set during completion, acrosscomfy/comfy-cli/comfycliand any alias, for fish/bash/zsh) and an early-return guard in_get_providers()so no telemetry provider (PostHog or Mixpanel) is constructed on the completion path. The guard is uncached, so a real invocation is never affected.tests/comfy_cli/test_tracking_completion.py: new regression tests — detection matrix across shells/entrypoints, a gateway test asserting_get_providers()builds nothing under completion, and an end-to-end test that drives the real Typer completion resolution for fish/bash/zsh and asserts the PostHog client is never constructed.Honest note on scope (please read)
While triaging I found the behavior was already fixed incidentally by #535 (BE-3289, "build telemetry providers lazily"), which landed on
mainearlier the same day — after #506 was filed (2026-07-11). With lazy construction, providers are built only inside_dispatch(), which never runs during completion. I verified this empirically: driving the actual Typer fish completion on cleanorigin/mainresolves the full command list and constructs zero telemetry providers (noposthogimport, noPostHogProvider.__init__, no_get_providerscall).So this PR is deliberately not a behavior fix on top of a broken
main. Its value is:pydantic_coreDLL lock, unrelated to completion). The two concerns are only coupled by accident today.Acceptance criteria
Testing
pytest tests/comfy_cli/test_tracking_completion.py tests/comfy_cli/test_tracking_providers.py tests/comfy_cli/test_tracking.py→ 142 passed.ruff check+ruff format --diff(CI-pinned 0.15.15), repo-wide → clean.