Skip to content

fix(dream): drop ANTHROPIC_API_KEY gate from patterns phase#2279

Open
brettdavies wants to merge 1 commit into
garrytan:masterfrom
brettdavies:fix/patterns-drop-anthropic-gate
Open

fix(dream): drop ANTHROPIC_API_KEY gate from patterns phase#2279
brettdavies wants to merge 1 commit into
garrytan:masterfrom
brettdavies:fix/patterns-drop-anthropic-gate

Conversation

@brettdavies

Copy link
Copy Markdown

Closes #2278

Summary

The bug. gbrain dream --phase patterns returns { status: 'skipped', reason: 'no_api_key' } on any non-Anthropic stack (litellm-proxy, codex-proxy, ollama, openrouter, any openai-compat deployment) regardless of how models.dream.patterns resolves. The phase never reaches its subagent submission below, which would have routed through the gateway and dispatched correctly.

The fix. Drop the if (!process.env.ANTHROPIC_API_KEY) short-circuit in src/core/cycle/patterns.ts. The subagent submission below already uses the same gateway model-tier resolver that synthesize uses; when the gateway is misconfigured, dispatch surfaces a clear AIConfigError per-call rather than a misclassified skipped: no_api_key verdict.

Diagnosis

  • src/core/cycle/patterns.ts:67-69 (pre-patch) short-circuits when ANTHROPIC_API_KEY is unset:

    ts if (!process.env.ANTHROPIC_API_KEY) { return skipped('no_api_key', 'ANTHROPIC_API_KEY unset; pattern detection skipped'); }

  • The submission immediately below the gate calls submitSubagent(...), which routes through gateway.toolLoop() via the recipe registered for whichever model the resolver selected. That path already supports every non-Anthropic recipe (litellm, ollama, openrouter, openai, claude-cli, …).

  • The sibling synthesize phase removed its equivalent gate (see the makeJudgeClient docstring at src/core/cycle/synthesize.ts:804, which "preserves the legacy 'no ANTHROPIC_API_KEY' cheap-skip semantics" while delegating real auth probing to the gateway recipe's auth_env.required machinery).

The patterns phase carries the same pattern in its body but never had the gate updated when the rest of the cycle moved to gateway-routed dispatch.

Reproduction

  1. Fresh brain with no ANTHROPIC_API_KEY in env, paid traffic routed through any non-Anthropic recipe.
  2. gbrain config set models.dream.patterns litellm:gpt-5.4 (or any non-anthropic:* model).
  3. gbrain dream --phase patterns --json.
  4. Expected: subagent dispatches and returns pattern detections.
  5. Actual (pre-patch): { status: 'skipped', reason: 'no_api_key' }.

Tests

  • Manual verification on a brain with models.dream.patterns = litellm:gpt-5.4 and no ANTHROPIC_API_KEY in env: pre-patch returned the skipped verdict; post-patch dispatched through the litellm route and returned pattern detections.
  • No new unit test added; the change deletes a literal env-var check and the existing patterns-phase tests cover the dispatch path. Happy to add a regression test that asserts the phase reaches the gateway when ANTHROPIC_API_KEY is unset if the maintainer prefers.

Adjacent observation (follow-up, not in this PR)

Other phases / commands may carry similar stale ANTHROPIC_API_KEY checks that pre-date the gateway-routed dispatch. Worth a rg -n 'ANTHROPIC_API_KEY' src/core/cycle src/commands sweep to catch siblings. The synthesize phase is already clean; patterns is the one this PR fixes. Anything else found would be a separate small PR per site.

Synthesize phase already removed its hardcoded `process.env.ANTHROPIC_API_KEY` cheap-skip; the makeJudgeClient docstring at synthesize.ts:804 documents why: non-Anthropic stacks (litellm/codex-proxy, deepseek, openrouter, ollama, etc.) reach their upstream through the gateway recipe machinery, not an env-var presence check. The patterns phase still carried the legacy gate, so on a codex-proxy stack `gbrain dream --phase patterns` short-circuited with `ANTHROPIC_API_KEY unset; pattern detection skipped` even though synthesize in the same cycle drained 800+ reflection subagents via litellm:gpt-5.5 without issue.

Removing the gate is the matching change. The subagent submission below uses the same gateway routing synthesize already proves works on this stack, and when the gateway IS misconfigured the subagent dispatch surfaces a clear AIConfigError rather than a silent "skipped: no_api_key" verdict that misclassifies the failure.

Verified end-to-end on a production-shaped brain: 834 reflections available for pattern mining, patterns phase wrote 5 pattern pages including `areas/patterns/bounded-subagents-and-orchestrator-writes`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dream patterns phase skips with no_api_key on non-Anthropic stacks even though the subagent submission below routes through the gateway

1 participant