Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Crash: memorySearch embeddings 429 with no failover to openai-codex OAuth #1004

@odrobnik

Description

@odrobnik

Summary

Gateway crashes with unhandled promise rejection when OpenAI embeddings API returns 429 (quota exceeded). The configured openai-codex OAuth accounts are not used as fallback.

Error

[clawdbot] Unhandled promise rejection: Error: openai embeddings failed: 429 {
    "error": {
        "message": "You exceeded your current quota, please check your plan and billing details.",
        "type": "insufficient_quota",
        "code": "insufficient_quota"
    }
}
  at Object.embed [as embedBatch] (file:///Users/oliver/Developer/clawdbot/src/memory/embeddings.ts:1:1562)
  at MemoryIndexManager.indexFile (file:///Users/oliver/Developer/clawdbot/src/memory/manager.ts:25:3078)
  at MemoryIndexManager.runSync (file:///Users/oliver/Developer/clawdbot/src/memory/manager.ts:25:2016)
error: script "clawdbot" exited with code 1

Environment

  • Clawdbot version: 2026.1.15
  • macOS (arm64)
  • Auth profiles: openai-codex:oliver, openai-codex:sylvia (both working for chat)
  • OPENAI_API_KEY env var set but account has no quota

Config

"memorySearch": {
  "provider": "openai",
  "fallback": "openai",
  "model": "text-embedding-3-small",
  "sync": { "watch": true }
}

Root Cause

  1. Schema restriction: memorySearch.provider only accepts "openai" | "local" — not "openai-codex"
  2. No real fallback: Both provider and fallback are "openai", so failure just fails again
  3. Credential resolution: resolveApiKeyForProvider({ provider: "openai" }) finds OPENAI_API_KEY env var (which has no quota) instead of using openai-codex OAuth tokens
  4. Crash on 429: Unhandled rejection crashes the gateway instead of graceful degradation

Attempted Fix

Setting "provider": "openai-codex" results in:

Invalid config: - agents.defaults.memorySearch.provider: Invalid input

Suggestion: Support Any OpenAI-Compatible Provider

Instead of hardcoding "openai" | "local", allow any provider that resolves to an OpenAI-compatible API:

// Current (restrictive):
provider: "openai" | "local";

// Suggested (flexible):
provider: "openai" | "openai-codex" | "local" | string;

Or better, reuse the existing provider resolution logic:

// In createOpenAiEmbeddingProvider():
const { apiKey } = await resolveApiKeyForProvider({
  provider: options.provider,  // Pass through as-is
  cfg: options.config,
  agentDir: options.agentDir,
});

This would allow:

  • "openai" → uses OPENAI_API_KEY or openai auth profiles
  • "openai-codex" → uses ChatGPT OAuth tokens (if embeddings are included in scope)
  • "openrouter" → uses OpenRouter (supports embeddings)
  • Any custom OpenAI-compatible provider

Additional Issues

  1. Crash vs graceful degradation: 429 should disable memory search, not crash the gateway
  2. Fallback is broken: "fallback": "openai" when provider is already "openai" is a no-op
  3. No warning on startup: If embeddings will fail, warn during config validation

Workaround

Use local embeddings:

"memorySearch": {
  "provider": "local",
  "fallback": "none"
}

Labels

bug, crash, memory, embeddings

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions