{"record":{"id":"3d66068e326d9b55","repo":"Hmbown/CodeWhale","slug":"runtime-event-replay-limit-cannot-exceed-max-runt","errorCode":null,"errorMessage":"Runtime event replay_limit cannot exceed {MAX_RUNTIME_EVENT_REPLAY_TAIL}","messagePattern":"Runtime event replay_limit cannot exceed (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":10734,"sourceCode":"        thread_id: &str,\n        offset: u64,\n        limit: Option<usize>,\n    ) -> Result<(Vec<RuntimeEventRecord>, u64)> {\n        let store = self.store.clone();\n        let thread_id = thread_id.to_string();\n        tokio::task::spawn_blocking(move || store.events_from_offset(&thread_id, offset, limit))\n            .await\n            .context(\"Runtime event cursor task failed\")?\n    }\n\n    pub(crate) async fn replay_events(\n        &self,\n        thread_id: &str,\n        since_seq: Option<u64>,\n        tail_limit: Option<usize>,\n    ) -> Result<RuntimeEventReplay> {\n        if tail_limit.is_some_and(|limit| limit > MAX_RUNTIME_EVENT_REPLAY_TAIL) {\n            bail!(\"Runtime event replay_limit cannot exceed {MAX_RUNTIME_EVENT_REPLAY_TAIL}\");\n        }\n        #[cfg(test)]\n        let replay_test_hook = { self.replay_test_hook.lock().take() };\n        #[cfg(test)]\n        if let Some(hook) = replay_test_hook {\n            let (resume, wait_for_resume) = oneshot::channel();\n            hook.send(ReplayTestPoint {\n                thread_id: thread_id.to_string(),\n                resume,\n            })\n            .map_err(|_| anyhow!(\"replay test hook closed\"))?;\n            wait_for_resume\n                .await\n                .map_err(|_| anyhow!(\"replay test hook dropped resume\"))?;\n        }\n        let (base_tx, base_rx) = oneshot::channel();\n        let (batch_tx, batches) = mpsc::channel(2);\n        let store = self.store.clone();","sourceCodeStart":10716,"sourceCodeEnd":10752,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L10716-L10752","documentation":"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.","triggerScenarios":"Calling the replay API on a runtime thread with tail_limit: Option<usize> set to a value greater than MAX_RUNTIME_EVENT_REPLAY_TAIL.","commonSituations":"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.","solutions":["Read MAX_RUNTIME_EVENT_REPLAY_TAIL in the crate and clamp tail_limit to it before calling the replay API","Omit tail_limit (None) to use the default bounded tail","Paginate using since_seq instead of one oversized tail request"],"exampleFix":"// before\nlet replay = thread.replay_events(&id, None, Some(100_000)).await?;\n// after\nlet replay = thread.replay_events(&id, None, Some(100_000).map(|n| n.min(MAX_RUNTIME_EVENT_REPLAY_TAIL))).await?;","handlingStrategy":"validation","validationCode":"fn valid_tail(limit: Option<usize>, max: usize) -> Option<usize> { limit.map(|l| l.min(max)) }","typeGuard":"let clamped = tail_limit.filter(|l| *l <= MAX_RUNTIME_EVENT_REPLAY_TAIL);","tryCatchPattern":"match thread.replay_events(&id, since, tail).await {\n    Ok(r) => r,\n    Err(e) if e.to_string().contains(\"replay_limit\") => thread.replay_events(&id, since, None).await?,\n    Err(e) => return Err(e),\n}","preventionTips":["Clamp tail_limit against MAX_RUNTIME_EVENT_REPLAY_TAIL at the call site","Validate any config-driven tail size at load time","Prefer since_seq pagination over huge tails"],"tags":["rust","validation","limit"],"backgroundTag":"value-out-of-range","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}