Hmbown/CodeWhale · error · anyhow::Error

Gemini model ` ` requires a thought signature to replay…

Error message

Gemini model `{model}` requires a thought signature to replay tool call `{id}`, but none was captured (the turn predates signature capture, or the provider omitted it). Start a new session before using tools on this route.

What it means

Gemini models that emit thought signatures require each replayed function call to carry the `thought_signature` captured when the model produced it. During wire-body construction, `validate_google_thought_signature_replay` checks every tool call for `/extra_content/google/thought_signature`; a missing one makes the turn unreplayable on this route, so it bails with guidance to start a new session. Raised in `crates/tui/src/client/chat.rs` around line 732.

Solutions

  1. Start a new session — old turns without signatures cannot be replayed on this route.
  2. Regenerate the affected turn so a signature is captured and stored.
  3. If history was imported/stripped, re-capture or drop the signature-less tool-call turns from the replayed history.
  4. Confirm the provider actually returned signatures for every tool call in the turn.
Defensive patterns

Strategy: validation

Validate before calling

fn replay_safe(call: &Value, requires_signatures: bool) -> Result<(), String> {
    if requires_signatures
        && call.pointer("/extra_content/google/thought_signature").and_then(Value::as_str).is_none()
    {
        return Err("tool call lacks thought signature; start a new session".into());
    }
    Ok(())
}

Type guard

fn has_thought_signature(call: &Value) -> bool {
    call.pointer("/extra_content/google/thought_signature")
        .and_then(Value::as_str)
        .map(|s| !s.is_empty())
        .unwrap_or(false)
}

Try / catch

match build_chat_wire_body(...) {
    Err(e) if e.to_string().contains("thought signature") => {
        log::warn!("stale session without signatures; starting fresh");
        start_new_session();
    }
    other => other,
}

Prevention

When it happens

Trigger: Building a chat wire body for a signature-requiring Gemini model where a history message contains a tool call whose stored `extra_content.google.thought_signature` is absent — sessions recorded before signature capture existed, or the provider omitted the signature when generating the call.

Common situations: Resuming an old session log created before thought-signature capture shipped; provider dropped the signature for some calls; importing/migrating history from another client that strips the extra_content metadata.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at crates/tui/src/client/chat.rs:732

) -> Result<()> {
    if !is_google_openai_compat_chat_route(base_url) {
        return Ok(());
    }
    let requires_signatures = google_model_requires_thought_signatures(model);
    let mut unsigned_call_ids: Vec<&str> = Vec::new();
    for message in messages {
        let Some(tool_calls) = message.get("tool_calls").and_then(Value::as_array) else {
            continue;
        };
        for call in tool_calls {
            let missing = call
                .pointer("/extra_content/google/thought_signature")
                .and_then(Value::as_str)
                .is_none();
            if missing {
                let id = call.get("id").and_then(Value::as_str).unwrap_or("?");
                if requires_signatures {
                    anyhow::bail!(
                        "Gemini model `{model}` requires a thought signature to replay tool call \
                         `{id}`, but none was captured (the turn predates signature capture, or \
                         the provider omitted it). Start a new session before using tools on \
                         this route."
                    );
                }
                unsigned_call_ids.push(id);
            }
        }
    }
    if !unsigned_call_ids.is_empty() {
        // Bounded: identifiers only, and only the first few of them.
        let sample = unsigned_call_ids
            .iter()
            .take(3)
            .copied()
            .collect::<Vec<_>>()
            .join(", ");

View on GitHub (pinned to 73e0f67d83)