The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(mcp): propagate dashboard OAuth flow errors to the callback waiter
liuhao10248e3d540534c1
diff --git a/tests/tools/test_mcp_dashboard_oauth.py b/tests/tools/test_mcp_dashboard_oauth.pyindex bf781e50f65..8d9abba5e65 100644--- a/tests/tools/test_mcp_dashboard_oauth.py+++ b/tests/tools/test_mcp_dashboard_oauth.py@@ -118,6 +118,61 @@ def test_mcp_oauth_helpers_use_dashboard_flow_without_loopback_port():assert flow.authorization_url == "https://idp.example/authorize?state=state-4"+def test_mark_error_surfaces_real_cause_to_callback_waiter():+ """A failure marked before any browser redirect (worker crash,+ authorization-URL timeout, user cancel) must reach the SDK's callback+ waiter, not the generic "did not include an authorization code" line."""+ from tools.mcp_dashboard_oauth import DashboardOAuthFlow++ flow = DashboardOAuthFlow(+ flow_id="flow-err",+ server_name="asana",+ profile=None,+ hermes_home="/tmp/hermes-test",+ redirect_uri="https://agent.example/mcp/oauth/callback/flow-err",+ )+ flow.mark_error("403 Forbidden from the OAuth registration endpoint")++ assert flow.snapshot()["error"] == "403 Forbidden from the OAuth registration endpoint"+ with pytest.raises(RuntimeError, match="403 Forbidden from the OAuth registration endpoint"):+ asyncio.run(flow.wait_for_callback())+++def test_mark_error_with_empty_message_stays_diagnosable():+ """str() of a bare TimeoutError() is ""; the waiter must still report a+ flow failure instead of falling through to the no-code message."""+ from tools.mcp_dashboard_oauth import DashboardOAuthFlow++ flow = DashboardOAuthFlow(+ flow_id="flow-empty",+ server_name="asana",+ profile=None,+ hermes_home="/tmp/hermes-test",+ redirect_uri="https://agent.example/mcp/oauth/callback/flow-empty",+ )+ flow.mark_error("")++ with pytest.raises(RuntimeError, match="empty error message"):+ asyncio.run(flow.wait_for_callback())+++def test_late_mark_error_cannot_override_delivered_callback():+ from tools.mcp_dashboard_oauth import DashboardOAuthFlow++ flow = DashboardOAuthFlow(+ flow_id="flow-late",+ server_name="reports",+ profile=None,+ hermes_home="/tmp/hermes-test",+ redirect_uri="https://agent.example/mcp/oauth/callback/flow-late",+ )+ asyncio.run(flow.publish_authorization_url("https://idp.example/authorize?state=s9"))+ flow.deliver_callback(code="code-9", state="s9", error=None)++ flow.mark_error("worker crashed after the browser redirected")+ assert asyncio.run(flow.wait_for_callback())[:2] == ("code-9", "s9")++def test_failed_reauth_rollback_preserves_newer_oauth_state(tmp_path, monkeypatch):from tools.mcp_oauth import HermesTokenStoragediff --git a/tools/mcp_dashboard_oauth.py b/tools/mcp_dashboard_oauth.pyindex 782cb70eb10..5caea620292 100644--- a/tools/mcp_dashboard_oauth.py+++ b/tools/mcp_dashboard_oauth.py@@ -112,6 +112,16 @@ class DashboardOAuthFlow:returnself.status = "error"self.error = error+ # The SDK's callback waiter reads _callback_error, not error — without+ # this copy, a failure marked before any browser redirect (worker+ # crash, authorization-URL timeout, user cancel) wakes the waiter+ # with no callback and no error, surfacing as the generic+ # "did not include an authorization code" RuntimeError while the+ # real cause stays unread. An empty message (str() of a bare+ # TimeoutError) must not fall through either. Guarded so a late+ # mark_error cannot override an already delivered callback.+ if self._callback is None and self._callback_error is None:+ self._callback_error = error or "MCP OAuth flow failed before the callback was received (empty error message)"self._authorization_ready.set()self._callback_ready.set()