fix(plugins): forward-port bundled SDK fallback hardening (#107131)

* fix(plugins): avoid bundled SDK fallback races

* fix(ci): satisfy plugin SDK LOC ratchet

* fix(ci): align fallback forward-port guards

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
Peter Steinberger
2026-07-13 21:50:46 -07:00
committed by GitHub
parent 2e58c2bc53
commit 61986571bb
5 changed files with 90 additions and 15 deletions

View File

@@ -33,11 +33,13 @@ type ResolvePluginModuleLoaderCacheEntryParams = {
pluginSdkResolution?: PluginSdkResolutionPreference;
cacheScopeKey?: string;
sharedCacheScopeKey?: string;
transformOpenClawDependencies?: boolean;
};
type PluginModuleLoaderCacheEntry = {
loaderFilename: string;
aliasMap: Record<string, string>;
tryNative: boolean;
transformOpenClawDependencies: boolean;
cacheKey: string;
scopedCacheKey: string;
};
@@ -157,12 +159,14 @@ function resolvePluginModuleLoaderCacheEntry(
}
: resolveDefaultPluginModuleLoaderConfig(params);
const { tryNative, aliasMap } = resolved;
const cacheKey =
const moduleConfigCacheKey =
resolved.cacheKey ??
createPluginLoaderModuleCacheKey({
tryNative,
aliasMap,
});
const transformOpenClawDependencies = params.transformOpenClawDependencies ?? tryNative;
const cacheKey = `${moduleConfigCacheKey}\0transform-openclaw=${transformOpenClawDependencies ? "1" : "0"}`;
const scopedCacheKey = `${loaderFilename}::${
params.sharedCacheScopeKey ??
(params.cacheScopeKey ? `${params.cacheScopeKey}::${cacheKey}` : cacheKey)
@@ -171,6 +175,7 @@ function resolvePluginModuleLoaderCacheEntry(
loaderFilename,
aliasMap,
tryNative,
transformOpenClawDependencies,
cacheKey,
scopedCacheKey,
};
@@ -220,13 +225,13 @@ function createPluginModuleLoader(params: {
loaderFilename: string;
aliasMap: Record<string, string>;
tryNative: boolean;
transformOpenClawDependencies: boolean;
createLoader?: PluginModuleLoaderFactory;
}): PluginModuleLoader {
// A declined native require can leave an ESM dependency in flight. The
// fallback must transform both the entry and OpenClaw SDK dependencies.
const getLoadWithSourceTransform = createLazySourceTransformLoader({
...params,
transformOpenClawDependencies: params.tryNative,
});
const loadedTargetExports = new Map<string, unknown>();
const loadCachedTarget = (target: string, rest: unknown[], load: () => unknown): unknown => {
@@ -304,6 +309,7 @@ export function getCachedPluginModuleLoader(
loaderFilename: cacheEntry.loaderFilename,
aliasMap: cacheEntry.aliasMap,
tryNative: cacheEntry.tryNative,
transformOpenClawDependencies: cacheEntry.transformOpenClawDependencies,
...(params.createLoader ? { createLoader: params.createLoader } : {}),
});
params.cache.set(cacheEntry.scopedCacheKey, loader);