Hmbown/CodeWhale · error

Runtime event replay_limit cannot exceed

Error message

Runtime event replay_limit cannot exceed {MAX_RUNTIME_EVENT_REPLAY_TAIL}

What it means

Runtime event replay requests are capped at MAX_RUNTIME_EVENT_REPLAY_TAIL to bound memory and channel traffic when a thread resumes history. Requesting a tail_limit above the cap is rejected before any events are collected. Lower the requested limit or paginate by since_seq.

Solutions

  1. Read MAX_RUNTIME_EVENT_REPLAY_TAIL in the crate and clamp tail_limit to it before calling the replay API
  2. Omit tail_limit (None) to use the default bounded tail
  3. Paginate using since_seq instead of one oversized tail request

Example fix

// before
let replay = thread.replay_events(&id, None, Some(100_000)).await?;
// after
let replay = thread.replay_events(&id, None, Some(100_000).map(|n| n.min(MAX_RUNTIME_EVENT_REPLAY_TAIL))).await?;
Defensive patterns

Strategy: validation

Validate before calling

fn valid_tail(limit: Option<usize>, max: usize) -> Option<usize> { limit.map(|l| l.min(max)) }

Type guard

let clamped = tail_limit.filter(|l| *l <= MAX_RUNTIME_EVENT_REPLAY_TAIL);

Try / catch

match thread.replay_events(&id, since, tail).await {
    Ok(r) => r,
    Err(e) if e.to_string().contains("replay_limit") => thread.replay_events(&id, since, None).await?,
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling the replay API on a runtime thread with tail_limit: Option<usize> set to a value greater than MAX_RUNTIME_EVENT_REPLAY_TAIL.

Common situations: Hardcoded large tail sizes copied from older code before the cap was introduced; config-driven tail sizes validated only client-side; callers passing usize::MAX or a very large 'give me everything' sentinel.

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/3d66068e326d9b55. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/runtime_threads.rs:10734

        thread_id: &str,
        offset: u64,
        limit: Option<usize>,
    ) -> Result<(Vec<RuntimeEventRecord>, u64)> {
        let store = self.store.clone();
        let thread_id = thread_id.to_string();
        tokio::task::spawn_blocking(move || store.events_from_offset(&thread_id, offset, limit))
            .await
            .context("Runtime event cursor task failed")?
    }

    pub(crate) async fn replay_events(
        &self,
        thread_id: &str,
        since_seq: Option<u64>,
        tail_limit: Option<usize>,
    ) -> Result<RuntimeEventReplay> {
        if tail_limit.is_some_and(|limit| limit > MAX_RUNTIME_EVENT_REPLAY_TAIL) {
            bail!("Runtime event replay_limit cannot exceed {MAX_RUNTIME_EVENT_REPLAY_TAIL}");
        }
        #[cfg(test)]
        let replay_test_hook = { self.replay_test_hook.lock().take() };
        #[cfg(test)]
        if let Some(hook) = replay_test_hook {
            let (resume, wait_for_resume) = oneshot::channel();
            hook.send(ReplayTestPoint {
                thread_id: thread_id.to_string(),
                resume,
            })
            .map_err(|_| anyhow!("replay test hook closed"))?;
            wait_for_resume
                .await
                .map_err(|_| anyhow!("replay test hook dropped resume"))?;
        }
        let (base_tx, base_rx) = oneshot::channel();
        let (batch_tx, batches) = mpsc::channel(2);
        let store = self.store.clone();

View on GitHub (pinned to 73e0f67d83)