Repository navigation
Description
Summary
agent.Summarize builds its completion request with only Messages set. It never
populates llmapi.Request.MaxOutputTokens, so the provider client applies its own
fallback, which is far smaller than the budget the session is configured with. On a long
conversation the summary is cut off mid-sentence, and the truncated fragment is then
persisted as the post-compaction resume prompt.
Where
cmd/rune-agent/agent/agent.go:1844
func Summarize(ctx context.Context, svc llmapi.Service, model llmapi.ModelEntry, messages []llmapi.Message) (string, error) {
...
summaryReq := llmapi.Request{
Messages: append(messages, prompt),
}Compare the chat path, which does set it, at cmd/rune-agent/agent/agent.go:802:
MaxOutputTokens: a.MaxOutputTokens(),Agent.MaxOutputTokens() holds the session value (set by /max_tokens, validated against
the bound model at cmd/rune-agent/extension/command_adapter.go:482 via
llmarg.ValidateMaxOutputTokens). agent.compact (agent.go:1642) does not pass it
through to CompactDialogue, and CompactDialogue (agent.go:1893) does not pass it to
Summarize.
Impact
With MaxOutputTokens == 0 every provider substitutes its own default:
internal/llm/anthropic/api.go:64-78falls through toparams.MaxTokens = 8192.
Config.AnthropicClientConfig()ininternal/llm/config.go:160never sets
anthropic.Config.MaxTokens, so the middle branch cannot fire either.internal/llm/openai/client.go:431falls back toconfig.MaxCompletionTokens.internal/llm/gemini/client.go:146falls back to the provider config limit.
The compaction prompt asks for a 9-section summary plus an <analysis> scratchpad, and
reasoning tokens share the same budget. On a long session (observed: 361 messages, 133
assistant turns, 224 tool results) the response hits the cap and the stream stops
mid-sentence. The result is a resume prompt containing an unterminated <summary> block
cut inside a fenced code block. See #78 for what the model does with it.
Proposed fix
Plumb the session's max-output-token value from Agent into CompactDialogue and
Summarize, and set it on the request:
- Add a field to
compactOptions(for exampleWithMaxOutputTokens(int)) or extend the
CompactDialogueandSummarizesignatures. Both are exported and have two production
call sites:agent.compact(agent.go:1642) and the agentshell/compactcommand
(cmd/rune-agent/agentshell/agentshell.go:1056). - In
Summarize, setsummaryReq.MaxOutputTokenswhen the value is non-zero.
Do not clamp inside the agent against a provider-specific ceiling. The summarize
service may be any provider. The session value is already validated against the bound
model by llmarg.ValidateMaxOutputTokens when it is set, and each provider client applies
its own ceiling (for example effectiveMaxOutputTokens at
internal/llm/gemini/client.go:160). Passing the value through unmodified is the correct
provider-agnostic behaviour. When it is 0 the existing provider defaults still apply.
Tests
Per the repo bug-fix policy, start with a failing test:
- In
cmd/rune-agent/agent/agent_test.go, assert that the request captured by the fake
llmapi.Serviceused by the existing compaction tests carries the configured
MaxOutputTokens. Table-driven: a configured value, and0meaning "leave unset". - Assert the agent does not rewrite the value (no clamping), so the test stays
provider-neutral.
Verification
go test -race -run TestCompact ./cmd/rune-agent/agent/
make generate && make lint && make test
Activity
Fix compaction summary to use session max-output-token budget (#80)