Repository navigation
Conversation
Reuse the existing normalized schema before depth traversal and record fixed prompt and bundle preparation phases in slow-chat diagnostics. Preserve prompt/tool bytes and per-run execution authority; include reproducible synthetic workloads and missing-observation/work-count regressions.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR checks the existing schema-normalization cache before depth traversal and exposes prompt and bundled-tool preparation timings without trace logging. Example: An operator investigates a slow chat using 80 MCP tools at info log level.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR provides a useful, maintainer-directed optimization and diagnostic improvement that current main lacks; no actionable correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherEmbedded turn preparation consumes tool schemas, provider options, workspace context, and run facts to produce model-facing tools and prompts, while the request observer collects preparation timings. flowchart LR
A[Chat request] --> B[Embedded preparation]
B --> C[Tool normalization cache]
C --> D[Model tools]
B --> E[System prompt preparation]
E --> F[Model prompt]
B --> G[Request timing observer]
G --> H[Slow chat diagnostics]
Technical reviewBest possible solution: Retain the existing normalization and diagnostic owners, skip depth work on cache hits, and publish fixed preparation phases without changing prompt bytes or execution authority. Do we have a high-confidence way to reproduce the issue? Current main visibly traverses schema depth before consulting its normalization cache and gates prompt phases on trace logging; the PR reports matching red/green regressions, but no target code was executed during this read-only review. Is this the best way to solve the issue? The smallest complete fix is the proposed cache-order change and reuse of the existing timing observer; the benchmark tooling supports measurement without adding a runtime cache, wrapper, or competing owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0a6aaf50f6c5. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +53, Docs +8, Other +769. Total +834 across 10 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed November 2, 2026, 3:32 PM ET / 20:32 UTC. |
|
Merged via squash auto-merge.
|
…penclaw#191437) * perf(agents): avoid repeated schema walks during turn preparation Reuse the existing normalized schema before depth traversal and record fixed prompt and bundle preparation phases in slow-chat diagnostics. Preserve prompt/tool bytes and per-run execution authority; include reproducible synthetic workloads and missing-observation/work-count regressions. * style(perf): satisfy benchmark script lint
What Problem This Solves
Chat turn preparation repeats a schema depth traversal even when normalization already has a prepared result, and slow-chat diagnostics hide system-prompt owner timings unless trace logging is enabled.
User Impact
Repeated tool preparation avoids discarded schema work. Slow chat startup records identify the prompt and MCP/LSP preparation owners without enabling trace logging. Prompt bytes, tool definitions, policy filtering, and per-run execution authority retain their existing contracts.
Why This Change Was Made
Check the existing normalization cache before walking the input schema. A miss still follows the same normalization and depth-bounding path; no new cache or lifecycle is introduced. Publish the existing prompt phases through the request observer and add a fixed set of bundle phases, including failure cleanup.
Workspace bootstrap and skills execute in separate stages. This change does not introduce a session snapshot or reuse executable closures. The workspace manifest revision describes projection synchronization, not every file mutation; workspace snapshot work overlaps #174235.
Evidence
Acceptance rule, recorded before comparison: use the same synthetic fixture with 62,000 workspace files, 64 plugin factories, 100 skills, and a real local MCP server. Compare first-turn and warm wall time, CPU, and sampled allocation in at least five alternating pairs with A/A controls; require exact unchanged prompt and tool bytes, fewer schema traversals, and no unexplained metric regression above 20%. Owner composition is not a full Gateway, Linux/btrfs, or production database benchmark.
Focused owner result (64 MCP tools × 20 nested fields, five alternating process pairs, 7,500 warm bindings/arm): wall p50/p95 1.426/1.452 → 0.0619/0.0735 ms, main CPU 1.4258 → 0.0612 ms/bind, process CPU 1.4875 → 0.0962 ms/bind, sampled allocation 6,065,777 → 153,947 B/bind (separate allocation passes). Tool bytes match exactly. A/A warm wall variation was 1.3%, process CPU 2.5%.
First catalog in each fresh process (n=5/arm): wall 23.693 → 24.165 ms, main CPU 23.718 → 24.208 ms, process CPU 38.334 → 40.121 ms, sampled allocation 51.115 → 50.928 MB. Later repeated fresh-catalog cohorts show a process-CPU median increase 31.338 → 40.121 ms (+28%), with flat main-thread/wall medians; unequal warm-loop duration may shift background compilation into those windows. That explanation is an inference, and the discrepancy is retained rather than called neutral. The subsequent whole-process check includes imports, setup, GC, warmups, verification and shutdown: CPU 12.21 → 2.46 s, wall 11.16 → 1.46 s, peak RSS 258.75 → 248.55 MB for 7,500 bindings. This supports reduced total work rather than moving it outside the owner timer.
The composed fixture uses 62,000 synthetic files (1.21 GB), 64 native plugin factories, 100 skills, 80 real stdio MCP tools, 5,002 session records and two 1,000-message histories. Five counterbalanced pairs with 100 warm observations per cohort/arm, plus A/A and separate allocation passes:
First host prompt wall p50/p95 74.13/357.62 → 73.71/75.84 ms; first bundle 1095.18/2539.10 → 1145.55/1183.91 ms, including real MCP initialization. First host prompt/bundle main CPU 39.57/180.91 → 40.86/194.29 ms. Sandbox session-first prompt/bundle wall 2.366/927.55 → 2.448/993.06 ms, sharing already-warm process imports; main CPU 2.336/29.52 → 2.434/31.36 ms. Cold allocation holds (host bundle 159.17 → 158.55 MB, prompt 27.93 → 28.05 MB). Exact prompt and tool bytes match all 924 campaign attempts and 84 diagnostic attempts.
Total five-owner warm wall p50/p95: host 28.686/38.731 → 27.397/35.376 ms, sandbox 28.220/63.264 → 28.052/31.522 ms. Total process CPU is flat (69.918 → 69.377 ms host, 68.758 → 69.393 ms sandbox). A/A total wall p50/p95: host 31.590/35.055 → 28.292/31.504 ms, sandbox 31.929/33.605 → 28.893/38.478 ms.
The first candidate pair has worse total p95 (host 30.55 → 37.37 ms, sandbox 28.31 → 50.15 ms), including 16–17 ms bootstrap CPU spikes; these samples remain in all aggregates. Later pairs and bounded unchanged-script CPU/GC diagnostics did not reproduce those spikes. Their cause remains unknown; neither GC nor scheduler noise is claimed as established. The aggregate first/warm latency and total-work measurements meet the performance rule; the individual adverse pair remains an unresolved limitation. This is a narrow optimization, not a universal per-pair win. Per-phase process CPU can include concurrent worker work and is not exclusive owner attribution.
Reproduce composition with
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/turn-preparation-measure.mjs --root <same-owned-absolute-path> --files 62000 --plugins 64 --sessions 5000 --history 1000 --iterations 20 --keep; add--allocationin separate runs. This source-runtime owner benchmark forces GC between turns and does not run inference or a full Gateway. The synthetic database is 16.77 MB. Sandbox commands are disabled; memory plugins, active-project memory, watches, subagent registry and default reference discovery are not exercised. The reported long production prompt tail was not reproduced: attribution is the deliverable for that remaining unknown.CPU profiles locate the removed work under
truncateToolSchemaDepth: 9,472.8 → 35.0 ms sampled in 7,500 bindings; candidate retains depth preparation on misses. Reproduction:node --expose-gc --import ./scripts/tsx.mjs scripts/perf/mcp-tool-materialization-measure.ts candidate timing 300; run the same committed script against the pinned baseline with its documented source override. Allocation usesallocation 100separately.Validation: regressions fail before the fixes and pass afterward; 45 preparation/diagnostic/prefix-stability tests, 35 normalization tests, five existing skill/plugin invalidation cases, 27 UI tools browser tests, and nine bundled chat messaging E2E tests passed. Codex autoreview against
b8ed94ff73d6, P0–P2, was scoped-clean with no actionable findings. The final prefix suite was rerun after the schema reorder (14 passed).pnpm check:changed --base b8ed94ff73d6completed: 35 gates passed; benchmark type/lint defects were corrected and both failed gates now pass on focused rerun. The sole remaining local red is inherited: unusedbuildRequestBodyinopenai-chatgpt-responses-request.ts, reproduced with zero dependency-resolution errors on exact parentb8ed94ff73d6d10a2e0bbae56cbe6c68f72064c1. It was introduced by1c03d49956ed(#191261) and is already repaired on main by7a96bac8ed5e. No gate was skipped or relabeled green.Production LOC: 0 for the optimization, +4 for attribution. The 53 test-line allocation covers the missing-observation and repeated-work regressions. No schema, configuration, dependency, or executable-lifetime changes.