Skip to content

fix(cli): prune old tool outputs in single-turn subagents - #13713

Merged
marius-kilocode merged 1 commit into
mainfrom
fix-single-turn-subagent-pruning
Sep 3, 2026
Merged

marius-kilocode merged 1 commit into
mainfrom
fix-single-turn-subagent-pruning

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Long-running Task and background subagents can execute many model/tool steps within one user turn. The two-user-turn pruning guard keeps all those outputs ineligible, including when the payload-limit safeguard runs.

Fixes #13710.

Why This Change Was Made

Allow older completed tool outputs to become eligible after two finished, non-error assistant steps. Keep the existing user-turn path, token protection and minimum, protected tools, and configuration guards. Stop only the new step-based fallback at summaries so existing post-compaction cleanup still works. Failed, preflight, and in-flight attempts do not consume the step protection buffer.

The change stays inside the existing marked pruning block. It adds no model call or new pruning trigger.

User Impact

Long single-turn runs can drop stale tool outputs at existing pruning boundaries without losing the recent working context or protected skill output. Normal pruning remains opt-in, and explicit compaction.prune: false still disables pruning. This is not a hard payload-size cap when recent or protected content is itself large.

Evidence

  • The single-user HTTP regression sent 1,452,763 bytes before the fix. It now verifies a request below the 1,250,000-byte threshold, persistent output clearing, retained recent outputs, and exactly one provider call.
  • A local source-backend smoke test completed an actual Task subagent with 32 Bash calls in one user turn. The first prune cleared 21 old outputs; consecutive provider requests dropped from 1,220,089 to 260,909 bytes while the newest two tool outputs remained intact. Auto-compaction was disabled and normal pruning was not enabled.
  • Focused regressions cover token thresholds, skill protection, failed and unfinished attempts, existing multi-turn behavior, summary boundaries, already-compacted output, and pruning opt-outs.

The smoke test used a local simulated provider, not a live model. No billing or latency improvement is claimed.

@kilo-code-bot

kilo-code-bot Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • .changeset/fix-single-turn-subagent-pruning.md
  • packages/opencode/src/session/compaction.ts
  • packages/opencode/test/kilocode/session-prompt-compaction-safety.test.ts
  • packages/opencode/test/kilocode/session-pruning.test.ts

Reviewed by grok-4.6 · Input: 226.1K · Output: 18.8K · Cached: 410.6K

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit 32ef5a7 into main Sep 3, 2026
32 checks passed
@marius-kilocode
marius-kilocode deleted the fix-single-turn-subagent-pruning branch September 3, 2026 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long-running single-turn subagents can bypass tool-output pruning and accumulate massive cached input

2 participants