fix(desktop): resolve runtime plugin SDK namespaces lazily and break sdk cycle - #107753
Closed
JoaoMarcos44 wants to merge 1 commit into
Closed
JoaoMarcos44 wants to merge 1 commit into
JoaoMarcos44 wants to merge 1 commit into
Conversation
…sdk cycle Break the static import cycle between sdk/index.ts and contrib/runtime-loader.ts by lazily importing discoverRuntimePlugins in plugins-tab.tsx upon manual rescan. Additionally, make GLOBALS in sdk/runtime.ts evaluate namespaces through getters at call time and guard Object.keys in shimUrl against uninitialized namespaces, preventing TypeError when loading runtime desktop plugins. Fixes NousResearch#107288.
Contributor
Duplicate of #107303 (earliest open fix for #107288 / #107352); #107518, #107603 and #107644 target the same bug. This PR also breaks the static import cycle in |
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.
Summary
Resolves #107288 by breaking the static module cycle between
sdk/index.tsandcontrib/runtime-loader.ts, and making runtime plugin SDK namespace resolution lazy and null-safe.Problem & Mechanism
Following the Capabilities → Plugins consolidation (#107212 and subsequent consolidation in commit
248ff2d3e8),sdk/index.tswas caught in a static module cycle:In production and packaged desktop builds, Rolldown's module topological sorting emitted
sdk/runtime.ts'sGLOBALSobject literal before thesdkexport namespace was evaluated (hoisted unassignedvar/ TDZ). Consequently:GLOBALS.__HERMES_PLUGIN_SDK__was captured asundefinedat module evaluation.contrib/runtime-loader.ts:113callsinstallPluginSdk(), which runssdkImportMap()andshimUrl('__HERMES_PLUGIN_SDK__').shimUrlexecutedObject.keys(GLOBALS[globalKey])onundefined, throwingTypeError: Cannot convert undefined or null to object.Solution
Cycle Break: In
apps/desktop/src/app/skills/plugins-tab.tsx, removed the top-level static importimport { discoverRuntimePlugins } from '@/contrib/runtime-loader'.discoverRuntimePluginsis only called insiderescanAll()(an asynchronous action triggered by the user clicking the Rescan button or after an agent plugin update), so it is now loaded lazily:This severs the sole static link from
app/skillstocontrib/runtime-loader.ts, reducing paths fromsdk/index.tstocontrib/runtime-loader.tsto 0.Call-Time Namespace Evaluation: In
apps/desktop/src/sdk/runtime.ts, convertedGLOBALSproperties to getters:When
installPluginSdk()executes,Object.assign(globalThis, GLOBALS)evaluates the getters at call time, assigning the fully initialized namespace objects.Null-Guarded Shim Generation: In
shimUrl(), guardedObject.keys(namespace ?? {})against nullish values to ensure graceful link-time handling instead of throwing in the host loader.Validation
sdk/index.tstocontrib/runtime-loader.tsandsdk/runtime.tsare 0.apps/desktop/src/sdk/runtime.test.tstesting global namespace assignment, import map construction, and safe evaluation.apps/desktop/src/app/skills/plugins-tab.test.tsxverifying rescan behavior.plugins-tab.test.tsx(17 tests) andruntime.test.ts(3 tests) pass.npm run typecheck(tscfor renderer, electron, e2e): passed (exit code 0).npm run lint(eslintacrosssrc/andelectron/): passed (0 errors).Fixes #107288.