@@ -7,9 +7,11 @@ import type {
77 OpenClawPluginNodeInvokePolicy ,
88} from "openclaw/plugin-sdk/plugin-entry" ;
99import type { PluginRuntime } from "openclaw/plugin-sdk/plugin-runtime" ;
10- import type {
11- SessionCatalogHost ,
12- SessionCatalogProvider ,
10+ import {
11+ listSessionCatalogEntries ,
12+ type SessionCatalogEntrySnapshot ,
13+ type SessionCatalogHost ,
14+ type SessionCatalogProvider ,
1315} from "openclaw/plugin-sdk/session-catalog" ;
1416import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime" ;
1517import { CODEX_CONTROL_METHODS } from "./app-server/capabilities.js" ;
@@ -372,6 +374,7 @@ async function listGatewayHost(params: {
372374 control : CodexSessionCatalogControl ;
373375 query : CodexSessionCatalogParams ;
374376 runtime : PluginRuntime ;
377+ sessionEntries ?: SessionCatalogEntrySnapshot ;
375378} ) : Promise < CodexSessionCatalogHost > {
376379 try {
377380 const page = parseCatalogPage (
@@ -387,6 +390,7 @@ async function listGatewayHost(params: {
387390 bindingStore : params . bindingStore ,
388391 config : params . config ,
389392 runtime : params . runtime ,
393+ sessionEntries : params . sessionEntries ,
390394 } ) ;
391395 return {
392396 hostId : CODEX_LOCAL_SESSION_HOST_ID ,
@@ -419,6 +423,7 @@ async function listCodexSessionCatalog(params: {
419423 control : CodexSessionCatalogControl ;
420424 query ?: CodexSessionCatalogParams ;
421425 onHost ?: ( host : CodexSessionCatalogHost ) => void ;
426+ sessionEntries ?: SessionCatalogEntrySnapshot ;
422427} ) : Promise < CodexSessionCatalogResult > {
423428 const query = readGatewayParams ( params . query ) ;
424429 const requestedHostIds = query . hostIds ? new Set ( query . hostIds ) : undefined ;
@@ -431,6 +436,7 @@ async function listCodexSessionCatalog(params: {
431436 control : params . control ,
432437 query,
433438 runtime : params . runtime ,
439+ sessionEntries : params . sessionEntries ,
434440 } ) ,
435441 ]
436442 : [ ] ;
@@ -470,6 +476,7 @@ async function listCodexSessionCatalog(params: {
470476 const adoptedNodeSessions = listNodeAdoptedSessionEntries ( {
471477 config : params . config ,
472478 runtime : params . runtime ,
479+ sessionEntries : params . sessionEntries ,
473480 } ) ;
474481 const nodeHosts = nodes . toSorted ( compareNodeLabels ) . map ( async ( node ) => {
475482 const host = await listPairedNode ( {
@@ -672,44 +679,44 @@ async function listAdoptedSessionEntries(params: {
672679 bindingStore : CodexAppServerBindingStore ;
673680 config ?: OpenClawConfig ;
674681 runtime : PluginRuntime ;
682+ sessionEntries ?: SessionCatalogEntrySnapshot ;
675683} ) : Promise < Map < string , AdoptedSessionEntry > > {
676684 const adopted = new Map < string , AdoptedSessionEntry > ( ) ;
677- for ( const agentId of listSupervisionAgentIds ( params . config ?? { } ) ) {
678- for ( const { entry, sessionKey } of params . runtime . agent . session . listSessionEntries ( {
679- agentId,
680- readOnly : true ,
681- } ) ) {
682- const sessionKeyRest = adoptionSessionKeyRest ( sessionKey ) ;
683- if (
684- ! sessionKeyRest . startsWith ( CODEX_SUPERVISION_SESSION_KEY_PREFIX ) ||
685- entry . initializationPending === true ||
686- entry . agentHarnessId !== "codex" ||
687- entry . modelSelectionLocked !== true
688- ) {
689- continue ;
690- }
691- const sessionId = entry . sessionId ?. trim ( ) ;
692- if ( ! sessionId ) {
693- continue ;
694- }
695- const binding = await params . bindingStore . read (
696- sessionBindingIdentity ( { sessionId, sessionKey, config : params . config } ) ,
697- ) ;
698- const sourceThreadId = binding ?. supervisionSourceThreadId ?. trim ( ) ;
699- const boundThreadId = binding ?. threadId . trim ( ) ;
700- if (
701- binding ?. connectionScope !== "supervision" ||
702- ! sourceThreadId ||
703- ! boundThreadId ||
704- sessionKeyRest !== adoptionSessionKey ( sourceThreadId )
705- ) {
706- continue ;
707- }
708- if ( adopted . has ( sourceThreadId ) ) {
709- throw new Error ( `multiple OpenClaw sessions adopt Codex thread ${ sourceThreadId } ` ) ;
710- }
711- adopted . set ( sourceThreadId , { key : sessionKey , sessionId, agentId, boundThreadId } ) ;
685+ for ( const { agentId, entry, sessionKey } of listSessionCatalogEntries ( {
686+ config : params . config ?? { } ,
687+ runtime : params . runtime ,
688+ sessionEntries : params . sessionEntries ,
689+ } ) ) {
690+ const sessionKeyRest = adoptionSessionKeyRest ( sessionKey ) ;
691+ if (
692+ ! sessionKeyRest . startsWith ( CODEX_SUPERVISION_SESSION_KEY_PREFIX ) ||
693+ entry . initializationPending === true ||
694+ entry . agentHarnessId !== "codex" ||
695+ entry . modelSelectionLocked !== true
696+ ) {
697+ continue ;
698+ }
699+ const sessionId = entry . sessionId ?. trim ( ) ;
700+ if ( ! sessionId ) {
701+ continue ;
702+ }
703+ const binding = await params . bindingStore . read (
704+ sessionBindingIdentity ( { sessionId, sessionKey, config : params . config } ) ,
705+ ) ;
706+ const sourceThreadId = binding ?. supervisionSourceThreadId ?. trim ( ) ;
707+ const boundThreadId = binding ?. threadId . trim ( ) ;
708+ if (
709+ binding ?. connectionScope !== "supervision" ||
710+ ! sourceThreadId ||
711+ ! boundThreadId ||
712+ sessionKeyRest !== adoptionSessionKey ( sourceThreadId )
713+ ) {
714+ continue ;
715+ }
716+ if ( adopted . has ( sourceThreadId ) ) {
717+ throw new Error ( `multiple OpenClaw sessions adopt Codex thread ${ sourceThreadId } ` ) ;
712718 }
719+ adopted . set ( sourceThreadId , { key : sessionKey , sessionId, agentId, boundThreadId } ) ;
713720 }
714721 return adopted ;
715722}
@@ -1266,7 +1273,7 @@ function registerCodexSessionCatalog(params: {
12661273 ) ,
12671274 list : async ( query ) => {
12681275 const localTerminalAvailable = resolveLocalCodexTerminalExecutable ( ) !== undefined ;
1269- const { onHost, ...gatewayQuery } = query ;
1276+ const { onHost, sessionEntries , ...gatewayQuery } = query ;
12701277 const mapHost = ( host : CodexSessionCatalogHost ) =>
12711278 toGenericCatalogHost ( host , localTerminalAvailable ) ;
12721279 return (
@@ -1276,6 +1283,7 @@ function registerCodexSessionCatalog(params: {
12761283 runtime : params . api . runtime ,
12771284 control : params . control ,
12781285 query : gatewayQuery ,
1286+ sessionEntries,
12791287 ...( onHost ? { onHost : ( host ) => onHost ( mapHost ( host ) ) } : { } ) ,
12801288 } )
12811289 ) . hosts . map ( mapHost ) ;
0 commit comments