Repository navigation
Conversation
Detach request-scoped HTTP callbacks and the inherited SDK logger from reusable WebSocket clients. Preserve HTTP fallback hooks and cached connection reuse. Add distinct-session idle and reopen diagnostics with source-runtime object counts.
|
🦞👀 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 removes request-scoped callbacks from cached WebSocket clients and extends the existing session-retention diagnostics. Example: Session session-1 completes a turn while its Responses WebSocket remains cached.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR fixes a retention edge still present on main, and inspection found no definite introduced correctness or security defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Responses transport receives prepared model requests and a request-specific OpenAI client, then leases a session-owned WebSocket or falls back to HTTP streaming. flowchart LR
A[Agent turn] --> B[Request HTTP client]
B --> C[WebSocket client clone]
C --> D[Session socket cache]
D --> E[Responses provider]
B --> F[HTTP fallback]
Technical reviewBest possible solution: Clear inherited fetch and logger references at the existing WebSocket-clone boundary while retaining HTTP fallback and session-resource ownership. Do we have a high-confidence way to reproduce the issue? The current-main clone and pinned SDK source establish the retaining path; the author reports both revised retention cases failing on base and passing on the fix, but this review executed no target code. Is this the best way to solve the issue? The production fix is minimal and addresses the retaining producer without changing session disposal, transcript isolation, eviction, or HTTP fallback. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 78e97d169703. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5, Tests +16, Docs +38, Other +210. Total +269 across 6 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 October 20, 2026, 12:21 PM ET / 16:21 UTC. |
…enclaw#178536) Detach request-scoped HTTP callbacks and the inherited SDK logger from reusable WebSocket clients. Preserve HTTP fallback hooks and cached connection reuse. Add distinct-session idle and reopen diagnostics with source-runtime object counts.
What Problem This Solves
Fixes completed agent sessions remaining reachable through cached OpenAI Responses WebSocket clients, retaining their transcript and tool state between turns.
User Impact
Cached WebSockets remain reusable without keeping the request-specific HTTP callbacks from the turn that opened them. HTTP fallback keeps its original response hooks. There are no configuration, schema, or retention-policy changes.
Why This Change Was Made
Embedded agent sessions already dispose after an attempt and reload from persisted history on the next turn. The leak crosses a different lifetime boundary: the cached SDK WebSocket retains a cloned OpenAI client. Its inherited fetch callback retains request/session state, while the SDK logger proxy retains the original HTTP client and its callbacks. The WebSocket-only clone now resets those two references. Resetting fetch alone still reproduced the leak.
The replay transcript is deliberately detached from mutable storage views by
cloneSessionModelContextEntries(). The agent copies the array but shares the supplied replay message objects. Sharing those mutable objects with the manager would let replay/tool-argument changes rewrite its stored-history view. This fix removes the cache's session reference so both views can collect at their existing lifecycle boundary. No eviction timer or second session cache is added.The
GatewayContextBindingOwneraudit found owner-attached symbol storage, not a global strong map. Immutable subagent records reserve a binding slot even when unbound, so the instance count includes retained records rather than just loaded sessions. The original production snapshot was unavailable for exact count attribution; no binding-lifetime change is included.The existing benchmark now supports touching distinct sessions in bounded cohorts, idling, and reopening them. It verifies unchanged persisted history and exactly one answer per turn; source-Gateway census mode counts live SessionManager, AgentSession, and Agent instances without retaining them or writing heap snapshots.
Evidence
Acceptance rule, recorded before sandbox measurement: 100 distinct sessions, cohorts of 10, 128 KiB synthetic prompts, then idle and reopen. Require exact history preservation; completed sessions must collect to the active set; post-idle heap should return within 10% of warmed baseline. Report first-turn and reopened-turn latency, major/minor GC and promotion separately. Paired timings use simultaneous isolated A/B instances, swapped 16-core CPU halves, and at least two pairs. No greater-than-noise regression is acceptable.
pnpm tsgo:core(native tsrs) passed.Runtime production change: +5 lines, needed to preserve the original HTTP client's callbacks while removing both references from the cached WebSocket client. The requested census and idle/reopen workload extend the existing diagnostic harness by +210 lines, with +38 lines of benchmark documentation. The prescribed non-test/non-
docs/diff is 299 insertions / 46 deletions (+253), including that harness and its README. No new production owner, cache, configuration option, or storage shape.Isolated Gateway Measurement
The source-Gateway census completed 100 distinct sessions with cohorts of ten, 128 KiB prompts, one real read tool per turn, six minutes idle, and 100 reopened turns. Synthetic fixture: 5,000 stored sessions, 6,000 retained runs, 200 approvals, 100 cron records, one project, 1 MiB logical background transcript. The background fixture preserves roster shape while avoiding multi-GB writes.
Reproduction (source entry, Node 26.8.2; add
--session-censusonly for the separate object-count diagnostic):Base:
15e634e42723ae988a28f03d48e087a2932d38c2; candidate:5f4c12b34ce2ff467328442be1000eb78d8df1a0. Both share the committed harness and dependencies. Concurrent pairs hold an exclusive lock, use separate identical fixtures/ports and 16-core allocations (96–111 versus 112–127), then swap those allocations. Outside CPU load is recorded per pair for context.Candidate census (main isolate):
Post-idle heap is 7.90% above warmed baseline, meeting the 10% target; all completed-session objects collected. All 100 histories stayed unchanged during idle, and all 100 reopen operations appended exactly one new final answer without changing the prior history. Incremental post-work heap was 0.919 MiB per touched session; this includes other caches and allocations and is not an exact retained-session object size.
The paired baseline census exceeded the existing 30-second profiler IPC deadline after idle; that side is incomplete. The successful candidate run is reported only as a standalone diagnostic. Two complete concurrent, core-swapped timing pairs (runs 3 and 4) then completed without census, as recommended by the harness documentation. All four runs passed 100 unchanged-history and 100 append-only reopen checks. GC timing excludes the explicit forced-GC checkpoints.
Complete paired results
GC and promotion for the measured windows (each turn phase contains 100 completed turns):
These are within-pair differences, not comparisons of absolute times across runs. The small reopen minor-GC increases are 63 ms and 135 ms per 100 turns; promotion stays within 2.7%. No measured regression exceeded 20%. Several pair-3 improvements exceeded 20%, but the SSE control does not exercise the changed WebSocket code, so they are not claimed as gains from the fix. Reopened p95 remains 13.5–14.7 seconds: these are full source-Gateway agent/tool round trips, not isolated storage-read timings.
Pair 3 used baseline CPUs 96–111 / candidate 112–127; pair 4 swapped them. Mean per-core busy time across CPUs 96–127 was 11.98% and 8.22%, including benchmark activity; individual 10-second core samples ranged 0–100% and 0–89.25%. Host load is context only. Both candidate idle heaps met the 10% bound (+8.91%, +8.90%), with unchanged history and comparable reopened-turn latency.
Scope: the loopback model uses SSE, so this workload checks general session disposal, heap bounds, transcript integrity, and reopening; it does not exercise the affected native cached-WebSocket branch. The real-OpenAI-SDK GC regression isolates that retention defect. The production four-hour memory slope remains to be verified after the next normal deployment/restart.
PR CI: https://github.com/openclaw/openclaw/actions/runs/39454335783 (exact submitted head).