Hmbown/CodeWhale · warning
PythonRuntime::with_state_path is deprecated — use PythonRun
Error message
PythonRuntime::with_state_path is deprecated — use PythonRuntime::new() or PythonRuntime::spawn_with_context()
What it means
While streaming an Anthropic-model response, one SSE event failed to parse from the provider's event stream. The malformed event is logged and skipped - the stream keeps yielding subsequent events and only ends at MessageStop - so a single bad event degrades content (a missing delta) rather than failing the whole turn.
Source
Thrown at crates/tui/src/repl/runtime.rs:187
impl PythonRuntime {
/// Spawn a REPL with no `context` variable and no LLM helpers wired up.
/// Used by the agent loop for inline `repl` blocks the model emits in
/// regular conversation.
pub async fn new() -> Result<Self, String> {
Self::spawn_inner(None, Some(ROUND_TIMEOUT)).await
}
/// Compatibility shim — older RLM code path used to pass a state file.
/// The state file is no longer used, but the path doubles as an extra
/// scratch location callers can rely on for cleanup symmetry.
pub fn with_state_path(_path: PathBuf) -> Self {
// Synchronous constructor is no longer meaningful: spawning Python
// is async. Callers in turn.rs already use `spawn_with_context` —
// this stub is kept only so the public surface compiles for any
// out-of-tree user. It returns a deliberately broken runtime that
// panics on first use, which is preferable to silently lying.
unreachable!(
"PythonRuntime::with_state_path is deprecated — \
use PythonRuntime::new() or PythonRuntime::spawn_with_context()"
)
}
/// Spawn a REPL with the long input preloaded from a file. Used by the
/// RLM turn loop.
pub async fn spawn_with_context(context_path: &Path) -> Result<Self, String> {
Self::spawn_inner(Some(context_path), None).await
}
async fn spawn_inner(
context_path: Option<&Path>,
round_timeout: Option<Duration>,
) -> Result<Self, String> {
let session_id = Uuid::new_v4().simple().to_string();
let bootstrap = render_bootstrap(&session_id);
View on GitHub (pinned to 0c42157ee5)
Solutions
- Point base_url directly at the real Anthropic endpoint to rule out gateway/proxy mangling
- Upgrade codewhale - new event variants are protocol additions picked up in newer releases
- Capture the raw stream (curl -N) and compare event names/payload shapes against what the client expects
- If answers look truncated, check whether the skipped event was a content_block_delta or whether MessageStop ever arrived
Defensive patterns
Strategy: fallback
Validate before calling
// Smoke-test the endpoint's SSE framing before pointing codewhale at it: // curl -N https://gateway/v1/messages -H 'content-type: application/json' -d @req.json // verify event:/data: lines match Anthropic's framing
Type guard
// Narrow only the events you depend on; tolerate skips of other kinds.
if let Ok(event) = result {
if let StreamEvent::ContentBlockDelta(delta) = event {
accumulate(delta);
}
} Try / catch
// Detect silent truncation: if MessageStop never arrived within the deadline,
// the skipped event may have cost real content - retry the turn instead of
// accepting a partial answer.
if !saw_message_stop {
retry_turn();
} Prevention
- Prefer first-party endpoints over SSE-rewriting proxies
- Upgrade codewhale alongside provider API changes
- Inspect answers for missing text after any gateway or proxy change
When it happens
Trigger: A malformed SSE frame from an Anthropic-compatible endpoint: a proxy or gateway rewriting/chunking the stream incorrectly, an intermediate layer corrupting event lines, or a provider protocol change introducing an event shape the client's deserializer rejects.
Common situations: Third-party Anthropic-compatible gateways with subtly different SSE framing; corporate proxies buffering or mangling event streams; version skew between codewhale's protocol support and a newly deployed provider API.
Related errors
- unrecognized SSE event: {e}
- runtime SSE frame exceeded {MAX_SSE_FRAME_BYTES} bytes witho
- runtime event stream ended before turn.completed
- SSE stream request failed: HTTP {status}: {error_text}
- MCP SSE server sent a message before declaring its endpoint
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/6e9539ecb56b0fab.
Report an issue: GitHub.