Repository navigation
perf(agents): release completed parents retained by fork replay - #173535
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. |
|
Inherited-failure landing evidence for reviewed head CI run 38821588178 passed all selected tests, build, types, lint, docs, guards, and security checks. Its sole root failure is The same Independent review is clean; focused SDK/fork/run tests pass, including 30 SDK sibling tests. No CI rerun or unrelated baseline edit. Native merge tooling could not start due its installed dependency mismatch; using the authorized exact-head API fallback under the inherited-failure exception. |
|
Codex review: needs maintainer review before merge. What this changesThis PR isolates the replay transport closure so retained fork snapshots can release completed parent sessions and transcript managers. Example: Six completed sessions each retain an 8 MiB prepared replay prefix in the reported isolated probe.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a concrete retention defect with a focused change and meaningful GC coverage; no introduced correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe session SDK assembles the agent's provider stream; background fork snapshots retain that stream and prepared request data for later read-only inference. flowchart LR
A[Session SDK] --> B[Isolated stream factory]
B --> C[Provider runtime]
D[Fork snapshot] --> B
D --> E[Prepared request prefix]
F[Background side question] --> D
Technical reviewBest possible solution: Retain the isolated transport factory and GC regression while preserving the existing replay prefix, runtime binding, and cleanup policies. Do we have a high-confidence way to reproduce the issue? Source shows snapshots retaining the inline SDK closure and its options; the supplied synthetic-provider probe and regression report collection failure before the fix and success afterward, but this review executed no target code. Is this the best way to solve the issue? The extraction fixes the retaining closure at its producer, preserves dynamic credential and settings resolution, and avoids weakening useful replay retention. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dbc41ff76ba1. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +12, Tests +74, Docs +2. Total +88 across 3 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 Reviewed October 15, 2026, 7:23 PM ET / 23:23 UTC. |
…claw#173535) * perf(agents): release completed parents retained by fork replay * test(agents): convert fork replay fixture messages at provider boundary
What Problem This Solves
Prepared native-session fork snapshots kept the disposed parent AgentSession and SessionManager alive alongside their intentionally retained replay prefix. Large conversations therefore retained an extra copy of their history until snapshot eviction or cleanup.
User Impact
Completed parents can now be garbage-collected while later read-only forks still replay the prepared request. No configuration, schema, expiry, byte-budget, or run-registration policy changes.
Why This Change Was Made
The SDK transport was created inside
createAgentSession, captured its full options, and shared the session factory's closure scope. A private transport factory now captures only the model registry, settings manager, and thinking flag. Per-request credential resolution, dynamic retry/attribution settings, and runtime binding remain intact.The old inline construction is removed. Production delta: +12 lines (39 added / 27 removed); the extra private function/type boundary is necessary to isolate the retained closure rather than clear useful replay data. Test delta: +74 lines. The simplification pass found no second policy or compatibility path to retain.
Evidence
Isolated Linux sandbox, synthetic data, exact base
2aca37525ff0804790c29d9ab6fea1bb9e5f700e, real SDK session construction and native stream selection, fixture provider, forced GC. Six completed sessions with 8 MiB histories:The fix removes approximately 8.03 MiB per run (50% of measured retention). The remaining 8 MiB per run is the intended prepared prefix. A separate twelve-run probe with 16.23 MiB prefixes stayed at 16.23 MiB for one session and plateaued at 48.69 MiB across distinct sessions under the existing 64 MiB budget; replacement, expiry, and cleanup released old data.
Registration investigation: the registration owner is a WeakMap. Twelve runs each through completion, abort, explicit finalizing-owner release, and lifecycle rotation left zero live handles, registrations, or 8 MiB SessionManagers. No registration-owner change was needed.
sdk.test.ts: 23 passed; latest Vitest 7.01 s / wrapper 32.97 s (test execution about 1.3 s).session-fork.test.ts: 28 passed.runs.test.tsandruns.generation.test.ts: 33 passed.sdk.auth-migration.test.ts,sdk.metadata-admission.test.ts, andsdk.tool-outcomes.test.ts: 30 passed (single worker, 51.11 s wrapper).git diff --check: passed. An initial root-config lint invocation triggered declaration preparation and was stopped; the successful check used the core config with preparation disabled.AgentMessage[]versus providerMessage[]). The test now uses the canonicalconvertToLlmboundary; focused tests/lint and independent review passed again. Production code and measurements are unchanged.Limits: this measures the real session/fork ownership boundary with a synthetic provider, not a live provider call or the complete production Gateway heap. It does not attribute all idle-process memory to this defect.
Final CI and inherited-failure attribution
Corrected head
5c04b86650d992e09e649022216552da1fcc268d, CI run 38821588178, attempt 1: all selected test lanes, build, production/test types, lint, docs, guards, andsecurity-fastpassed. The only root failure ischecks-fast-baseline-ratchets;openclaw/ci-gatefails downstream.The failure table labels it new because the older scheduled main job passed. Independent reproduction on the actual unchanged CI main parent proves it inherited:
68166d8e61e94ce46aeeed9fe439e82e7da7114f:node --import ./scripts/tsx.mjs scripts/check-test-mock-exports.mts --base 68166d8e61e94ce46aeeed9fe439e82e7da7114fexits 1.e9a7a10816e4d7b27d44af31f13aca184853db3f(ordered parents: that main parent, corrected PR head): same command exits 1 with the identical entry below.Landing under the authorized inherited-failure exception; the unrelated baseline is not changed in this PR.
Native
scripts/pr merge-runcould not start because installedtsx4.23.12 differs from the trusted tooling requirement 4.23.15. Shared dependencies were left untouched; the operator-authorized exact-head GitHub API fallback is used for this inherited-only landing.