bytedance/deer-flow · warning · HTTPException

Too many pending channel connection codes. Wait for existing

Error message

Too many pending channel connection codes. Wait for existing codes to expire or use one of them.

What it means

429 from the connect-code creation helper (channel_connections.py:346): repo.create_oauth_state_within_cap() returned false, meaning the owner already has _MAX_PENDING_CONNECT_CODES_PER_PROVIDER (5) unexpired binding codes for this provider. The insert is an atomic delete-expired + count + insert so concurrent POSTs from one owner cannot each see count < cap and all insert past it. Codes expire after _STATE_TTL_SECONDS (600s = 10 minutes); this is per-user-per-provider throttling of pending connect codes.

Source

Thrown at backend/app/gateway/routers/channel_connections.py:346

    repo: ChannelConnectionRepository,
    *,
    owner_user_id: str,
    provider: str,
) -> str:
    now = datetime.now(UTC)
    state = _new_binding_code()
    # Atomic delete-expired + count + insert so concurrent connect POSTs from one
    # owner cannot each see count < cap and all insert past the cap.
    inserted = await repo.create_oauth_state_within_cap(
        owner_user_id=owner_user_id,
        provider=provider,
        state=state,
        expires_at=now + timedelta(seconds=_STATE_TTL_SECONDS),
        max_pending=_MAX_PENDING_CONNECT_CODES_PER_PROVIDER,
        now=now,
    )
    if not inserted:
        raise HTTPException(
            status_code=429,
            detail="Too many pending channel connection codes. Wait for existing codes to expire or use one of them.",
        )
    return state


def _connect_instruction(provider: str, code: str) -> str:
    if provider == "telegram":
        return f"Send /start {code} to the DeerFlow Telegram bot."
    meta = _PROVIDER_META.get(provider)
    if meta is None:
        raise HTTPException(status_code=404, detail="Unknown channel provider")
    return f"Send /connect {code} to the DeerFlow {meta['display_name']} bot."


def _connect_url(config: ChannelConnectionsConfig, provider: str, code: str) -> str | None:
    if provider == "telegram":
        provider_config = _provider_config(config, provider)

View on GitHub (pinned to 1dd6ba1acb)

Solutions

  1. Reuse one of the already-issued pending codes (the error text says exactly this) — they remain valid until they expire
  2. Wait for the oldest codes to expire (up to 10 minutes, _STATE_TTL_SECONDS=600) before requesting a new one
  3. Fix the client: request a code once and display/reuse it; do not loop on code creation — respect 429 with the standard Retry-After backoff posture

Example fix

// before — frontend mints a code on every render
useEffect(() => { postConnect(provider); }, [provider]);

// after — mint once, reuse while pending
const [code, setCode] = useState(null);
useEffect(() => {
  if (!code) postConnect(provider).then(r => setCode(r.code)).catch(e => {
    if (e.status === 429) showPendingCodes(e); // surface existing codes
  });
}, []);
Defensive patterns

Strategy: retry

Validate before calling

# Client: track pending codes per provider before requesting more
const pending = await fetchPendingCodes(provider);
if (pending.length >= 5) return pending[0]; // reuse instead of minting

Try / catch

try { code = await createConnectCode(provider) }
catch (e) {
  if (e.status === 429) { const codes = await fetchPendingCodes(provider); return codes[0]; } // reuse existing
  throw e;
}

Prevention

When it happens

Trigger: POSTing /api/channels/connections/{provider}/connect (or equivalent code-issuing endpoint) six or more times within 10 minutes without completing or expiring the earlier codes — e.g. a UI retry loop, repeated button clicks, or an automation that requests a fresh code per attempt.

Common situations: User repeatedly clicking 'generate connect code'; frontend re-requesting a code on every render/poll; scripts minting codes without consuming them.

Related errors


AI-assisted analysis of bytedance/deer-flow@1dd6ba1acb (2026-08-14). Data as JSON: /api/errors/2f73db49e7bf1187. Report an issue: GitHub.