11/** Agent-run lease admission for lifecycle-owned prepared model runtimes. */
2- import fsp from "node:fs/promises" ;
3- import path from "node:path" ;
42import { isReservedSystemAgentId } from "../system-agent/agent-id.js" ;
53import {
64 PreparedModelRuntimeOwnerNotPublishedError ,
@@ -10,7 +8,6 @@ import {
108 normalizePreparedModelRuntimeInput ,
119 publishModelRuntimeSnapshot ,
1210 rebindInputToCommittedConfiguredOwner ,
13- resolveCommittedConfiguredOwner ,
1411 type PreparedModelRuntimeInput ,
1512 type PreparedModelRuntimeLease ,
1613 type PreparedModelRuntimeOwner ,
@@ -23,7 +20,6 @@ import type { PreparedModelRuntimeCatalogMode } from "./prepared-model-runtime.t
2320type PreparedModelRuntimeLeaseContext = {
2421 owners : Map < string , PreparedModelRuntimeOwner > ;
2522 agentBuildCompletions : Map < string , Promise < void > > ;
26- workspacePluginRootPresenceResolutions : Map < string , Promise < boolean | undefined > > ;
2723 retainedDirectRunOwners : PreparedModelRuntimeOwnerRetention ;
2824 retainedGatewayRunOwners : PreparedModelRuntimeOwnerRetention ;
2925 getBuildTimeoutMs ( ) : number ;
@@ -32,66 +28,6 @@ type PreparedModelRuntimeLeaseContext = {
3228 prepareSnapshot ( input : PreparedModelRuntimeInput ) : Promise < PreparedModelRuntimeSnapshot > ;
3329} ;
3430
35- function resolveReusableConfiguredPluginGeneration (
36- input : PreparedModelRuntimeInput ,
37- workspacePluginRootPresent : boolean | undefined ,
38- context : PreparedModelRuntimeLeaseContext ,
39- ) {
40- if ( workspacePluginRootPresent !== false ) {
41- return undefined ;
42- }
43- const owner = resolveCommittedConfiguredOwner ( context . owners , input ) ;
44- const generation = owner ?. pluginGeneration ;
45- if (
46- ! owner ||
47- ! generation ||
48- JSON . stringify ( owner . input . runtimePluginSelections ) !==
49- JSON . stringify ( input . runtimePluginSelections ) ||
50- generation . pluginMetadataSnapshot . index . plugins . some ( ( plugin ) => plugin . origin === "workspace" )
51- ) {
52- return undefined ;
53- }
54- return generation ;
55- }
56-
57- async function resolveCoalescedWorkspacePluginRootPresence (
58- input : PreparedModelRuntimeInput ,
59- context : PreparedModelRuntimeLeaseContext ,
60- ) : Promise < boolean | undefined > {
61- const key = ownerKey ( input ) ;
62- const existing = context . workspacePluginRootPresenceResolutions . get ( key ) ;
63- if ( existing ) {
64- return await existing ;
65- }
66- const pending = resolveWorkspacePluginRootPresence ( input ) ;
67- context . workspacePluginRootPresenceResolutions . set ( key , pending ) ;
68- try {
69- return await pending ;
70- } finally {
71- if ( context . workspacePluginRootPresenceResolutions . get ( key ) === pending ) {
72- context . workspacePluginRootPresenceResolutions . delete ( key ) ;
73- }
74- }
75- }
76-
77- export async function resolveWorkspacePluginRootPresence (
78- input : PreparedModelRuntimeInput ,
79- ) : Promise < boolean | undefined > {
80- if ( input . workspacePluginRootPresent !== undefined || ! input . workspaceDir ) {
81- return input . workspacePluginRootPresent ;
82- }
83- return await fsp
84- . stat ( path . join ( input . workspaceDir , ".openclaw" , "extensions" ) )
85- . then ( ( ) => true )
86- . catch ( ( error : unknown ) => {
87- const code = ( error as NodeJS . ErrnoException ) . code ;
88- if ( code === "ENOENT" || code === "ENOTDIR" ) {
89- return false ;
90- }
91- throw error ;
92- } ) ;
93- }
94-
9531export async function acquirePreparedModelRuntimeLeaseFromOwners (
9632 rawInput : PreparedModelRuntimeInput ,
9733 provenance : "run" | "ephemeral" ,
@@ -121,18 +57,7 @@ export async function acquirePreparedModelRuntimeLeaseFromOwners(
12157 }
12258 }
12359 }
124- const retainedWorkspacePluginRootPresent = context . owners . get ( ownerKey ( normalizedInput ) ) ?. input
125- . workspacePluginRootPresent ;
126- const workspacePluginRootPresent =
127- rawInput . workspacePluginRootPresent ??
128- retainedWorkspacePluginRootPresent ??
129- ( provenance === "run"
130- ? await resolveCoalescedWorkspacePluginRootPresence ( normalizedInput , context )
131- : undefined ) ;
132- let input = normalizePreparedModelRuntimeInput ( {
133- ...normalizedInput ,
134- ...( workspacePluginRootPresent === undefined ? { } : { workspacePluginRootPresent } ) ,
135- } ) ;
60+ let input = normalizedInput ;
13661 let key = ownerKey ( input ) ;
13762 let owner : PreparedModelRuntimeOwner ;
13863 let snapshot : PreparedModelRuntimeSnapshot ;
@@ -187,9 +112,6 @@ export async function acquirePreparedModelRuntimeLeaseFromOwners(
187112 }
188113 }
189114 try {
190- const reusablePluginGeneration =
191- options . pluginGeneration ??
192- resolveReusableConfiguredPluginGeneration ( input , workspacePluginRootPresent , context ) ;
193115 if ( existing && ! staleDynamicOwner ) {
194116 snapshot = await context . prepareSnapshot ( input ) ;
195117 } else {
@@ -204,7 +126,7 @@ export async function acquirePreparedModelRuntimeLeaseFromOwners(
204126 undefined ,
205127 provenance ,
206128 options . catalogMode ,
207- reusablePluginGeneration ,
129+ options . pluginGeneration ,
208130 ) ;
209131 }
210132 } catch ( error ) {
0 commit comments