Skip to content

fix(web): send /clear without compacting a stale thread first - #31100

Open
HoneyPaptan wants to merge 6 commits into
pingdotgg:mainfrom
HoneyPaptan:fix/clear-skips-compact
Open

HoneyPaptan wants to merge 6 commits into
pingdotgg:mainfrom
HoneyPaptan:fix/clear-skips-compact

Conversation

@HoneyPaptan

Copy link
Copy Markdown
Contributor

Problem

Fixes #31092.

On a Claude thread that has gone idle past its cache TTL (the "Compact" chip is showing), typing /clear sends /compact first and then /clear. The compaction re-reads the whole cold context (345K uncached tokens in the report) to write a summary that /clear discards a moment later.

Change

planComposerTurn already skips compact-before-send for a typed /compact. The same pattern now also matches /clear, so it is sent on its own. Matching is the same as for /compact: case-insensitive, the command must be the whole first word (/clearly ... still compacts first).

Not included: hiding the "Compact" chip while the composer holds /clear. That's a UI follow-up and the chip no longer causes a compaction for this message.

Scope and approval

A very small, focused fix for an obvious bug: the exact case the reporter hit, with the code path they pointed to. One regular expression and its comment, plus test cases.

Verification

  • Extended the existing planComposerTurn test in ChatView.logic.test.ts: /clear and /Clear no longer set compactBeforeSend or queue behind a compaction, while hello, /compactfoo and /clearly not a command still do. vp test run --project unit src/components/ChatView.logic.test.ts: 47 passed.
  • effect-tsgo typecheck of apps/web, plus vp fmt --check and vp lint on the changed files: clean.
  • Not checked: a live idle Claude thread in the app. The send path in useComposerSend.ts reads compactBeforeSend from this plan and is unchanged.

Model and harness: Claude Opus 5.5 (claude-opus-5-5) in Claude Code.

Compact-before-send only exempted /compact, so /clear on an idle Claude thread ran a full compaction of the old context and then discarded it.

Fixes pingdotgg#31092
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 4, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at c5e235d

Macroscope's review found this PR approvable — Explicit /clear commands now skip unnecessary stale-thread compaction, avoiding wasted work before context is discarded. Ordinary messages and existing queue safeguards retain their behavior.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The composer now skips pre-send compaction when a message begins with /clear or /compact at a command boundary. Tests cover /clear bypassing compaction and command-like prefixes that do not match.

Changes: Stale-session command handling

Layer / File(s) Summary
Command exclusion and validation
packages/client-runtime/src/state/contextWindow.ts, apps/web/src/components/ChatView.logic.ts, packages/client-runtime/src/state/contextWindow.test.ts, apps/web/src/components/ChatView.logic.test.ts
The shared pattern matches /clear and /compact, case-insensitively, when followed by whitespace or the end of the message. Pre-send compaction checks use this pattern. Tests cover /clear bypassing compaction and command-like prefixes that do not match.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested reviewers: juliusmarminge

Merge Risk: Minimal · up to 6040c

Sending /clear on a stale thread no longer compacts the thread first, while similar-looking inputs such as /clearly still do. The change is small, covered by tests, and easy to revert, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: /clear is now sent without a compact-before-send step on a stale thread. It matches the changeset, which swaps the compact exemption pattern for one that also covers /…
Description check Passed The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section states the bug, the reproduction context, and the cost (345K uncached tokens). The Change s…
Linked Issues check Passed [#31092] The only directly linked issue is closed and completed. Its text states that it is historical context only and not a requirement for this pull request. No active directly linked target remain…
Out of Scope Changes check Passed [#31092] All changed files implement one behavior: skip compact-before-send for a typed /clear. The changes are the web composer plan (ChatView.logic.ts), the shared predicate that replaces `COMPA…
Full details: Title check

Explanation

The title names the main change: /clear is now sent without a compact-before-send step on a stale thread. It matches the changeset, which swaps the compact exemption pattern for one that also covers /clear in planComposerTurn and compactBeforeSendTokens. The title follows the conventional commit form the template suggests.

Full details: Description check

Explanation

The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section states the bug, the reproduction context, and the cost (345K uncached tokens). The Change section explains the regex-based fix and its matching rules, and notes the out-of-scope chip hiding. The Scope section explains why no separate issue is needed and links #31092 (Fixes #31092). The Verification section lists the focused test command and its result (47 passed), the typecheck and lint results, and what was not checked (a live idle Claude thread). The template's optional agent-model line is also present. The description is complete for a small bug fix.

Full details: Linked Issues check

Explanation

[#31092] The only directly linked issue is closed and completed. Its text states that it is historical context only and not a requirement for this pull request. No active directly linked target remains, so no linked-issue coding requirements apply. The change is still consistent with the issue's intent. At the reviewed head, NO_COMPACT_BEFORE_COMMAND_PATTERN (shared packages/client-runtime/src/state/contextWindow.ts) matches /clear and /compact case-insensitively at the first-word boundary. compactBeforeSendTokens returns null for both. planComposerTurn in apps/web/src/components/ChatView.logic.ts uses this pattern. The test file covers /clear and non-matching inputs such as /compactfoo and /clearly not a command. The issue's suggested Compact chip change is not an active requirement and is not part of this review.

Full details: Out of Scope Changes check

Explanation

[#31092] All changed files implement one behavior: skip compact-before-send for a typed /clear. The changes are the web composer plan (ChatView.logic.ts), the shared predicate that replaces COMPACT_COMMAND_PATTERN (contextWindow.ts), and tests (ChatView.logic.test.ts, contextWindow.test.ts). The shared predicate also changes mobile shouldCompactBeforeSend. This extends the same /clear rule to mobile. It is a direct consequence of sharing the predicate, not an unrelated change. The current PR description mentions only the web change, so the mobile effect is a scope expansion the author has not described. It is not an unrelated change. No change unrelated to the /clear compaction behavior was identified in the reviewed diff summary. Scope was assessed from the summary and the stated changes; no additional repository inspection was needed.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e1e9b42 and 6040c74.

Files selected for processing: 4

  • apps/web/src/components/ChatView.logic.test.ts
  • apps/web/src/components/ChatView.logic.ts
  • packages/client-runtime/src/state/contextWindow.test.ts
  • packages/client-runtime/src/state/contextWindow.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

# Conflicts:
#	apps/web/src/components/ChatView.logic.ts
@maria-rcks

Copy link
Copy Markdown
Collaborator

Note

Written by claude-opus-5-5 on behalf of Maria

Merged current main (merge commit, no rebase) to clear the conflict in ChatView.logic.ts.

main moved the /compact exemption into packages/client-runtime/src/state/contextWindow.ts (#27935) so web and mobile share it. I resolved the conflict by moving this PR's pattern there as NO_COMPACT_BEFORE_COMMAND_PATTERN and importing it in ChatView.logic.ts. Mobile's shouldCompactBeforeSend now also skips compaction for /clear, with one added row in its existing contextWindow.test.ts table.

vp run check:changed passes (format, lint, knip, typecheck, tests).

@github-actions github-actions Bot added size:S 10-29 changed lines (additions + deletions). and removed size:XS 0-9 changed lines (additions + deletions). labels Nov 5, 2026
HoneyPaptan and others added 3 commits November 6, 2026 12:52
…lear-skips-compact

# Conflicts:
#	apps/web/src/components/ChatView.logic.ts
AI-assisted; verified with the tests and tools listed above.

Copy link
Copy Markdown
Member

Evidence

Web client, Chromium, 1280×800, light theme, separate fresh databases, real Claude connection, identical synthetic histories reporting 660,789 context tokens.

Connect without freshContext, advance the client clock past the cache TTL, leave Compact 661k enabled, type /clear, dismiss suggestions, restore the clock, and press Enter. Base sends /compact then queues /clear; head sends only /clear.

Before After
b3fdf2b10f e1e9b42a6b
Before: compaction occurred before clear After: clear completed without compaction
Before recording After recording

Reproduction instructions · Seed driver · Settings setup · Browser preparation · Compatibility proxy · Command audit

Controlled setup: the client clock was accelerated; no natural one-hour idle wait was performed. The proxy omitted freshContext to simulate an older server advertisement while forwarding real app traffic. Runtime model identifiers were excluded from evidence. Both recordings and stills were visually inspected.

AI-assisted; verified with the tests and tools listed above.

Not shown:

  • Natural prompt-cache expiry was not observed: client time was accelerated instead of waiting one hour.
  • An installed historical server release was not exercised: its missing freshContext advertisement was simulated by the compatibility proxy.
  • Provider billing and desktop/mobile surfaces were not measured; this proof demonstrates the web client's command ordering.

@github-actions

Copy link
Copy Markdown
Contributor

This PR conflicts with main. Rebase it or merge main into it. If it still conflicts after 7 days with no activity, it will be closed automatically.

See the conflict window.

@github-actions github-actions Bot added the needs-rebase Conflicts with its base branch. Closes after 7 days with no activity. label Nov 22, 2026
@juliusmarminge juliusmarminge added takeover:in-progress A takeover lead is working on this PR takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member

The automated pipeline stopped on this pull request and will not merge it:

the fix is written and reviewed, but proving it needs something no worker has:

  • Permanent blocker: the reported reproduction requires access to a compatible Claude server without freshContext and a stale Claude conversation above the compaction threshold. That server/account setup was not available; first-party Claude OAuth is explicitly unavailable in this worker environment. The scenario runner's generic ACP replay does not create the required Claude state.
  • The fallback dispatch order for /clear remains unverified on both commits.

It stays open for a person to finish or close.

@juliusmarminge juliusmarminge added takeover:blocked Takeover blocked; reason in the PR body and removed takeover:ready Takeover done; auto-lands when gates pass labels Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase Conflicts with its base branch. Closes after 7 days with no activity. size:S 10-29 changed lines (additions + deletions). takeover:blocked Takeover blocked; reason in the PR body vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Sending /clear on a stale Claude thread compacts the old context first, then clears

3 participants