Repository navigation
fix(core): invalidate AISDK caches when plugin hooks change - #67129
Open
imarshallwidjaja wants to merge 1 commit into
Open
imarshallwidjaja wants to merge 1 commit into
imarshallwidjaja wants to merge 1 commit into
Conversation
Resolved SDKs and language models were cached for the life of the location layer, so after a plugin hot reload disposed its sdk or language hook, language() kept returning the disposed generation's entries and never called the replacement hook. Every hook register or dispose now replaces the cache pair with fresh maps, and each language() call reads and writes only the pair it saw at entry, so an in-flight lookup from the old hook set cannot repopulate the live caches.
Contributor
There was a problem hiding this comment.
This looks good to me. I ran the hot-reload reproduction from #67116 from source. On the base branch, after editing the plugin file, the new plugin's sdk hook was never called, and both the existing session and a new one failed with generation … was disposed (stale SDK reused). With this PR, the new plugin's hook runs and both turns are served by it. The five new tests fail against the base aisdk.ts and pass with the fix, and typecheck:tsc is clean.
Public API: unchanged. The only behaviour change is internal: the sdk/language model caches are reset whenever one of those hooks is registered or disposed.
I have no concerns that should block a merge.
This was referenced Nov 29, 2026
Open
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #67116
Type of change
What does this PR do?
After a plugin hot reload, the AISDK location layer kept serving SDKs and language models built by the disposed plugin generation. The
sdks/languagescaches inpackages/core/src/aisdk.tslived for the life of the location layer, and disposing ansdk/languagehook only removed the callback, solanguage()kept hitting the stale entries and never called the new generation's hook. (A full location reload rebuilds the layer, so this only showed up on in-place plugin reloads.)The fix treats a cache entry as valid only for the hook set that was current when it was created:
sdkorlanguagehook swaps in fresh maps in the same step as the hook-list update. Registering is included so a hook that loads late (plugins load asynchronously) supersedes entries cached before it existed.language()captures the pair at entry and uses it for all reads and writes. A lookup that is in flight while hooks change still returns its result to its own caller, but writes into the retired pair instead of repopulating the live caches.No feature flag: this is a bug fix for stale resolution, and the only behavior change is that model resolution re-runs the current hooks after they change.
How did you verify your code works?
Added five tests to
packages/core/test/aisdk.test.ts: sdk hook disposal observed with no registration in between (falls back to an earlier hook), language hook disposal, disposal through scope close (the plugin reload finalizer path), a late-registered hook superseding a cached SDK, and an in-flightDeferred-gated lookup that must not re-cache (checked with both the same model and a second model sharing the SDK cache key). The new tests fail against the unmodifiedaisdk.tsand pass with the fix. I also checked they bite under targeted mutations: removing the dispose-time cache replacement fails the disposal tests, and writing through the live caches instead of the captured pair fails the in-flight test.From
packages/core:bun run script/test.ts test/aisdk.test.ts— 49 passbun run script/test.ts test/plugin/supervisor.test.ts— 11 passbun run typecheck:tsc— cleanThe push also ran the pre-push
bun run checkunder Bun 1.4.4 (37/37 tasks).Screenshots / recordings
N/A, no UI change.
Checklist
Added by the opencode bot (AI-generated).
Related: #62068, #52333