Repository navigation
fix(agents): keep fenced code byte-for-byte through duplicate-block collapse - #135945
Conversation
…ollapse collapseConsecutiveDuplicateBlocks split the reply on blank lines without consulting code regions, so blank lines inside fences produced chunks that compared equal after whitespace folding and were silently deleted; kept chunks were re-emitted trimmed, stripping indentation from the first line of fenced code. Protect any block overlapping a code region (never deleted, never re-trimmed) and rejoin with the original blank-line separators. Co-Authored-By: Claude <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed September 2, 2026, 3:40 PM ET / 19:40 UTC. ClawSweeper reviewWhat this changesThe branch protects Markdown code during outbound duplicate-paragraph collapse, with supporting regressions and test-runtime reliability updates. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep this PR open: current main still corrupts code-bearing duplicate blocks, and the PR has credible Telegram Test Server proof, but its parser masking leaves the prior P2 regression for identical prose containing inline code unresolved. Priority: P1 Review scores
Verification
How this fits togetherThe shared outbound text sanitizer normalizes assistant replies before channels deliver them. Its duplicate-paragraph filter must preserve code bytes while still collapsing genuinely repeated prose. flowchart TD
Reply[Assistant reply] --> Sanitizer[Outbound text sanitizer]
Sanitizer --> Projection[Text projection filters]
Projection --> Duplicate[Duplicate paragraph collapse]
Duplicate --> Code[Markdown code-region handling]
Code --> Delivery[Channel delivery]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +38, Tests +101, Other +4. Total +143 across 12 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Protect fenced and indented code as byte-preserving barriers while retaining the existing duplicate match for identical prose paragraphs that contain inline code, then cover that contract through the existing partitioned projection test table. Do we have a high-confidence way to reproduce the issue? Yes—source inspection gives a high-confidence reproduction: pass two identical paragraphs such as Run Is this the best way to solve the issue? No—the branch correctly protects fenced code but masks inline spans too, changing ordinary prose semantics. Block-code-only protection or equivalent stable matching is the narrower maintainable repair. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1e37a56c7528. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (14 earlier review cycles; latest 8 shown)
|
…ons untrimmed The duplicate-block collapse discovered code regions from already-trimmed text, so an initial indented code block lost its leading indentation before the parser could classify it, and a protected block's normalized text stayed in the comparison state, letting prose after it collapse against prose before it. Restructure the collapse around parser-owned code regions: protected code is emitted byte-for-byte and ends the duplicate sequence, and each code-free prose run collapses independently with its run edges kept byte-exact. Co-Authored-By: Claude <[email protected]>
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
# Conflicts: # .github/workflows/ci.yml # test/scripts/ci-workflow-guards.test.ts
# Conflicts: # ui/src/styles/corner-shape.browser.test.ts
# Conflicts: # test/helpers/openclaw-test-instance.ts # test/scripts/ci-linux-git.test.ts
|
Thanks @ruel225! Proof: Telegram Test Server direct message preserved the exact 226-character rendered reply, four-space code indentation, three repeated fenced lines, and two code entities with one provider request.
|
…#135945) ## What Problem This Solves Every delivered assistant reply passes through `sanitizeUserFacingText`. Its final `collapseConsecutiveDuplicateBlocks` stage split the reply on blank lines without consulting code regions. Repeated lines inside a fence could be deleted. Any duplicate elsewhere also caused retained fenced chunks to be trimmed, which removed meaningful indentation. The stored transcript stayed correct while channel users received corrupted code. Fixes openclaw#135882 ## Why This Change Was Made The shared duplicate-paragraph projector keeps its incremental candidate detector. When that detector finds a possible duplicate, the canonical transform uses the existing parser-owned `findCodeRegions` ranges. - Each code region becomes a deterministic unique token with no whitespace or line breaks. - The existing prose collapse runs unchanged on the masked text. - Unique tokens prevent code-touched paragraphs from comparing as duplicates and make code a sequence barrier. - The exact parser-owned bytes replace the tokens after prose collapse. - Streaming stays on the current fast path until a duplicate candidate appears. This stays in the shared text-projection owner used by the sanitizer. It adds no Telegram branch and no second Markdown parser. ## User Impact Telegram and other channel users receive fenced code with its indentation and repeated lines intact. Adjacent duplicate prose still collapses as before. Production delta: +74/-6, net +68. Tests and test support: +139/-30, net +109. Current `main` absorbed the CI workflow, Chromium, and complete CLI-output repairs. The production growth carries the parser-owned block/inline distinction needed to preserve block code while retaining inline-prose duplicate collapse. ## Evidence ### Telegram Test Server Ran the real Telegram direct-message path with the deterministic mock provider on baseline main `d1196942a01194b32399182af6e5f9bfe9861c35` and final exact head `8c740cc4e325c344108689738b266561285c5b0c` after integrating current main `925e94d08db3014f004b4abefb609d82d18f7dd5`. The model response contained an indented Python method and three blank-line-separated repeated lines inside fenced code. | Result | Current main | Exact head | | --- | --- | --- | | Delivered characters | 203 | 226, exact expected rendered text | | `def log` indentation | column 0 | column 4 | | `[worker] retrying` lines | 2 | 3 | | Telegram code entities | 2 | 2 | | Provider requests | 1 | 1 | | Stored fenced transcript | exact | exact | Exact delivered head text: ```text Here is the retry loop and the log it produced: class Worker: def run(self): self.log("retrying") def log(self, msg): print(msg) [worker] retrying [worker] retrying [worker] retrying [worker] done ``` The same run read the per-agent SQLite transcript before cleanup. It retained the original Markdown fences, indentation, and all three repeated lines. ### Tests and checks - New regression test on current main: 3 expected failures for fenced bytes, initial indented code, and code-barrier reset. - Current exact-head projection and sanitizer tests: 28 passed. - Earlier full owner and sanitizer suites: 142 tests passed; delivery sibling suites: 228 tests passed. - 12,960 generated code-free inputs matched the previous prose-collapse output. - Oxfmt, Oxlint, and `git diff --check`: passed. - Prior Codex Sol autoreview: no accepted or actionable P0 findings. The exact-head landing review runs after push. - CI root-cause repair: required comparison bases now load during the authenticated checkout. The guard, protocol, and npm-lock lanes no longer fetch after credentials are removed. Workflow and Git lifecycle suites passed 416 tests, and workflow validation passed. - CI flake repair: the lease cleanup test now uses the existing 10-second worker-lifecycle lease, so constrained runners cannot turn its abort assertion into an unrelated lease-expiry result. The focused owner suite passed 10 tests. - Windows CI cleanup repair: terminal test-instance cleanup now reuses the existing force-tree path on Windows, so inherited Gateway pipes cannot outlive completed assertions. The shared helper suite passed 36 tests; exact Windows proof runs in CI. - Lease worker startup repair: the process-exit test now uses the existing compiled test-subprocess owner instead of launching a TypeScript child that can exhaust the production heartbeat readiness deadline. State lease suites passed 14 tests; compiled-subprocess inventory passed 39 tests. - ClawSweeper review repairs: the original incremental duplicate projector now owns continuation suffixes after parser-backed reconciliation. A code-bearing regression keeps parser calls at one across 256 appends. The abort test now awaits heartbeat-worker exit before checking that lease state stays unchanged. - Hosted Chromium repair: the corner-shape browser probe now treats the computed CSS alias `superellipse(1)` as semantic `round`. All 3 focused browser tests passed locally; exact hosted proof runs in CI. - Built-CLI proof repair: finite CLI commands now wait for child stream closure and retain complete output, while long-lived Gateway logs remain bounded. The exact failed artifact emitted 288,423 bytes beyond the old 262,144-byte cap. The inherited-pipe and 300 KiB regressions pass with all 38 shared helper tests. ## ClawSweeper Rank-Up Moves - Applied the remaining merge-risk move: parser-backed masking remains the single canonical code-protection path, while the existing suffix fast path and direct sanitizer and streaming regressions remain in place. - Applied the inline-code move: parser-owned block regions remain unique barriers, while identical inline spans reuse stable tokens and collapse as ordinary prose across static and partitioned streaming input. Co-authored-by: Claude <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Every delivered assistant reply passes through
sanitizeUserFacingText. Its finalcollapseConsecutiveDuplicateBlocksstage split the reply on blank lines without consulting code regions.Repeated lines inside a fence could be deleted. Any duplicate elsewhere also caused retained fenced chunks to be trimmed, which removed meaningful indentation. The stored transcript stayed correct while channel users received corrupted code.
Fixes #135882
Why This Change Was Made
The shared duplicate-paragraph projector keeps its incremental candidate detector. When that detector finds a possible duplicate, the canonical transform uses the existing parser-owned
findCodeRegionsranges.This stays in the shared text-projection owner used by the sanitizer. It adds no Telegram branch and no second Markdown parser.
User Impact
Telegram and other channel users receive fenced code with its indentation and repeated lines intact. Adjacent duplicate prose still collapses as before.
Production delta: +74/-6, net +68. Tests and test support: +139/-30, net +109. Current
mainabsorbed the CI workflow, Chromium, and complete CLI-output repairs. The production growth carries the parser-owned block/inline distinction needed to preserve block code while retaining inline-prose duplicate collapse.Evidence
Telegram Test Server
Ran the real Telegram direct-message path with the deterministic mock provider on baseline main
d413210bc7420923d101ce64211511cdac7b9464and final exact head8c740cc4e325c344108689738b266561285c5b0cafter integrating current mainfcbe9938d8c6b71917d4b70bdc8d2049d6c18547.The model response contained an indented Python method and three blank-line-separated repeated lines inside fenced code.
def logindentation[worker] retryinglinesExact delivered head text:
The same run read the per-agent SQLite transcript before cleanup. It retained the original Markdown fences, indentation, and all three repeated lines.
Tests and checks
git diff --check: passed.superellipse(1)as semanticround. All 3 focused browser tests passed locally; exact hosted proof runs in CI.ClawSweeper Rank-Up Moves