Skip to content

Commit 7d5da81

Browse files
committed
fix: filter in-flight snapshot text
1 parent f5dc4d1 commit 7d5da81

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/gateway/chat-abort.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,16 @@ describe("resolveInFlightRunSnapshot", () => {
468468
).toEqual({ runId: "run", text: "" });
469469
});
470470

471+
it("does not surface suppressed control-token lead fragments from the live buffer", () => {
472+
expect(
473+
snap({
474+
chatAbortControllers: new Map([["run", inFlightEntry("agent:main:s")]]),
475+
chatRunBuffers: new Map([["run", "NO_"]]),
476+
sessionKey: "agent:main:s",
477+
}),
478+
).toEqual({ runId: "run", text: "" });
479+
});
480+
471481
it("scopes the shared global session by agent so one agent's run is not restored into another", () => {
472482
const controllers = new Map<string, ChatAbortControllerEntry>([
473483
["run-a", inFlightEntry("global", { agentId: "main" })],

src/gateway/chat-abort.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { isAbortRequestText } from "../auto-reply/reply/abort-primitives.js";
88
import type { OpenClawConfig } from "../config/types.openclaw.js";
99
import { emitAgentEvent } from "../infra/agent-events.js";
1010
import { jsonUtf8Bytes } from "../infra/json-utf8-bytes.js";
11+
import { projectLiveAssistantBufferedText } from "./live-chat-projector.js";
1112

1213
const DEFAULT_CHAT_RUN_ABORT_GRACE_MS = 60_000;
1314

@@ -235,7 +236,11 @@ export function resolveInFlightRunSnapshot(params: {
235236
// only at completion — so there is nothing to show mid-run, but the client
236237
// should still adopt the run and show a `streaming` status (not idle) and
237238
// render the result cleanly when it lands.
238-
return { runId: best.runId, text: params.chatRunBuffers?.get(best.runId) ?? "" };
239+
const bufferedText = params.chatRunBuffers?.get(best.runId) ?? "";
240+
const projected = projectLiveAssistantBufferedText(bufferedText, {
241+
suppressLeadFragments: true,
242+
});
243+
return { runId: best.runId, text: projected.suppress ? "" : projected.text };
239244
}
240245

241246
export function boundInFlightRunSnapshotForChatHistory(params: {

0 commit comments

Comments
 (0)