{"record":{"id":"91be4bd11573aa8d","repo":"Hmbown/CodeWhale","slug":"mcp-sse-connect-cancelled-before-the-request-compl","errorCode":null,"errorMessage":"MCP SSE connect cancelled before the request completed","messagePattern":"MCP SSE connect cancelled before the request completed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/tui/src/mcp/sse.rs","lineNumber":111,"sourceCode":"        auth: McpHttpAuth,\n        tx: tokio::sync::mpsc::Sender<SseInbound>,\n        cancel_token: tokio_util::sync::CancellationToken,\n    ) -> Result<()> {\n        let headers = tokio::select! {\n            biased;\n            _ = cancel_token.cancelled() => {\n                anyhow::bail!(\"MCP SSE connect cancelled before authentication completed\")\n            }\n            headers = auth.resolved_headers() => headers?,\n        };\n        let request = apply_safe_custom_headers(\n            with_default_mcp_http_headers(client.get(&url), false),\n            &headers,\n        );\n        let response = tokio::select! {\n            biased;\n            _ = cancel_token.cancelled() => {\n                anyhow::bail!(\"MCP SSE connect cancelled before the request completed\")\n            }\n            response = client.send(request) => response.with_context(|| {\n                format!(\n                    \"MCP SSE connect failed (transport=http url={})\",\n                    mask_url_secrets(&url),\n                )\n            })?,\n        };\n        let status = response.status();\n        if !status.is_success() {\n            let body_excerpt = bounded_body_excerpt(response, ERROR_BODY_PREVIEW_BYTES).await;\n            let body_excerpt = auth.server_error_preview(&body_excerpt);\n            anyhow::bail!(\n                \"MCP SSE rejected (transport=http url={} status={}): {}\",\n                mask_url_secrets(&url),\n                status,\n                body_excerpt,\n            );","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp/sse.rs#L93-L129","documentation":"The SSE connect sent its initial HTTP GET but the cancellation token fired before the response arrived; the pending request is abandoned with this error. Cancellation wins over the in-flight request in the biased select.","triggerScenarios":"Cancelling the token while the initial `client.send(request)` to the MCP SSE endpoint is still in flight (slow server, network latency, shutdown).","commonSituations":"User aborts a slow-connecting MCP server; shutdown during startup; proxy/network causing multi-second connection latency before the response arrives.","solutions":["Retry the connect with the same or a fresh token if cancellation was accidental","Increase client connect/request timeouts if aborts fire before intended timeouts","Check who cancels the token (UI abort, supervisor) and gate it on user intent"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match run_sse_loop(...).await {\n    Err(e) if e.to_string().contains(\"cancelled before the request\") => { /* intentional abort */ }\n    Err(e) => return Err(e.context(\"SSE connect failed\")),\n    Ok(v) => Ok(v),\n}","preventionTips":["Set sane client timeouts so cancellation isn't the only guard","Surface cancellation from actual user actions only"],"tags":["mcp","sse","cancellation","network"],"backgroundTag":"operation-cancelled","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"}