fix(opencode): retry output-limit responses

Merged
MA
3mo ago
+187-4

Summary

  • retry output-limit responses with at most three total LLM calls
  • resample the identical LLM request object without adding a continuation message
  • replace only attempts that will actually be retried, while rolling their billed usage into one final persisted step-finish record
  • preserve the third call's partial output when all attempts truncate, matching Cloud's intentional partial-result-plus-error behavior
  • leave existing retry behavior for rate limits, transport failures, and provider 5xx responses unchanged

Production evidence

Four V4 runs in the audited 12-hour window ended at provider output limits. None made another LLM request; two had no extractable answer and two retained only a truncated partial answer.

Historical behavior

  • output partials have been persisted since the 2025-11-17 agent-loop refactor
  • Cloud PR #5002 intentionally returns a final truncated partial next to its failure
  • generic retries were originally bounded at 10; the same 2025-11-17 refactor replaced that loop with an unbounded one

Validation

  • bun test test/session/retry.test.ts (34 passed)
  • targeted processor regression proves identical input, one final persisted boundary, and combined usage (1 passed)
  • real local bcode run: successful resample made 2 calls; exhausted resample stopped at exactly 3 calls and exited 1
  • the plain CLI stdout streams partial attempts before cleanup; Cloud's final result is extracted from the cleaned persisted transcript
  • package and root typecheck passed with Bun 1.3.14 (16/16 root tasks)
  • targeted oxlint: 0 errors