Composio action calls fail with 'Connection error, try to authenticate' for 30-60s after OAuth completes — add retry / readiness probe
Summary
When a Composio toolkit connection completes OAuth and the chat-runtime's tool surface is refreshed (via PR #1670 / PR #1687), the very first delegate_<toolkit> dispatch against the new connection often returns Connection error, try to authenticate and succeeds on the second attempt 30-60 seconds later. The orchestrator's routing is correct; the failure is in Composio's runtime not having the OAuth token usable yet for action execution.
Either add a retry inside integrations_agent's action-execution path, or extend wait_for_connection_active to confirm token usability (not just connection status) before declaring the connection ready.
Problem
What happened vs expected
Reproduces on every fresh Composio OAuth where the user immediately asks the orchestrator to use the just-connected toolkit. Validated against staging on Windows desktop dev build (commit 6ed41e44, branch fix/orchestrator-mid-session-tool-refresh):
- Click "Connect Google Calendar" in Settings → Connections. OAuth through, Allow.
- ~2 seconds later,
[composio:bus] connection observed active; invalidating + eagerly warming integrations cache toolkit=googlecalendarfires. Cache is hot. - Orchestrator's next turn picks up the change:
[agent_loop] connection set changed mid-session ... refreshing tool schema+[agent] refresh_delegation_tools: ... added=["delegate_googlecalendar"]. - User asks "what's on my calendar this week?".
- Model correctly dispatches via
delegate_googlecalendar→integrations_agentwithskill_filter=googlecalendar. Routing is right. integrations_agentmakes a Composio action call (e.g.googlecalendar.events.list).- Composio returns the literal string
Connection error, try to authenticate(a 401-equivalent at the action layer). - Orchestrator surfaces a "calendar is connected but I can't read events" message to the user.
- User says "try now" 60 seconds later. Same dispatch, same path. Second attempt succeeds, returns actual calendar events.
Live evidence from this run:
03:16:32:INF:bus [composio:bus] connection observed active; invalidating + eagerly warming integrations cache toolkit=googlecalendar status=ACTIVE
03:16:53:INF:log [agent] delegating to integrations_agent via delegate_googlecalendar (skill_filter=googlecalendar)
03:17:01:DBG:log [agent] tool output for delegate_googlecalendar: **Connection error, try to authenticate**
03:17:19:INF:log [agent] (retry) delegating to integrations_agent via delegate_googlecalendar
03:17:48:DBG:log [agent] tool output for delegate_googlecalendar: Based on the Google Calendar data retrieved, here are the upcoming events:
Observed the same pattern with googlecalendar (twice) and github (once) during the same session.
Root cause
Composio reports connection state in two phases that aren't simultaneous:
-
status == "ACTIVE"on the connection record. Whatwait_for_connection_activeinsrc/openhuman/composio/bus.rspolls for. Reached as soon as Composio's connection-management layer accepts the OAuth callback and exchanges the auth code for a token. ~1-2 seconds after the user clicks Allow. -
Token usable for action execution. Composio's action-execution gateway has to sync the new token from the connection store to its execution cache, run scope validation against the provider (Google, GitHub, etc.), and sometimes wait out an internal rate-limit window before first use. Typically 30-60 seconds for Google Workspace toolkits, occasionally longer.
The gap between (1) and (2) is the window in which our code does everything correctly — list_connections returns the toolkit as ACTIVE, our cache has it, the agent's schema has delegate_<toolkit>, the model routes correctly — but the underlying Composio action call returns the auth error.
Why this isn't fixable in PR #1687
PR #1687 (mid-session tool refresh) handles every layer up to and including the dispatch. The error originates downstream of delegate_<toolkit>, inside integrations_agent's call to Composio's /agent-integrations/composio/execute endpoint. The chat-runtime gets back a normal success: true from the sub-agent (the sub-agent ran to completion; it just got an error string from the API), so there's no signal at the orchestrator layer to retry.
Solution (optional)
Three viable directions, ranked by invasiveness.
A — Retry inside integrations_agent action-execution loop (smallest, recommended)
In whatever path inside integrations_agent executes a Composio action (likely src/openhuman/composio/tools.rs or the per-action ComposioActionTool::execute), detect the specific failure string and retry once after a short backoff (5-10 s). Pseudo-code:
let result = client.execute_action(...).await?;
if result.error_message.as_deref() == Some("Connection error, try to authenticate") {
tokio::time::sleep(Duration::from_secs(10)).await;
result = client.execute_action(...).await?; // single retry
}
Pros: tiny scope, isolated to the integration-execute path, doesn't change any external contract. Cons: hardcodes a string match; if Composio rewords the error our retry stops firing silently.
B — Probe-based readiness check in wait_for_connection_active (more thorough)
Extend wait_for_connection_active (composio/bus.rs:467+) to not just poll for status == ACTIVE but also issue a no-op probe action call (e.g. googlecalendar.calendarList.list with maxResults=1, github.users.get_authenticated, etc.) and only consider the connection "ready" when the probe succeeds. Per-toolkit probe map needed.
Pros: eliminates the gap entirely from the user's perspective. Cache invalidate + agent refresh only fires when the toolkit is actually usable. Cons: requires a per-toolkit probe registry (many toolkits, mapping not obvious). Adds 1-2 extra round-trips per OAuth completion. Slower OAuth-to-tool-ready end-to-end.
C — Surface to model via prompt hint (cheapest, partial fix)
Add a line to the orchestrator's prompt explaining the Composio post-OAuth lag and instructing the model to silently retry once on Connection error, try to authenticate. Lets the model self-recover without any runtime plumbing.
Pros: zero code. Works for any toolkit. Cons: depends on the model actually following the instruction; one user-visible "calendar is connected but I can't read events yet" message before the retry kicks in.
Recommendation
A for the immediate ergonomic win. Add a WAIT_RETRY_AUTH_ERROR_STRINGS: &[&str] constant near the action-execution path so the retry isn't gated on a free-form match, and so Composio rewording the string is a one-line update. Combined with C as a prompt-side belt-and-braces — costs nothing and helps the model communicate the wait to the user gracefully if A's single retry isn't enough.
Acceptance criteria
- [ ] Repro gone — connecting a fresh Composio toolkit in Settings → Connections, then immediately asking the orchestrator to use it, succeeds on the first attempt instead of returning
Connection error, try to authenticate. - [ ] No silent regression on real auth errors — actual revoked / mis-scoped connections still surface the auth error to the user after a single retry attempt, with a clean message.
- [ ] Regression coverage — unit / integration test that exercises a
ComposioActionTool::executeagainst a mock returning the auth-error string and asserts a single retry fires. - [ ] Diff coverage ≥ 80% — fix PR meets the changed-lines coverage gate.
Related
- PR #1670 —
fix(agent): synthesise delegate_<toolkit> tools after live integrations fetch. Made mid-session toolkit awareness possible. - PR #1687 —
fix(agent): refresh delegation surface on mid-session Composio connect/revoke. This issue surfaced during validation of #1687; the chat-runtime side is correct, this is the downstream Composio gap. - Issue #1659 — original orchestrator-can't-pick-Gmail report. Resolved by #1670 + #1687.
🤖 Filed via Claude Code as a follow-up to PR #1687's live validation on staging.
Picking this up. Will go with option A — single retry on the auth-error string inside the composio execute path (mirrors the slack rate-limit retry already in providers/slack). 8s backoff, gated on a small RETRYABLE_AUTH_ERRORS list so a Composio wording change is a one-line patch. PR up shortly.