Repository navigation
fix(text): gate delivery filters on real tag shape, not bare mentions - #196624
roboclaw-bot merged 5 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. What this changesThis PR activates memory and MiniMax delivery filters only after a bounded probe detects relevant tag syntax. Example: A streamed reply contains 36,107 characters discussing relevant-memories and minimax:tool_call without emitting tags.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses a current-main streaming performance defect, resolves the prior findings, and has no remaining actionable correctness findings; required CI is still pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherProvider text deltas enter the agent's shared text projection, which removes internal scaffolding and emits visible text as append deltas or replacement snapshots. flowchart LR
A[Provider text deltas] --> B[Agent message update handler]
B --> C[Assistant visible text projection]
C --> D[Bounded tag activation probes]
D --> E[Canonical text transforms]
E --> F[Visible deltas or replacements]
Technical reviewBest possible solution: Retain the shared bounded activation probe and unchanged canonical parsers, then land this PR after required current-head CI passes. Do we have a high-confidence way to reproduce the issue? Current-main activation tokens and projector control flow establish the repeated-scan path, supported by the contributor's before/after Gateway and replay output; this read-only review did not execute it. Is this the best way to solve the issue? The change fixes activation at the existing shared owner, preserves canonical parsing and replacement resets, and addresses both prior findings without introducing a competing sanitizer. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e212edede209. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +44, Tests +109, Other +9. Total +162 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed November 10, 2026, 10:17 PM ET / November 11, 2026, 03:17 UTC (Revision 4). |
The relevant-memories and minimax delivery filters used bare word
activation tokens ("relevant-memories" / "minimax:tool_call"). Under
createActivatedProjector the probe latches on the first mention and the
canonical transform then re-scans the whole accumulated reply on every
delta. Gate activation on the real <relevant-memories> / <minimax:tool_call>
tag shapes so ordinary replies that merely mention the words never pay the
whole-reply re-scan.
a76ee50 to
bc17aa9
Compare
…bounded probe The canonical memory parser accepts <\s*\/?\s*relevant[-_]memories, but literal activation tokens only matched the exact '<relevant-memories' shape. A whitespace-bearing opener or a tag word split across deltas never latched the delivery stage, so the memory block stayed in the streamed visible text while the batch transform removed it. Replace the literal tokens with a bounded incremental probe that mirrors the parser grammar (unbounded whitespace, optional slash, split tag word, word boundary). Ordinary prose and bare mentions still never latch, so the whole-reply re-scan stays off the hot path for both delivery and internal-scaffolding profiles.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Review follow-up: literal activation tokens missed the canonical MiniMax invocation-cleanup path (a completed <invoke> block with a spaced minimax marker but no exact envelope), leaving the payload visible in streamed text while batch filtering removed it. Replace the separate per-stage state machines with one bounded tag projector that folds each delta's whitespace runs into a fixed-size tail, so the canonical \s* grammar stays representable across unbounded gaps and delta splits. The minimax stage additionally requires an earlier marker word before an invocation/tag shape can activate, keeping bare mentions off the whole-reply re-scan while restoring batch/streaming parity. Also remove the redundant plain MiniMax-envelope case (already covered in assistant-visible-text.minimax.test.ts) and add a batch/streaming parity case for the reviewed invocation-cleanup shape.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…rder-free Review follow-up on the two remaining P2 findings: - Whitespace was collapsed within each delta separately, so a whitespace run delivered as many one-character deltas still pushed the opening '<' out of the bounded tail. Normalize the carried tail and the incoming delta together before truncation. - The MiniMax marker was required to appear before an invocation shape, but the canonical transform needs its marker anywhere in the accumulated text. Latch the shape and the marker independently, order-free, while a bare mention alone still satisfies neither. Add a regression case for each reviewed append schedule, asserting payload removal and batch parity, and align the test-lines allocation with the net test-line delta.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Follow-up on the two P2 findings and the CI exception:
|
076ff9b to
efac72b
Compare
|
Merged via squash.
|
…openclaw#196624) Avoid repeated canonical memory/MiniMax scans when a streamed reply only mentions tag names. Bounded shape probes preserve canonical parsing, split-whitespace tags, and marker ordering. Reviewed head: efac72b. Focused validation: 3 files / 150 tests passed. Local autoreview of 8f593cd..efac72b through P2 completed scoped-clean. Supplied Gateway proof is reused; scan-work improvement is not a wall-clock latency claim. Thanks @SunnyShu0925. Co-authored-by: Patrick-Erichsen <[email protected]> Co-authored-by: SunnyShu0925 <[email protected]>
What Problem This Solves
Streaming a reply that mentions
relevant-memoriesorminimax:tool_callwithout emitting a real tag currently makes the delivery sanitizer re-run the canonical memories/minimax transform over the whole accumulated reply on every delta — a 64 KB reply that only mentions these words pays ~4.1 s (memories) and ~49 s (minimax) of per-append work before it completes. This PR replaces bare-word activation with one bounded tag probe shared by both delivery stages, so ordinary prose stays off the hot path while every shape the canonical transforms strip is still stripped from streamed visible text.createActivatedProjectorpermanently; with no checkpoint, a latched stage runstext = transform(input.text)on the entire accumulated reply for every delta.createBoundedTagProjectorfolds each delta's whitespace runs into a bounded tail and matches a canonical-shaped regex.memoriesTextFilteruses<\s*\/?\s*relevant[-_]memories\bdirectly.minimaxToolCallTextFilterrequires an earlierminimax:tool_call(or encoded envelope) marker plus an invocation/tag shape, because the canonical transform also removes completed<invoke>blocks whenever that marker occurs — even without an exact<minimax:tool_call>token. A bare mention has no such shape and never latches.src/shared/text/assistant-visible-text.ts(the shared probe and both filter definitions),src/shared/text/assistant-visible-text.streaming-work.test.ts(whitespace-tag and batch/streaming parity cases), and the test-lines allocation. Net PR surface: **182 changed lines including deletions (172 added, 10 removed)**.transformbodies (stripRelevantMemoriesTags,stripMinimaxToolCallXml) are untouched, so batch parity, syntax ownership, code protection, andrecoverUnclosedstreaming semantics are preserved exactly.Why This Change Was Made
The repo invariant at
model-special-tokens.ts:148-149("Delivery filter: batch parity throughtransform, bounded work throughcreate") requires bounded work once a stage activates. These two delivery stages were the last that still latched on a bare word and re-scanned the whole reply per delta; every other stage already ships acreate/checkpoint.transformas the single source of truth and only replace activation gating. The carried tail and the incoming delta are normalized together before truncation, so a whitespace run delivered as many one-character deltas still collapses to one space instead of pushing the opening<out of the 32-character tail. Shape and marker are latched independently and order-free: the canonical MiniMax transform needs its marker anywhere in the accumulated text, so an<invoke>shape seen before the marker must still be remembered. One character after a shape match is required, which confirms a delta-split\bboundary instead of latching on a partial tag word.\s*or a tag word split across deltas, and they miss the invocation-cleanup path where a completed<invoke>block is stripped without an exact minimax envelope. A fixed-size raw tail probe was also rejected, since an unbounded whitespace run can push the<out of the window.#153944introduced selective activation to stop ordinary angle-bracket comparisons (x < y) from repeatedly rescanning a growing answer while preserving canonical parsing and delivered text;a36d0483flater reused that policy for theinternal-scaffoldingprofile. The single sharedmemoriesTextFilterconstant is still consumed by both profile orderings, so the two paths cannot drift. Activation remains selective — a bare mention orx < ynever latches — and unlike literal tokens it restores the full parser grammar and the invocation-cleanup behavior, i.e. the "canonical parsing + delivered text" half of#153944's intent.recoverUnclosedbehavior the canonical transform already applies.User Impact
Long streamed replies that merely discuss
relevant-memoriesorminimax:tool_callno longer stall on a whole-reply re-scan per token. Replies containing real memory tags — including whitespace-bearing or delta-split ones — and completed minimax invocations are stripped exactly as the batch parser would strip them, so users no longer briefly see internal scaffolding that later disappears. No configuration, migration, or change to which content is stripped is required.Compatibility
<invoke>blocks keep their existing stripping behavior; batch output is unchanged.#153944; internal-scaffolding reuse ina36d0483f.Evidence
All runs below used an isolated local Gateway started from this checkout with a real configured provider, driven through the shipped
chat.sendRPC (so the agent turn and the assistant-visible text projection run inside the Gateway process). AGatewayClientsubscribed to the broadcastchatframes. Credentials, the provider endpoint, host paths and non-public addresses are omitted; only loopback and aggregate numbers are shown.Before / after behavior matrix
Before= the code onmainbefore this PR (bare-word tokens).After= this PR.Reviewed head=8dc32ed5, the RED arm for the two newly reported P2 findings; the earlier whitespace-tag and spaced-marker findings had already been fixed by that head, so their RED arms were the literal-token /3f73a42revisions (sections 3 and 4). Rows use the same captured Gateway delta frames (290 frames / 36,107 chars forS1, 4 frames / 299 chars forS3) or the reviewer's exact fixtures.8dc32ed5S1bare mention: sanitizer scan work (regexWorkChars)S1bare mention: delivered visible charsS2real<relevant-memories>tag: delivered visible charsS3whitespace tag: delivered visible charsP2completed<invoke>with spaced minimax marker: batch/streaming parity3f73a42)P2whitespace run delivered as 64 single-space deltas: batch/streaming parityP2invocation shape before a later minimax marker: batch/streaming parityS2/S3batch final text across variantsThe
Afterscan-work number is slightly above the intermediatePR headbecause the shared probe also covers the invocation-cleanup shape; it is still ~12x belowBefore, and the delivered text is identical in every workload.1. Shipped-path streaming run, three source variants
The
chatframes were captured to JSON.replace:trueframes are the Gateway's delivered visible text:2. Reduced work on the real captured deltas
The exact delta frames broadcast by the Gateway in the
S1run were replayed through the productioncreateAssistantVisibleStreamText("final_answer")projector.regexWorkCharscounts characters passed toRegExp.prototype.test/exec— a direct proxy for whole-reply re-scan cost. Same input for all three variants:3. Whitespace-tag regression: failing on the literal-token revision, passing after repair
The same captured
S3Gateway frames replayed through the production projector on the earlier literal-token revision and on the current source. Literal tokens never activate on a whitespace-bearing opener, so the internal memory block stays in the streamed visible text; the batch transform still removes it, which was the reviewed mismatch:Real tags (
S2) strip identically on all three variants (visibleChars: 48, no leaked block).4. P2 regression: invocation cleanup without an exact envelope
The reviewer's exact fixture —
Ready.\n<minimax:tool_call >\n<invoke name="exec">secret</invoke>\n</minimax:tool_call >\nDone.— asserts batch/streaming parity (the payload must not be visible). Same assertion, same input, only the source variant changes:The minimax stage's
requiresmarker keeps a bare mention alone off the re-scan:bareMentionPreserved=true,bareMentionRegexWorkChars=2841for the same probe.5. The two new P2 findings: RED on the reviewed head, GREEN after repair
Both findings were reproduced with the reviewer's exact append schedules. Same acceptance condition for every arm — batch/streaming parity, with the internal payload never visible.
headhere is8dc32ed5:Both schedules are now pinned by added regression cases asserting
not.toContain("secret")and equality withsanitizeAssistantVisibleStreamText(batch).6. CDP CPU profiles of the Gateway process
Profiler.start/stoparound eachS1turn (the turn executes inside the Gateway process), measured on the earlier revision of this PR before the probe was consolidated:These columns are close across variants because a real provider emits coarse deltas (290 frames for this 36 KB reply), so the number of whole-reply re-scans is bounded by frame count even though each re-scan walks the entire accumulated reply. Process-wide self-time is too coarse to rank the variants;
regexWorkCharsin section 2 is the direct measure and was re-run on the final source for every row in the table above. On a client receiving one-character deltas (as in the original 64 KB measurement) the same ~12x ratio applies to every one of tens of thousands of appends, which is where the multi-second stalls come from.7. Focused regression assertion and suites
The
expectPrefixParitycase checks the spaced-marker P2 fixture at every delta split againstsanitizeAssistantVisibleStreamText(batch), so the streaming path cannot drift from batch. Two further cases pin the newly reviewed schedules — a whitespace run delivered as 64 single-space deltas, and an<invoke>shape arriving before the minimax marker — each asserting both payload removal and equality with the batch transform. The original whitespace cases still cover a split opener/closer and an unbounded gap (4,096 then 2,048 spaces) in a single append. The low-value plain real-MiniMax-envelope case was removed on review feedback;assistant-visible-text.minimax.test.tsalready streams complete envelopes in four-character chunks with surrounding prose assertions.oxfmt --checkandoxlint --type-awarereport 0 warnings and 0 errors on both changed source files.CI attribution
Two CI failures were attributed and fixed:
checks-fast-baseline-ratchets/test-lines: the first run reportedover by: 7; net delta: +96(the allocation under-funded the added test lines); the second run reportedTest line allocation credit 92 exceeds allowed ceiling growth 85(the credit exceeded the new net delta). The allocation is now set to exactly the net test-line delta of this revision (109). Locally, in both--stagedand working-tree modes,check-test-lines-ratchetreportsTest lines OK: 6613703; ceiling: 6613733; slack: 30andcheck-line-cap-ratchetreports no new violations; the CI run on this head passedchecks-fast-baseline-ratchets.checks-ui-e2e (1/2): apage.waitForFunction: Timeout 30000ms exceededinui/src/e2e/screen-requester-routing.e2e.test.ts(mock-Gateway Control UI browser test, 80 passed / 1 failed / 1 skipped), waiting on atools.github.statusrequest during GitHub-identity setup navigation. It is not caused by the shared-text changes here (this PR does not touch anyui/file, and the timeout is in a Control-UI routing flow unrelated to assistant text). The same test fails on unrelated PRs that also do not touchui/— e.g. PR fix(memory): stream session memory exports in bounded pages #196480 (6b5c7e4396) and PR perf(sandbox): avoid full content hashing after workspace imports #196937 (56845faf22) both reportchecks-ui-e2e (1/2): failurewith the identical timeout. The repository's rerun endpoint requires admin rights, so this upstream-flaky job is left for a normal CI retry.Scan changed paths (precise), the sixSecurity HighCodeQL shards andSelect Critical Quality shardsin earlier runs were GitHub installation API rate-limit errors, i.e. infrastructure.PR context and evidenceissuccesson the latest head, andvitestreports 150/150 passing acrossassistant-visible-text.streaming-work,assistant-visible-text.minimaxandtool-call-xml.streaming-work;oxfmt --checkandoxlint --type-awarereport 0 warnings and 0 errors.What was not tested
regexWorkCharsis the isolated measure of sanitizer scan cost, not end-user wall-clock time.Open PR collision check
Searched open PRs by changed-file list for
src/shared/text/assistant-visible-text.tsandsrc/shared/text/assistant-text-transforms.ts: apart from this PR (#196624), none of the matching open PRs (#192357, #181990, #196690, #143937, #191562) modifies either file. The related sibling PR #193871 (closed legacy-bracket checkpoint settlement) is a separate root cause in a different subsystem and remains its own open PR.