Skip to content

modules: default image quality has no accepted quality-error fallback #3984

Open

Description

@schlessera

Out of scope

No new image models, live provider qualification, paid API requests, quality-capability claims, resolution policy (#1822), GIF/SVG/markup features, general retry/backoff policy or persisted capability cache. Do not alter an explicitly requested quality, including auto or max.

Context

Part of #3781. The final Scope and quality-fallback acceptance criterion of closed #3782 require a default-only max → xhigh → high fallback when OpenAI rejects the quality parameter. #3786 delivered the model/default/complexity changes, but this accepted fallback is absent from inspected main 3c44ac6fc56d27675dadaf38a16254db53c39f69.

openaiProvider (packages/module-images/src/providers/openai.ts:318) sends the default max (DEFAULT_OPENAI_QUALITY, same file:110). Both the generation response at lines 382–387 and multipart edit response at lines 412–413 immediately enter readError (same file:215), which does not read error.param or step down. estimateOpenAiOutputCost (same file:182) and the existing result note provide the relevant cost/reporting surfaces.

Observed, keyless reproduction (2026-11-11): importing the actual provider at that SHA, installing the repository network guard and stubbing its fetch to return HTTP 400 with {"error":{"message":"Unsupported quality tier","type":"invalid_request_error","param":"quality"}} produced one request, qualities: ["max"], and OpenAI: Unsupported quality tier. The accepted behavior requires at most three requests, in order ["max", "xhigh", "high"]. Zero real provider calls were made. This proves the missing fallback, not which tiers a live provider accepts.

Scope

  • Implement the previously accepted fallback for generation JSON and multipart edits, including the selectable 2.5 pair.
  • Only when quality was omitted, HTTP status is exactly 400 and the parsed error's param is exactly quality, retry the same request one tier lower: max, then xhigh, then high. If high is rejected, surface the error. No more than three quality attempts.
  • Preserve all other fields and edit bytes across attempts. An explicit quality and unrelated errors keep their existing behavior and never trigger a tier change.
  • When fallback succeeds, the existing result note names the effective tier. Reported cost or estimate uses the actual successful tier and existing usage evidence; unknown costs remain unknown. A dry run still estimates the initial default, without a request.
  • Keep the documentation and changeset accurate about the default-only step-down, without claiming live support for an unverified tier.

Acceptance criteria

  • Offline provider tests cover a first-attempt success, success at xhigh, success at high, and failure at high; assert exact outbound quality order, request count, unchanged payload fields/bytes and effective-tier note for generation and edit.
  • Explicit low, medium, high, xhigh, max and auto are never changed by a quality error. Another/missing param, another status and a malformed/non-JSON error cannot trigger tier fallback.
  • A CLI-level offline case proves successful fallback reports the existing JSON envelope with the effective-tier note and correct cost/estimate behavior. Existing usage-based costing remains accurate; unsupported estimates remain unknown.
  • Named tests fail on current main for the missing fallback, then pass. Removing the fallback and incorrectly applying it to explicit quality each kill a named test on its expected assertion; restore both mutations and record receipts.
  • No real network/API key is needed. Existing image module checks and required PR checks pass.

Verification

Use the existing offline fetch patterns in packages/module-images/tests/providers.test.ts and packages/module-images/tests/cli.test.ts, under the test network guard. Run focused tests with the repository test script and bun run check:pr --base origin/main. Record the failing-first and mutation receipts in the PR. Do not qualify this with a paid request.

Contract impact

Reuse the existing CLI JSON fields and provider result note; no envelope, MCP, schema or frontmatter change is required. This restores the final accepted #3782 behavior. Include the affected package's fix changeset under the release procedure when implementing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: modulesFirst-party content modules and the module seam.priority: p1Scheduled into the current or next milestone.type: fixSomething is broken and must behave the way it is documented.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions