Skip to content

Commit 9813b29

Browse files
committed
fix(acp): preserve chunk whitespace in background-task progress summary
Token-streamed chunks (especially CJK output, paths, URLs, identifiers) may split mid-word, so leading/trailing whitespace on a chunk carries the inter-chunk word-boundary signal. The current appendBackgroundTaskProgressSummary trims each chunk via normalizeOptionalString and inserts a forced join space, which corrupts mid-word splits — e.g. ["디","렉","토","리"] renders as "디 렉 토 리" and ["/home/","user/","file.","txt"] as "/home/ user/ file. txt". Drop the trim and the forced join space; collapse only internal whitespace runs (newlines, tabs, multi-space) to a single space and keep the existing length cap. Cover the new behavior with focused unit tests (CJK one-char-per-chunk, path mid-segment, CamelCase mid-word, leading-/trailing-space, newline/tab collapse, length cap, empty-chunk no-op). Fixes #78312
1 parent ffafa90 commit 9813b29

3 files changed

Lines changed: 93 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Docs: https://docs.openclaw.ai
121121
- Feishu: hydrate missing native topic starter thread IDs before session routing so first turns and follow-ups stay in the same topic session. Fixes #78262. Thanks @joeyzenghuan.
122122
- LINE: reject `dmPolicy: "open"` configs without wildcard `allowFrom` so webhook DMs fail validation instead of being acknowledged and silently blocked before inbound processing. Fixes #78316.
123123
- Telegram/Codex: keep message-tool-only progress drafts visible and render native Codex tool progress once per tool instead of duplicating item/tool draft lines. Fixes #75641. (#77949) Thanks @keshavbotagent.
124+
- ACP/background tasks: preserve chunk whitespace in background-task progress summaries so token-streamed CJK output no longer loses inter-character boundaries (e.g. `디렉토리` rendering as `디 렉 토 리`) when the parent channel announces the terminal result. Fixes #78312. Thanks @bykim0119.
124125
- Providers/xAI: stop sending OpenAI-style reasoning effort controls to native Grok Responses models, so `xai/grok-4.3` no longer fails live Docker/Gateway runs with `Invalid reasoning effort`.
125126
- Providers/xAI: clamp the bundled xAI thinking profile to `off` so live Gateway runs cannot send unsupported reasoning levels to native Grok Responses models.
126127
- Matrix/approvals: retry approval delivery up to 3 times with a short backoff so transient Matrix send failures do not strand pending approval prompts. (#78179) Thanks @Patrick-Erichsen.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { describe, expect, it } from "vitest";
2+
import { appendBackgroundTaskProgressSummary } from "./manager.core.js";
3+
4+
describe("appendBackgroundTaskProgressSummary", () => {
5+
it("preserves CJK characters across one-char-per-chunk streaming", () => {
6+
// Codex frequently emits one Hangul syllable per chunk; trimming each
7+
// chunk and forcing a join space would produce "디 렉 토 리".
8+
const chunks = ["디", "렉", "토", "리"];
9+
let summary = "";
10+
for (const chunk of chunks) {
11+
summary = appendBackgroundTaskProgressSummary(summary, chunk);
12+
}
13+
expect(summary).toBe("디렉토리");
14+
});
15+
16+
it("preserves a path streamed in mid-segment chunks", () => {
17+
// Real-world Codex output: paths split between segments lose their
18+
// separators and gain spurious spaces when each chunk is trimmed.
19+
const chunks = ["/home/", "user/", "file.", "txt"];
20+
let summary = "";
21+
for (const chunk of chunks) {
22+
summary = appendBackgroundTaskProgressSummary(summary, chunk);
23+
}
24+
expect(summary).toBe("/home/user/file.txt");
25+
});
26+
27+
it("preserves a CamelCase identifier streamed mid-word", () => {
28+
const chunks = ["unbeliev", "able"];
29+
let summary = "";
30+
for (const chunk of chunks) {
31+
summary = appendBackgroundTaskProgressSummary(summary, chunk);
32+
}
33+
expect(summary).toBe("unbelievable");
34+
});
35+
36+
it("preserves a leading-space chunk as the inter-word boundary", () => {
37+
const chunks = ["hello", " world"];
38+
let summary = "";
39+
for (const chunk of chunks) {
40+
summary = appendBackgroundTaskProgressSummary(summary, chunk);
41+
}
42+
expect(summary).toBe("hello world");
43+
});
44+
45+
it("preserves a trailing-space chunk as the inter-word boundary", () => {
46+
const chunks = ["hello ", "world"];
47+
let summary = "";
48+
for (const chunk of chunks) {
49+
summary = appendBackgroundTaskProgressSummary(summary, chunk);
50+
}
51+
expect(summary).toBe("hello world");
52+
});
53+
54+
it("collapses newlines and tabs to a single space within a chunk", () => {
55+
expect(appendBackgroundTaskProgressSummary("", "line one\nline two")).toBe("line one line two");
56+
expect(appendBackgroundTaskProgressSummary("", "col\tA\tcol\tB")).toBe("col A col B");
57+
});
58+
59+
it("collapses runs of whitespace inside a chunk to a single space", () => {
60+
expect(appendBackgroundTaskProgressSummary("", "foo bar")).toBe("foo bar");
61+
});
62+
63+
it("returns the current summary unchanged for empty or non-string chunks", () => {
64+
expect(appendBackgroundTaskProgressSummary("foo", "")).toBe("foo");
65+
expect(appendBackgroundTaskProgressSummary("foo", undefined as unknown as string)).toBe("foo");
66+
expect(appendBackgroundTaskProgressSummary("foo", null as unknown as string)).toBe("foo");
67+
});
68+
69+
it("truncates to the cap with an ellipsis when the combined length overflows", () => {
70+
// Matches ACP_BACKGROUND_TASK_PROGRESS_MAX_LENGTH in manager.core.ts.
71+
const cap = 240;
72+
const long = "a".repeat(cap + 50);
73+
const result = appendBackgroundTaskProgressSummary("", long);
74+
expect(result.length).toBe(cap);
75+
expect(result.endsWith("…")).toBe(true);
76+
});
77+
78+
it("does not insert spaces between successive empty-yielding chunks", () => {
79+
let summary = "";
80+
summary = appendBackgroundTaskProgressSummary(summary, "abc");
81+
summary = appendBackgroundTaskProgressSummary(summary, "");
82+
summary = appendBackgroundTaskProgressSummary(summary, "def");
83+
expect(summary).toBe("abcdef");
84+
});
85+
});

‎src/acp/control-plane/manager.core.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ function summarizeBackgroundTaskText(text: string): string {
9797
return `${normalized.slice(0, ACP_BACKGROUND_TASK_TEXT_MAX_LENGTH - 1)}…`;
9898
}
9999

100-
function appendBackgroundTaskProgressSummary(current: string, chunk: string): string {
101-
const normalizedChunk = normalizeText(chunk)?.replace(/\s+/g, " ");
102-
if (!normalizedChunk) {
100+
export function appendBackgroundTaskProgressSummary(current: string, chunk: string): string {
101+
if (typeof chunk !== "string" || chunk.length === 0) {
103102
return current;
104103
}
105-
const combined = current ? `${current} ${normalizedChunk}` : normalizedChunk;
104+
// Token-streamed chunks (especially CJK) may split mid-word, so leading or
105+
// trailing whitespace on a chunk carries the word-boundary signal. Collapse
106+
// internal whitespace runs but do not trim chunk edges or force a join space.
107+
const normalizedChunk = chunk.replace(/\s+/g, " ");
108+
const combined = current + normalizedChunk;
106109
if (combined.length <= ACP_BACKGROUND_TASK_PROGRESS_MAX_LENGTH) {
107110
return combined;
108111
}

0 commit comments

Comments
 (0)