Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

Merge remote-tracking branch 'origin/main' into fix/827-compaction-fallback-retention

vastsa760d3f75542f
diff --cc docs/adr/README.md
index 07271915d,9d1c8a5c4..1bba2caf8
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@@ -329,7 -329,7 +329,8 @@@ Each ADR includes
| 0298 | [The app ships no fonts](0298-remove-bundled-fonts.md) | Accepted (D598; amends ADR 0083 / D232) |
| 0299 | [Subagent context budget and delegate compaction](0299-subagent-context-budget.md) | Accepted for implementation (amends ADR 0064; extends ADR 0062 / ADR 0279) |
| 0300 | [Host-owned encrypted portable configuration sync](0300-host-owned-encrypted-portable-configuration-sync.md) | Accepted for implementation |
+ | 0301 | [Explicit append-only WebDAV compatibility mode](0301-explicit-append-only-webdav-compatibility-mode.md) | Accepted for implementation |
+| 0302 | [A failed compaction keeps the recent window, and an oversized summary is chunked](0302-compaction-fallback-recent-window-and-chunked-summary.md) | Accepted for implementation (issue #827; amends ADR 0049 / ADR 0282) |
| turn-process-and-thinking-display | [Turn process and thinking presentation](turn-process-and-thinking-display.md) | Accepted |
| provider-display-order | [Provider display order](provider-display-order.md) | Accepted |
| registry-header-variable-spelling | [Remote header variables accept the registry's `{name}` spelling](registry-header-variable-spelling.md) | Proposed |
diff --cc docs/spec/08-meta/decisions-log.md
index 43ffa8461,5dca06777..f044b4ae1
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@@ -6596,28 -6596,62 +6596,88 @@@ that was sitting at the bottom — incl
`apps/desktop/test/image-generation-default.test.mjs`, with
`provider-model-config.test.mjs` asserting the add branch consults them.
+ ## 2026-09-22 — An unreadable command source refuses a slash submission (D613, issue #795)
+
+ - Composer send-time resolution read the merged command list and swallowed a
+ failure as `null`, which the submit path could not tell apart from "no such
+ command". `/compact` typed while that IPC read failed was therefore sent to the
+ model as literal prompt text, and the model acted on it as an instruction.
+ - Resolution now answers with three outcomes instead of one nullable value:
+ resolved (builtin/plugin/extension dispatch), unknown (templates, aliases, and
+ id-less entries continue as prompt text), and unavailable. Unavailable refuses
+ the submission, keeps the draft, and shows
+ `chat.slashCommandSourceUnavailable`. The failed read leaves the TTL cache
+ cold, so the next submit retries it; a warm cache still resolves through a
+ source blip.
+ - The refusal is fail-closed on purpose: only the command source can say whether
+ `/name` is a control command, so while it cannot be read a `name` that looks
+ like plain text is refused rather than guessed. Templates and genuinely unknown
+ aliases keep the old prompt path. Pinned by
+ `apps/desktop/test/slash-command-source.test.mjs` and
+ `03-runtime/01-ipc-protocol.md` §13c.
+
+ ## 2026-09-22 — A manual compaction has its own transport deadline and a durable verdict (D614, issue #795)
+
+ - `agent.compact` is a blocking RPC that spends a whole model summary request
+ inside the sidecar: pi serializes the conversation, streams the summary, and
+ retries a transient failure. It ran under the flat 130s transport default, so a
+ ~158s compaction on an 888KB context ended as `sidecar RPC timeout` while the
+ sidecar kept working and persisted the checkpoint — the user was told the
+ compaction failed, and the next turn proved it had succeeded.
+ - The deadline is now derived from the ceilings the sidecar actually enforces:
+ one stream watchdog (180s) per attempt, `1 + 3` attempts, the 2s/4s/8s retry
+ backoff, and transport slack — `AGENT_COMPACT_RPC_TIMEOUT_MS`, deliberately
+ per-method rather than a wider global default.
+ - Either host path (Electron `agentCompact` IPC and `RuntimeService.compact`)
+ also stops treating a transport timeout as the sidecar's verdict: it re-reads
+ the durable `session.compaction` record and reports success when a new
+ checkpoint landed, logs the mismatch, and rethrows the timeout otherwise. A
+ verdict the sidecar reported itself is never reconciled. Pinned by
+ `packages/host-runtime/src/runtime-service.test.ts`,
+ `packages/shared/src/protocol.test.ts`,
+ `apps/desktop/test/plugin-timeout-budgets.test.mjs`, and
+ `03-runtime/01-ipc-protocol.md` §5.4.
+
+ ## 2026-09-22 — An empty transcript read is retried and never cached (D615, issue #795)
+
+ - The renderer treated every durable `session.get` window as the truth, and
+ cached it. A window that came back empty for a session with thousands of
+ messages — the host answers such a read from a transcript file it may be
+ rewriting — was stored as an empty snapshot, hover prefetch re-served it, and
+ the pane stayed blank until the app restarted. Nothing distinguished a failed
+ or stale read from an empty conversation, and no path retried one.
+ - A read is now judged against the session's own count: zero messages for a
+ session the sidebar counts as having history triggers one more read, then keeps
+ the snapshot the user already has, and otherwise reports
+ `chat.sessionTranscriptEmpty`. The empty page is never written to the
+ transcript cache, so a hover prefetch cannot poison every later open.
+ - This is a defense, not the host-side root cause: the transcript rewrite is the
+ reporter's 0.15.1 storage layout, and the read side still answers "session
+ exists, no messages" instead of reporting an unreadable transcript. See
+ `04-ux/09-interaction-patterns.md` §Session isolation across tabs.
++
+## 2026-09-22 — A failed compaction keeps the recent window (D617, issue #827)
+
+- An automatic compaction whose summary request failed installed a
+ retained-tail checkpoint that carried at most the latest user message, and a
+ rebuild narrowed a stored checkpoint's tail the same way. A long turn
+ therefore reached the next model request as one user sentence: the reported
+ session lost roughly 168 messages (3 user / 34 assistant / 131 tool) between
+ two checkpoints while the transcript on disk and the UI row stayed intact.
+- The fallback now retains the real recent window — the newest contiguous
+ messages of the compacted range, every role, bounded by the keep-recent
+ target and by what the carried summary and the recovery notice leave — and
+ marks it with `details.retainedTailShape`, so a rebuild replays it. A
+ checkpoint without the marker (every successful checkpoint, and every record
+ written before it existed) still normalizes to the latest user message. An
+ `active_turn` fallback also keeps the active task's user message when the
+ window cannot hold it, the fallback drops the assistant messages pi drops
+ anyway and any tool result whose call is not in the window, and
+ `details.failureReason` records `no_new_history` / `summary_budget` /
+ `summary_provider` / `checkpoint_oversized` instead of provider error text.
+- A summary prompt that is still too large after the single reduced pass is no
+ longer skipped: the range is split into contiguous chunks that each fit, at
+ most 16 requests, each carrying the previous chunk's summary, and the
+ checkpoint reports the summed usage of the requests that produced it. Only an
+ empty range, or one past that request bound, still falls back on budget
+ grounds. See ADR 0302, `03-runtime/02-agent-runtime.md`, ADR 0049, ADR 0282.
diff --cc docs/zh-CN/spec/08-meta/decisions-log.md
index 86ec8956e,6db8ed12d..248279a0b
--- a/docs/zh-CN/spec/08-meta/decisions-log.md
+++ b/docs/zh-CN/spec/08-meta/decisions-log.md
@@@ -4678,19 -4678,46 +4678,63 @@@ that amendment are retired by ADR 0268
`apps/desktop/test/image-generation-default.test.mjs` 固定,
`provider-model-config.test.mjs` 断言新增分支会走这两个判断。
+ ## 2026-09-22 —— 指令源不可读时拒绝斜杠提交(D613,issue #795)
+
+ - Composer 在发送时读取合并后的指令列表,并把失败吞成 `null`,而提交路径无法把它与
+ “没有这个指令”区分开。于是在该 IPC 读取失败时输入的 `/compact` 会作为字面提示词发给
+ 模型,模型据此把它当成指令执行。
+ - 解析现在返回三种结果,而不再是一个可空值:已解析(内置 / 插件 / 扩展分发)、未知
+ (模板、别名与无 id 条目继续走提示词路径)、不可用。不可用时拒绝提交、保留草稿并显示
+ `chat.slashCommandSourceUnavailable`。失败的读取不写 TTL 缓存,因此下一次发送会重试;
+ 缓存仍热时,一次数据源抖动不会影响解析。
+ - 拒绝是刻意 fail-closed:只有指令源能判断 `/name` 是否为控制指令,因此读不到时,看起来像
+ 普通文本的名称也会被拒绝,而不是靠猜测。模板与确实未知的别名保持原有提示词路径。由
+ `apps/desktop/test/slash-command-source.test.mjs` 与
+ `03-runtime/01-ipc-protocol.md` §13c 固定。
+
+ ## 2026-09-22 —— 手动压缩有自己的传输超时与持久化判定(D614,issue #795)
+
+ - `agent.compact` 是阻塞式 RPC,会在 sidecar 内消耗一次完整的模型摘要请求:pi 序列化会话、
+ 流式生成摘要,并重试瞬时失败。它此前沿用扁平的 130 秒传输默认值,因此 888KB 上下文约
+ 158 秒的压缩以 `sidecar RPC timeout` 结束,而 sidecar 仍在继续工作并落盘了检查点——用户
+ 被告知压缩失败,而下一个回合证明它其实成功了。
+ - 超时现在由 sidecar 真正执行的预算推导:每次尝试的流空转看门狗(180 秒)、`1 + 3` 次
+ 尝试、2/4/8 秒重试退避,以及传输余量 —— 即 `AGENT_COMPACT_RPC_TIMEOUT_MS`,刻意按方法
+ 区分,而不是放宽全局默认值。
+ - 两条宿主路径(Electron 的 `agentCompact` IPC 与 `RuntimeService.compact`)也不再把手动
+ 压缩的传输超时当作 sidecar 的判定:它们会重新读取持久化的 `session.compaction` 记录,
+ 发现新检查点已落盘就报告成功、记录该不一致,否则原样抛出超时。sidecar 自己报告的判定
+ 绝不会被这样改写。由 `packages/host-runtime/src/runtime-service.test.ts`、
+ `packages/shared/src/protocol.test.ts`、
+ `apps/desktop/test/plugin-timeout-budgets.test.mjs` 与
+ `03-runtime/01-ipc-protocol.md` §5.4 固定。
+
+ ## 2026-09-22 —— 空记录读取会重试,且绝不入缓存(D615,issue #795)
+
+ - 渲染层把每一次持久化 `session.get` 窗口都当真,并写入缓存。当宿主正在重写记录文件时,
+ 对拥有数千条消息的会话返回的空窗口被当成“空快照”存下,侧边栏悬停预取又反复送出它,
+ 于是面板一直空白,只有重启应用才能恢复。此前没有任何逻辑区分“读取失败或读到陈旧数据”
+ 与“真的空会话”,也没有任何路径重试。
+ - 现在的判断依据是会话自己的计数:若侧边栏计为有历史的会话返回零条消息,就再读一次,
+ 随后保留用户已有的快照,否则显示 `chat.sessionTranscriptEmpty`。这类空页绝不会写入记录
+ 缓存,因此悬停预取不会污染之后每次打开。
+ - 这是防御措施,而不是宿主侧根因:记录重写是报告者 0.15.1 的存储布局,而读取侧仍然返回
+ “会话存在但没有消息”,而不是报告记录不可读。见 `04-ux/09-interaction-patterns.md`
+ §跨选项卡的会话隔离。
++
+## 2026-09-22 —— 摘要失败的压缩保留真实近期窗口(D617,issue #827)
+
+- 自动压缩的摘要请求失败时安装的保留尾部检查点最多只带一条最新用户消息,重建存储的
+ 检查点也会以同样方式收窄尾部。于是在一条长回合里,下一次模型请求只剩一句用户话:
+ 报告中的会话在两次检查点之间丢掉约 168 条消息(3 条用户 / 34 条助手 / 131 条工具),
+ 而磁盘上的转录本与界面行看起来完好。
+- 回退现在保留真实的近期窗口——压缩范围内最新的连续消息,包含所有角色,上限为
+ keep-recent 目标,以及携带摘要与恢复提示之后安全预算剩余的空间——并用
+ `details.retainedTailShape` 标记,使重建时回放整窗。没有该标记的检查点(每个成功
+ 检查点,以及标记出现之前写入的记录)仍归一化为只保留最新的用户消息。`active_turn`
+ 回退还会在窗口装不下时保留当前任务的用户消息;回退会丢弃 pi 本来就会丢的助手消息,
+ 以及调用不在窗口内的工具结果;`details.failureReason` 记录 `no_new_history` /
+ `summary_budget` / `summary_provider` / `checkpoint_oversized`,而不是提供商错误文本。
+- 单次缩减后仍过大的摘要提示不再被跳过:范围会被切成每片都能放下的连续分片,最多 16 次
+ 请求,每次携带上一片的摘要,检查点报告这些请求的用量总和。只有空范围或超过该请求上限
+ 的范围才因预算原因回退。见 ADR 0302、`03-runtime/02-agent-runtime.md`、ADR 0049、ADR 0282。