Repository navigation
perf(agents): avoid duplicate active-computer preparation before turns - #185407
Conversation
|
🦞👀 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. |
|
The subscriber-visible session-start harness is merged in #185389. Use one tooling checkout containing that change against each already-built Gateway revision, with fresh output directories and the same sandbox mode: node --import ./scripts/tsx.mjs scripts/perf/turn-start-phases.ts --entry /path/to/base/dist/entry.js --output .local/session-start-base --port 52000
node --import ./scripts/tsx.mjs scripts/perf/turn-start-phases.ts --entry /path/to/candidate/dist/entry.js --output .local/session-start-candidate --port 52010For sandbox proof, add
|
|
Codex review: needs changes before merge. What this changesThis PR removes duplicate active-computer preparation for embedded turns, adds trace-level prompt timings, and extends performance measurement tooling. Example: An embedded turn prepares context for synthetic-computer.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: the optimization is useful and the earlier logger failure is fixed, but the updated mock now fails the exact-head mock-export ratchet. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherHarness selection dispatches admitted agent turns; prompt preparation combines requester-scoped computer context, tools, memory, and runtime facts into the model request. flowchart TD
A[Admitted agent turn] --> B[Harness selection]
B --> C[Built-in prompt preparation]
B --> D[Plugin context preparation]
C --> E[Current requester computer context]
D --> E
E --> F[Model request]
Technical reviewBest possible solution: Retain the runtime optimization and repair the logger mock through export preservation or justified isolation, pruning its obsolete baseline entry. Do we have a high-confidence way to reproduce the issue? Source confirms duplicate preparation on main, and exact-head CI plus the fingerprinting implementation establish the changed-mock failure; no target code was executed during review. Is this the best way to solve the issue? Skipping the redundant built-in refresh uses the existing consuming owner without caching, while trace-only timing avoids unconditional instrumentation cost. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2eeec18db4c5. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +114, Tests -41, Docs +8, Other +447. Total +528 across 9 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
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 HistoryReview history (1 earlier review cycle)
Reviewed October 27, 2026, 12:29 AM ET / 04:29 UTC (Revision 2). |
b158a2d to
970c8f5
Compare
|
Addressed both items on @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Avoid the duplicate early refresh for the embedded harness while preserving plugin harness preparation and live authority checks. Add trace-level system-prompt subphases and rich-history turn-start measurement with MCP catalog verification.
970c8f5 to
82ee077
Compare
|
Resolved the remaining mock-export finding on @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
openclaw#185407) * perf(agents): prepare active computer context at its consuming boundary Avoid the duplicate early refresh for the embedded harness while preserving plugin harness preparation and live authority checks. Add trace-level system-prompt subphases and rich-history turn-start measurement with MCP catalog verification. * test(agents): complete the prompt preparation logger fixture * test(agents): remove unused prompt preparation logger mock
What Problem This Solves
Embedded agent turns refresh active-computer pairing context twice before the first model request, and slow system-prompt preparation lacks a useful subphase breakdown.
User Impact
Normal embedded turns do one less pairing refresh. Plugin harnesses retain their preparation boundary, and current-binding and admitted-run checks remain in place. Prompt construction order and bytes are preserved. Detailed system-prompt timings are available at the existing trace log level; no new configuration option or migration is required.
Why This Change Was Made
Prompt assembly already refreshes active-computer context immediately before consuming it. The earlier harness-selection refresh is redundant only for the built-in harness. This removes that duplicate work without adding a cache or weakening authorization.
The requested diagnostic detail is gated on trace logging: a separate incremental model showed that unconditional subphase bookkeeping would cost more than this small saving. The existing turn-start harness now supports 100 historical tool-call turns, two MCP servers with 40 tools each, and memory-core among 40 plugins. It verifies the history at the provider boundary and all 80 consumed MCP catalog entries. Usage is in the scripts' headers.
The setup audit found a dependency chain: tool-base feeds bundle/MCP preparation, bundle tools feed the policy/catalog, catalog capabilities and bootstrap feed the system prompt, and prepared tools/prompt plus the transcript lifecycle lock feed session runtime. Catalog registration has owned cleanup and permission refresh changes its facts. Bootstrap/bundle and some prompt reads may permit overlap, but the measured whole prompt was only 2.67 ms p50; this change does not introduce parallel failure/drain machinery without an expensive overlap to justify it. Auth publication, skill hydration, and transcript/session-manager changes remain with their owning lanes.
Evidence
The call-count regression failed on the baseline (built-in outer refresh expected 0, observed 1; plugin case passed), then passed with the change. Independent subagent review (autoreview route unavailable) is clean after addressing the measurement-harness findings. The configured autoreview route was rejected by its operator-config check; no operator configuration was changed.
The owner-work model uses a real synthetic 64-device pairing store, 2,000 operations per arm, AB/BA order, and separate untraced timing and allocation passes. It is not a full-turn benchmark. Two refreshes versus one reduced mean main-thread CPU from 15.61 to 8.32 µs/op and sampled allocation from 10,986 to 5,500 B/op. Both timing pairs had zero GC. A separate incremental model including the default-level trace guard retained the saving: 15.85 to 9.89 µs/op, 16,818 to 11,513 B/op. This is a small improvement, not an explanation for multi-second startup stalls.
Isolated Gateway phase distributions
Built dist baseline
a7fe06b17a966a1a1a518f805f85c7cbfaf9fee5with timing-only instrumentation versus the same source plus the refresh deletion. Both ran at trace level, where the final diagnostic gate leaves the measured instrumentation enabled. Each arm used 10,800 retained synthetic sessions, 40 plugins, 65 WebSockets, four concurrent mock-provider turns with real tool execution, sidebar/list/search churn, one warmup, and 40 measured warm turns. All 44 provider-history checks per arm and all four sessions' 80-tool catalog checks passed.These sequential loaded-host runs are descriptive, not a causal estimate of whole-Gateway speedup. One-minute host load was 90.7→75.1 for baseline and 48.1→46.5 for candidate. The baseline fixture was reused after setup/proof-harness failures; the candidate used fresh equivalent inventory. No production Gateway was touched. The bounded duplicate-work fast-path protocol was used instead of a ten-minute multipair stress campaign. Memory-core was active, but search/embeddings were disabled; no active computer was attached to the Gateway fixture. Allocation was measured at the owner, not as a whole-Gateway rate.
Each phase has 40 observations; p95 is descriptive below 200 samples. Nested phases overlap and cannot be summed. ACK timing pairs receipt timestamps for each turn, rather than subtracting percentiles; it is not a server ACK-sent/provider-write measurement. The warm p50 <1 s target remains unmet. Session/runtime, skill hydration, and loaded-host scheduling remain the large residual costs; this PR does not parallelize dependent preparation or modify their owners.
CPU occupancy reflects different throughput and polling work; RSS/heap are not retained-memory claims. Candidate list p99 and both major-GC distributions lack gate-sized samples. No adverse conclusion or large whole-Gateway speedup is claimed from these unequal-load arms.
Focused validation: 131 tests across harness selection, runtime prompt, attempt system prompt, and prompt-prefix stability; 29 closure tests; export-name collision guard; changed-file lint/format;
git diff --check. The context-test extraction and trace gate were rechecked with their affected tests. No Testbox lease was used. PR CI supplies broad validation.Production growth is the requested trace-only attribution and preservation of the plugin harness contract; no parallel fast path or cache was introduced. The oversized harness test file shrinks by moving its related context cases into a sibling module. Runtime source is +23 net lines: +3 preserve the separate plugin-harness preparation contract and +20 provide the requested trace-only phase attribution. The remainder is reproducible measurement tooling, documentation, and tests. The final integration onto
e5aa4489f728preserves the subscriber-visible reporting added by #185389, including its four retained 2,000-entry histories. The table above remains evidence from the earlier matched protocol, before that reporting change; it is not mixed with the integration smoke. The production change is unchanged by the rebase. The later #185368 conflict was only adjacent harness setup blocks; both are retained. A fresh integrated Gateway smoke passed one warm round (four measured turns plus four warmup turns): all eight provider requests replayed the 100-turn history, all four sessions consumed 80 MCP tools, and subscriber assistant/tool receipts were recorded. It used the already-built candidate runtime with the integrated source harness; this validates tooling integration, not a new performance comparison. The 14 turn-start report tests also passed. The first CI run found an incomplete logger mock inattempt-session.test.ts. AddingisEnabledfixed the runtime test failures, then the next CI run correctly rejected that changed partial mock. The final repair removes the unused logger mock entirely and prunes its single grandfathered exception with the canonical mock-export guard; no new baseline exception is added. All 23 tests in the file and the mock-export guard pass locally. The final rebase was conflict-free, and range-diff reports all three commits unchanged.