Repository navigation
perf(agents): avoid repeated turn and tool preparation - #133184
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 4:14 AM ET / 08:14 UTC. ClawSweeper reviewWhat this changesThe PR avoids unused historical-media projection, indexes transcript contexts for matching, and removes an intermediate tool-schema wrapper during agent-turn preparation. Merge readinessNo introduced correctness or security defect was found in the reviewed agent-preparation paths. This member-authored, maintainer-labelled performance PR remains for ordinary maintainer review once exact-head checks complete. Priority: P3 Review scores
Verification
How this fits togetherBefore a model request, OpenClaw normalizes prior messages, restores needed transcript context, and prepares the authorized tool set. These changes reduce work at that boundary while retaining the prepared model input and tool behavior. flowchart LR
A[Stored messages] --> B[Transcript context matching]
C[Media attachments] --> D[Historical media projection]
B --> E[Prepared agent turn]
D --> E
F[Authorized tools] --> G[Schema normalization]
G --> E
E --> H[Model request]
Decision needed
Why: The PR has a protected maintainer label and its author is a repository member, so automated cleanup must not close or merge it. Before merge
Agent review detailsSecurityNone. PR surfaceSource +21, Other 0. Total +21 across 4 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single canonical preparation path, preserve its existing boundary contracts, and complete normal maintainer review after the current head’s checks finish. Do we have a high-confidence way to reproduce the issue? Not applicable: the PR is a performance cleanup, not a report of broken existing behavior. Source inspection establishes the affected preparation paths and their existing behavioral coverage. Is this the best way to solve the issue? Yes: the change removes repeated work at the preparation owners while keeping the existing transcript projection and metadata-copy seams intact. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8f71fb28ed5a. 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.
|
What Problem This Solves
Turn preparation repeats work whose results are already available or never consumed. Historical captioned media is normalized and projected even though its caption wins. Transcript context matching repeatedly copies and scans the remaining context set. Schema normalization creates an intermediate tool wrapper that is immediately spread into another wrapper.
Why This Change Was Made
No persistent cache, provider policy, prompt format, runtime config, protocol, or storage change. The assertion-safety baseline decreases after removing redundant timestamp casts; it is tooling metadata, not a runtime configuration change.
Production +57/−36, net +21: context ownership/indexing +29, lazy media projection +2, wrapper deletion −10. Tooling baseline +1/−1. No new tests duplicate the existing behavior suites; existing tests plus complete-owner differential probes cover the changed paths.
Evidence
Two fresh Node 26.8.1 processes with opposite starting orders, uninstrumented runtime owners, paired samples, exact output checks, and retained source hashes:
The blank-media control is effectively unchanged. Isolated lookup-only one-clone work regresses by 0.06–0.13 µs, and isolated blank-media-only work by 5.3–11.1 µs; the complete measured boundary compositions improve. These are preparation measurements, not provider/network latency or memory claims.
Operation witnesses: 1,000 messages/32 cloned contexts reduce 32,000 identity comparisons, 31,008 structural comparisons, and 2,000 Set-to-array copies to 1,000 identity lookups, 32 structural comparisons, and no Set copies. Captioned-media normalization and unused marker projection drop from 100 each to zero. The optional tool path removes one intermediate object allocation and spread.
Correctness evidence includes 3,203 complete-boundary cases across seven compositions, 815 identity cases, and 864 argument comparisons across 108 schema/provider/preparer combinations. Output bytes, object/content identity, nonmutation, duplicate-context ordering, active-turn overrides, original preparer receiver, and action metadata remain covered. Other metadata families continue through the unchanged canonical copy helper and existing tests.
119 tests across four boundary/cache-stability/context-registry/schema suites pass, including a fresh run after rebasing onto merged main (21.39 seconds wall time). The complete changed-file gate passed core and test types, lint, assertion/boundary/import/dead-export guards. Initial assertion-ratchet failures were corrected by deleting unnecessary casts and lowering the baseline, not suppressing the guard. Independent source review and fresh complete automated Codex review reported no accepted findings at the configured P0 threshold. The rebase preserves the exact patch apart from Git blob-index lines.
At head
1cb67e30521b5805edc1f530f9e5f282df166d81, a fresh build passed in 166.56 seconds. An isolated real-OpenAI Gateway completed nine turns: seven in one conversation, including web fetch, plus session listing and native web search. Tool and terminal receipts passed, as did 30 assertions across 14 read-only RPCs, including unchanged baseline titles/previews, tool inventories, and model catalog. CPU profiles were retained and the task Gateway stopped cleanly. Live history was text and web-tool history; historical-media variants are proved by the complete-owner probes and canonical boundary suites. Live timings are observational.Landing Review
Exact-head CI run 33300641780 is green at
1cb67e30521b5805edc1f530f9e5f282df166d81. The latest ClawSweeper review found no actionable code defect; its rank-up move was to finish the remaining exact-head checks, now satisfied. Maintainer landing review accepts the scoped indexing/lazy-projection tradeoff and the disclosed small isolated controls. The independent owner reviews, full changed-file checks, fresh automated review, build and live Gateway evidence above are complete.