Repository navigation
fix(claude): 会话闲着时的后台压缩不再让卡片卡在「思考中」 - #388
Merged
Merged
Conversation
While a session sits idle, Claude Code precomputes its next compaction (about 54 minutes after the turn ended; seen with Claude Code 2.1.308 and CodeIsland 1.0.40). It reports PreCompact with trigger "auto" and the SubagentStop of the agent that ran it, then no Stop. CodeIsland read the PreCompact as work: a finished card went to "thinking" for good, and a card the idle sweep had removed came back as "thinking". An automatic PreCompact/PostCompact from Claude on an idle card, or on one that is gone, now changes nothing and opens no card (isIdleBackgroundCompaction, checked in the reducer and in AppState.handleEvent before it creates a card). A manual /compact and a compaction mid-turn show as before. The SubagentStop is handled as before: it still records the agent as closed, so late permission requests from it get no card (ApprovalTrustBoundaryTests). A card the sweep had removed therefore comes back idle with that stop, until the idle timeout sweeps it again. A card restored idle after CodeIsland restarts mid-turn no longer shows "Compacting" for an automatic compaction; its next tool call sets it running. ClaudeIdleCompactionTests (reducer) and AppStateIdleCompactionTests cover a finished card, a swept card, a compaction mid-turn and a manual /compact.
…e too A compaction Claude Code runs on a finished session fires more than its PreCompact. The agent that writes the summary stops when it is done (SubagentStop, under an id the card never saw start), and where Claude Code applies the summary at once (its idle "compact" mode, rather than keeping the summary for the user's return) the conversation then starts over from it (SessionStart, source "compact"; read in Claude Code 2.1.312). With only the PreCompact dropped, the stop still brought back a card the idle sweep had removed, idle for another full timeout, and reset a finished card's idle clock; the restart rebuilt a finished card, wiping its last reply, and rang the session-start sound where it is on. AppState now asks BackgroundCompactionFilter first. Once a background compaction has begun on a card, the hooks of agents the card does not know, and the restart from the summary, change nothing while the card is still finished or gone. The compaction ends with that restart, with anything else from the session's main thread (the next prompt, above all), or after ten minutes. Requests and questions never pass through handleEvent, so nothing is answered for the user here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wxtsky
added a commit
that referenced
this pull request
Oct 28, 2026
A card removed with "Remove idle cards" (#385) came back for work, and a compaction starting counted as work, so Claude Code's background compaction of the finished session (#388) passed the removed-card check first: it spent the card's tombstone, and only then did the compaction filter drop the event. The card stayed away, but the next discovery scan brought it back. The filter now runs before the removed-card check, so none of the compaction's hooks touch a removed card or its tombstone; a /compact the user types still brings the card back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wxtsky
added a commit
that referenced
this pull request
Oct 28, 2026
… idle removal and more Unreleased notes for this round: the island's 20 fps clock (#381, #391), "Always allow" holding in its session and Codex rules Codex can use (#380), shortcuts and pinned displays with a second monitor (#384), pi and Oh My Pi ringing once a task (#386), the Claude Desktop answer and background compaction fixes (#389, #388), removing idle cards (#385), the Codex Desktop thread jump (#387), the DeepSeek whale (#390) and the Grok / DeepSeek Harness sections in Group by CLI. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
感谢 @Junyu06!排查很细致。PreCompact/PostCompact 这部分的判断是对的,只限 Claude 也对:Codex 的 PreCompact 必带 turn_id,其他 agent 的压缩也都发生在一轮之内。 我在你的提交上面加了一个维护者提交(39e61d2),把这次后台压缩剩下的 hook 也收住了:
现在后台压缩开始后,只要卡片仍是空闲的或已经不在,卡片不认识的 agent 发来的 hook 和这个 另外,和同时合入的 #385(一键移除空闲卡片)一起用时,后台压缩也不会让用户手动移除的卡片回来,这部分在 main 上单独补了一个提交(5367be1)。已 squash 合并,会随下个版本发布。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claude Code 的会话做完、闲了大约 54 分钟后,卡片会变回「思考中」并一直停着,已经被空闲清理掉的卡片也会带着「思考中」重新出现。这是 Claude Code 在后台提前压缩上下文:它发出
PreCompact(trigger是auto)和执行压缩的 agent 的SubagentStop,之后没有Stop,卡片就回不到空闲。改了什么
来自 Claude 的自动
PreCompact/PostCompact,如果卡片已经空闲或已经不在,就不改卡片,也不新建卡片。一轮进行中的压缩和手动/compact照旧显示「Compacting context…」。验证
swift test只有 main 上本来就失败的CodexTmuxRoutingTests.testProbeAgainstIsolatedTmuxServer。CODEISLAND_ISOLATED=1)用 hook 重放这串事件:1.0.40 上,做完的卡片和已被清理的卡片都停在「思考中」;这个分支上都没有卡片进入「思考中」。