Skip to content

Telemetry tests fail (12 of 35) on any machine where the developer has opted out of telemetry #892

Closed

Description

@pleasedodisturb

Filed as an issue rather than a pull request: PR creation from outside accounts is currently refused on this repo (GraphQL returns FORBIDDEN for CreatePullRequest), and no non-owner PR has been opened since 2026-06-11. Issue creation still works, so I'm following CONTRIBUTING's preference for issues anyway.

Branch with the change, if useful as a reference: fix/telemetry-test-isolation


Problem

The telemetry-core test suite reads the real ~/.jcode, so whether it passes depends on whose machine it runs on. On any machine where the developer has opted out of telemetry, 12 of 35 tests fail.

Reproduction, on a clean checkout with no other changes:

touch ~/.jcode/no_telemetry
cargo test -p jcode-telemetry-core --lib
# test result: FAILED. 23 passed; 12 failed

A single marker file is enough.

Why the failure looks unrelated to telemetry

This is the part that took me a while to see, so it seems worth writing down.

is_enabled() reads ~/.jcode/no_telemetry, so begin_session_with_mode returns early and leaves SESSION_STATE as None. The first expect(...) then panics while holding the lock, which poisons it. The remaining session tests fail with PoisonError, not with anything mentioning telemetry or opt-out. So only the first failure points at the real cause and the other 11 are noise.

Second, quieter problem

Before this change, running the test suite wrote into the developer's own ~/.jcode: telemetry_id, session-start records, and telemetry_active_sessions/ entries. Tests were mutating real user state.

Fix

jcode_dir() already honors JCODE_HOME, so the fix is to point it at a directory owned by the test binary for the duration of the run.

The directory is a per-pid path under a shared root rather than a tempfile::TempDir held in a static. I originally wrote the static version, on the model of the tempfile::tempdir() + JCODE_HOME pattern in jcode-provider-openrouter-runtime, and it is wrong here: Rust does not drop statics, so it leaked one directory per cargo test run. I noticed only after 82 of them had accumulated in my own home directory. Each run now also sweeps sibling entries untouched for ten minutes, which reclaims the homes of runs that crashed before cleaning up, while leaving a concurrently running test process alone.

One file, no production code touched.

Verification

35 passed; 0 failed in four configurations:

  • real HOME with the opt-out marker present (previously 23/12)
  • sandboxed HOME with the marker
  • sandboxed HOME without the marker
  • --test-threads=1 and the default parallel runner

Also confirmed the suite writes nothing into a real jcode home, and that three consecutive runs add no leftover directories. The sweep itself is verified by planting a back-dated entry and watching the next run remove it.

cargo fmt, clippy -D warnings, and the five ratchet scripts flag exactly the same files on this branch as on master, none from this change. (Master is currently red on several of those gates independently of this change, so I compared file sets rather than pass/fail.)

Notes

This fits CONTRIBUTING's issue-first preference well, since it reproduces with a single touch. The branch is linked above only in case the diff is useful as a reference. Happy for it to be treated purely as a reproduction.

Disclosure: written with agent assistance, reviewed and verified by me. The reproduction and the four-configuration verification above were actually run, not assumed.

Activity

  1. added
    bug
    priority: medium
    triage: reproducible
    autonomous: clear
    tech-debt
    triage: fixed-pending-release
    on Aug 12, 2026
  2. 1jehuang commented on Aug 12, 2026

    @1jehuang
    Owner

    Isolated telemetry tests from the developer's real Jcode home and opt-out state in #907. The telemetry-core suite passes with 39 tests.


    — Jcode agent (automated triage), on behalf of @1jehuang

  3. added a commit that references this issue on Aug 12, 2026
    cbec09d
  4. added a commit that references this issue on Aug 15, 2026
    a8e0afd
  5. added 5 commits that reference this issue on Aug 30, 2026
    21eb74d
    ea9655c
    cd34824
    26bb276
    6c5022f
  6. added a commit that references this issue on Sep 18, 2026
    2f9f949
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: clearbugpriority: mediumtech-debttriage: fixed-pending-releasetriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions