Skip to content

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

fix: 在 steering 后为恢复回复分配新消息身份

geng yue71cee3a78d09
diff --git a/docs/spec/03-runtime/02-agent-runtime.md b/docs/spec/03-runtime/02-agent-runtime.md
index 373f3be4d..87536c774 100644
--- a/docs/spec/03-runtime/02-agent-runtime.md
+++ b/docs/spec/03-runtime/02-agent-runtime.md
@@ -1,5 +1,10 @@
# 02. Agent Runtime
+Consumed steering closes any pre-steering streaming reservation and separates
+the next assistant reply, including during provider/overflow/silent/progress
+recovery. Recovery stays within the durable turn but never replaces a reply
+located before the steering user row (Refs #1699).
+
## 1. Goal
Applied decisions: **D002/D003/D008/D158/D189/D190/D193/D194/D278/D378**.
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 6b73f1bfb..be4fe2509 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1,5 +1,13 @@
# 04. E2E Test Plan
+### E2E-STEERING-recovery-reply-order
+
+Feed consumed steering between an earlier reply and the next recovery response.
+The earlier reservation settles and the next reply gets a new ID. Cover
+provider, overflow, silent and progress recovery in `runtime.test.ts`.
+`e2e-transcript-render.mjs` verifies production event projection and the
+existing one-bubble overflow recovery when no steering is consumed.
+
## E2E-SCHEDULED-independent-loading-and-route-return
- **Preconditions:** Synthetic tasks; controllable task, latest-run, history and
diff --git a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
index e010adcdb..72ea9692a 100644
--- a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
+++ b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
@@ -1,5 +1,9 @@
# 02. Agent 运行时
+接收 steering 后结束此前尚未落定的回复片段,下一条回复使用新身份。
+提供商、溢出、空回复及进度恢复仍属于原持久化回合,但不会覆盖位于用户
+补充消息之前的旧回复(Refs #1699)。
+
> **翻译说明:** 本页是与 [英文源规格](/spec/03-runtime/02-agent-runtime) 一一对应的机器辅助翻译。代码、协议字段和标识符保持原文;如翻译与英文源事实有歧义,以英文版本为准。
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index d5ea19d98..9f9a69279 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -1,5 +1,12 @@
# 04. E2E 测试 Plan
+### E2E-STEERING-recovery-reply-order
+
+在早先回复和下一次恢复回复之间送入已消费的 steering,旧片段结束,下一条
+回复使用新 ID。`runtime.test.ts` 覆盖提供商、溢出、空回复及进度恢复。
+`e2e-transcript-render.mjs` 验证生产事件投影,以及无 steering 时原有的
+单气泡溢出恢复行为。
+
## E2E-SCHEDULED-independent-loading-and-route-return
- **Preconditions:** Synthetic tasks; controllable task, latest-run, history and
diff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.ts
index d7c3f6f70..59e878382 100644
--- a/packages/agent-runtime/src/runtime.test.ts
+++ b/packages/agent-runtime/src/runtime.test.ts
@@ -1315,6 +1315,28 @@ function runtimeFirstMismatch(
}
describe("system transcript reconstruction", () => {
+ it.each(["progressTurnRerunInProgress", "silentTurnRerunInProgress", "providerRetryInProgress", "overflowRecoveryInProgress"])("starts a new recovery reply after consumed steering during %s (#1699)", async (recovery) => {
+ const onEvent = vi.fn();
+ const runtime = createRuntime({ onEvent, turnId: "active-turn" });
+ const internal = runtime as any;
+ const progress = assistantMessage({ content: [{ type: "text", text: "Checking the task" }] });
+ await internal.handleAgentEvent({ type: "message_start", message: progress });
+ const firstId = internal.currentAssistant.id;
+ const steering = { role: "user", content: "Are you stuck?", timestamp: Date.now() };
+ internal.pendingSteering.set(steering, { id: "steering-user", toolNames: [] });
+ internal[recovery] = true;
+ await internal.handleAgentEvent({ type: "message_end", message: steering });
+ const next = assistantMessage({ content: [{ type: "text", text: "No, continuing now" }] });
+ await internal.handleAgentEvent({ type: "message_start", message: next });
+ const events = onEvent.mock.calls.map(([envelope]) => (envelope as any).event);
+ const starts = events.filter(event => event.type === "message_start" && event.message.role === "assistant");
+ expect(starts).toHaveLength(2);
+ expect(starts[1].message.id).not.toBe(firstId);
+ expect(events).toContainEqual(expect.objectContaining({
+ type: "message_end", message: expect.objectContaining({ id: firstId, status: "complete" }),
+ }));
+ await runtime.dispose();
+ });
it("keeps provider usage valid when rebuilding an unchanged prefix", async () => {
const runtime = createRuntime();
const internals = runtime as any;
diff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.ts
index 5cc1e776d..e60941607 100644
--- a/packages/agent-runtime/src/runtime.ts
+++ b/packages/agent-runtime/src/runtime.ts
@@ -8498,6 +8498,14 @@ Do not invent objections or turn speculative risks into blockers. Stop when the
const steering = this.pendingSteering.get(event.message);
const id = steering?.id ?? this.pendingUserMessageId ?? randomUUID();
if (steering) {
+ // 后续回复必须位于已接收的用户补充之后,恢复重试也不能复用前一气泡。
+ if (this.currentAssistant?.status === "streaming") {
+ this.emit({ type: "message_end", message: {
+ ...this.currentAssistant,
+ status: this.currentAssistant.error ? "error" : "complete",
+ } });
+ }
+ this.currentAssistant = undefined;
if (steering.toolNames.length) {
this.activateDeferredTools(steering.toolNames);
this.setAgentTools(this.activeTools());