{"record":{"id":"363a490a62257234","repo":"Hmbown/CodeWhale","slug":"runtime-api-turn-response-missing-turn-id","errorCode":null,"errorMessage":"runtime API turn response missing turn.id","messagePattern":"runtime API turn response missing turn\\.id","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/app-server/src/lib.rs","lineNumber":1798,"sourceCode":"            }\n            request[\"images\"] = json!(images);\n        }\n        if let Some(limit) = max_output_tokens {\n            request[\"maxOutputTokens\"] = json!(limit);\n        }\n        let turn = self\n            .request_json(\n                self.authed(\n                    self.client\n                        .post(format!(\"{}/v1/threads/{thread_id}/turns\", self.base_url)),\n                )\n                .json(&request),\n            )\n            .await?;\n        let turn_id = turn\n            .pointer(\"/turn/id\")\n            .and_then(Value::as_str)\n            .ok_or_else(|| anyhow!(\"runtime API turn response missing turn.id\"))?\n            .to_string();\n        let response_id = format!(\"{thread_id}:{turn_id}\");\n\n        if let Some(transcript) = transcript.as_deref_mut() {\n            transcript.model = turn\n                .pointer(\"/thread/model\")\n                .and_then(Value::as_str)\n                .map(str::to_string);\n            transcript.events.push(EventFrame::ResponseStart {\n                response_id: response_id.clone(),\n            });\n        }\n\n        emit_stdio_event(\n            writer,\n            json!({\n                \"type\": \"response_start\",\n                \"response_id\": response_id,","sourceCodeStart":1780,"sourceCodeEnd":1816,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/app-server/src/lib.rs#L1780-L1816","documentation":"Thrown while parsing the runtime API's turn-start HTTP response. The code extracts the turn identifier from the JSON pointer `/turn/id` and requires it to be a string; if the pointer is absent, null, or not a string, it cannot construct the `thread_id:turn_id` response key and raises this error. It guards against the upstream runtime returning a malformed or incomplete turn payload.","triggerScenarios":"The POST that starts a turn returns JSON without a string at `turn.id` — e.g. the runtime accepted the request but the response shape changed, or an error was returned as a 200 with a different body.","commonSituations":"Runtime API version drift changing the response schema; server-side errors returning partial payloads; proxies or gateways rewriting responses; hitting the wrong endpoint.","solutions":["Log/capture the full raw response body to see what the runtime actually returned for `/turn/id`.","Check that the runtime API server version matches the version this client was built against.","Verify the endpoint is the turn-creation route and not an error or fallback route.","Add a guard that validates `turn.id` presence and reports the payload before constructing the response id."],"exampleFix":"// before\nlet turn_id = turn.pointer(\"/turn/id\").and_then(Value::as_str).ok_or_else(|| anyhow!(\"runtime API turn response missing turn.id\"))?;\n// after\nlet turn_id = turn.pointer(\"/turn/id\").and_then(Value::as_str)\n    .ok_or_else(|| anyhow!(\"runtime API turn response missing turn.id: {}\", serde_json::to_string(&turn).unwrap_or_default()))?;","handlingStrategy":"validation","validationCode":"if turn.pointer(\"/turn/id\").and_then(Value::as_str).is_none() {\n    // reject/log payload before calling the turn-start API\n}","typeGuard":"fn has_turn_id(v: &Value) -> bool { v.pointer(\"/turn/id\").map_or(false, Value::is_string) }","tryCatchPattern":"match start_turn(...).await {\n    Err(e) if e.to_string().contains(\"missing turn.id\") => { /* log raw response, check runtime version */ }\n    other => other?,\n}","preventionTips":["Pin and verify the runtime API version on both sides","Validate response schemas in integration tests against a live mock","Include the raw payload in error messages for diagnosability"],"tags":["json","api-response","missing-field"],"backgroundTag":"unexpected-api-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"}