Record the OpenCode Go usage window and retry-after when `provider.go-limit` refuses a CI OpenCode run

Merged
DS
22d ago
+154-49

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

No issue: a maintainer-requested CI telemetry change.

Why we make these changes

When OpenCode Go refuses a CI OpenCode run, the job log and the OpenCode run span say only error type provider.go-limit, status 429. They do not say which usage window refused the run (5 hour, weekly or monthly), or how long until it lets runs through again, so a short 5-hour stall reads the same as a spent monthly window. OpenCode's own Logfire telemetry records neither value.

OpenCode 2.2.5, the version CI pins, already reads both: goLimit takes the window from the 429 body's metadata.limitName, and providerError sets retryAfterMs on the error from the response's Retry-After (to-session-error.ts, test). This PR records them from the stream's last error event.

New public surface

None: CI scripts only. The OpenCode run span gains opencode_fallback.limit_name and opencode_fallback.retry_after_ms.

User-visible behavior

Job log of a Go-limit refusal:

-OpenCode run on opencode-go/deepseek-v4.1-flash on OpenCode Go failed with error type provider.go-limit, status 429.
+OpenCode run on opencode-go/deepseek-v4.1-flash on OpenCode Go failed with error type provider.go-limit, status 429, 5 hour limit, retry after 120000 ms.
  • The same body names the Go workspace in metadata.workspace. It is never read: job logs and spans are public.
  • The window prints only when shaped like one, and the retry-after only when it is an integer. Every other error type logs as before.

Verification

Not verified: whether live OpenCode Go 429s carry limitName and Retry-After. The fixture follows OpenCode 2.2.5's own test, and CI keeps no raw event stream. A missing value records nothing, so the first Go-limit refusal after merge shows it.

What changes for existing users

Nothing.

Scope notes
  • report_failure moves from a closure in run_with_fallback to module-level _report_failure, unchanged apart from the new block: Ruff's C901 counts nested functions toward run_with_fallback, which sat at the limit of 15 on main.
  • Only provider.go-limit is covered. retryAfterMs on other error types and the PR Review Checks review span stay unchanged.
  • THREAT_MODEL.md is unchanged: the change reads the error event the job already reads, and moves no input path, authority, trust or disclosure default, or backend guarantee.
PR decisions

2026-11-14 · Record the Go window and retry-after only for provider.go-limit · iter -

2026-11-14 · Move report_failure to module level · iter -

  • Decision: Moved the nested report_failure to module-level _report_failure next to _export_run
  • Why: Ruff C901 counts nested defs toward run_with_fallback (15 on main, 20 with the new branches); agent_docs/complexity.md Extract a method forbids nested helpers
  • Source: https://github.com/pydantic/pydantic-ai/tree/opencode-go-limit-window
  • Session: e7a00fe8-0c1e-4b6a-992b-49056b8b8823

2026-11-14 · Live limitName and Retry-After presence unverified before merge · iter -

  • Decision: Ship shape-checked fields that record nothing when absent; the first go-limit refusal after merge shows whether live 429s carry them
  • Why: No Go key on the box and CI keeps no raw stream; Logfire holds only OpenCode's AI.Error exception attributes, which carry no response body
  • Source: https://github.com/pydantic/pydantic-ai/tree/opencode-go-limit-window
  • Session: e7a00fe8-0c1e-4b6a-992b-49056b8b8823

2026-11-14 · No THREAT_MODEL.md update · iter -

2026-11-14 · pre-push review 1 of 3 at 02b408886c1effb76741b607dc71f7d6d0116246 · iter -

2026-11-14 · pre-push review 1 of 3 at 02b408886c1effb76741b607dc71f7d6d0116246 · iter -

2026-11-14 · exempt delta fe3913d55 chained from reviewed 02b408886 · iter -

  • Decision: push without another pre-push review: docstring-only delta (Attempt.retry_after_ms), applying douwebot's Optional finding
  • Why: pushing-commits-to-the-repo exempt row 'Comments or docstrings only, no docs/** page': git diff 02b408886..fe3913d55 changes one docstring line
  • Source: https://github.com/pydantic/pydantic-ai/pull/13452#discussion_r4573754271
  • Session: e7a00fe8-0c1e-4b6a-992b-49056b8b8823

2026-11-14 · Keep the int check on retryAfterMs · iter -

  • Decision: Declined douwebot's Optional bool-subclass finding; answered and resolved
  • Why: OpenCode 2.2.5 types retryAfterMs NonNegativeInt on QuotaExceededError and Session.StructuredError, so the pinned CLI cannot emit a bool; matches the existing status check; a fix would cost another full review round
  • Source: https://github.com/pydantic/pydantic-ai/pull/13452#discussion_r4573962776
  • Session: e7a00fe8-0c1e-4b6a-992b-49056b8b8823

2026-11-14 · Merge criteria stand in for the second-opinion choice · iter -

  • Decision: No additional review surface; enqueue at the manager-relayed merge criteria
  • Why: David's relayed task set enqueue criteria (CI green, clean douwebot APPROVE, Optional comments fixed or answered and resolved, no unresolved threads) without a second opinion
  • Source: https://github.com/pydantic/pydantic-ai/pull/13452
  • Session: e7a00fe8-0c1e-4b6a-992b-49056b8b8823

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_01BYcNCmfrFK9dMidbo4xvLu