Record the OpenCode Go usage window and retry-after when `provider.go-limit` refuses a CI OpenCode run
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
test_go_limit_names_its_window_and_retry_after: the job-log line, including values not shaped like a window or retry-after, and a non-Go-limit error.test_logfire_token_exports_a_span_per_run: the span attributes; theexportedfixture asserts the workspace id never reaches Logfire.
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_failuremoves from a closure inrun_with_fallbackto module-level_report_failure, unchanged apart from the new block: Ruff'sC901counts nested functions towardrun_with_fallback, which sat at the limit of 15 onmain.- Only
provider.go-limitis covered.retryAfterMson other error types and thePR Review Checksreview span stay unchanged. THREAT_MODEL.mdis 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 -
- Decision: Read metadata.limitName and retryAfterMs only when the error type is provider.go-limit; never read metadata.workspace
- Why: OpenCode 2.2.5 reads limitName only in goLimit; job logs and spans are public, so the workspace id in the same body stays out
- Source: https://github.com/anomalyco/opencode/blob/v2.2.5/packages/core/src/session/to-session-error.ts
- Session: e7a00fe8-0c1e-4b6a-992b-49056b8b8823
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 -
- Decision: Leave THREAT_MODEL.md unchanged
- Why: No trigger in Keeping this model current applies: same input (the error event already read), no authority, trust or disclosure default, or backend change
- Source: https://github.com/pydantic/pydantic-ai/tree/opencode-go-limit-window
- Session: e7a00fe8-0c1e-4b6a-992b-49056b8b8823
2026-11-14 · pre-push review 1 of 3 at 02b408886c1effb76741b607dc71f7d6d0116246 · iter -
- Decision: reserved; dispatching
- Why: tree 1c5bd6e88f0931461893e160984289b896e3b4a5; scope fb64b4100c0882b4d5e1be8b9a38d7ae6b70c795..02b408886c1effb76741b607dc71f7d6d0116246 (full branch); first review
- Source: https://github.com/pydantic/pydantic-ai/tree/opencode-go-limit-window
- Session: e7a00fe8-0c1e-4b6a-992b-49056b8b8823
2026-11-14 · pre-push review 1 of 3 at 02b408886c1effb76741b607dc71f7d6d0116246 · iter -
- Decision: one finding (show the THREAT_MODEL.md call): dismissed; the PR body states it, and the job-log disclosure rule's owner is .github/workflows/AGENTS.md, updated here
- Why: tree 1c5bd6e88f0931461893e160984289b896e3b4a5; scope fb64b4100..02b408886c1effb76741b607dc71f7d6d0116246; Haiku, policy-base checkout, no fan-out
- Source: https://github.com/pydantic/pydantic-ai/tree/opencode-go-limit-window
- Session: e7a00fe8-0c1e-4b6a-992b-49056b8b8823
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.