Repository navigation
perf(reply): overlap first-message diff capture - #169592
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: needs real behavior proof before merge. What this changesThis PR overlaps first-message workspace baseline capture with model preparation and moves capture waits to execution boundaries. Example: Start a first built-in reply in the supplied 2,000-file Gateway fixture.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 6 items remain This PR is a worthwhile maintainer-authored optimization, but async provider preparation still bypasses the attribution barrier; the prior hook and native-transcript findings are resolved. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherReply initialization starts the existing session baseline owner, then carries its completion through queued turns, tools, hooks, sandbox preparation, and native or CLI dispatch so session diffs exclude pre-existing changes. flowchart TD
A[First session message] --> B[Reply initialization]
B --> C[Session baseline capture]
B --> D[Model preparation]
D --> E[Tools hooks and runtime dispatch]
C --> E
C --> F[Session diff filtering]
E --> G[Reply settlement]
Technical reviewBest possible solution: Keep one capture owner and permit overlap only after every workspace-capable callback, including async provider preparation, joins its completion. Do we have a high-confidence way to reproduce the issue? Source establishes the provider-callback bypass: a first local operator turn with pending capture and dynamic model preparation reaches the async provider callback before any capture wait; no reproduction was executed. Is this the best way to solve the issue? Moving waits to effect owners is reasonable, but the implementation must also cover async provider preparation to preserve the existing session-diff contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 84482abc0448. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: shipped entry point. SecurityNeeds attention: The hook authority changes strengthen checks, but retained-capability rejection still needs proof at the guarded network effect. EvidenceWhat I checked:
PR surfaceSource +189, Tests +988. Total +1177 across 47 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel 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 (4 earlier review cycles)
Reviewed October 12, 2026, 6:07 AM ET / 10:07 UTC (Revision 5). |
59a2d6e to
fc0b399
Compare
|
Start the existing capture alongside reply initialization and model preparation, and keep attribution ahead of native, bound, inline, queued, and CLI effects. Preserve current session metadata when the capture settles. Synthetic Gateway proof: one-way initialization 304 ms to 128 ms; 20-way first-model p95 5901 ms to 5504 ms. Full current-base validation follows rebase over the inherited reactive UI type failure.
Move capture startup, pending selection, error handling, and final settlement into the existing reply diff-baseline module. Preserve behavior while keeping get-reply within its existing line allowance.
21c795e to
86e1b14
Compare
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
|
The remaining CI failures were reproduced without this PR on unchanged main
Those inputs are byte-identical between that main parent and CI's tested merge |
* perf(reply): overlap first-message diff baseline capture Start the existing capture alongside reply initialization and model preparation, and keep attribution ahead of native, bound, inline, queued, and CLI effects. Preserve current session metadata when the capture settles. Synthetic Gateway proof: one-way initialization 304 ms to 128 ms; 20-way first-model p95 5901 ms to 5504 ms. Full current-base validation follows rebase over the inherited reactive UI type failure. * refactor(reply): keep diff capture lifecycle in its owner Move capture startup, pending selection, error handling, and final settlement into the existing reply diff-baseline module. Preserve behavior while keeping get-reply within its existing line allowance. * test(reply): omit default deferred type arguments * fix(reply): preserve attribution across execution boundaries * fix(reply): fence attribution-dependent preparation * test(reply): omit redundant deferred type arguments * test(reply): expect closed hook request authority
What Problem This Solves
First-message reply initialization waits for a Git diff baseline even though the model request does not need it. In the synthetic Gateway fixture, this added 176 ms to a 304 ms one-way initialization.
User Impact
Start ordinary model preparation and requests while the session-owned baseline capture runs. Preserve attribution ordering before workspace effects: inline commands and skills, host tools, plugin callbacks, custom context-engine startup, sandbox setup, attachment staging, native harness dispatch, and legacy CLI launch all settle capture before acting.
Why This Change Was Made
Carry the existing capture completion through direct and queued turns. The existing reply baseline owner starts and drains the work; background settlement merges only baseline fields into the current session entry. Later runtime callbacks share the harness-selection barrier. Earlier callbacks and plugin workspace provisioning settle at their existing owners, with live authority rechecked after the wait. Native adapter and relay contracts are unchanged. Capture invalidation aborts the owning attempt rather than becoming a recoverable tool-policy error. The lane controller supplies the existing cancellation/lifecycle/source checks, and retained hook assertions use the existing request scope.
Production delta: +245 / -56 lines, net +189. This growth preserves the existing attribution contract across the execution boundaries after removing the unconditional early wait; it is callback propagation and effect gating, not another capture implementation. The existing
sessions.diffcontract requires that pre-existing dirty files stay excluded while tool, hook, command, and setup writes remain attributable. No new config, schema, dependency, or durable state. Skill-snapshot reuse is omitted because it showed no reliable measured gain.Evidence
Blacksmith Testbox
tbx_01m4pfs9g1feejwthvavh9pe24, profileopenclaw-check, 16 vCPU, Node 24.19.0. Canonicalpnpm openclaw gateway run, loopback synthetic Responses server, 2,000 project files, 128 workspace skills, 513 model entries, 128 sessions, and Code Mode. Each compared revision completed all 21chat.send → agent.waitflows with exactly 21 primary model requests;sessions.diffexcluded the pre-existing dirty file.One-way initialization improves 2.38×; 20-way first-model p95 improves 6.7%. Parent/child spans overlap and must not be summed. P95 is the maximum of 20 samples. Baseline-to-baseline initialization varied materially (671–821 ms average), so the concurrent result is a bounded sample, not a demonstrated 1.5× gain. The <2 s initialization target was already met on this host. Gateway RSS after the wave was 2,314,320 KiB before / 2,300,508 KiB after; no allocation improvement is claimed. Measurements cover the builtin/no-hook flow and predate the attribution-boundary corrections; native/custom callbacks intentionally wait.
Proof
cbx_710eb3813359: 259 focused tests, export-name collision guard, and 20 closure tests passed. Earlier local proof passed 43 inline-command/skill cases, 7 reply-routing cases, and 49 memory-runner cases (overlapping coverage). Earlier AWScbx_19e6ee422c34: full build passed in 4m54s.node scripts/check-changed.mjs --base 477826faf279b74cb8dbf2b2fb440031d6a4cfb5passed all structural checks, production types, and 23 core test-type groups before stopping inagents-sessions. The only errors are TS2532 at lines 41 and 56 of unchangedsrc/config/sessions/session-entry-patch.authority.test.ts. Runningnode scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.agents-sessions.json --incremental --tsBuildInfoFile .local/lane790/baseline-agents-sessions.tsbuildinfoon unchanged base477826faf279b74cb8dbf2b2fb440031d6a4cfb5reproduced both exactly. This PR does not change that fixture or its session-entry owner. Main subsequently fixed those expectations in684874efa1c5; the PR merge CI includes that repair. Broad validation remains with exact-head PR CI.The branch is rebased onto main including the type-suppression inventory fix
64f11ced. Independent review of the complete rebased candidate is clean through P2 (two completed evidence passes). A conflict refresh onto9405010d01e3preserves an identical added/deleted lane patch and main's workspace-readiness owner. The 38 affected reply, tool-preparation, and workspace-readiness tests pass in 96.76 s; focused lint passes. The full clean review and clean incremental test-correction reviews remain applicable. The generated-assets failure is independently reproduced on main run 38232649109, head7ff232960ab65ed8d9498e42362342dbf245dca9, job114755915461: the same ClawRouter, Workboard, and X plugin manifests differ from regenerated bytes. Main fixed that inherited drift ina2af18c6c14f; the required conflict rebase includes the fix. This PR changes none of those manifests or their browser build inputs. Final CI 38233281944, head86e1b14970618fd999450a41bbd2063ad0672bcd: all 88 jobs are terminal. Build artifacts, production types, lint, security, and the affected reply/agent suites passed. The two remaining failing test shards are inherited:run.session-workspace-authority.test.tsfails the operator/managed cases identically on unchanged CI main parent9c5bc4daaf4e(full file: 2 failures, 5 passes, 39.73 s; the same failures also reproduce on rebase parent9405010d01e3), and the two wrapper-inventory cases fail identically on CI main parent9c5bc4daaf4e(10.72 s focused run). The missing wrapper input issrc/sessions/user-turn-transcript.message.ts. These failing inputs are byte-identical between that main parent and tested mergee182736d5dc904d31bbc2a2d51542994915f832a; this PR changes no cron or wrapper-inventory implementation. The automatic CI classifier used the older hourly main run38226928416, so it reports the cron shard as unknown and the newer wrapper failure as new; direct baseline runs on the relevant main revisions establish the inherited classification. No CI was rerun or dispatched to chase green. Landing uses the authorized inherited-failure exception. No new remote leases were created for this continuation. Team was not accessed.