Repository navigation
fix(plugin-sdk): retain prepared models through host cleanup - #143270
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: blocked before merge. Reviewed September 9, 2026, 2:51 PM ET / 18:51 UTC (Revision 2). ClawSweeper reviewWhat this changesRetains plugin-prepared models under their original host through completion and cleanup, preserves the public SDK shape, and removes the obsolete internal preparation adapter. Merge readiness⛔ Blocked before merge - 1 item remains This remains a useful, focused repair: current main still releases the SDK preparation lease before returning the executable model. No actionable introduced defect was found, and the reported compiled-runtime proof covers the changed lifecycle. Priority: P2 Review scores
Verification
How this fits togetherPlugins use the completion SDK to turn agent configuration into prepared models and provider responses. The Gateway or CLI host now owns those models until accepted completion, callback, and cancellation work finishes. flowchart TD
A[Plugin preparation request] --> B[Capture original host]
B --> C[Acquire model resources]
C --> D[Prepared model]
D --> E{Host and caller current?}
E -->|Yes| F[Provider completion and callbacks]
E -->|No| G[Reject execution]
F --> H[Drain work and release at shutdown]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +86, Tests +272, Docs +13. Total +371 across 14 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Preserve the public SDK contract with explicit host-owned retention, documented post-close rejection, and the demonstrated fresh-host recovery path. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the premature release: current main releases the acquired lease before returning the prepared model. The PR supplies focused failing-before/passing-after evidence; this review did not execute tests. Is this the best way to solve the issue? Yes. Reusing the existing acquisition, host, and asynchronous work owners repairs the lifetime boundary while preserving public types and leaving provider selection and request authority intact. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6d37d60fc8de. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
aab1860 to
731e23f
Compare
|
Maintainer decision: retain the documented host boundary. A prepared model owned by a closed Gateway or CLI host must reject new execution; callers prepare again under the current open host. Keeping the old model usable would retain retired resources or silently change its model/authentication ownership. The public preparation/result types remain unchanged, and standalone callers retain process-lifetime ownership. The host-lifetime behavior is documented in |
|
Merged via squash.
|
Keep source-authored model overrides while filling omitted capabilities from the same prepared catalog identity. Clear inherited capabilities when the configured API or endpoint changes, and reuse the prepared policy instead of rebuilding its configured catalog. Compose admitted-runtime checks with the public SDK host lifetime and keep internal configuration and authority fields out of prepared results. Retain acquired models through HTTP completion in the affected test flows. Related: #130706, #134496, #143270
…w#143270) * fix(plugin-sdk): retain prepared models through host cleanup * refactor: remove obsolete core completion adapter
Related: #140674. Internal caller migrations landed in #143302, #143307, and #143308.
What Problem This Solves
Resolves a problem where plugins receive an executable prepared model after its preparation lease has already been released. Completion callbacks and nested preparation can then outlive the model's owner, particularly during cancellation or host shutdown.
Why This Change Was Made
Keep the existing bare-result SDK API under its SDK host. Capture the host before lazy preparation, retain the successful model, and track actual completion and callback work through host closure. Re-enter that host for nested preparation without replacing Gateway request authority.
With all three internal callers using acquisition, delete the obsolete core bare adapter. Shared parameter and result types preserve the public fingerprint, optional selection fields, and deprecated parameter; the SDK runtime import remains lazy. Core preparation tests now release acquired results. The distinct direct preparation API remains unchanged.
User Impact
Plugins keep their existing prepared-model API and gain reliable host-owned cleanup. Host closure joins pending work and refuses new requests afterward. Provider selection, authentication checks, and public result shapes are preserved.
Evidence
The original native SDK regressions and a separately reproduced nested-callback host-context failure pass after repair. Final validation passed 166 focused tests, the unchanged export-collision guard, all selected changed-file gates, fresh isolated Codex review through P2, and a full build in 248.17 seconds.
A plain Node run of the built public SDK used actual ModelRegistry instances, a synthetic provider, and loopback HTTP. It exercised nested preparation in a real response callback, prompt cancellation while that callback remained held, host drainage, independent request stores, base-catalog reuse, post-close refusal, and fresh preparation after the last host closed. It also verified that the built core exposes acquisition and no longer exports the obsolete bare adapter.
That strict, joined run completed in 2.495 seconds, observing two base catalogs, four request forks, and three HTTP calls. All 21,093 build artifacts remained unchanged; 2,880 resolved modules had no application TypeScript/source fallback. Preparation samples were 145.059 / 3.162 / 5.768 ms for initial, retained, and fresh-after-closure preparations; these are local observations, not a comparative speedup benchmark.
After rebasing onto the three landed caller migrations, all 14 source files match the reviewed proof. The collision guard and 42 SDK composition tests passed again. This does not activate general run-registration physical disposal or claim a paid-provider or operator-Gateway test.