Skip to content

fix(acp): preserve chunk whitespace in background-task progress summary [AI-Assisted] - #78319

Closed
bykim0119 wants to merge 1 commit into
openclaw:mainfrom
bykim0119:fix/append-progress-summary-whitespace
Closed

bykim0119 wants to merge 1 commit into
openclaw:mainfrom
bykim0119:fix/append-progress-summary-whitespace

Conversation

@bykim0119

@bykim0119 bykim0119 commented May 6, 2026 •

Copy link
Copy Markdown

Summary

Fixes #78312.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: when Codex via ACP streams Korean output that includes a workspace path, the auto-announced terminal summary in the parent Discord channel renders inter-chunk word boundaries with spurious spaces (현재 작업 디 렉 토 리 는 / home / by kim 0119 / . open claw / workspace 입니다), losing both the CJK word grouping and the path separators. After the fix, the same announce renders the original text verbatim (현재 작업 디렉토리는 /home/bykim0119/.openclaw/workspace 입니다).

  • Real environment tested: production OpenClaw 2026.4.21 install (/usr/lib/node_modules/openclaw) on Ubuntu 24.04, Discord channel bound to a Hermes orchestrator agent, ACP backend acpx, child agent codex (Codex CLI 0.121.0, gpt-5.3-codex via ChatGPT Plus auth, ACP runtime spawned by sessions_spawn). The same appendBackgroundTaskProgressSummary source on main at 2026.5.5 has the identical buggy code path, confirmed by git show upstream/main:src/acp/control-plane/manager.core.ts | sed -n '99,109p'.

  • Exact steps or command run after this patch:

    1. Applied this patch's src/acp/control-plane/manager.core.ts change to the installed bundled file /usr/lib/node_modules/openclaw/dist/manager-BPXdclo2.js (the chunk-whitespace portion only — the cap and terminalSummary fields were left at their current upstream values).
    2. sudo systemctl restart openclaw.
    3. From the orchestrator agent in Discord: trigger a sessions_spawn(runtime: "acp", agentId: "codex", task: "<Korean prompt asking Codex to print the absolute path of its current working directory>").
    4. Waited for the background-task done announce to land in the parent channel; captured the rendered text.
    5. Locally, ran the new unit-test file: pnpm test src/acp/control-plane/manager.background-task-progress.test.ts.
  • Evidence after fix:

    Live Discord rendering of the announce after the patch (run 7495ffdb → fec2c09c in OpenClaw's task-run log):

    현재 작업 디렉토리는 /home/bykim0119/.openclaw/workspace 입니다
    

    Same announce before the patch (same prompt, same agent, same model):

    현재 작업 디 렉 토 리 는 / home / by kim 0119 / . open claw / workspace 입니다
    

    Local unit-test output (10 deterministic cases including the live-mirroring CJK and path scenarios):

    RUN  v4.1.5 /home/bykim0119/autonormal/openclaw
    
     ✓ |unit-fast| src/acp/control-plane/manager.background-task-progress.test.ts (10 tests) 8ms
    
     Test Files  1 passed (1)
          Tests  10 passed (10)
       Duration  2.32s
    

    Existing manager test suite, run for regression coverage on the same change:

     ✓ |unit-fast| src/acp/control-plane/manager.test.ts (56 tests) 141ms
    
     Test Files  1 passed (1)
          Tests  56 passed (56)
       Duration  1.52s
    
  • Observed result after fix: the live announce in Discord renders the Korean and the path verbatim, matching what Codex actually emitted; chunked unit-test inputs (CJK syllables, path segments, mid-word identifier, leading-/trailing-space chunks, whitespace-run chunks, empty chunks, oversized inputs) all produce the expected concatenation; existing AcpSessionManager test suite still passes unchanged.

  • What was not tested: I did not exercise the non-Codex ACP runtimes (e.g. claude-code) end-to-end — the helper is generic and the unit tests cover the chunk surface, but live verification was only done against Codex via acpx. I did not run the full pnpm test / pnpm test:extensions suites locally; I ran pnpm check:changed --base upstream/main --head HEAD instead, which is the smart-gate equivalent for the changed paths and passed (typecheck core + core test, oxlint core, import-cycle, runtime-sidecar-loaders, webhook/auth guards, oxfmt).

  • Before evidence: same Korean prompt against the unpatched 2026.4.21 install:

    현재 작업 디 렉 토 리 는 / home / by kim 0119 / . open claw / workspace 입니다
    

    Programmatic before-state from the buggy helper (deterministic, no ACP runtime needed):

    run(["디", "렉", "토", "리"])               // "디 렉 토 리"
    run(["/home/", "user/", "file.", "txt"]) // "/home/ user/ file. txt"
    run(["unbeliev", "able"])                // "unbeliev able"
    

Root Cause (if applicable)

  • Root cause: normalizeText is normalizeOptionalString from src/shared/string-coerce.ts, which unconditionally .trim()s its input. That is the right contract for whole strings but wrong for streaming chunks: trimming strips the leading/trailing whitespace that carries the inter-chunk word-boundary signal. The downstream ${current} ${normalizedChunk} template then re-inserts a single space at every join, which produces visible gaps inside what was originally a single word for any tokenizer that splits chunks mid-word (CJK syllables, path segments, CamelCase identifiers).
  • Missing detection / guardrail: no unit test directly exercised appendBackgroundTaskProgressSummary with chunked inputs; the only coverage was via end-to-end AcpSessionManager tests that use English-only single-chunk inputs, which incidentally hide this regression class because BPE leading-space tokens align with the forced-space behavior.
  • Contributing context (if known): the helper was written against the assumption that the runtime emits whole-line progress strings; the assumption holds for some runtimes, but Codex's ACP runtime emits token-by-token progress, which exposes the chunk-boundary contract.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: new src/acp/control-plane/manager.background-task-progress.test.ts.
  • Scenario the test should lock in: appending a sequence of mid-word chunks (CJK syllables, path segments, mid-word identifiers) must concatenate verbatim, while leading-/trailing-space chunks, whitespace-run chunks, empty/non-string chunks, and oversized inputs still behave correctly.
  • Why this is the smallest reliable guardrail: the helper is pure, deterministic, and called per-chunk on the streaming path. A unit test directly on the helper deterministically catches any future regression of either the trimming or the forced-space behavior, at far lower cost than reviving the ACP+Codex live path.
  • Existing test that already covers this (if any): none. AcpSessionManager tests in manager.test.ts cover the surrounding state machine but not the chunk-progress contract.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

Parent-channel ACP background-task terminal summaries now render token-streamed text verbatim instead of with spurious inter-chunk spaces. No config or default changes. No change to summary length or truncation marker.

Diagram (if applicable)

Before:
chunks = ["디", "렉", "토", "리"]
  → trim each chunk          → ["디", "렉", "토", "리"]
  → join with forced space   → "디 렉 토 리"   ✗

After:
chunks = ["디", "렉", "토", "리"]
  → collapse internal \s runs only   → ["디", "렉", "토", "리"]
  → concatenate verbatim             → "디렉토리"     ✓

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

The change is a string-handling fix in a pure helper that processes already-received progress chunks. It cannot widen any trust boundary.

Repro + Verification

Environment

  • OS: Ubuntu 24.04.4 LTS (x86_64)
  • Runtime/container: Node 22.22.2, npm-global OpenClaw 2026.4.21 install (live env), upstream main at cbaf999bd2 for the patch (2026.5.5)
  • Model/provider: gpt-5.3-codex via Codex CLI 0.121.0, ChatGPT Plus auth
  • Integration/channel (if any): Discord, parent agent (Hermes / openai-codex/gpt-5.4) → ACP acpx → Codex child
  • Relevant config (redacted): acp.backend: "acpx", acp.defaultAgent: "codex", acp.allowedAgents: ["codex"], acp.dispatch.enabled: true, ~/.codex/config.toml with model = "gpt-5.3-codex"

Steps

  1. Trigger a sessions_spawn(runtime: "acp", agentId: "codex", task: "<Korean prompt asking Codex to print the absolute path of its current working directory>") from the orchestrator agent.
  2. Wait for the background-task done announce in the parent channel.
  3. Compare the rendered text against the actual Codex response in the child session log.

Expected

  • Announce text matches Codex's underlying response verbatim (Korean syllables joined, path separators preserved).

Actual (with this patch applied)

  • Announce text matches Codex's underlying response verbatim. Reproduced 1/1 immediately after applying the patch and restarting the gateway.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

The before/after announce text is included verbatim in the Real behavior proof section above. Unit-test output before the source change would fail at expect(summary).toBe("디렉토리") (actual "디 렉 토 리"); after the change all 10 cases pass.

Human Verification (required)

  • Verified scenarios:
    • Korean prompt to Codex via ACP, before and after patch, real Discord channel.
    • Mixed Korean + English path prompt to Codex, after patch — path separators preserved, Korean joined correctly.
    • Local unit tests on the patched helper for CJK one-char-per-chunk, path mid-segment, CamelCase mid-word, leading-/trailing-space chunks, whitespace-run chunks, empty/non-string chunks, length cap (240).
  • Edge cases checked: empty chunk, null/undefined chunk (cast through unknown), pure-whitespace chunks, single-character chunks, oversized chunk that triggers the cap and … truncation.
  • What you did not verify: non-Codex ACP runtimes (Claude Code etc.) end-to-end; native Windows or macOS gateway runs (the helper is platform-independent so this should not matter); full pnpm test / pnpm test:extensions suite (ran pnpm check:changed instead, which is the smart-gate equivalent for the changed paths).

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

(No conversations yet at PR open time; will keep these in sync as bot reviews land.)

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No
  • If yes, exact upgrade steps: N/A.

Risks and Mitigations

  • Risk: a runtime that previously relied on the trim+force-space behavior to compress whitespace-only chunks into clean prose might now show extra leading whitespace if its first chunk is whitespace.
    • Mitigation: any leading whitespace from a stream's first chunk is still bounded by the existing length cap, and the downstream resolveBackgroundTaskTerminalResult already does its own .trim() on the final summary before producing user-visible text, so this surface is normalized at the edge. Internal multi-line chunks are still collapsed to a single space line within the helper.

Scope vs #74070 / PR #74103

Independent. PR #74103 raises the cap and surfaces progress as terminalSummary on success — both useful — but keeps the same trim-and-force-space pattern in appendBackgroundTaskProgressSummary, so the rendered output would still show 디 렉 토 리 even after #74103 lands. This PR is orthogonal and safe to merge in either order; if both land, the resulting helper retains both improvements (visible inter-word boundaries from this PR, larger cap and success-path terminal summary from #74103).

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. size: S labels May 6, 2026
@clawsweeper

clawsweeper Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Close as implemented: current main already contains a slightly broader ACP chunk-boundary fix from #78383, with regression coverage for the Korean/path streaming case and beta release provenance in v2026.5.9-beta.1.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep the merged main implementation, which preserves streamed chunk boundaries while keeping the helper internal and testing the real ACP manager path.

Do we have a high-confidence way to reproduce the issue?

Yes. The original failure is source-reproducible from the old helper and the PR body includes live Discord before/after output; current main now covers the fixed behavior with an ACP manager regression test.

Is this the best way to solve the issue?

Yes. The current-main fix is the best direction because it addresses the same bug through the real manager path and avoids exporting an internal helper solely for tests.

Security review:

Security review cleared: The PR only changes string handling, tests, and changelog text; it does not alter secrets, permissions, network calls, dependencies, CI, or code execution surfaces.

What I checked:

Likely related people:

  • amknight: Authored and merged the current-main implementation in Fix ACP streamed progress summary spacing #78383, touching the ACP helper, manager regression tests, and changelog. (role: introduced current fix; confidence: high; commits: fa445003b5eb; files: src/acp/control-plane/manager.core.ts, src/acp/control-plane/manager.test.ts, CHANGELOG.md)
  • steipete: Recent GitHub history for src/acp/control-plane/manager.core.ts shows several ACP manager fixes and strictness updates around the same control-plane area. (role: recent area contributor; confidence: medium; commits: 20ed5974957f, 277cc640b19b, 8f1a214a2342; files: src/acp/control-plane/manager.core.ts, src/acp/control-plane/manager.test.ts)
  • mbelinky: Recent task-runtime extraction work touched the detached task lifecycle that ACP background-task summaries write through. (role: adjacent task lifecycle contributor; confidence: medium; commits: 0787266637fd, bd3ad3436efd; files: src/acp/control-plane/manager.core.ts, src/tasks/detached-task-runtime.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 42b95a9eb1eb; fix evidence: release v2026.5.9-beta.1, commit fa445003b5eb.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 6, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
@byungskers

This comment was marked as low quality.

@bykim0119 bykim0119 changed the title fix(acp): preserve chunk whitespace in background-task progress summary fix(acp): preserve chunk whitespace in background-task progress summary [AI-Assisted] May 6, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
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 openclaw#78312
@bykim0119
bykim0119 force-pushed the fix/append-progress-summary-whitespace branch from 80e1dc4 to 9813b29 Compare May 6, 2026 09:38
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
@bykim0119

Copy link
Copy Markdown
Author

Excellent fix for the CJK chunking issue! The test cases are very well thought out—covering Hangul syllables, paths, CamelCase, and whitespace edge cases. The logic of preserving chunk edges while collapsing internal whitespace is the right approach for token-streamed output. One thing to double-check: exporting "appendBackgroundTaskProgressSummary" is a public API change—are there any other modules or external consumers that might be affected? If it's internal-only, no worries. Great work! 🎯

Thanks — I double-checked this. The export was added only for the focused unit test, and I don’t see any external/runtime consumer of appendBackgroundTaskProgressSummary beyond manager.core.ts itself and the new test. It also isn’t re-exported from the barrel or exposed through the package exports, so this shouldn’t expand the public/runtime surface in practice. Happy to switch to a test-only shim if you’d prefer.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 14, 2026
@clawsweeper clawsweeper Bot closed this May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ACP background-task summary corrupts token-streamed text (CJK breaks into single chars, paths split with spaces)

2 participants