Hmbown/CodeWhale · error

Runtime Chat operation key is too long

Error message

Runtime Chat operation key is too long

What it means

validate_operation_key first applies the general relay-id rules and then enforces a maximum length of MAX_OPERATION_KEY_BYTES. Operation keys that exceed this byte budget are rejected because keys are used as state-map keys and must stay bounded.

Solutions

  1. Truncate or hash the operation key (e.g. SHA-256 hex) before validating
  2. Shorten the components concatenated into the key (use shorter ids or drop redundant prefixes)
  3. Check MAX_OPERATION_KEY_BYTES and assert key length at construction time
  4. Stop using unbounded user input as an operation key

Example fix

// before
let key = format!("{route}/{thread}/{turn}/{fingerprint}");
// after
let key = sha256_hex(format!("{route}/{thread}/{turn}/{fingerprint}"));
Defensive patterns

Strategy: validation

Validate before calling

fn operation_key_fits(key: &str) -> bool { key.len() <= MAX_OPERATION_KEY_BYTES }
fn bounded_key(parts: &[&str]) -> String {
    let joined = parts.join(":");
    if joined.len() > MAX_OPERATION_KEY_BYTES {
        sha256_hex(&joined) // fixed-length fallback
    } else { joined }
}

Type guard

fn as_operation_key(value: &str) -> Option<&str> {
    (value.len() <= MAX_OPERATION_KEY_BYTES).then_some(value)
}

Try / catch

if let Err(e) = validate_operation_key(&key) {
    if e.to_string().contains("too long") {
        let key = hash_key(&raw); // retry with a hashed, fixed-length key
    }
}

Prevention

When it happens

Trigger: Calling validate_operation_key with a string longer than MAX_OPERATION_KEY_BYTES (check the constant in crates/tui/src/runtime_chat_relay.rs) — typically very long generated operation ids or concatenated labels.

Common situations: Building operation keys by concatenating route + thread + turn ids without bounding them; a provider returning oversized operation identifiers; unbounded user input used as an operation key.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at crates/tui/src/runtime_chat_relay.rs:1705

fn validate_relay_id(value: &str, label: &str) -> Result<()> {
    if value.is_empty()
        || value.len() > MAX_RELAY_ID_BYTES
        || value.contains("..")
        || value.contains("://")
        || !value.bytes().all(|byte| {
            byte.is_ascii_alphanumeric()
                || matches!(byte, b'.' | b'_' | b':' | b'@' | b'/' | b'+' | b'~' | b'-')
        })
    {
        bail!("invalid Runtime Chat {label}");
    }
    Ok(())
}

fn validate_operation_key(value: &str) -> Result<()> {
    validate_relay_id(value, "operation key")?;
    if value.len() > MAX_OPERATION_KEY_BYTES {
        bail!("Runtime Chat operation key is too long");
    }
    Ok(())
}

fn validate_virtual_thread_id(value: &str) -> Result<()> {
    if value.len() != 37
        || !value.starts_with("local_thread_")
        || !value[13..]
            .bytes()
            .all(|byte| byte.is_ascii_digit() || matches!(byte, b'a'..=b'f'))
    {
        bail!("invalid Runtime Chat virtual thread id");
    }
    Ok(())
}

fn validate_virtual_turn_id(value: &str) -> Result<()> {
    if value.len() != 35

View on GitHub (pinned to 73e0f67d83)