{"record":{"id":"2cd399cbaaad48cd","repo":"Hmbown/CodeWhale","slug":"runtime-event-stream-ended-before-turn-completed","errorCode":null,"errorMessage":"runtime event stream ended before turn.completed","messagePattern":"runtime event stream ended before turn\\.completed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/app-server/src/lib.rs","lineNumber":1982,"sourceCode":"                                    channel: ResponseChannel::Text,\n                                });\n                            }\n                        }\n                    }\n                    \"turn.completed\" => {\n                        let status = turn_terminal_status(&payload);\n                        let error = payload\n                            .pointer(\"/turn/error\")\n                            .and_then(Value::as_str)\n                            .map(str::to_string);\n                        return Ok((last_seq, status, error));\n                    }\n                    _ => {}\n                }\n            }\n        }\n\n        bail!(\"runtime event stream ended before turn.completed\")\n    }\n\n    #[cfg(test)]\n    fn from_base_url_for_test(base_url: String) -> Self {\n        install_rustls_crypto_provider();\n        Self {\n            base_url,\n            client: codewhale_release::platform_http_client_builder()\n                .timeout(Duration::from_secs(5))\n                .build()\n                .expect(\"build reqwest test client\"),\n            auth_token: None,\n            child: None,\n            last_seq_by_thread: HashMap::new(),\n        }\n    }\n}\n","sourceCodeStart":1964,"sourceCodeEnd":2000,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/app-server/src/lib.rs#L1964-L2000","documentation":"After consuming the runtime's SSE event stream to completion, the client looks for a terminal turn.completed event. If the stream ends without one, it throws this error because a turn's outcome could not be confirmed.","triggerScenarios":"The runtime's event stream closes (EOF on the HTTP chunked response) after emitting events but before sending turn.completed — e.g. the runtime crashed, the connection dropped, or the server ended the stream early.","commonSituations":"Runtime process killed mid-turn (OOM, panic, deploy restart); idle connection closed by a proxy timeout; runtime bug that skips the terminal event.","solutions":["Check the runtime process logs for a crash or restart during the turn.","Retry the turn; transient disconnections are the most common cause.","Look at proxy/gateway idle-timeout settings and raise them for long-running turns.","Upgrade the runtime if it can terminate a stream without a terminal event (a known bug)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Rust\nmatch turn.wait_completed() {\n    Err(e) if e.to_string().contains(\"ended before turn.completed\") => {\n        // treat as indeterminate outcome; check runtime liveness, then retry once\n    }\n    other => other,\n}","preventionTips":["Set proxy/gateway idle timeouts above your longest expected turn.","Monitor runtime process health (OOM, restarts) during long turns.","Retry turns that end without a terminal event; treat the outcome as unknown."],"tags":["sse","streaming","network","incomplete-response"],"backgroundTag":"unexpected-response-shape","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"}