Repository navigation
perf(channels): defer partial-reply sanitization to consumption - #118349
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 9:14 PM ET / August 3, 2026, 01:14 UTC. ClawSweeper reviewWhat this changesThe PR defers sanitizing cumulative streaming partial replies until a throttled Telegram draft stream consumes the newest pending update, while direct-delivery consumers still materialize each partial immediately. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 4 items remain Keep this PR open for maintainer review. The source change preserves the existing eager path for direct consumers while moving Telegram draft-stream sanitization to flush-time, and the focused tests cover the lazy ownership seam; however, the repository’s Telegram review policy calls for real Telegram streaming proof, which is not present in the PR body or supplied review context. Priority: P3 Review scores
Verification
How this fits togetherAgent streaming emits cumulative assistant partials through the auto-reply presentation layer to channel callbacks. Telegram’s draft controller coalesces those updates before editing its visible preview message, while direct channels consume a partial as soon as they receive it. flowchart LR
A[Provider streaming partials] --> B[Reply presentation]
B --> C[Classify heartbeat and silent tokens]
C --> D[Lazy sanitized partial payload]
D --> E[Direct channel consumer]
D --> F[Telegram draft throttle]
E --> G[Immediate channel update]
F --> H[Flush newest preview edit]
Decision needed
Why: The patch is source-consistent and test-covered, but the applicable Telegram policy explicitly prefers real streaming proof and the available PR evidence contains only test and CI claims. Before merge
Agent review detailsSecurityNone. PR surfaceSource +104, Tests +419. Total +523 across 12 files. View PR surface stats
Review metricsNone. Mantis proof suggestionA Telegram Desktop proof would materially validate that deferred materialization preserves visible preview edits and finalization; it complements, rather than replaces, the focused tests. A maintainer can ask Mantis to capture proof by posting this exact PR comment: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single lazy ownership path, add redacted after-fix Telegram streaming evidence for a throttled multi-part reply and finalization, then merge only after the remaining required checks complete. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main sanitizes every streaming partial before invoking the channel callback, while the proposed branch defers that work behind a memoized callback payload for the throttled Telegram consumer. No local execution was performed because this review is read-only. Is this the best way to solve the issue? Yes, conditionally: splitting cheap classification from deferred sanitization keeps direct consumers eager and places coalescing optimization at the Telegram draft-stream owner boundary. A live Telegram proof is the remaining evidence needed to confirm this is the safest implementation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0839f12ccdd4. LabelsLabel changes:
Label justifications:
EvidenceWhat 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
|
|
ClawSweeper rank-up moves handled:
There are no unresolved implementation findings; this is an explicit maintainer acceptance of test-only proof for the unavailable live-proof lane. |
|
Merged via squash.
|
…delta after a preview is visible (#171417) * fix(reply): stop re-sanitizing streamed Telegram replies on every delta #118349 made partial reply text a lazy getter so Telegram sanitizes it only when its draft stream flushes a preview. The visible-partial checks from #117603 read that text after every visible partial, which runs sanitizeUserFacingText over the whole cumulative reply on every model delta once a preview is visible (progress mode after any tool call, and partial mode). The checks only set a flag that never resets and that only failure handling reads, so stop reading once it is set. Both checks need this: the getter is memoized per payload, so either one reading it runs the sanitizer. On the Telegram dispatch path a 24k-character reply drops from about 1.0 s to 0.1 s of Gateway CPU, and from about 48 s to 1 s when a line starts with a Markdown link; Telegram sends are unchanged. * test(reply): bound lazy preview sanitization regressions Extend the Telegram-style visibility regressions to hundreds of deltas, including initially hidden or sanitizer-empty content and entity/markup boundaries. Preserve canonical whole-snapshot sanitization at consumption and the existing terminal failure recovery contract. Remove a duplicate comment without expanding production code. Original fix by @boeingchoco for #171416. Co-authored-by: boeingchoco <[email protected]> * test(reply): prepare session facts for recovery authorization CI exposed a recovery fixture calling the synchronous authorization consumer without preparing its session facts. Use the existing async owner and release the retained authorization after the test. Preserve the live authority assertion and every recovery assertion. --------- Co-authored-by: boeingchoco <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
…delta after a preview is visible (openclaw#171417) * fix(reply): stop re-sanitizing streamed Telegram replies on every delta openclaw#118349 made partial reply text a lazy getter so Telegram sanitizes it only when its draft stream flushes a preview. The visible-partial checks from openclaw#117603 read that text after every visible partial, which runs sanitizeUserFacingText over the whole cumulative reply on every model delta once a preview is visible (progress mode after any tool call, and partial mode). The checks only set a flag that never resets and that only failure handling reads, so stop reading once it is set. Both checks need this: the getter is memoized per payload, so either one reading it runs the sanitizer. On the Telegram dispatch path a 24k-character reply drops from about 1.0 s to 0.1 s of Gateway CPU, and from about 48 s to 1 s when a line starts with a Markdown link; Telegram sends are unchanged. * test(reply): bound lazy preview sanitization regressions Extend the Telegram-style visibility regressions to hundreds of deltas, including initially hidden or sanitizer-empty content and entity/markup boundaries. Preserve canonical whole-snapshot sanitization at consumption and the existing terminal failure recovery contract. Remove a duplicate comment without expanding production code. Original fix by @boeingchoco for openclaw#171416. Co-authored-by: boeingchoco <[email protected]> * test(reply): prepare session facts for recovery authorization CI exposed a recovery fixture calling the synchronous authorization consumer without preparing its session facts. Use the existing async owner and release the retained authorization after the test. Preserve the live authority assertion and every recovery assertion. --------- Co-authored-by: boeingchoco <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Final piece of the #118027 hot-path series (deferred from #118192, see its "Not changed" note). Every streaming partial ran
stripHeartbeatToken+ silent-token checks +sanitizeUserFacingTextover the full cumulative text — even for partials the channel draft throttle never delivers. Draft-streaming channels paid O(turn length) sanitize CPU per token on the gateway main loop.Why This Change Was Made
Sanitize cost now follows consumption instead of emission:
createAgentTurnPresentationsplits eagerclassifyStreamingPartial(silent-expected, heartbeat strip decision, silent-prefix checks — cheap, keeps today's skip semantics at the same point) from deferredsanitizeStreamingText(the expensivesanitizeUserFacingText+ empty→skip rule).PartialReplyPayloadwhosetextis an enumerable memoized getter: first read sanitizes and caches. Direct-delivery channels (MS Teams, Feishu, QQ, QA) read every partial and keep byte-identical behavior and cost; the Telegram draft stream stores the lazy payload and materializes only at flush (updateLazy), paying O(flushes). All four direct consumers already guard falsy text, so the one new observable state (textmaterializing to undefined on rare sanitize-to-empty) is a no-op everywhere.User Impact
No change to delivered channel output (randomized equivalence tests over heartbeat/silent/empty-sanitize/media sequences assert identical delivered edit sequences). Draft-streaming turns stop paying per-token sanitize CPU, removing the last known O(n²)-per-turn pattern from the streaming fanout.
Evidence
Part of the #118027 follow-up track. Siblings landed: #118192, #118207, #118193, #118334.