{"record":{"id":"144097dc68bba781","repo":"Hmbown/CodeWhale","slug":"telemetry-is-disabled","errorCode":null,"errorMessage":"telemetry is disabled","messagePattern":"telemetry is disabled","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"info","filePath":"crates/telemetry/src/envelope.rs","lineNumber":64,"sourceCode":"    /// When a flush was last *attempted*, RFC3339 UTC. Attempt, not success, so\n    /// a permanently offline machine tries at most once per interval.\n    #[serde(default)]\n    pub last_flush: Option<String>,\n}\n\n/// Read the install id, minting a fresh one if it is missing, unreadable,\n/// **not a UUID**, or older than [`ROTATION_DAYS`].\n///\n/// The UUID check is not a formatting nicety. `install_id` is the one\n/// envelope field read verbatim off disk into a batch, so without it the file\n/// is a free-form string slot on the wire for anything that can write\n/// `$CODEWHALE_HOME/telemetry/install_id.json`. Minting a fresh random id is\n/// always the safe direction — the cost is one rotation, and the docs already\n/// say no count derived from `install_id` is a user count.\npub fn read_or_create_install_id(root: &Path) -> Result<InstallId> {\n    buffer::try_with_lock(root, || {\n        if buffer::tombstone_present(root) {\n            anyhow::bail!(\"telemetry is disabled\");\n        }\n        let path = buffer::install_id_path(root);\n        let existing = std::fs::read_to_string(&path)\n            .ok()\n            .and_then(|body| serde_json::from_str::<InstallId>(&body).ok())\n            .filter(|record| uuid::Uuid::parse_str(record.install_id.trim()).is_ok())\n            .filter(|record| !is_expired(&record.rotated_at));\n        if let Some(record) = existing {\n            return Ok(record);\n        }\n        let record = InstallId {\n            schema_version: 1,\n            install_id: uuid::Uuid::new_v4().to_string(),\n            rotated_at: now_rfc3339(),\n        };\n        codewhale_config::persistence::atomic_write_json(&path, &record)\n            .with_context(|| format!(\"failed to write {}\", path.display()))?;\n        Ok(record)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/telemetry/src/envelope.rs#L46-L82","documentation":"read_or_create_install_id mints or loads the anonymous install identifier stored in $CODEWHALE_HOME/telemetry/install_id.json. It refuses to run when a tombstone is present, because a tombstone means the user wiped/opted out of telemetry — minting or reading an id then would violate that choice, so it bails with 'telemetry is disabled'.","triggerScenarios":"Calling read_or_create_install_id(root) while buffer::tombstone_present(root) is true, i.e. after wipe() created the tombstone in the telemetry directory.","commonSituations":"User disabled telemetry earlier; app code path still unconditionally builds the install id (e.g. envelope construction); stale tombstone left from a previous opt-out; running a command that touches telemetry after the user wiped it.","solutions":["Check telemetry::buffer::tombstone_present(root) before calling and skip install-id creation when telemetry is off.","Call buffer::arm() (or re-enable telemetry with user consent) to clear the tombstone, then retry.","Treat the error as expected opt-out: handle it in the caller and continue without telemetry.","Remove a stale tombstone only if the user explicitly re-enabled telemetry."],"exampleFix":"// before: unconditional id creation\nlet id = read_or_create_install_id(root)?;\n// after: guard on the tombstone\nlet id = if buffer::tombstone_present(root) {\n    None\n} else {\n    Some(read_or_create_install_id(root)?)\n};","handlingStrategy":"validation","validationCode":"fn can_read_install_id(root: &Path) -> bool {\n    !telemetry::buffer::tombstone_present(root)\n}","typeGuard":null,"tryCatchPattern":"match read_or_create_install_id(root) {\n    Err(e) if e.to_string().contains(\"telemetry is disabled\") => {\n        InstallId::absent() // continue without telemetry\n    }\n    r => r?,\n}","preventionTips":["Gate all telemetry calls behind tombstone_present checks","Stop envelope building when the user opted out","Clear the tombstone only via an explicit user re-consent flow","Treat this error as expected control flow, not a crash"],"tags":["telemetry","privacy","opt-out"],"backgroundTag":"feature-not-enabled","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}