{"record":{"id":"51ec55adc6993e73","repo":"aaif-goose/goose","slug":"failed-to-receive-authorization-code-51ec55","errorCode":null,"errorMessage":"Failed to receive authorization code","messagePattern":"Failed to receive authorization code","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/goose/src/config/signup_tetrate/mod.rs","lineNumber":141,"sourceCode":"                eprintln!(\"Server error: {}\", e);\n            }\n        });\n\n        let auth_url = self.get_auth_url(port);\n\n        println!(\"Opening browser for Tetrate Agent Router Service authentication...\");\n        eprintln!(\"Auth URL: {}\", auth_url);\n\n        if let Err(e) = webbrowser::open(&auth_url) {\n            eprintln!(\"Failed to open browser automatically: {}\", e);\n            println!(\"Please open this URL manually: {}\", auth_url);\n        }\n\n        println!(\"Waiting for authentication callback on port {}...\", port);\n\n        let code = match timeout(AUTH_TIMEOUT, code_rx).await {\n            Ok(Ok(code)) => Ok(code),\n            Ok(Err(_)) => Err(anyhow!(\"Failed to receive authorization code\")),\n            Err(_) => Err(anyhow!(\"Authentication timeout - please try again\")),\n        }?;\n\n        println!(\"Authorization code received. Exchanging for API key...\");\n        eprintln!(\"Received code: {}\", code);\n\n        let api_key = self.exchange_code(code).await?;\n\n        // Shutdown the server if it's still running\n        if let Some(tx) = self.server_shutdown_tx.take() {\n            let _ = tx.send(());\n        }\n\n        Ok(api_key)\n    }\n}\n\npub use self::PkceAuthFlow as TetrateAuth;","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/aaif-goose/goose/blob/3810898a7447ec3299be72e223d3570a7aabf0ab/crates/goose/src/config/signup_tetrate/mod.rs#L123-L159","documentation":"Tetrate signup waits on a channel for the OAuth authorization code delivered by the local callback server. Ok(Err(_)) means the channel closed without a code: the server task (or its sender) went away before the callback arrived. The timeout case produces a separate 'Authentication timeout' error instead.","triggerScenarios":"The callback server fails to bind its port (occupied by another process) or otherwise exits early, dropping the sender; the browser then has nowhere to deliver the code. Root-cause output appears on stderr.","commonSituations":"Concurrent signup flows competing for the callback port; a stale process holding the port; restricted environments where the local listener cannot start.","solutions":["Check stderr for the server failure line; free the callback port (kill the stale/parallel flow) and rerun","Run only one Tetrate signup flow at a time","Retry the flow — a clean restart re-creates the listener"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before the flow, ensure the callback port is bindable:\nif std::net::TcpListener::bind((\"127.0.0.1\", port)).is_err() {\n    // report the port conflict instead of letting the server task die silently\n}","typeGuard":null,"tryCatchPattern":"let code = match wait_for_code().await {\n    Err(e) if e.to_string() == \"Failed to receive authorization code\" => {\n        // server dropped the channel: free the port / stop the parallel flow, then restart\n        retry_flow().await?\n    }\n    Err(e) if e.to_string().starts_with(\"Authentication timeout\") => {\n        // user never finished the browser step; restart and guide them\n        retry_flow().await?\n    }\n    other => other?,\n};","preventionTips":["Run a single Tetrate signup flow at a time","Watch stderr for the server error that precedes this failure","Make sure the browser can reach the loopback callback URL"],"tags":["auth","oauth","tetrate","network"],"backgroundTag":null,"analyzedSha":"3810898a7447ec3299be72e223d3570a7aabf0ab","analyzedAt":"2026-08-16T10:14:26.282Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}