Hmbown/CodeWhale · error

telemetry privacy lock is held

Error message

telemetry privacy lock is held

What it means

read_or_create_install_id takes a privacy lock around install-id creation; this error means the lock was already held — concurrent initialization or a leaked guard — so the caller must not read or mint an install id concurrently.

Solutions

  1. Retry once the current privacy-buffer operation releases the lock.
  2. If it persists, a lock was leaked by an earlier panic — restart the process.
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/telemetry/src/envelope.rs:84 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/0145deb8da80a40f. Report an issue: GitHub.

Appendix: source

Thrown at crates/telemetry/src/envelope.rs:84

        let path = buffer::install_id_path(root);
        let existing = std::fs::read_to_string(&path)
            .ok()
            .and_then(|body| serde_json::from_str::<InstallId>(&body).ok())
            .filter(|record| uuid::Uuid::parse_str(record.install_id.trim()).is_ok())
            .filter(|record| !is_expired(&record.rotated_at));
        if let Some(record) = existing {
            return Ok(record);
        }
        let record = InstallId {
            schema_version: 1,
            install_id: uuid::Uuid::new_v4().to_string(),
            rotated_at: now_rfc3339(),
        };
        codewhale_config::persistence::atomic_write_json(&path, &record)
            .with_context(|| format!("failed to write {}", path.display()))?;
        Ok(record)
    })?
    .ok_or_else(|| anyhow::anyhow!("telemetry privacy lock is held"))
}

fn is_expired(rotated_at: &str) -> bool {
    let Ok(parsed) = chrono::DateTime::parse_from_rfc3339(rotated_at) else {
        // An unreadable timestamp is treated as expired: minting a fresh random
        // id is always the safe direction.
        return true;
    };
    let age = chrono::Utc::now().signed_duration_since(parsed.with_timezone(&chrono::Utc));
    age.num_days() >= ROTATION_DAYS
}

/// Read `state.json`, or a default when it is missing or unreadable.
#[must_use]
pub fn read_state(root: &Path) -> TelemetryState {
    std::fs::read_to_string(buffer::state_path(root))
        .ok()
        .and_then(|body| serde_json::from_str::<TelemetryState>(&body).ok())

View on GitHub (pinned to 73e0f67d83)