{"record":{"id":"640d2f032574bfb5","repo":"Hmbown/CodeWhale","slug":"telemetry-permission-changed-before-arming","errorCode":null,"errorMessage":"telemetry permission changed before arming","messagePattern":"telemetry permission changed before arming","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/telemetry/src/buffer.rs","lineNumber":466,"sourceCode":"}\n\n/// Clear the tombstone and drop anything buffered before this process was\n/// permitted.\n///\n/// Called by `init` on every arming. Both the exact tombstone generation and a\n/// fresh durable permission check must still match while the wipe lock is held.\n/// A stale buffer left by an earlier run or by a bug cannot enter the new\n/// process's batch.\npub(crate) fn arm(\n    root: &Path,\n    observed_generation: Option<&TombstoneGeneration>,\n    permission_still_enabled: impl FnOnce() -> bool,\n) -> Result<()> {\n    ensure_dir(root)?;\n    with_lock(root, || {\n        let current_generation = tombstone_generation(root)?;\n        if current_generation.as_ref() != observed_generation {\n            anyhow::bail!(\"telemetry permission changed before arming\");\n        }\n        if !permission_still_enabled() {\n            anyhow::bail!(\"telemetry permission is no longer enabled\");\n        }\n        let tombstone = tombstone_path(root);\n        if tombstone.exists() {\n            fs::remove_file(&tombstone)\n                .with_context(|| format!(\"failed to remove {}\", tombstone.display()))?;\n        }\n        truncate(&buffer_path(root))\n    })\n}\n","sourceCodeStart":448,"sourceCodeEnd":479,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/telemetry/src/buffer.rs#L448-L479","documentation":"arm() enables telemetry buffering using an optimistic-concurrency check: the caller passes the tombstone generation it observed earlier, and arm re-reads it under the privacy lock. If the generation changed — meaning the tombstone was created or removed between the observation and arming, i.e. the user toggled (likely disabled) telemetry — arming is refused with this error instead of overwriting the user's decision.","triggerScenarios":"Calling arm(root, observed_generation, permission_still_enabled) after another process (or the user) modified/deleted the tombstone file, so tombstone_generation(root) no longer equals observed_generation.","commonSituations":"Two codewhale processes racing to enable telemetry; user ran wipe/disable in another terminal just as a session tried to arm; stale observed_generation held across a long-lived session; tests manipulating the telemetry dir concurrently.","solutions":["Re-read the current tombstone generation and retry arm with the fresh value.","If telemetry was disabled meanwhile, respect it — do not force arm; surface the state to the user.","Serialize arming through a single owner (same process/lock discipline) to avoid racing with wipe.","For long sessions, re-observe the generation immediately before arming rather than caching it at startup.","Check for other codewhale processes running concurrently (pgrep) when the error repeats."],"exampleFix":"// before: generation observed long ago\nlet observed = tombstone_generation(root)?;\n// ... much later ...\narm(root, observed, || enabled)?; // may bail\n// after: re-observe just before arming\nlet observed = tombstone_generation(root)?;\narm(root, observed, || enabled)?;","handlingStrategy":"retry","validationCode":"// Re-observe the generation immediately before arming\nlet fresh = telemetry::buffer::tombstone_generation(root)?;\nanyhow::ensure!(fresh.as_ref() == Some(&observed), \"tombstone generation drifted\");","typeGuard":"fn generation_unchanged(root: &Path, observed: &Option<TombstoneGeneration>) -> bool {\n    telemetry::buffer::tombstone_generation(root).ok().as_ref().flatten() == Some(observed)\n}","tryCatchPattern":"match arm(root, observed, || enabled) {\n    Err(e) if e.to_string().contains(\"changed before arming\") => {\n        let fresh = tombstone_generation(root)?;\n        if !disabled_by_user(&fresh) { arm(root, fresh, || enabled)?; }\n    }\n    r => r?,\n}","preventionTips":["Re-read the tombstone generation just before arming, not at startup","Serialize wipe/arm through a single process or lock","Treat a generation change as a user decision, not a retryable glitch","Avoid running multiple codewhale instances that toggle telemetry"],"tags":["telemetry","race-condition","concurrency"],"backgroundTag":"invalid-state-transition","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"}