Repository navigation
fix: preserve literal final tags in delivered code examples - #138989
shakkernerd merged 4 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 9:09 AM ET / 13:09 UTC. ClawSweeper reviewWhat this changesPreserves literal final tags in Markdown code examples during reply cleanup, shares that behavior with reasoning cleanup, and adds regression coverage and documentation. Merge readiness✅ Ready for maintainer review This remains a useful, focused fix: current main and v2026.9.2 still contain the reported sanitizer defect. No blocking findings remain, and the prior cursor-narrowing concern is resolved. Priority: P2 Review scores
Verification
How this fits togetherReply cleanup turns assistant output into text suitable for delivery. Its shared final-tag helper removes model control markers before CLI results and channel replies reach users. flowchart TD
A[Assistant output] --> B[Reply normalization]
B --> C[User-facing cleanup]
D[Markdown code regions] --> E[Final-tag cleanup]
C --> E
E --> F[Preserve code literals]
E --> G[Remove outside markers]
F --> H[Normalized reply]
G --> H
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +8, Tests +53, Docs +4. Total +65 across 6 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep code-literal protection in the shared final-tag owner; the small cursor-state increase supports ordered lookup while replacing the duplicate reasoning-cleanup loop. Do we have a high-confidence way to reproduce the issue? Yes: current-main source deterministically removes final tags inside inline and fenced code, matching the supplied baseline CLI receipt; this review did not execute a reproduction. Is this the best way to solve the issue? Yes: repairing the shared stripping owner aligns final sanitization with existing code-preserving reasoning behavior; a channel-specific workaround would leave other callers broken. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4bd1d6e305e5. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
|
Fixed: delivered Markdown code examples retain literal final tags while model final-answer markers outside code are removed. With thanks to @Alix-007. |
…#138989) Preserve literal final tags in delivered Markdown code examples while removing model final-answer markers outside code. Document the sanitization boundary and share it with reasoning cleanup. Refs openclaw#133152. Reviewed-by: @shakkernerd Co-authored-by: Shakker <[email protected]>
Related: #133152 (the explicitly recorded final-delivery sanitizer follow-up).
What Problem This Solves
Fixes an issue where users receiving XML examples would lose literal
<final>tags inside fenced or inline code when the reply passed through final delivery sanitization. The raw answer could contain the correct example while the delivered text silently changed it.The merged maintainer-authored #133152 records this exact failed live scenario and leaves it as a named follow-up. This PR repairs that remaining behavior.
Why This Change Was Made
The final-tag owner now reuses the existing Markdown Core code regions, preserving literal code while removing control markers outside it. Ordered tag matches and code regions are traversed with one advancing cursor, avoiding a per-tag scan of every region. Reasoning cleanup delegates to this same owner instead of retaining its duplicate stripping loop; its original early-return and trimming conditions remain unchanged.
Existing-solutions preflight: OpenClaw already has the required CommonMark parser and code-region contract. No new parser, dependency, plugin, configuration, or alternative execution path is needed.
Production: +22/-14, net +8, across two files. Tests: +53, across three files. Documentation: +4 in the canonical Markdown formatting guide, clarifying the same boundary as the helper API comment. The production growth protects literal source text and bounds region lookup; the connected duplicate loop is removed. No changelog or proof assets are added to the product branch.
User Impact
Code examples retain their original XML tags. Real final-answer markers outside code are still removed without deleting the answer they enclose. Fenced, inline, indented, blockquoted, and unfinished fenced examples are covered, including attributed tags and mixed code/control text.
No config/default, protocol/schema, permissions, security-policy, persistence, migration, or upgrade change. This does not expose reasoning contents or relax private-scaffolding filtering; those are separate policies.
Evidence
Recorded CLI Behavior Receipt
5654f5f36b2dadaab504060017d440cb858e6dc9.c22b1b79cf975dc9335bb45dd19b19ac3e60203a. The recorded CLI receipt predates the behavior-equivalent cursor type correction and documentation/API-comment clarification. The latter emits identical JavaScript with comments removed; the CLI evidence remains applicable.336b75a11d13bd173582dc7e3064b412c133bdcd. Both affected production files remain byte-identical on current main at the final pre-publication check.pnpm --silent openclaw agent --local --agent main \ --session-id alix-final-tags-patched --channel telegram \ --message "Return the fixture response exactly." \ --thinking off --timeout 60 --jsonNo
--deliveris supplied. The explicit channel selects real reply normalization without dispatching a channel message. The assertion reads canonicalpayloads[].text, not raw assistant metadata or a direct helper result.sanitizeUserFacingText->stripFinalTags.POST /v1/responsesat the loopback provider. The receipt retains the exact command, input, expected/actual output, source SHA, session ID and observation time.alix-final-tags-baselinereturnedpayloadinstead of<final data-model="demo">payload</final>inside the XML fence, andinlineinstead of<final>inline</final>inside inline code. Baseline run and logs.2026-09-05T09:45:33.911Z, sessionalix-final-tags-patched. Exact-head run.<final>Outside answer</final>becomesOutside answeron both baseline and patched runs. The fixture combines this control with both literal-code cases in one reply.Tests and Review
pnpm build, focused repository formatting, and diff hygiene passed in secretless fork CI.c22b1b79cf975dc9335bb45dd19b19ac3e60203a: pass, no findings. The original quadratic lookup finding and later cursor type-narrowing finding are resolved.AI-assisted implementation and review; the behavior results above were read back from the isolated executions, not inferred from passing unit tests.