Skip to content

feat(compaction): disable thinking by default; add compaction.thinking override#34554

Closed
iamcobolt wants to merge 2 commits intoopenclaw:mainfrom
iamcobolt:feat/compaction-thinking
Closed

feat(compaction): disable thinking by default; add compaction.thinking override#34554
iamcobolt wants to merge 2 commits intoopenclaw:mainfrom
iamcobolt:feat/compaction-thinking

Conversation

@iamcobolt
Copy link
Copy Markdown

AI-assisted — drafted and iterated with Claude Code (claude-sonnet-4-6). Lightly tested: unit tests pass, pnpm tsgo clean, pnpm check passes; timeout-retry path validated by code review; not exercised against a live timeout event. I have personally reviewed all code changes prior to this commit and take responsibility for their correctness.

Summary

  • Problem: compaction runs on the session's active thinking level, so sessions using slow/high-think models (e.g. Opus + thinking:high) can take 4+ minutes to compact — exceeding channel timeout windows (Discord 30s, Telegram 240s) and causing a stale-response retry loop (Compaction timeout races against channel timeout, causing stale-response loop #25272).
  • Why it matters: affects any user running a thinking-enabled model on a chat surface with a strict reply timeout; the loop is deterministic and requires manual intervention to break.
  • What changed: compaction now runs with thinking=off by default regardless of session model. New agents.defaults.compaction.thinking key — "off" (default) or "on" (inherit the session model's current thinking level). When a compaction run times out with thinking enabled, the runner retries once without thinking automatically. The before_compaction hook is guarded to fire exactly once per compaction event.
  • What did NOT change: primary session model and thinking level are unchanged; compaction prompt content, threshold logic, and retry limits in run.ts are unchanged; no new network calls or auth paths.

Schema

agents.defaults.compaction.thinking: "off" (default) | "on"

  • "off": compaction always runs without extended thinking regardless of the session model — preventing timeout races on channels with strict reply windows.
  • "on": compaction inherits the session model's current thinking level. On timeout, automatically retries once without thinking.

Renders as a two-button segmented control in the config UI.

UI — Before / After

Before (upstream main — no Compaction Thinking field):

before

After — new Compaction Thinking field with off / on segmented control:

after

Change Type

  • Feature
  • Docs

Scope

  • Gateway / orchestration
  • API / contracts
  • UI / DX

Linked Issue/PR

User-visible / Behavior Changes

  • Compaction now always runs with thinking: off by default. Existing sessions unaffected — this only changes the thinking level used during the compaction summarization turn.
  • New config key agents.defaults.compaction.thinking (opt-in; defaults to "off").

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

  1. Set a thinking-enabled model (e.g. Opus + thinking: high)
  2. Trigger compaction via context threshold
  3. Confirm compaction completes without thinking ([compaction-diag] log shows thinking=off)
  4. Set agents.defaults.compaction.thinking: "on", repeat — confirm thinking is used and timeout-retry path activates if needed

Evidence

  • 5 unit tests covering all resolveCompactionThinkLevel branches (absent, "off", "on" with various session levels)
  • Diagnostic log fields: thinking=${effectiveThinkLevel} thinkAttempt=${thinkAttempt} on every [compaction-diag] start/end line

Human Verification

  • Verified: unit tests pass, pnpm tsgo clean, pnpm check passes
  • Edge cases: absent config, "off" with thinking session, "on" with non-thinking session, hookFired guard
  • Not verified: live timeout race against a real channel deadline

Compatibility / Migration

  • Backward compatible: thinking is optional; default is "off" (no change for existing sessions without explicit opt-in)
  • To opt in: agents.defaults.compaction.thinking: "on"

Failure Recovery

  • To revert: remove agents.defaults.compaction.thinking from config (or set to "off")
  • Bad symptom: compaction always uses thinking regardless of config — check resolveCompactionThinkLevel return value in logs

Risks and Mitigations

  • Risk: users with thinking: "on" who expect fast compaction may see slower compaction on first attempt before timeout-retry kicks in.
    • Mitigation: "on" is opt-in; default is "off" which is strictly faster.

…g override

Compaction now runs with thinking=off by default, regardless of the session
model's thinking level. On channels with strict reply windows (Discord 30s,
Telegram 240s), extended thinking during compaction can race against the
channel timeout and trigger a stale-response loop (openclaw#25272).

New config key: agents.defaults.compaction.thinking ("off" | "on")
- "off" (default): compaction always runs without extended thinking
- "on": inherits the session model's current thinking level; retries once
  without thinking on timeout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jalehman jalehman self-assigned this Mar 4, 2026
@jalehman
Copy link
Copy Markdown
Contributor

jalehman commented Mar 4, 2026

I found one blocking issue in the new timeout-retry path: on timeout, attempt 2 can start while attempt 1 compaction is still running. compactWithSafetyTimeout does not cancel session.compact(), and session.dispose() does not abort compaction. Please abort/await in-flight compaction (session.abortCompaction()) before retrying, then add a timeout-retry regression test to ensure only one compaction append occurs.

@jalehman
Copy link
Copy Markdown
Contributor

This PR has gone stale. Closing for now. Feel free to re-open if still needed on an up-to-date branch.

@jalehman jalehman closed this Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction timeout races against channel timeout, causing stale-response loop

2 participants