Repository navigation
perf(agents): reuse assistant and reply payload preparation - #133264
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 6:58 AM ET / 10:58 UTC. ClawSweeper reviewWhat this changesThe PR removes repeated assistant-text extraction and reply-directive parsing in the path from completed model output to channel reply payloads. Merge readinessKeep this member-authored, maintainer-labeled PR open. The reviewed extraction and payload changes preserve the covered phase, media, error, and delivery branches, but the required direct Codex protocol-source audit could not be completed because the sibling checkout is absent; that is a merge-decision gap, not a contributor defect. Priority: P3 Review scores
Verification
How this fits togetherEmbedded-agent output is separated into commentary, final text, thinking, errors, and media before channel delivery. The changed utilities select visible text and prepare the final reply payload used by terminal completion and streaming subscribers. flowchart LR
A[Provider response] --> B[Assistant text extraction]
B --> C[Phase selection]
C --> D[Reply payload preparation]
D --> E[Terminal delivery]
C --> F[Streaming subscribers]
D --> G[Media and error handling]
Decision needed
Why: The PR’s claimed compatibility depends on native Codex phase and reasoning semantics, while the required sibling checkout was unavailable to this read-only review. Before merge
Agent review detailsSecurityNone. PR surfaceSource -87, Tests +1. Total -86 across 10 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Before merge, inspect the exact native Codex protocol types for phase-bearing text and reasoning items, then retain this net-reducing canonical preparation path only if those contracts match the reviewed final/commentary behavior. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is a behavior-preserving performance refactor, not a report of a reproducible defect. Existing focused tests define the relevant phase and payload behavior, but no code was executed in this read-only review. Is this the best way to solve the issue? Unclear: the reviewed code simplifies the existing owner without an identified semantic regression, but direct Codex protocol-source verification is still required for the stated compatibility claim. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8e1cda9854ad. LabelsLabel 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
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
Block: inline raw-answer resolver in run/payloads.ts (drift residue). Home: restored to upstream (drift residue). Upstream moved resolveRawAssistantAnswerText into its owner src/shared/assistant-answer-text.ts (0863f26 openclaw#150539, then 06e6c06 openclaw#148360). Our payloads.ts kept a private copy (isAssistantTextContentBlockType, readAssistantTextContentBlock, sanitizeCanonicalAssistantItemText, resolveRawAssistantAnswerParts). It also kept assistantTextsHaveMedia / normalizedRawAnswerText and a redundant !assistantTextsHaveMedia guard that 162c33e (openclaw#133264) removed. Restore upstream's import and media-comparison bytes. The continuation need (one raw part per final-answer block, optionally keeping item whitespace) moves to the owner as resolveRawAssistantAnswerParts; resolveRawAssistantAnswerText now joins its parts and keeps upstream's output for every input. payloads.ts keeps only rawAnswerHasContinuation, the earlier-continuation per-hop split and preserveTextWhitespace. Refs #1418 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Assistant text extraction projected unphased replies twice, while terminal payload preparation eagerly parsed streamed text, normalized error strings and assembled comparisons that could not affect the selected reply. This repeated work sits between completed provider output and channel delivery.
Why This Change Was Made
Two measured changes simplify the existing owners:
Remove newly orphaned helper-barrel exports and keep the billing copy private to its owner. Existing integration tests use the canonical billing formatter; direct copy tests still assert the literal. No compatibility alias or parallel processing path is added.
Production +110/−197 = net −87; existing tests +16/−15 = net +1, with no test case added or removed. No dependency, config, schema, protocol, authorization or public API change.
Measurements and Tradeoffs
Four complete source compositions were measured in fresh Node 26.8.1 processes with opposite starting orders, balanced warmups and all samples retained. Instrumentation and correctness checks were excluded from timed loops. The combined change improved all 28 terminal-payload workloads in both orders:
Isolated variants show payload preparation supplies most of these gains. Extraction alone improves the complete 64-block native-thinking subscriber workload from 74.365/73.121 to 66.364/67.568 µs. The combined short-final subscriber costs another 0.912/0.752 µs; the 64-block, 100-delta subscriber costs another 12.462/8.132 µs (about 1.2/0.8%). Final-at-last utility controls add 0.188/0.168 µs, and commentary/one-delta results are mixed. These costs are retained and accepted against the broader simplification and terminal preparation gains. No universal, provider/network, whole-turn or memory speedup is claimed.
Contracts and Verification
The final composition is compared against unchanged main with four variants: baseline, extraction only, payload preparation only and both changes. All 73 source/dependency bindings match. Differential proofs cover 11,458 leaf inputs, 708 subscriber scenarios (including 36 with raw diagnostics enabled), 672 payload cases and 55 controls. The separate payload-owner matrix covers 9,655 cases, 28,965 comparisons and 27 controls; these are distinct proof units, not an aggregate canonical-test total. Coverage includes explicit and inherited phases, empty/malformed final blocks, signed text, in-place transport mutation, complete subscriber events, canonical finals, media directives, streamed text, stored delivery/TTS, billing/provider errors, timeouts, aborts and suppression metadata. Output bytes and relevant object identity remain unchanged.
All 1,236 canonical tests across 48 files pass. The complete changed-file gate passes types, lint, import boundaries, dead exports and all other guards in 211.50 seconds. The initial gate exposed orphaned exports; removing them revealed four downstream test imports, which were migrated and rerun. Both failed receipts are retained. Fresh automated Codex review across P0–P3 and independent complete-owner review are clean.
The lead personally inspected the native Codex contracts in
codex-rs/protocol/src/models.rsandcodex-rs/protocol/src/protocol.rsin the sibling Codex checkout, alongside the OpenClaw extraction, subscriber and terminal owners. Optional message phases and separate reasoning/signature ownership remain unchanged. This is not a claim of live native Codex execution.This is an internal performance refactor. Release-note context is recorded here; the release workflow owns the changelog. The separately recorded pre-existing literal-final-tag delivery defect remains outside this semantics-preserving scope.
At the published head
2c4ad2593df2f46f593900a95b72d9ea66700bc9, a fresh build passed in 155.92 seconds and another P0–P3 automated review is clean. An isolated real OpenAI Gateway completed three turns and two actualweb_fetchcalls, passing 51 assertions over 18 RPCs. The new-connection reader recovered in-flight tool progress; final conversation/history/list/status and cleanup checks passed. Raw diagnostics were enabled, with 93 records correlated to the three exact run IDs, including text, thinking and terminal events. The owned Gateway stopped cleanly and both Node CPU profiles were retained. These are behavior proofs, not controlled network-latency measurements. Exact-head hosted CI remains the final landing gate.Landing Review
The completed ClawSweeper review found no introduced correctness or security defect. Its rank-up request for direct native-contract inspection is addressed: the lead personally inspected the sibling Codex checkout at
6478a751fde8884b2fdc76486fe23175a8e795d4, includingcodex-rs/protocol/src/models.rs:850–1060(text content, optional message phase, and separate reasoning summary/encrypted content),codex-rs/protocol/src/protocol.rs:2448–2538(message/reasoning events), andcodex-rs/app-server-protocol/src/protocol/v2/item.rs:249–253,878–900(app-server message projection). Absent phases remain unknown and retain the existing fallback.OpenClaw's
textSignatureencoding is its own unchanged transport representation, not a new native Codex field. The lead also checkedsrc/shared/chat-message-content.ts:26–80, the complete Codex conversation collector and assistant-message projector: native commentary filtering, unphased persisted narration and signed reasoning replay ownership remain unchanged. This direct source inspection resolves the review worker's missing-checkout limitation; it is not a claim of human review or live native Codex execution. The remaining rank-up request is completed exact-head CI; a queued review refresh does not replace that gate.Exact-head CI run 33307266738 is now green. The long-running compact-small-35 shard passed without a retry. Both rank-up requests are addressed, and no accepted actionable finding remains. The final source review, 1,236 tests, full changed-file gate, build and real Gateway proof all cover the published head.