Skip to content

fix(init): honor RTK_TELEMETRY_DISABLED in consent prompt (#1307)#2477

Open
ousamabenyounes wants to merge 2 commits into
rtk-ai:developfrom
ousamabenyounes:fix/issue-1307
Open

fix(init): honor RTK_TELEMETRY_DISABLED in consent prompt (#1307)#2477
ousamabenyounes wants to merge 2 commits into
rtk-ai:developfrom
ousamabenyounes:fix/issue-1307

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

Fixes #1307.

rtk init's telemetry consent prompt only bailed on a non-TTY check. Some non-interactive environments (devcontainer postCreateCommand, certain CI agents) hand rtk a pseudo-TTY, so is_terminal() returns true and the prompt blocks forever waiting on stdin. RTK_TELEMETRY_DISABLED=1 is the documented opt-out and is honoured by telemetry::maybe_ping, but the consent prompt ignored it.

Fix

Add a telemetry_disabled_by_env() helper and short-circuit prompt_telemetry_consent() with return Ok(()) when RTK_TELEMETRY_DISABLED=1, before the TTY heuristic — mirroring the check already used in maybe_ping.

Test verification (RED → GREEN)

The hang itself only reproduces under a real pseudo-TTY, which the test harness can't provide; the regression is guarded by a unit test on the new telemetry_disabled_by_env() helper that the fix is built on.

RED — patch reverted (helper removed):

error[E0425]: cannot find function `telemetry_disabled_by_env` in this scope
error: could not compile `rtk` (bin "rtk" test) due to 4 previous errors

GREEN — with the fix:

running 1 test
test result: ok. 1 passed; 0 failed

(Re-proposes the accidentally-closed #1369, rebased onto current develop.)

`rtk init -g --hook-only --auto-patch` hangs in non-interactive
environments (devcontainer postCreateCommand, some CI agents) when
`is_terminal()` returns true on a pseudo-TTY that nobody can answer.
Setting `RTK_TELEMETRY_DISABLED=1` used to only gate `telemetry::maybe_ping`,
so the documented workaround still hit the blocking prompt.

Short-circuit `prompt_telemetry_consent` on that env var before the TTY
heuristic so the init flow exits cleanly in any non-interactive context.

Fixes rtk-ai#1307

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM, thanks

Comment thread src/hooks/init.rs Outdated
@KuSh KuSh self-assigned this Jun 18, 2026
Address KuSh review on rtk-ai#2477: export the `RTK_TELEMETRY_DISABLED`
opt-out check as a public `telemetry_cmd::telemetry_disabled_by_env()`
instead of a private copy in `init.rs`. Collapses the three duplicated
`std::env::var("RTK_TELEMETRY_DISABLED") == "1"` checks (init prompt,
`telemetry status`, `telemetry::maybe_ping`) into one function, so the
accepted values can evolve (e.g. "true"/"y") in a single place without
divergence.

Behavior-preserving: the rtk-ai#1307 regression test (env opt-out
short-circuits the consent prompt) is unchanged and still green; suite
2200/2200.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread src/hooks/init.rs
/// All cases are bundled in one test to serialize env-var mutations (env is
/// process-global and cargo runs tests in parallel).
#[test]
fn test_telemetry_disabled_by_env_honors_opt_out() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those tests should go to telemetry_cmd. After that LGTM!

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.

rtk init hangs in non-interactive environments (v0.36.0 telemetry consent gate)

2 participants