fix(cli,mcp): keep live authorize alive through the OAuth flow#281
Merged
warren618 merged 1 commit intoJun 22, 2026
Merged
Conversation
The connector authorize OAuth handshake timed out before the token was persisted (HKUDS#259). Two root causes: 1. The OAuth flow is driven lazily by the list_tools discovery request, which is bounded by the per-call tool_timeout (default 30s), not init_timeout. The prior fix widened only init_timeout, so a Robinhood face-scan sign-in (>30s) still tripped the handshake. 2. The 30s timeout was retried, and the retry opened a fresh client context that started a SECOND OAuth callback server on a new port, orphaning the sign-in the user had just completed. Fix: - cmd_live_authorize now raises BOTH tool_timeout and init_timeout to a configurable authorize deadline (VIBE_LIVE_AUTHORIZE_TIMEOUT_SECONDS, default 300s), raise-only so a larger user value is preserved. - The authorize handshake runs a single non-retried list_tools attempt via build_mcp_tool_wrappers(..., max_list_tools_attempts=1), so a transient failure cannot spawn a duplicate OAuth flow. - _run_with_retry takes a configurable attempts cap; runtime/registry callers keep the default 2 (one transient retry) unchanged. Closes HKUDS#259 Signed-off-by: Robin1987China <41602358+Robin1987China@users.noreply.github.com>
This was referenced Jun 22, 2026
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #259 —
vibe-trading connector authorize <broker>times out before the OAuth token is persisted, soconnector checkstill reportsOAuth token: missingeven though the browser sign-in succeeded.The reporter's follow-up log (after the earlier
init_timeoutbump) pins down two root causes:The widened timeout was the wrong one. The FastMCP OAuth flow is driven lazily by the first request to the server — the
list_toolsdiscovery handshake — which is bounded by the per-calltool_timeout(default 30s), not theinit_timeoutthat the authorize command already raised to 300s. A Robinhood face-scan sign-in takes longer than 30s, solist_toolstimes out mid-flow.The retry orphaned a successful authorization. The 30s timeout is treated as transient, so
list_toolswas retried. The retry opens a fresh client context that starts a second OAuth callback server on a new port, abandoning the sign-in the user had just completed on the first one. The log shows exactly this — callback on:58132, timeout + retry, then a new callback on:58173.Changes
agent/cli/_legacy.py—cmd_live_authorizenow raises bothtool_timeoutandinit_timeoutto a configurable authorize deadline (raise-only; a larger user-configured value is preserved). The deadline is read fromVIBE_LIVE_AUTHORIZE_TIMEOUT_SECONDS(default 300s) via a new_authorize_timeout_seconds()resolver.agent/cli/_legacy.py— the authorize handshake runs a single, non-retriedlist_toolsattempt (build_mcp_tool_wrappers(..., max_list_tools_attempts=1)), so a transient failure can't spawn a duplicate OAuth flow.agent/src/tools/mcp.py—build_mcp_tool_wrappersandMCPServerAdapteraccept amax_list_tools_attempts(default 2);_run_with_retrytakes a configurableattemptscap instead of a hard-coded2. Runtime/registry callers are unchanged (still one transient retry).Why this is enough
FastMCP's OAuth provider already persists the token when the browser callback returns. The fix just keeps the single handshake alive long enough for the human flow and stops a retry from starting a competing callback server — which is sufficient to land the token. (Decoupling persistence from discovery entirely would be a larger FastMCP-side change; left out of scope.)
Test Plan
ruff check— cleanpytest agent/tests/test_cli_live.py agent/tests/test_mcp_client_adapter.py— 85 passedNew tests:
tool_timeoutto the deadline (regression for the wrong-knob bug)VIBE_LIVE_AUTHORIZE_TIMEOUT_SECONDSoverride honored; invalid/empty/non-positive → 300s defaultlist_toolsattempt withmax_list_tools_attempts=1(no duplicate OAuth flow); default still retries onceCloses #259