Skip to content

[Feature] Auto-compact on headless, ACP, and subagent loops #1048

Closed

Description

@Dhirenderchoudhary

Description

autoCompact is on by default (60% of the model limit, source/config/index.ts loadAutoCompactConfig). Docs (docs/features/context-compression.md) talk like it is a product-wide behaviour.

It only runs in the interactive TUI loop. performAutoCompact is called from processAssistantResponse in source/hooks/chat-handler/conversation/conversation-loop.tsx (around 551), after the assistant message is committed.

These paths never call it:

  • source/plain/conversation.ts (~168) client.chat for --plain / nanocoder run
  • source/acp/acp-conversation.ts (~183) ACP / VS Code / Zed
  • source/subagents/subagent-executor.ts (~436) client.chat(messages) with no cap and no compact

Plain and ACP do use capMessagesForModel (count, default 1000). Subagents do not even do that. Token budget is ignored everywhere except the TUI.

Local Ollama / 8k models in nanocoder run, editor ACP, and delegated subagents will keep stuffing tool results until the provider 400s. The setting in agents.config.json does nothing there.

Use Case

CI / --plain job on a small local model. Daemon skill that launches a subagent. VS Code ACP session. Same autoCompact config, none of those loops honour it.

Proposed Solution

Call the existing helper. Do not write a second compressor.

  1. After each assistant turn on the three loops, call performAutoCompact the same way the TUI does (messages, system message, tokenizer / getModelContextLimit, native tool defs).
  2. Subagents also pass through capMessagesForModel before client.chat. Plain and ACP already do.
  3. Mechanical strategy if LLM compact is too heavy for a tiny subagent. Reuse autoCompact.strategy. No new config key required for v1.

Tests: fixture that is over threshold on the plain loop compact; subagent history longer than maxMessages is sliced without orphaning tool rows (message-capping.ts already walks back).

Alternatives Considered

  • Leave it as TUI-only. Then the default config is a lie for --plain, ACP, and subagents, which is most of the local-first story.
  • Fold this into [Feature] Semantic Context Compiler (Intelligent Context Budget Management) #793. 793 is send-time stubs / a compiler. This is wiring a function that already exists. Smaller and shippable alone.
  • Truncate harder per tool (truncateToolResult). Already done. Does not replace history compact on long loops.

Additional Context

Happy to take this if assigned.

Activity

  1. Dhirenderchoudhary commented on Aug 29, 2026

    @Dhirenderchoudhary
    ContributorAuthor

    @akramcodez can I take this one?
    looked at current main first so we are not duplicating.
    happy to start once assigned.

  2. akramcodez commented on Aug 30, 2026

    @akramcodez
    Member
  3. added
    performance
    on Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementperformance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions