Repository navigation
Conversation
|
Codex review: found issues before merge. Reviewed August 2, 2026, 2:26 AM ET / 06:26 UTC. ClawSweeper reviewWhat this changesThe branch adds sanitization for proxy-degraded Merge readinessThis PR still addresses a real current-main gap: visible-text handling accepts Priority: P1 Review scores
Verification
How this fits togetherModel output flows through shared visible-text and tool-call-repair sanitizers before OpenClaw delivers messages to channels and records assistant text in session history. Markdown code-region detection tells those sanitizers which tool-shaped text is a literal example rather than leaked control markup. flowchart LR
ModelOutput[Model output] --> VisibleText[Visible-text sanitizer]
ModelOutput --> PersistStripper[Persisted-message stripper]
VisibleText --> CodeRegions[Markdown code-region detector]
PersistStripper --> CodeRegions
VisibleText --> DeliveredReply[Channel reply]
PersistStripper --> SessionHistory[Assistant history]
Decision needed
Why: The behavior fix is needed, but repository policy blocks an external manifest and lockfile graph change; only maintainers can decide whether the ownership move is acceptable. Before merge
Findings
Agent review detailsSecurityNeeds attention: No new third-party package is introduced, but the external PR changes a workspace manifest and lockfile dependency graph that requires exact-head authorization. PR surfaceSource +319, Tests +391, Config +7, Generated 0, Other +3. Total +720 across 19 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: 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: Rebase onto current Do we have a high-confidence way to reproduce the issue? Yes, from current source: the visible sanitizer only accepts Is this the best way to solve the issue? No: the proposed behavior is directionally correct, but this stale branch is not the best current solution until it rebases and preserves the protected-range plugin-SDK contract added on August 1, 2026. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b671c1bfe7c3. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
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 (84 earlier review cycles; latest 8 shown)
|
c345a7b to
f6576ab
Compare
|
Pushed the streaming-prefix fix for the remaining P1 (the streamed invoke recognizer now mirrors the final parser's whitespace-flexible grammar via a phase scanner, with split-whitespace regression coverage), and added redacted real-behavior proof under |
|
Addressed the latest review:
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
790e9c0 to
6bba759
Compare
|
Addressed the visible-text stripping finding: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Rebased onto latest upstream/main (clean, no conflicts); branch head is now 1e076955. @clawsweeper re-review |
|
Rebased onto latest upstream/main (clean, no conflicts); branch head is now 0e72cf8f. @clawsweeper re-review |
|
Rebased onto latest upstream/main (clean, no conflicts); branch head is now 92d06db8. @clawsweeper re-review |
|
Rebased onto latest upstream/main (resolved a generated plugin-sdk API baseline conflict by regenerating the baseline; |
|
Rebased onto latest upstream/main (clean, no conflicts; no source changes). New head is current. @clawsweeper re-review |
|
Rebased onto latest upstream/main (resolved the generated plugin-sdk API baseline conflict by regenerating the baseline; |
|
Rebased onto latest upstream/main (clean, no conflicts; no source changes). @clawsweeper re-review |
|
Rebased onto latest upstream/main (clean, no conflicts). @clawsweeper re-review |
3 similar comments
|
Rebased onto latest upstream/main (clean, no conflicts). @clawsweeper re-review |
|
Rebased onto latest upstream/main (clean, no conflicts). @clawsweeper re-review |
|
Rebased onto latest upstream/main (clean, no conflicts). @clawsweeper re-review |
|
Rebased onto latest upstream/main (clean, no conflicts). Verified head now at e262bff0. Requesting a fresh review on the current head. @clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Rebased onto latest upstream/main (clean, no conflicts). Head now at a85bca71. Requesting a fresh review on the current head. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Rebased onto latest upstream/main. This time upstream had overlapping changes: it extracted a shared code-regions helper and a CJK-chars module in packages/normalization-core, so there were conflicts in packages/normalization-core/src/index.ts and src/shared/text/code-regions.ts. Resolved by keeping normalization-core as the single canonical home for findCodeRegions/isInsideCode/CodeRegion (re-exported from src/shared/text/code-regions.ts) alongside upstream's cjk-chars export, so there is one implementation rather than a forked copy, and our code-region-preservation behavior is retained. Head now at bb06cae1. Requesting a fresh review on the current head. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Addressed the remaining P1 (preserve indented Markdown code regions). The shared code-region detector regressed when it moved into
It contains no @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Dependency GuardThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
Dependency graph changes are blockedOpenClaw does not accept dependency graph changes through PRs unless a repository admin or security explicitly authorizes the current head SHA. Dependency updates are generated internally by maintainers so external PRs cannot change the resolved graph. Detected dependency graph changes:
Auto-scrub was not attempted because this PR changes package manifest dependency graph fields:
Dependency graph changes must be reviewed by security or handled by maintainers internally. Please remove lockfile changes manually if they are not needed. To remove lockfile changes, restore them from the target branch: git fetch origin
git checkout 'origin/main' -- 'pnpm-lock.yaml'
git commit -m 'chore: remove dependency lockfile change'
git pushIf this PR intentionally needs a dependency graph change, ask a repository admin or member of The action will approve the current head SHA ( |
|
Fix C1 landed at f43b089b2abe: moved code-region detection to a canonical mdast-backed adapter in @openclaw/markdown-core, deleted the flat leaf scanner in normalization-core, and repointed tool-call-repair + src/shared/text/code-regions.ts. This preserves qualified antml:/mm: invoke examples in indented code nested under CommonMark list containers (the real reachable P1 case) while still scrubbing plain-paragraph 4-space continuations and tight/loose list non-code continuations. New test coverage for nested-list, blockquote-list, single-list, blockquote invariant lock, and the three negative over-preserve guards. Also added a cheap tag-presence gate on the reasoning-progress streaming hot path so mdast is only invoked when a reasoning tag is actually present (17KB no-tag sample: normalize 965ms→17ms, format 1706ms→62ms, merge 44ms→1ms across 200 iterations). PR body Evidence section refreshed with the real-behavior proof for all six nested-code cases. @clawsweeper re-review |
…out deleting code examples (openclaw#97750) Some proxies degrade native Anthropic/MiniMax tool calls into namespaced or bare XML text using the attribute dialect `<invoke name="tool"><parameter name="x">v</parameter></invoke>`, optionally wrapped in `<function_calls>...</function_calls>` and optionally prefixed with `antml:` or `mm:`. This markup leaked into user-visible text and was mishandled on the persist path. Visible text: mirror the existing `antml:` handling for the `mm:` namespace in the assistant-visible-text stripper so truncated/mid-line `mm:invoke` leaks are removed. The `<function_calls>`-wrapped bare invoke case is already handled by the package strip stage in the delivery pipeline. Persist path: teach the tool-call-repair strip to recognize a complete standalone invoke block (bare/antml:/mm:, `<function_calls>` wrapper, self-closing, and zero-parameter forms) via a dedicated linear scanner. The scanner returns none/incomplete/complete so the strip loop bails on an unterminated open exactly like the existing dialects, keeping the scan linear (no quadratic rescan on adversarial input). The strip now takes an optional code-region predicate so fenced and inline Markdown examples of the invoke dialect are preserved while unfenced standalone leaked blocks are scrubbed; without a predicate it lazily computes code regions so a bare package call still spares examples. Keep the exported plugin-SDK helper strict by default (forces a scrub of every region) with an opt-in `{ preserveCodeRegions: true }` for code-aware callers, and keep the closed `(?:antml:|mm:)?` namespace allow-list so arbitrary `ns:` tokens in prose are never matched. Move findCodeRegions/isInsideCode/CodeRegion into normalization-core so the tool-call-repair package can share one implementation without importing app source; the shared/text module re-exports them so existing callers are unaffected. Add focused regression tests for the invoke-dialect variants, code-region preservation, the predicate override, the SDK preserveCodeRegions option, the mm: visible-text case, and a linear-time guard against many unterminated opens. Split the standalone invoke strip helpers into payload-strip-invoke.ts and the visible-text tool-call pattern constants into assistant-visible-text-tool-call-patterns.ts. This is a pure structural extraction with no behavior change, keeping the two touched legacy files within the changed-file size ratchet.
…l stripper Restore stripPlainTextToolCallBlocks to its single-argument strict contract and remove the StripPlainTextToolCallOptions type. The preserveCodeRegions opt-in was added on this branch and never shipped in a release; no production caller uses it, so it is dead public surface. The code-region-aware path remains available in the internal packages/tool-call-repair helper, and package-level tests keep that coverage. Decrement the public export surface budget accordingly and regenerate the plugin-sdk API baseline.
…y qualified forms Narrow the standalone-invoke scrubber so a bare (un-namespaced, unwrapped) full-line <invoke>...</invoke> block is preserved as legitimate content on both the visible-delivery and persisted-history paths. Only namespace-qualified (antml:/mm:) or <function_calls>-wrapped forms are treated as degraded tool-call leakage and removed, matching the actual scope of the reported proxy degradation. - grammar.ts: make the namespace group capturing; scanStandaloneXmlishInvokeBlock now returns 'none' for an unqualified bare block while keeping the incomplete (linearity/ReDoS) bail ahead of the qualification check. - payload.ts: tighten the strip trigger prefilter so a bare <invoke> no longer arms the scrub pass on its own; wrapper/namespaced forms still arm it. - tests: move the bare case out of the scrub set, add bare-survives regressions across the visible-delivery and persisted-history profiles, and update the openclaw#97750 visible-text test to assert the preservation contract.
…ode-region detector findCodeRegions only recognized fenced and inline-backtick spans after the detector moved into normalization-core, dropping the indented (four-space / tab) CommonMark code-block detection the previous shared helper provided via the Markdown scanner. Qualified antml:/mm: invoke examples and <details> examples inside an indented code block were therefore treated as ordinary text and stripped/flattened on both the visible-delivery and persisted-history paths. Add a self-contained CommonMark indented-code-block detector (no markdown-core import, which would cycle since markdown-core depends on normalization-core): - indent measured in columns (tab advances to the next multiple of four) - a block opens only at document start or after a blank line whose nearest non-blank predecessor is unindented; a four-column line following prose stays a lazy paragraph continuation and remains scrubbable - region spans the first indented line through the last non-blank indented line, keeping interior blanks and excluding trailing blanks - runs after the fenced pass and before the inline pass Add code-regions unit coverage (fenced/indented/inline/tab/interior-blank/ paragraph-continuation-negative) plus delivery- and history-profile regressions for a qualified invoke example inside an indented block.
…pter The old flat scanner in packages/normalization-core/src/code-regions.ts opened an indented code block only when the nearest non-blank predecessor line was itself unindented. That heuristic misfires for valid indented code nested under a CommonMark list container whose content indent is >= 4 columns (nested lists, or a list item whose continuation line is itself indented). A qualified antml:/mm:/ function_calls invoke example placed in such nested code was recognised as prose by the downstream visible-text and persistence scrubbers and silently removed from both delivered replies and persisted assistant history. Route the code-region source through the canonical mdast implementation: - Add packages/markdown-core/src/code-regions.ts, a small adapter over findMarkdownCodeSpans exposing the existing CodeRegion / findCodeRegions / isInsideCode surface via a dedicated @openclaw/markdown-core/code-regions subpath. - Delete the leaf flat scanner from packages/normalization-core and drop its export; a leaf cannot import markdown-core without cycling. - Repoint packages/tool-call-repair/src/payload-strip-invoke.ts and src/shared/text/code-regions.ts to the markdown-core adapter. The link tool-call-repair -> markdown-core -> normalization-core stays acyclic. - Regenerate docs/.generated/plugin-sdk-api-baseline.sha256 via the repo's own generator; the public CodeRegion shape is preserved. Add coverage across the sanitiser boundary: - Positive-preserved: qualified invoke in indented code nested under a >= 4 column list container (real reachable case); a second container variant; single-level list still preserved; blockquote invoke preserved as an invariant lock, with a comment noting the scrubber requires '<' at line start (skipLineIndentation skips only spaces/tabs, not '>'), so any future scrubber change consuming '>' must re-check code detection. - Negative still-scrubbed: plain paragraph + 4-space continuation, tight-list lazy continuation, loose-list non-code continuation. Guard the reasoning-progress streaming hot path with a cheap tag-presence gate in src/channels/progress-draft-status-text.ts so the mdast-backed detector only runs when a reasoning tag is actually present. Micro-bench on a 17KB no-tag sample: normalize 965 ms -> 17 ms, format 1706 ms -> 62 ms, mergeDeltas 44 ms -> 1 ms across 200 iterations.
|
Closing this PR as superseded by upstream work. Since this PR was opened, upstream #117089 landed and now handles the The only residual difference is the Closing to keep the queue clean. If the |
Closes #97750
What Problem This Solves
Some deployments serve a Claude/MiniMax model through a proxy that intermittently degrades a native
tool_useblock into plain text. In that degraded case the tool call arrives as the namespaced attribute dialect —<invoke name="tool"><parameter name="x">v</parameter></invoke>prefixed withantml:ormm:, and/or wrapped in<function_calls>...</function_calls>.On current
maintwo gaps remained:antml:prefix but not themm:prefix, so a degradedmm:invokeblock leaked verbatim into the user-visible reply.packages/tool-call-repairstripPlainTextToolCallBlocks) did not recognize the attribute-dialect invoke at all, so an unfenced standalone degraded invoke block was written into the durabledone.messageinstead of being scrubbed.A follow-up review then surfaced a P1 code-region regression: the shared code-region detector was a flat scanner that only opened an indented code block when the nearest non-blank predecessor line was itself unindented. That heuristic misfired for valid indented code nested under a CommonMark list container whose content indent was ≥ 4 columns, so a qualified
antml:/mm:/<function_calls>invoke example placed in such nested code was treated as prose by the downstream visible-text and persistence scrubbers and silently removed from both delivered replies and persisted assistant history.Why This Change Was Made
The degraded tool call should never reach the user, and it must not be persisted into session state either — but a legitimate
<invoke>XML example must be preserved, not deleted. Two kinds of legitimate example matter: fenced/inline code spans, and a bare (un-namespaced, unwrapped) standalone<invoke>block written as plain prose content.Because the reported degradation only ever carries a provider-owned signature — an
antml:/mm:namespace or a<function_calls>wrapper — the scrubber is scoped to exactly those qualified forms. A bare, un-namespaced, unwrapped<invoke>block carries no degradation signature and is therefore treated as legitimate content and preserved on both the visible-delivery and persisted-history paths. This keeps the change inside the actual scope of #97750 (namespaced/proxy-degraded leaks) and avoids an over-broad content-removal policy on durable transcripts, where a false positive would be unrecoverable. This mirrors the pre-existing sibling stripperstripToolCallXmlTags, which likewise only enumerates theantml:/mm:namespaces and never removes a bareinvoke.Scope of the net delta that still reproduces on
main:assistant-visible-text.ts): mirror the existingantml:handling for themm:namespace in the tag-name scan, quick-check, and payload-start patterns. The<function_calls>-wrapped case is scrubbed by the package strip stage in the delivery pipeline.packages/tool-call-repair): a dedicated linear scanner recognizes a standalone invoke block and classifies it. It returnscompleteonly when the block is namespace-qualified (antml:/mm:) or<function_calls>-wrapped; a bare unqualified block returnsnone(preserved). On an unterminated open it returnsincompleteso the strip loop bails and preserves the remainder, keeping the scan linear on adversarial input.findCodeRegions/isInsideCode/CodeRegionnow live in@openclaw/markdown-coreas a dedicatedcode-regionssubpath adapter over the canonicalfindMarkdownCodeSpans(mdast). The prior flat scanner innormalization-core— which could not resolve container-relative indentation — has been deleted (a leaf package cannot importmarkdown-corewithout cycling, which is why the flat scanner was inlined there in the first place).tool-call-repairnow depends onmarkdown-coredirectly (tool-call-repair → markdown-core → normalization-corestays acyclic;pnpm check:import-cyclesandpnpm check:madge-import-cyclesboth report 0 cycles).src/shared/text/code-regions.tsre-exports the adapter so every existing caller sees the identicalCodeRegionshape; the plugin-SDK surface is preserved (regenerated viascripts/generate-plugin-sdk-api-baseline.ts).src/channels/progress-draft-status-text.tscalls the code-region detector on accumulated reasoning text. To avoid paying full mdast parsing on chunks that carry no reasoning tag at all, the three progress helpers now short-circuit on a cheapREASONING_PROGRESS_TAG_RE.test(text)gate before invokingfindCodeRegions. On a 17 KB no-tag reasoning-progress sample this tooknormalizeReasoningProgressLinefrom 965 ms → 17 ms (200 iterations),formatReasoningProgressDisplayLinefrom 1706 ms → 62 ms, andmergeReasoningProgressTextfrom 44 ms → 1 ms (measured locally).stripPlainTextToolCallBlocksstays strict by default for its scrub-region behavior, with code-aware behavior available only via the explicit{ preserveCodeRegions: true }opt-in.Non-goals/boundaries: the native Anthropic/DSML transports are untouched; no runtime fallback execution from sanitized text is introduced; the equals dialect (
<function=...>/<parameter=...>), bracket, and Harmony paths are unchanged; the invoke dialect is recognized only by the strip/sanitize paths (never promoted to an executable call and never wired into the stream-buffering scanner).User Impact
Users on proxied Claude/MiniMax routes no longer see raw namespaced (
antml:/mm:) or<function_calls>-wrappedinvoketool-call XML in their replies, and the leaked block is no longer written into the persisted message (no session-state content loss). Legitimate<invoke>XML examples are preserved rather than stripped on both the visible and persisted paths — inside code fences/inline code, inside indented code blocks nested under CommonMark list containers whose content indent is ≥ 4 columns (the reachable P1 case), inside single-level list indented code, and as a bare, un-namespaced, unwrapped standalone block in plain prose. A resolved-review audit also removed an O(n²) worst case on the persist strip path, so adversarial degraded text cannot cause pathological CPU use. The reasoning-progress streaming hot path no longer pays full mdast parsing on chunks that carry no reasoning tag.Evidence
Focused regression tests cover the sanitiser and code-region boundary at every layer that owns the contract:
packages/tool-call-repair/src/payload.test.ts: qualified invoke-dialect scrub variants (antml:/mm:,function_callswrapper, self-closing, zero-param), bare-survives cases (multi-parameter, self-closing, zero-parameter, and under a strict predicate), code-region preservation vs. unfenced qualified scrub, a linear-time guard against many unterminated opens, nested-list code preservation (real reachable P1 case), blockquote-list continuation preservation, single-level-list preservation, blockquote invariant lock, and negative over-preserve guards (plain-paragraph 4-space continuation, tight-list lazy continuation, loose-list non-code continuation).src/shared/text/assistant-visible-text.test.ts: themm:invoke/mm:parametervisible-text scrub case (parallel to the existingantml:case), plus bare-survives regressions on both the delivery and history/persisted profiles, and the nested-code positive / negative-over-preserve pair.src/agents/embedded-agent-utils.test.ts: a bare unfenced<invoke>example is preserved verbatim byextractAssistantText([Bug]: Anthropicantml:namespaced tool-call XML leaks into visible content (and fails the turn) when proxy degrades tool_use to text #97750 preservation contract).packages/markdown-core/src/code-regions.test.ts: direct adapter coverage — fenced (incl. markers), inline (incl. backticks), doc-start 4-space, indent-after-blank, paragraph-continuation, leading tab, interior/trailing blank exclusion, and a nested-container positive case.Real-behavior proof (before =
mainsanitize/strip; after = this branch head), driving the ACTUALsanitizeAssistantVisibleTextandstripPlainTextToolCallBlockson the reported leak shapes:Nested-Markdown code-region proof (before = flat scanner in
normalization-core; after = canonical mdast adapter in@openclaw/markdown-core/code-regions), driving the ACTUALfindCodeRegionsandstripPlainTextToolCallBlockson the persist path:Perf gate proof (before = mdast on every chunk; after = cheap
REASONING_PROGRESS_TAG_RE.test()gate first), 200 iterations on a 17 KB no-tag reasoning-progress sample driving the actual functions:Correctness of the gate:
REASONING_PROGRESS_TAG_REis the single source of truth for which tags matter on the reasoning-progress path; if.test()reports no match, there is nothing to strip and nothing to gate against code regions, sofindCodeRegionsis redundant work. The three helpers resetlastIndexbefore and after the gate to avoid stateful regex leakage.Verification suite on this branch head:
node scripts/run-vitest.mjs packages/tool-call-repair/src/payload.test.ts→ 46 tests pass.node scripts/run-vitest.mjs src/shared/text/assistant-visible-text.test.ts→ 124 tests pass.node scripts/run-vitest.mjs packages/markdown-core→ 25 files / 261 tests pass.node scripts/run-vitest.mjs src/channels/progress-draft-lines.test.ts→ 3 tests pass.node scripts/run-vitest.mjs src/channels/progress-draft-compositor.test.ts→ 40 tests pass.pnpm tsgo:core→ exit 0.pnpm tsgo:core:test→ exit 0.pnpm check:import-cycles→ 0 runtime value cycles.pnpm check:madge-import-cycles→ 0 cycles.O(n²) audit fix: a resolved-review pass measured the persist strip degrading quadratically on adversarial input with many unterminated invoke opens (720 KB ≈ 977 ms, scaling to seconds for a few MB). Making the scanner bail on
incomplete(mirroring the existing unterminated-candidate bail) brought the same 720 KB input to ≈ 0.8 ms and restored linear scaling; a regression test locks this.