zeroclaw-labs/zeroclaw · info

serialize canonical content

Error message

serialize canonical content

What it means

compute_entry_hash() serializes a JSON object built with json! from actor/action/result/security strings and a numeric sequence, then hashes the serialized bytes for the append-only audit hash chain. serde_json::to_string on such a value is infallible (no unserializable types, no streaming IO), so this expect documents an invariant rather than a recoverable error path.

Source

Thrown at crates/zeroclaw-runtime/src/security/audit.rs:195

    pub fn with_security(mut self, sandbox_backend: Option<String>) -> Self {
        self.security.sandbox_backend = sandbox_backend;
        self
    }
}

fn compute_entry_hash(prev_hash: &str, event: &AuditEvent) -> String {
    // Build a canonical representation of the content fields only.
    let content = serde_json::json!({
        "timestamp": event.timestamp,
        "event_id": event.event_id,
        "event_type": event.event_type,
        "actor": event.actor,
        "action": event.action,
        "result": event.result,
        "security": event.security,
        "sequence": event.sequence,
    });
    let content_json = serde_json::to_string(&content).expect("serialize canonical content");

    let mut hasher = Sha256::new();
    hasher.update(prev_hash.as_bytes());
    hasher.update(content_json.as_bytes());
    hex::encode(hasher.finalize())
}

/// Internal chain state tracked across writes.
struct ChainState {
    prev_hash: String,
    sequence: u64,
}

/// Audit logger
pub struct AuditLogger {
    log_path: PathBuf,
    config: AuditConfig,
    chain: Mutex<ChainState>,

View on GitHub (pinned to 88bb9c8533)

Solutions

  1. If extending the audit entry schema, keep fields to JSON-native types or propagate serialization as a Result.
  2. No action needed for runtime users; verify_chain failures about hash mismatches are unrelated to this expect.
  3. Run the audit log/verify_chain tests after schema changes.
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Any audit log() or verify_chain() call goes through this code; the panic would require serde to fail on plain strings and integers, which cannot happen. Not triggerable via audit event content.

Common situations: None for users. Maintainers extending the audit event schema with non-serializable custom types would need to revisit this expect.

Related errors


AI-assisted analysis of zeroclaw-labs/zeroclaw@88bb9c8533 (2026-08-23). Data as JSON: /api/errors/12832165367865ec. Report an issue: GitHub.