Files
coder/coderd/x
Michael Suchacz 3576e04e2d fix(coderd/x/chatd): keep the chat output cap on compaction summaries (#31042)
Compaction summaries asked the provider for 1.5 times the model's
configured output cap. When an admin adds a known model, the form fills
`max_output_tokens` with the provider maximum, 128,000 for
`claude-opus-5-5`, so each summary request sent `max_tokens: 192000`.
Anthropic rejected it with HTTP 400 (`max_tokens: 192000 > 128000, which
is the maximum allowed number of output tokens for claude-opus-5-5`), so
compaction failed and the chat could not shrink its context.

`compactionSummaryCall` now keeps the chat call's cap. The 50% headroom
came from #28886, which accepted the overshoot for caps set at a
provider ceiling as a tradeoff. With catalog defaults, that case is the
common one. `GenerateCompaction` still lowers the cap to the remaining
context window when that is smaller.

Closes [CODAGT-1428](https://linear.app/codercom/issue/CODAGT-1428).

The ticket also shows "Your input exceeds the context window" on a
summary request. That is a separate failure, which #30766 handles
(merged after the ticket was filed), so this PR does not change it.

**Tests**

- New `TestActiveServer_ManualCompaction/summary keeps the configured
output cap`: a 128,000 cap reaches both the chat turn and the summary
request unchanged. On the old code it fails with `expected: 128000
actual: 192000`.
- `TestBuildTurnEnvironmentClampsRequestedReasoningEffortToMax` and the
compaction hook tests now expect the unchanged default cap (32,000
instead of 48,000). #30942 rewrites the first test and keeps a `3 *
defaultChatMaxOutputTokens / 2` expectation, so whichever PR merges
second drops that factor.

**Validation**

- `go test ./coderd/x/chatd/ ./coderd/x/chatd/chatloop/ -count=1`:
passes
- `make pre-commit`: passes
- Remote dogfood UAT against `claude-opus-5-5` with a 128,000 cap: on
`main`, manual, automatic, and compaction-model-override summaries asked
for 192,000 tokens and failed with the 400 above. On this branch, all 16
summary requests (the same flows plus an unset cap and a small context
window) succeeded, and none asked for more than its configured cap. Chat
turn `max_tokens` was the same on both. UAT ran on `9230a6e9fa1`; the
head `3633adef53e` only adds a comment edit.
- No new dependencies. The polish pass and the test audit changed no
files.
- Codex review on `3633adef53e`: no findings.

> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.
2026-10-20 13:06:57 +02:00
..