Skip to content

fix(autocompact): retry circuit breaker after cooldown - #3

Closed
chioarub wants to merge 1 commit into
mainfrom
fix/autocompact-cooldown
Closed

chioarub wants to merge 1 commit into
mainfrom
fix/autocompact-cooldown

Conversation

@chioarub

@chioarub chioarub commented May 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes Twigpine#1373.

  • Change the auto-compact failure circuit breaker from permanent suppression to a cooldown-based breaker.
  • Add half-open retry behavior: after cooldown, one compaction attempt is allowed; success resets failures, failure re-trips the breaker.
  • Do not count user-aborted compactions as automatic compaction failures.
  • Carry auto-compact cooldown state across REPL and SDK query calls so repeated turns do not forget the breaker window.
  • Fail closed with clear recovery guidance when automatic compaction is cooling down and the live context remains above the auto-compact threshold.
  • Preserve the original protection against repeated doomed compaction attempts.

Why

The existing breaker stops auto-compact after 3 consecutive failures to avoid retry storms. In a long-running query loop, that state can suppress future automatic compaction while history continues to grow. This keeps the retry-storm protection but makes the breaker recoverable.

Behavior

  • Before 3 failures: unchanged.
  • On the 3rd non-user failure: auto-compact enters cooldown.
  • During cooldown: OpenClaude skips automatic compaction attempts instead of hammering the compact endpoint.
  • After cooldown: one half-open compaction attempt is allowed.
  • On success: failure state resets.
  • On failure: cooldown is renewed with failure count capped at the breaker threshold.
  • If the conversation is already over the safe threshold while compaction is cooling down, OpenClaude stops before sending another oversized request and shows recovery guidance.

Out of scope

  • Does not raise Node/V8 heap limits; launcher heap behavior is tracked separately.
  • Does not add a naive absolute state.messages cap because arbitrary message slicing can corrupt tool_use/tool_result pairing and compact-boundary semantics.
  • Does not broadly refactor in-process teammates; teammate-specific retention work should stay in a follow-up if it needs a larger design.

Testing

  • bun install --frozen-lockfile
  • bun install --cwd web --frozen-lockfile
  • python -m pip install -r python/requirements.txt
  • bun run smoke
  • bun test src/services/compact/autoCompact.test.ts
  • bun test src/query/*.test.ts
  • bun test src/services/compact/
  • python -m pytest -q python/tests
  • bun run security:pr-scan -- --base upstream/main
  • bun run test:provider
  • npm run test:provider-recommendation
  • bun run --cwd web typecheck && bun run --cwd web build
  • bun run build
  • git diff --check

Local full-suite note:

  • bun test --max-concurrency=1 was run under a sanitized CI-like environment. Result: 2951 passed, 1 unrelated existing failure in src/utils/conversationRecovery.hooks.test.ts (deserializeMessagesWithInterruptDetection strips thinking blocks only for OpenAI-compatible providers). Auto-compact tests pass in full-suite order after this PR's test isolation fix. Upstream main PR Checks are green at 7419d380; GitHub CI should rerun the workflow when this branch is opened against upstream.

Notes

The breaker remains intentionally conservative. Cooldown retry is half-open rather than a full reset, so an unrecoverable compaction failure causes one retry per cooldown window rather than another burst of repeated attempts.

Upstream compare

GitHub API permissions in this environment blocked creating the cross-repo PR against Gitlawb/openclaude. The upstream-ready compare is:

Twigpine/openclaude@main...chioarub:fix/autocompact-cooldown

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9ddcfb52-45f1-4053-ba0a-4903ff064b9c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/autocompact-cooldown

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chioarub

Copy link
Copy Markdown
Owner Author

Closed in favor of the upstream PR: Twigpine#1375

@chioarub chioarub closed this May 26, 2026
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.

[critical]: JavaScript heap OOM after prolonged use — auto-compact circuit breaker permanently disables compaction

1 participant