Repository navigation
perf(agents): build session forks only when requested - #182844
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 180f769393
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codex review: needs maintainer review before merge. What this changesThis PR builds session-fork requests from live context or persisted history when requested instead of retaining snapshots during normal turns. Example: Request “Review the parent” for the persisted session agent:research:telegram:direct:fork-transport-parent without a process-local parent snapshot.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored optimization removes eager fork work, repairs the prior findings, and has no remaining actionable defect found in the reviewed diff. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherPlugin fork requests pass through Gateway session-read authorization, reconstruct the model context, and call a guarded provider transport that returns text and usage without executing tools. flowchart TD
A[Plugin fork request] --> B[Session read authority]
B --> C[Live attempt or persisted transcript]
C --> D[Context reconstruction]
D --> E[Guarded provider transport]
E --> F[Text and usage]
Technical reviewBest possible solution: Land the single reconstruction path with its existing authority guards and documented best-effort cache contract. Do we have a high-confidence way to reproduce the issue? Current-main source confirms eager capture on ordinary requests and failure when no snapshot exists; the supplied regression records the persisted-history case failing on its baseline and passing after reconstruction. Is this the best way to solve the issue? Removing the separate snapshot store and reusing live-session, transcript, projection, and provider owners is a coherent complete solution; its weaker cache guarantee is explicitly accepted. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against aea06ddedfbf. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -24, Tests -275, Docs -6, Other -337. Total -642 across 34 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 (1 earlier review cycle)
Reviewed October 24, 2026, 5:31 PM ET / 21:31 UTC (Revision 2). |
180f769 to
d4de242
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d4de242c3f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Rebuild read-only fork requests from live session context or durable history. Remove eager request snapshots, publication copies, and expiry/budget machinery; preserve tool denial, current authority, and pending-call pairing. Existing history can be forked after restart, with best-effort cache reuse for reconstructed context.
d4de242 to
412f17f
Compare
|
Addressed all four review findings on
Focused proof passed: embedded-runtime integration (4), fork transport (19), prompt-prefix stability (11), native WebSocket siblings (12), projection owner (12), cold persisted reconstruction (1), and import/source closure (22). Image-policy SDK coverage and the expanded scoped typecheck also passed. Independent subagent review (autoreview route unavailable) is clean. The PR body records paired CPU/allocation/GC measurements and the limits of the retention and mock-provider cache evidence. The final-head failed shard contains only the two inherited plugin-lifecycle assertions documented in the PR: @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Remove ordinary-turn fork capture, snapshot retention, expiry timers, and publication copies. Build tool-free fork requests from current live context or the persisted transcript only when requested, preserving current session authority, tool-result projections, image policy, history limits, and pending-call pairing. Sessions with history can fork after cleanup or restart without first sending another normal message. Reconstructed forks omit parent cache identity; cache reuse remains best effort when transient request preparation cannot be reproduced. Release-note context and paired performance evidence are recorded in PR openclaw#182844.
What Problem This Solves
Every normal embedded model request paid to prepare and retain a replay snapshot for an optional session fork, even when no caller ever forked the session.
User Impact
forkSessionnow prepares its request only when called. Existing sessions can be forked after runtime cleanup or restart, including compacted history, without first sending another normal message. Forks still return text and usage, cannot execute tools, and remain bound to current session/model authority.Why This Change Was Made
The active session and persisted transcript already own conversation history. Forks borrow the current live context or reconstruct the transcript's model view, hydrate its pinned prompt/tool checkpoint through the existing worker, and use the normal provider payload builders. This removes request capture, publication copies, expiry timers, and the separate snapshot budget/store rather than adding an opt-in capture path or plugin contract.
Stored continuation remains a possible optimization for qualifying completed OpenAI Responses requests. The current continuation owner claims parent state and is process-local; ChatGPT uses connection-scoped continuation with
store:false, while other providers and restarted sessions still need reconstruction. This change uses one complete reconstruction path. The actual production endpoint/store setting was not inspected, and stored continuation was not benchmarked against reconstruction.Unchanged native Responses prefixes, tool schemas, and instructions remain identical in the integration proof. All reconstructed forks, including live forks, omit parent cache identity because they do not share the complete one-shot request preparation. Completed forks honor the configured channel history window. Cache reuse is best effort elsewhere: older routes without a prompt pin rebuild their configured/bootstrap instructions, and transient hook additions or explicit run-only cache keys cannot be recovered after completion. Parent one-shot hooks are never rerun. Current credentials, proxy/TLS policy, pending-call pairing, and hosted/local tool denial remain enforced. Forks replay already-admitted tool-result projections without changing parent pruning state, including durable pre-compaction checkpoints and branch/reset boundaries. Normal turns and forks share one image-policy converter; blocked inline and deferred images cannot reach the provider.
Runtime production LOC: −24. The requested production diff excluding tests, test-support files, and
docs/*is −362, including removal/update of obsolete benchmark machinery. Test code is −275 LOC.Evidence
42f68fade98da4f30f56a182a3392700f62ef2d5fails the persisted-history case with the original missing-parent-snapshot error. The history-window assertion separately failed on the initial PR head before its repair.pnpm tsgo:core, and the expanded typecheck scoped to the seven affected fork/image/projection test files passed.Mock-provider cache-read usage proves usage forwarding alongside exact wire-prefix assertions; this is not live provider billing/cache-effectiveness evidence.
Inherited CI Evidence
Both unrelated plugin lifecycle assertions expect
restartRequired: falseafter a bundled-plugin reload, while the owner changed in #182403 returnstrue.src/gateway/server-plugins.lifecycle.channels.test.ts:405, “hands off webhook accounts…”: identical assertion in scheduled main CI at28d61de4e4d1870d6f2765282eabaaa71f317ec4.src/gateway/server-plugins.lifecycle.test.ts:459, “keeps Gateway available after timeout cleanup refuses replacement”: reproduced against exact main source4d49d348a5c21381bdca622d053faa3b4f98e3b4withnode scripts/run-vitest.mjs src/gateway/server-plugins.lifecycle.test.ts --maxWorkers=1(3 passed, 1 failed, same false→true assertion, 57.14s). The lane patch was temporarily reversed and restored with byte-for-byte verification; no unrelated source was changed.Measurement Protocol
Two concurrent, CPU-swapped pairs completed under the shared guard on the isolated Linux sandbox. The committed workload runs 27,000 ordinary requests over 200 synthetic sessions with 256 KiB prepared inputs and 75% continuation suffixes, using the actual stream-selection/capture/request-encoding owners. This is a fixed-count owner workload, not a production Gateway or elapsed-hour soak.
Count, untraced timing/GC/loop, collected-object allocation, and forced-GC retention passes are separate. Concurrent pairs swap interleaved CPUs with synchronized warm/measurement starts and the shared production guard. Acceptance is zero fork-specific capture/publication/expiry work, identical parent request counts/encoded bytes, and no material regression under the predeclared absolute GC/loop rules. Retention counters are reported separately because external/ArrayBuffer accounting overlaps.
Each measured side encoded exactly 1,771,857,720 bytes. Measured starts were simultaneous in both timing pairs and within 1 ms in the separate allocation/retention pairs. The 1,000-request count pass reduced fork-capture V8 serializations 2,000 → 0 and expiry timers 1,000 → 0. Remaining JSON/Blob construction is ordinary provider request encoding. No provider network calls or forks occur in this default-turn workload.
The separate forced-GC retention pass removed 50.05 MiB of ArrayBuffer backing storage in both pairs (52,477,322 → 32 bytes). External deltas were 319,744 → 72 bytes. JS heapUsed deltas were −4,250,216 → 232,808 and −4,243,360 → 232,784 bytes, so this does not prove a lower JS heapUsed delta. RSS growth was 384,827,392 → 11,534,336 and 447,549,440 → 3,145,728 bytes; allocator context only. These overlapping counters are not summed.
Untraced per-kind GC (count / total ms / maximum ms):
Loop p95/p99/max was 12.886/14.909/15.630 → 10.297/10.330/10.494 ms in pair 1 and 14.074/22.561/29.835 → 10.379/10.461/10.519 ms in pair 2. Counts were 406/428 baseline and 75/77 candidate, so loop tails are context only. GC pause percentiles likewise lack paired sample counts. No promotion claim is made. No adverse total-GC or maximum-pause gate fired; rejection-control A/A pairs were therefore unnecessary.
The 27,000-request sequence equals an hour only at the chosen 450 requests/minute. It is not an elapsed-hour Gateway soak, a verified production route census, or whole-Gateway CPU/cache billing evidence. The sandbox was removed after results were collected. One initial barrier setup failed before measurement and produced no result; atomic publication fixed it before the valid passes. No measured pauses or windows were trimmed.