Skip to content

enrich: 'Chat gateway unavailable' despite valid chat model + key — availability gate runs before gateway configuration (--background path unaffected) #2590

Description

@ikamal97

Version: 0.42.56.0, Postgres engine. chat_model = openai:gpt-4o-mini (confirmed via gbrain config get chat_model), OPENAI_API_KEY exported in the shell.

Observed:

  • gbrain enrich --thin --types person --limit 3 --max-usd 0.25 → exits with Chat gateway unavailable. Configure a chat model…
  • gbrain enrich … --dry-run → works (14 candidates enumerated).
  • gbrain enrich … --background + gbrain jobs workall jobs complete successfully with the same env/config.
  • Passing --model openai:gpt-4o-mini explicitly does not change the direct-path failure.

Cause (from reading the source): the gate at src/commands/enrich.ts (if (!parsed.dryRun && !isAvailable('chat'))) runs before the engine/gateway is configured. isAvailable (src/core/ai/gateway.ts) returns false whenever _config is null — configureGateway() hasn't been called yet at that point in the direct CLI path — so the check reports "unavailable" regardless of actual config/keys. The jobs worker configures the engine before executing the handler, which is why --background succeeds.

Suggestion: move the availability gate after engine/gateway initialization (or call configureGateway from resolved config + process.env before the gate). The current error message sends users chasing model/key config that is actually fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-reviewNeeds a human skim to classifyp3P3: low priority / needs glance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions