Repository navigation
refactor(agents): reduce per-turn policy and tool preparation - #134246
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 1:20 PM ET / 17:20 UTC. ClawSweeper reviewWhat this changesThis PR removes repeated per-turn policy, tool, model, schema, and session-copy preparation while preserving existing Gateway session checks and Codex dynamic-tool behavior. Merge readinessKeep open for maintainer review. No concrete introduced defect was found in the inspected owner paths, but the native Codex environment-selection contract could not be independently checked because the required sibling Priority: P3 Review scores
Verification
How this fits togetherGateway chat admission prepares a session, model, and tool surface before the provider turn begins, then reply dispatch rechecks session ownership before writing transcripts. The Codex plugin converts those prepared facts into app-server dynamic tools. flowchart LR
A[Incoming chat turn] --> B[Gateway admission]
B --> C[Session and model preparation]
C --> D[Codex dynamic tools]
D --> E[Provider turn]
E --> F[Reply dispatch and transcript]
C --> G[Session ownership rechecks]
Decision needed
Why: The changed native execution gate directly depends on Codex app-server behavior, and repository policy requires the acting reviewer to inspect that source personally. Before merge
Agent review detailsSecurityNone. PR surfaceSource -114, Tests +148. Total +34 across 20 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single prepared policy flow, but complete an exact-head review in an environment containing the required Codex checkout and verify that explicit empty environments still suppress native shell and filesystem tools. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a performance refactor, not a report of broken existing behavior. The supplied PR body describes real Gateway runs, but this read-only review did not execute them. Is this the best way to solve the issue? Unclear until the direct Codex contract check is complete. The inspected OpenClaw changes keep the policy fact local to a tool build and retain later session rereads, which is the appropriate owner-boundary shape. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ce097a1497c9. 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
History |
|
Completed the direct Codex source check requested by the review and its rank-up move. I personally inspected the clean sibling checkout at the publicly available Codex commit 94cbbddafc17:
The reused fact is scoped to one The stored-data alert for |
|
Final candidate: f759357. Production is unchanged from the integrated runtime tested at e711f55.
The PR body reports the measured improvements and negative results. Production remains +202/−316 (net −114); tests +232/−84 (net +148). The exact-reader alternative was removed because private history and provisioning/validation contracts differ. Existing borrowed reads preserve those contracts and the post-await fence. No end-to-end speedup is claimed. CI recovery: a later draft-state run canceled the ready-state CI and skipped its own jobs; the ready-state run was rerun on the original candidate commit. Dependency detection also returned a GitHub API 500 and its failed job was rerun. No gates were bypassed. Follow-up: examine the draft/ready event ordering in CI concurrency separately from this runtime refactor. CI also exposed a stale timeout-fixture cleanup assertion requiring The test-only follow-up also passed Landing-tooling follow-up: temporary materialization of the current-main wrapper omitted Read the refreshed ClawSweeper review for exact head CI also exposed two fixed wall-clock performance limits on a loaded runner. Replaced them with deterministic parser-work budgets; all 197 cases passed with their original fixture/output checks. Mutation probes demonstrate the regression guards: preceding-prefix slices rise from 2 to 600 without cached trust, and whole-prefix reasoning reparsing breaches its input budget after 938 bytes. Changed-code gates completed after type/lint corrections; final complete-candidate autoreview is clean at P0 (0.96). No production parser code changed or timeouts increased. Exact-head hosted CI is now complete and green for |
|
Merged via squash.
|
…aw#134246) * perf(agents): reduce repeated turn preparation * test(agents): keep timeout proof independent of auth discovery * test(parsers): measure prefix work without wall-clock limits
What Problem This Solves
Warm chat turns repeat policy and authentication discovery, build coding tools that are immediately discarded, traverse tool schemas more than necessary, and deep-copy unrelated session entries during admission and transcript handling. This adds preparation work before the model can respond, especially with larger session stores.
Why This Change Was Made
Reuse the native execution policy within each Codex tool build, resolve absent-search policy only when its persistent-policy callback needs it, and consume prepared model/auth facts before discovering them again. Remove discarded coding-tool construction and redundant factory forwarding, and combine schema validation traversal while preserving numeric-overflow diagnostics.
Admission and transcript consumers use the existing borrowed-read option. Initial session resolution still owns detached entries; all later lookups and post-await session fences remain. This keeps listing visibility, private exact history, provisioning, validation, and lifecycle behavior unchanged. The rebase preserves main's separate policy/execution agent identities and catalog-pricing precedence. No new configuration, dependencies, caches, or storage/schema changes.
Related: #133782, #133184. These earlier preparation improvements cover different work.
User Impact
Less repeated per-turn work and 114 fewer production lines (+202/−316). Tests: +232/−84, net +148. Existing tools, policy decisions, session history, and model selection retain their behavior.
The first matched live experiment reduced median preparation from 115.71 to 96.55 ms (16.6%), but did not improve complete-reply latency or aggregate CPU. The additional session-copy change reduced isolated 1,000-row lookup time from 8.613 to 0.835 ms and fixture-row copies across two live turns from 14,000 to 8,000. It did not establish another live latency improvement: small-store preparation stayed near 95.9 ms; with 1,000 retained fixtures, median preparation was 187.09→191.76 ms and complete reply 1,390.55→1,492.55 ms. The candidate's 782.79 ms preparation outlier is included. These serial shared-machine measurements do not establish an end-to-end speedup, and the two comparisons must not be added together.
Evidence
openai/gpt-5.6-luna, low reasoning, fast mode off. Matched stopped-state snapshots, persistent WebSocket client, fresh process per workload, warmups, CPU profiles, and separate copy/allocation instrumentation. First pass: 152 comparison turns (104 measured); session-copy continuation: 144 turns (96 measured). All measured replies matched the expected response. Plain reply, file-read, and session-status tool smoke passed.node scripts/run-vitest.mjsand those focused files.codex-rs/app-server/src/request_processors/turn_processor.rs(turn admission),codex-rs/core/src/client.rs(WebSocket lifetime), and app-server protocol thread start/resume contracts. No Codex protocol changes.An exact-reader replacement was rejected because private companion history intentionally reads hidden current-session rows and exact access has different provisioning/validation contracts. The retained borrowed mode preserves those contracts. Remaining follow-up: profile other full-store consumers and filesystem-watcher work; full-store enumeration remains in this PR.