Repository navigation
fix(agent-ipc): hold the session operation across manual compaction - #2290
Conversation
vastsa
left a comment
There was a problem hiding this comment.
The normal-path lock closes the launch-resolution admission window, but its lifetime still does not match the runtime operation after a transport deadline. I executed the production compact handler/helper (TypeScript-transpiled, controlled Host/sidecar boundary) on an integration candidate with main 30dd376. Normal completion retains the operation until the sidecar settles. With sidecar RPC timeout while compaction is still running and session.get still returning the old checkpoint, compactSession throws and finally releases the operation; a waiting prompt immediately acquires it while compaction is still running. The real transport in packages/host-runtime/src/agent-sidecar.ts rejects/removes the pending request on timeout without cancelling runtime work.
Please make the post-timeout ownership/settlement policy explicit and keep prompt admission serialized until authoritative completion/cancellation, or provide a runtime-owned equivalent that safely queues/retries admission. Do not simply increase the RPC deadline. Add deterministic handler-level regression coverage for delayed launch, timeout-before-checkpoint, failure release, and independent sessions. This PR currently adds no behavioral tests; existing context-compaction tests pass 13/13 but do not cover this concurrency contract.
Also, the issue's claim of simultaneous streaming/context corruption is stronger than the current code supports: compactManually checks streaming/compactionInProgress and prompt's assertNotRunning checks getStatus().isRunning (including compaction). Those guards can reject the competing operation; this diagnostic establishes premature admission/AGENT_BUSY risk, not proven transcript corruption. Please describe and test the actual user-visible queue/rejection behavior. No full local Electron E2E run or approval yet.
|
The race is real ( |
agentCompact now holds the session operation across admission (busy check, settings, session read, launch resolution) so a prompt submitted during setup queues behind it instead of beginning a turn the compaction would run against mid-stream. The operation is released before awaiting the sidecar compaction and a compacting-sessions mark takes over admission: queued prompts are refused with AGENT_BUSY while the mark holds, and agentAbort acquires the released operation immediately, so Stop still cancels a running compaction instead of waiting for the summarization. The mark clears when the sidecar call settles, including the transport-timeout reconciliation path. Review follow-up to vastsa#2290: the previous draft held the operation for the whole compaction, which made Stop wait behind the summarization. Regression tests execute the production handler: the queued prompt is refused by the mark, abort completes while the compaction is in flight, and an idle compaction still refuses a session with an active turn.
c3fbd55 to
bf22dbf
Compare
|
复查 bf22dbf:原 prompt setup race / Stop 三项测试已独立通过,释放锁再等待 sidecar 的方向解决了先前 Stop 阻塞。但 compact 自身没有在持锁 admission 中检查 compactingSessions:第一次压缩仍 pending 时,第二次 agentCompact 也能 add 同一个 Set 项;第二次 sidecar 报 already compacting 并进入 finally 后,会删除第一次仍持有的标记,接着 prompt 越过 admission。已在提交的 production registerAgentIpc harness 中追加此场景复现:3 原测试通过,新增断言 AGENT_BUSY 失败(拿到后续 sentinel,说明已通过 guard)。请在同一锁内同时检查 activeTurns 与 compactingSessions,在成功取得该压缩所有权后才允许 finally 清标记;补上重复 compact 被拒且不清除首次 guard 的回归,再验证 Stop 仍可取消。暂不合入。 |
sessionDelete now mirrors session.moveProject's contract: acquire the session operation, then check activeTurns, then cascade. The check-after-acquire ordering closes the queued-start window — a prompt holding the operation registers its turn and releases it, and the delete still refuses that turn (issue vastsa#2291). The sidebar's row menu and batch delete pre-check running sessions and surface a translated notice (nav.deleteRunningSessionBlocked, all locales), and project-slice's deleteSession renders the main-side AGENT_BUSY backstop through the same message instead of the raw IPC error. Branch rebuilt from latest main so it carries only the delete fix; the agentCompact rework lives on fix/compact-session-operation (vastsa#2290). Regression tests execute the production handler: busy refusal before any host cascade, the prompt-held-operation repro, operation held for the delete's duration, and a clean idle delete.
|
Reworked per your direction — head What changed in
Regression tests (
Desktop |
…act-session-operation
…act-session-operation
… guard agentCompact now checks compactingSessions inside the same locked admission as activeTurns, so a second compact behind a still-pending first one is refused before it can reach the sidecar or re-add the mark. The clearing side of the mark is ownership-guarded: only the call that won compaction ownership clears it in its finally, so a rejected duplicate (or any other path) can never un-guard the first compaction's admission. Re-review follow-up on vastsa#2290: the duplicate's failure path previously deleted the first compaction's mark and let prompts slip past admission. Regression: the duplicate is refused with AGENT_BUSY without a second sidecar call, the first mark still guards prompts, Stop still cancels the pending compaction, and admission reopens only when the owning call settles.
|
Fixed per your re-review — head
Regression added ( |
|
复查 2b20dc8:重复 compact 的 locked admission 检查与 ownsCompaction 清理保护已补齐上次指出的问题。独立执行 production registerAgentIpc harness 4/4 通过;与当前 main 已合入的 session delete guard 一起执行共 8/8 通过,覆盖 setup 排队 prompt、重复 compact 不清除首个 guard、Stop 不等待压缩、settle 后恢复准入与删除锁顺序。测试仅将 typescript import 指向本机已安装版本以修复隔离 worktree 的依赖解析,没有改产品代码或断言。当前还需完成最新集成候选的相关 E2E,且远端 CI 正在运行;本条不作为最终批准或合入。 |
vastsa
left a comment
There was a problem hiding this comment.
最终复查:原 setup admission race 与 Stop 阻塞、重复 compact 清除首个 guard 的问题均有直接回归证据;当前改动仅限主进程 admission/ownership 及测试,未改协议或持久化。当前 head 2b20dc8 已包含 main 9ff4a9a;GitHub 集成 f857cec 的 tree 50146bdc 与测试 head 完全一致。production handler compact + session delete 回归 8/8 通过;重新 bundle 后 production sidecar context-usage-compaction 3/3 通过;desktop build 通过。真实 Electron composer 测试已输出 fullComposerSubmissionAndOverflow/scratchBytesVerified 成功,含异步 compact 五种草稿场景,但整个脚本随后在 history prepare 阶段超时;main 对照同样在 line450 超时,不能宣称完整本地 Electron E2E 通过。该脚本不执行此 PR 主进程 compact handler,主进程并发保障由上述8项直接生产 handler 测试覆盖。远端五项 Actions(含 Electron E2E、Windows)全绿,Vercel 账户 blocked 属既有部署账户问题。本次据此允许 SHA-guard 合入。
Fixes #2289.
What
agentCompactheld no session operation: itsactiveTurnsbusy check went stale the moment it passed, and the settings read, session detail, and launch resolution between the check andagent.compactleft a window where a prompt could start a turn the compaction then ran against mid-stream.The change
Same contract as
agentPromptandagentAbort: acquire the session operation before the busy check, release infinally. The setup body moves to acompactSessionhelper so the handler reads as guard → work → release; behavior is otherwise identical, including the transport-timeout reconciliation.A compaction in flight now queues prompts and aborts for its duration, which is the existing lock semantic for every other session operation.