Skip to content

Compaction summary request sends no max-output-token budget and silently falls back to the provider default #77

Closed

Description

@ernestrc

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-78 falls through to params.MaxTokens = 8192.
    Config.AnthropicClientConfig() in internal/llm/config.go:160 never sets
    anthropic.Config.MaxTokens, so the middle branch cannot fire either.
  • internal/llm/openai/client.go:431 falls back to config.MaxCompletionTokens.
  • internal/llm/gemini/client.go:146 falls 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:

  1. Add a field to compactOptions (for example WithMaxOutputTokens(int)) or extend the
    CompactDialogue and Summarize signatures. Both are exported and have two production
    call sites: agent.compact (agent.go:1642) and the agentshell /compact command
    (cmd/rune-agent/agentshell/agentshell.go:1056).
  2. In Summarize, set summaryReq.MaxOutputTokens when 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.Service used by the existing compaction tests carries the configured
    MaxOutputTokens. Table-driven: a configured value, and 0 meaning "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

  1. added
    good first issue
    help wanted
    agent
    on Sep 16, 2026
  2. added a commit that references this issue on Sep 20, 2026
    11db287
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

    agentgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions