Fall back to DeepInfra when the OpenCode Go usage limit refuses a CI OpenCode run

Merged
DS
23d ago
+652-195

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

No issue: this fixes a CI incident from 2026-11-11.

Why we make these changes

The OpenCode Go subscription hit its weekly usage limit on 2026-11-11, and every CI OpenCode run has exited 1 within seconds since then. PR Review Checks reports "No result" (run). OpenCode threat detection fails all 4 attempts with engine_error (run), so warn mode publishes safe outputs with no verdict. David chose a DeepInfra fallback over Go's Extra Usage or a full switch.

Every CI OpenCode run now starts through run_with_fallback in .github/scripts/douwebot_opencode_run.py. That covers douwebot's OpenCode fallback, PR Review Checks and threat detection. The helper reruns on deepinfra/deepseek-ai/DeepSeek-V4.1-Flash only when all of these hold:

  • Go exited non-zero and finished no step.
  • Go's last error event has type provider.go-limit or provider.quota. OpenCode 2.2.5 gives an unretried quota rejection those types (to-session-error.ts).
  • DEEPINFRA_API_KEY is set. Without it, behavior is unchanged.

New public surface

None, because this changes CI only. Douwebot receipts gain engine=opencode-deepinfra, and the review names deepinfra/deepseek-ai/DeepSeek-V4.1-Flash. PR Review Checks spans gain pr_review_checks.provider.

Also in this PR: both OpenCode stream readers now end an event only at LF. OpenCode's JSON.stringify leaves U+2028 raw, and splitlines() cut such an event and failed the review. A test reproduced the failure before the fix. THREAT_MODEL.md gains a pointer: on a fallback, DeepInfra receives the same PR content, fork content included.

Verification

  • Fallback and no-fallback cases at each call site: test_douwebot_opencode_run.py, test_gh_aw_opencode_detect.py, test_run_pr_review_check.py. Receipts: test_pr_gates.py and test_douwebot_config_approval.py.
  • Live probe with OpenCode 2.2.6 and a fake key: deepinfra/deepseek-ai/DeepSeek-V4.1-Flash resolves under --standalone, and DeepInfra answers 401 invalid_api_key. A misspelled model id gives provider.no-route instead.
  • agentic_workflow_guard.py check passes. All 12 locks were recompiled with gh-aw v1.2.1.

bots.yml, pr-review-checks.yml and their scripts run from main, so this PR cannot exercise its own change. The first real run comes after merge.

Lock security review:

  • One new secret, DEEPINFRA_API_KEY. It is in the detection post-step env and gh-aw's redaction list of every lock, and in the douwebot-opencode and PR Review Checks review steps.
  • OpenCode receives that key only on a DeepInfra run. A Go run never sees it.
  • No action, container or network changes.
  • A DeepInfra run sends DeepInfra the same content Go receives, fork PR content included.

What changes for existing users

Nothing. This change is CI only.

PR decisions

2026-11-11 · fallback trigger matches the Go quota error · iter -

  • Decision: Rerun on DeepInfra only on non-zero exit + no step_finish + last error type provider.go-limit or provider.quota + DEEPINFRA_API_KEY set
  • Why: OpenCode 2.2.5 maps a Go usage limit to provider.go-limit, unretried (upstream test 'records OpenCode Console's Go usage limit 429 as a typed step failure without retrying'); a rejected key or outage stays visible
  • Source: https://github.com/anomalyco/opencode/blob/v2.2.5/packages/core/src/session/to-session-error.ts
  • Session: aae7335e-d3a1-43e4-9bbf-bff6a84cdacd

2026-11-11 · new receipt engine opencode-deepinfra · iter -

2026-11-11 · one time budget across both runs · iter -

2026-11-11 · THREAT_MODEL.md unchanged · iter -

2026-11-11 · pre-push review 1 of 3 at 09aa91d38b7b70307417a971facd89cad775a169 · iter -

2026-11-11 · pre-push review 1 of 3 at 09aa91d38b7b70307417a971facd89cad775a169 outcome · iter -

2026-11-11 · pre-push review 2 of 3 at 198c91100548523732e834d427a075bf3eb6550e · iter -

2026-11-11 · pre-push review 2 of 3 at 198c91100548523732e834d427a075bf3eb6550e outcome · iter -

  • Decision: remediated in 558a4cf91: isinstance guard on the quota error type (regression from inlining), provider.quota test, THREAT_MODEL.md pointer sentence, receipt engine values owned by the review-gates section; 2.2.5 binary probe not run (install blocked by the auto-mode classifier)
  • Why: Reviewed tree of 198c91100; 5 findings: 4 fixed, 1 a verification gap that cannot run here
  • Source: https://github.com/pydantic/pydantic-ai/tree/opencode-deepinfra-fallback
  • Session: aae7335e-d3a1-43e4-9bbf-bff6a84cdacd

2026-11-11 · THREAT_MODEL.md gets a pointer sentence · iter -

  • Decision: Add one sentence to THREAT_MODEL.md 'Repository CI and agentic workflows' pointing at .github/workflows/AGENTS.md#opencode-falls-back-from-opencode-go-to-deepinfra; option detail stays there
  • Why: Two independent pre-push reviews read the 'changes a trust or disclosure default' trigger as applying: fork PR content now can reach DeepInfra; a one-sentence pointer is cheap
  • Source: https://github.com/pydantic/pydantic-ai/blob/main/THREAT_MODEL.md#keeping-this-model-current
  • Session: aae7335e-d3a1-43e4-9bbf-bff6a84cdacd
  • Supersedes: THREAT_MODEL.md unchanged

2026-11-11 · pre-push review 3 of 3 at 558a4cf91e4c251b0fd80be2c4fa5ba5b3c2b51b · iter -

2026-11-11 · pre-push review 3 of 3 at 558a4cf91e4c251b0fd80be2c4fa5ba5b3c2b51b outcome · iter -

2026-11-11 · final_text LF fix included · iter -

  • Decision: Fix douwebot_opencode_result.final_text to split at LF only in this PR rather than a follow-up issue
  • Why: Reproduced (failing test on 558a4cf91): a raw U+2028 in model text cut the event and failed every OpenCode review that read it; one line in the stream reader this PR's fallback check mirrors
  • Source: https://github.com/pydantic/pydantic-ai/tree/opencode-deepinfra-fallback
  • Session: aae7335e-d3a1-43e4-9bbf-bff6a84cdacd

2026-11-11 · PR Review Checks red on this PR is expected · iter -

  • Decision: Do not chase PR Review Checks on this PR; it runs main's code against the spent Go quota, and this PR is the fix
  • Why: David: "pr review checks will fail, this PR fixes it"
  • Source: https://github.com/pydantic/pydantic-ai/pull/13158
  • Session: aae7335e-d3a1-43e4-9bbf-bff6a84cdacd

2026-11-11 · merge main at d889cf44e: AGENTS.md conflict · iter -

  • Decision: Kept both new top-level sections in .github/workflows/AGENTS.md (this PR's OpenCode fallback section and #13030's CI Linux runner section); no other conflict; no lock recompile needed
  • Why: Merge queue marked #13158 UNMERGEABLE (CONFLICTING) after #13030 landed; review budget already spent, so no fourth pre-push review
  • Source: https://github.com/pydantic/pydantic-ai/pull/13158
  • Session: aae7335e-d3a1-43e4-9bbf-bff6a84cdacd

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

https://claude.ai/code/session_01NXARKgTQjEAA7jaYSyrSrf


Summary by cubic

When OpenCode Go refuses a CI run because of a usage limit, CI now retries with DeepInfra if DEEPINFRA_API_KEY is configured. Other failures keep their existing behavior.

  • Applies to douwebot reviews, PR Review Checks, and OpenCode threat detection.
  • Review receipts and telemetry identify which provider served the run.
  • DeepInfra receives the same pull request content as OpenCode Go, including content from fork PRs.
  • OpenCode stream readers now split events only at LF, preserving text that contains Unicode line separators.