Repository navigation
fix(llm): retain prepared runtimes through transport cleanup - #142197
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 maintainer review before merge. Reviewed September 8, 2026, 9:57 AM ET / 13:57 UTC. ClawSweeper reviewWhat this changesThe PR keeps prepared model runtimes alive until response callbacks and cancellation cleanup finish, while allowing cancelled callers to return promptly. Merge readiness✅ Ready for maintainer review This remains a useful follow-up to the merged completion-lease repair: current main still releases ownership before pending transport cleanup settles. No blocking correctness or security defect was found. Priority: P2 Review scores
Verification
How this fits togetherPlugins request model completions through OpenClaw’s host runtime, which prepares provider resources and invokes the transport. This change connects pending transport work to the completion’s resource lifetime and parent cleanup. flowchart TD
A[Plugin completion request] --> B[Acquire prepared runtime]
B --> C[Provider transport]
C --> D[Caller result or cancellation]
C --> E[Pending callbacks and cleanup]
E --> F[Drain owned work]
F --> G[Release prepared runtime]
F --> H[Parent cleanup completes]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +27, Tests +234. Total +261 across 6 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep caller completion independent while retaining the existing prepared lease through all accepted transport work and parent drainage. Do we have a high-confidence way to reproduce the issue? Yes, from source: hold a response callback or cancellation promise, let the caller finish, and start an overlapping completion. Current main releases the lease before that held work settles; the reported baseline probes exercise this sequence. Is this the best way to solve the issue? Yes. Tracking actual transport promises through the existing work scope repairs the resource owner without delaying caller cancellation or changing the public completion API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a39239faf938. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
A direct plugin completion can return after cancellation while its response callback or response-body cancellation is still running. Releasing the prepared runtime at that point drops its last lease, so an overlapping request rebuilds the same generation while accepted work still uses the previous one. Parent shutdown can also finish without joining that work.
Why This Change Was Made
Keep the existing lease inside the existing AsyncWorkScope until accepted transport callbacks and cancellation promises settle. A narrow transport-host observer records the actual promises before they can be lost behind a cancellation race. The caller receives its result independently; parent cleanup retains and drains the operation before releasing the lease.
This six-file slice follows #141938 and replaces part of #140674. It reuses the existing work-scope implementation and preserves callback deferral, synchronous cancellation invocation, and the original completion error. Physical registration disposal remains a separate change.
User Impact
Cancelled calls still return before a held cleanup operation finishes. Overlapping calls reuse prepared facts while keeping independent mutable request stores. Once accepted work and the overlapping call finish, the generation can retire normally.
Evidence
The two new native cases fail on the original code: parent drainage finishes early and the overlapping request creates a second generation. Both pass with the fix, along with all nine existing native ownership cases. The selected native, package transport, and runtime suites pass 124 tests. Full canonical changed checks, a complete build, and independent Codex review pass.
Separate compiled baseline and candidate processes call createPluginRuntime().llm.complete through a registered synthetic provider and real loopback HTTP. Both callback-after-abort and native cancellation cases demonstrate:
The cancellation probe uses the public guarded-fetch and transport-notification helpers with a native Web Streams cancellation operation. It verifies emitted host/transport ownership, not the private cancellation internals of a particular provider SDK. Source and compiled artifacts remain unchanged through the probes; all owned processes, sockets, and synchronization operations are joined. These are structural reuse observations, not a general inference-latency claim.