Files
coder/coderd
Dean Sheather acbcd0e807 fix(coderd/x/chatd): remember quickgen parameter rejections per model (#31493)
On Claude Opus 5.5, chat title generation and the turn-status label each
made four upstream requests, three of them rejected with a 400. The
temperature retry in `generateQuickgenObject` called `generateObject`
again, which restarted from the forced tool call the model had already
rejected. Each turn left about six `bad_request` rows in
`aibridge_interceptions` and added 1.5 to 3.5 seconds of latency.

This replaces the per-call fallbacks with `quickgenParamModel`, a
wrapper applied in `resolveModelCall`. It falls back to plain JSON text
when the model rejects the forced `tool_choice`, drops `temperature`
when the model rejects it, and records each rejection in a replica-wide
`sync.Map` keyed by AI provider ID, model, and parameter, following the
existing `thinkingDropBlock` map. Entries expire after 6 hours so a
provider that starts accepting a parameter again is picked up without a
restart. Only quickgen calls `GenerateObject`, so chat turns are
unaffected.

| Opus 5.5 | Before | First job per replica (and after expiry) | Later
jobs |
|---|---|---|---|
| Title / status label | 4 (3 rejected) | 3 (2 rejected) | 1 |
| Summary | 2 (1 rejected) | 2 (1 rejected) | 1 |

Rejections are still detected by matching `tool_choice` or `temperature`
in a 400 body, as before. A false match now persists for the TTL on that
replica rather than one job; the worst case is text mode or no
temperature for that model.

Closes
[CODAGT-1411](https://linear.app/codercom/issue/CODAGT-1411/quickgen-side-jobs-make-3-rejected-requests-per-run-on-claude-opus-55)

<details>
<summary>Decision log</summary>

- Opus 5.5 reports one rejected parameter per 400, so a job that knows
nothing yet needs 3 requests; the issue's "2 requests" target for the
minimal fix isn't reachable.
- A per-job flag (first iteration) only got jobs to 3 requests. Sharing
rejections across jobs gets steady state to 1 without a hardcoded model
list, which wouldn't match gateway aliases such as Bedrock IDs anyway.
- Per-replica memory over a database column or admin setting: no
migration, no request-path writes, self-healing via TTL. Each replica
pays the learning cost once per model per TTL window.
- Keyed by provider ID plus model so the same model name behind
different providers is learned independently.

</details>

> Generated by Coder Agents on behalf of @deansheather.
2026-11-09 22:39:29 +11:00
..