Repository navigation
fix(idle-compact): 闲置计时只从真实对话轮之后起算,冷启动/重连不再误压缩 - #3247
Conversation
原来闲置自动压缩以屏幕「忙→闲」边沿作为闲置起点。CLI 刚启动或重连 (daemon 重启重连、挂起后冷恢复、网页终端/Dashboard 打开、CLI 在 worker 内崩溃重启、--resume 启动先闪「工作中」)的第一次空闲也会开一段新区间, 于是闲置数天的会话 55 分钟后被压缩并报「闲置 55 分钟」——此时提示缓存早已 过期,压缩反而要冷读整段上下文。 改为:只有 botmux 发起的对话轮(beginNewTurn)能开新的热区间。轮开始记 arm(时间戳),看到它的忙碌期后,紧接着的空闲边沿开区间;arm 在忙碌边沿 持久化,daemon 中途重启后按轮开始时间起算(只会更旧,不会更热)。其它 忙→闲(启动转圈、本地斜杠命令、终端直接输入)沿用已有区间;没有区间即 为冷,不计时。自身 /compact 不开区间,Ctrl-C 后不会再压一次;10 分钟内 未进入忙碌的 arm 作废;本地应答的斜杠命令(/model、/cost 等)不开区间。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad01f3dc73
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const persisted = ds.session.idleAutoCompact?.idleSince; | ||
| return persisted !== undefined && persisted <= live ? persisted : live; | ||
| if (ds.idleSinceAt === undefined) return undefined; | ||
| return ds.idleAutoCompactWarmSince ?? ds.session.idleAutoCompact?.idleSince; |
There was a problem hiding this comment.
Discard unproven legacy idle stamps
An enabled row can contain idleSince written before this change, when any idle edge could create the marker. A cold CLI that boots or reconnects without a botmux request is indistinguishable from a turn-backed stretch here; if the legacy timestamp is past the configured threshold but under 60 minutes and the session is otherwise eligible, the sweep can send /compact against the cold context. Version or clear legacy timestamps unless they have turn proof.
AGENTS.md reference: AGENTS.md:L164-L168
Useful? React with 👍 / 👎.
| if (turnId.startsWith(IDLE_AUTO_COMPACT_TURN_PREFIX)) return; | ||
| // Started while the CLI is already busy: no new busy edge will follow, the | ||
| // turn runs on in the same busy period. | ||
| ds.idleAutoCompactArm = { at: now, busy: BUSY_SCREEN_STATUSES.has(ds.lastScreenStatus ?? '') }; |
There was a problem hiding this comment.
Persist arms for turns started while already busy
For an enabled session, a turn admitted while the CLI is already working or analyzing gets an in-memory busy: true arm, but the persisted setting.armed is not updated here. Repeated same-status screen updates return before syncing it, so if the daemon restarts before the next idle edge, restore has no arm for this request (or only an older one), and the turn's warm stretch is lost or dated from the previous turn. Persist this arm when recording it for the no-new-busy-edge case.
AGENTS.md reference: AGENTS.md:L164-L168
Useful? React with 👍 / 👎.
| // must not arm a warm idle-auto-compact stretch (core/idle-auto-compact.ts). | ||
| const idleCompactArm = ds.idleAutoCompactArm; | ||
| beginNewTurn(ds, commandContent, turnId); | ||
| if (isLocalCliCommand(cmd)) ds.idleAutoCompactArm = idleCompactArm; |
There was a problem hiding this comment.
On Claude and Codex, /goal is explicitly a cold-start passthrough that starts goal work (src/adapters/cli/claude-code.ts:1701-1703, src/adapters/cli/codex.ts:604-610). The initial-session path stages it as pendingRawInput, which prompt_ready sends directly (src/core/worker-pool.ts:19247-19283) without calling beginNewTurn or this arm. If idle-compact is enabled during or after that first task, its idle edge leaves the warm start unset, so that model-backed stretch is never eligible until another botmux turn. Arm accepted initial raw turns too.
AGENTS.md reference: AGENTS.md:L146-L148
Useful? React with 👍 / 👎.
|
感谢贡献,已合并 🎉 这个改动把闲置自动压缩的计时判据收紧到「只有 botmux 对话轮之后的闲边沿才开热区间」,冷启动、重连、崩溃重启等无请求场景不再误压缩,方向和测试覆盖都很扎实。 评审中确认的已知边界(失败方向均为少压缩一次或一次性过渡,不丢消息、不重复压缩)已汇总到 follow-up issue #3259,包括:
欢迎继续参与,也欢迎在 #3259 下补充想法。 |
|
@Wait845 @deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。 这次运行覆盖 c53afd0…af0f83d7f(7 个提交),同批合入的还有 #3244 #3236 #3243 #3240 #2843 #3246,失败不一定由本 PR 引起。
|
|
🚀 Released in v3.59.0 |
问题
闲置自动压缩(#2682)用屏幕「忙→闲」边沿作为闲置计时起点。但 CLI 刚启动或刚重连时第一次报空闲,也会被当成一段新的闲置:
/restart、改模型重启claude --resume启动大会话(>15s)时,屏幕先闪「工作中」再变空闲结果:一个已经闲置两天的会话,碰上其中一种,55 分钟后就被压缩并报「会话已闲置 55 分钟,已自动 /compact」。而此时 Anthropic 的提示缓存(1h)早已过期,压缩反而要无缓存冷读整段上下文——正是这个功能想省掉的开销。原测试里还有一条把「挂起后打开会话、55 分钟后压缩」当成正确行为写死了。
改动
把判据从「屏幕忙→闲」改成「只有 botmux 发起的对话轮(唯一能证明有请求打到模型、缓存是热的)之后的空闲,才开新的热区间」:
noteIdleAutoCompactTurnStarted记一个带时间戳的 arm({ at, busy });看到该轮的忙碌期后,紧接着的空闲边沿把区间起点定在空闲时刻setting.armed),daemon 在对话轮进行中重启后仍能开区间;但此时按「轮开始时间」起算(请求不会早于它,区间只会更旧、不会更热),停机数天后自然落到过期分支、直接跳过/compact(auto-compact:idle:前缀)不开区间;用户 Ctrl-C 掉它之后不会 55 分钟后再压一次/model、/cost、/context等白名单)在deliverPassthroughToExistingSession里不开区间;/review、/compact、技能等会打模型的照常计时clearIdleAutoCompactStretch)一并清掉热区间、arm 与 inFlight影响面
仅
core/idle-auto-compact.ts的闲置压缩判定,经worker-pool.ts的stampIdleSinceAt、daemon.ts的beginNewTurn/ passthrough 路径触达。不改其它 CLI / 后端 / 会话类型的行为;该功能本就只对 Claude Code 与 tmux 上的 Codex 生效。验证
bunx tsc --noEmit:通过bun run build:通过提交前独立对抗复核
按仓库规范(持久状态语义变更)在提交前做了两轮独立对抗复核,用真实模块 + 假时钟复现:
working先于首个idle、同 worker 内崩溃重启prev仍为idle、crash 重启在热区间中途新开区间可能越过缓存窗压缩),以及两个漏压缩/重复压缩场景——据此重做为「对话轮 arm」判据🤖 Generated with Claude Code