@@ -45,7 +45,11 @@ import { emitTrustedDiagnosticEvent } from "openclaw/plugin-sdk/diagnostic-runti
4545import { expectDefined } from "openclaw/plugin-sdk/expect-runtime" ;
4646import type { ImageContent , TextContent } from "openclaw/plugin-sdk/llm" ;
4747import { normalizeOpenAIToolSchemas } from "openclaw/plugin-sdk/provider-tools" ;
48- import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime" ;
48+ import {
49+ asOptionalRecord ,
50+ isRecord ,
51+ normalizeOptionalString ,
52+ } from "openclaw/plugin-sdk/string-coerce-runtime" ;
4953import {
5054 DEFAULT_MAX_LIVE_TOOL_RESULT_CHARS ,
5155 estimateToolResultTextChars ,
@@ -381,10 +385,24 @@ export type CodexDynamicToolBridge = {
381385 toolMediaUrls : string [ ] ;
382386 toolAudioAsVoice : boolean ;
383387 successfulCronAdds ?: number ;
388+ acceptedSessionSpawns : Array < { runId : string ; childSessionKey : string } > ;
384389 quarantinedTools : CodexDynamicToolSchemaQuarantine [ ] ;
385390 } ;
386391} ;
387392
393+ function normalizeAcceptedSessionSpawn ( result : unknown ) : {
394+ runId : string ;
395+ childSessionKey : string ;
396+ } | null {
397+ const details = asOptionalRecord ( asOptionalRecord ( result ) ?. details ) ;
398+ if ( ! details || details . status !== "accepted" ) {
399+ return null ;
400+ }
401+ const runId = normalizeOptionalString ( details . runId ) ;
402+ const childSessionKey = normalizeOptionalString ( details . childSessionKey ) ;
403+ return runId && childSessionKey ? { runId, childSessionKey } : null ;
404+ }
405+
388406/** Namespace attached to OpenClaw-owned dynamic tools exposed to Codex. */
389407const CODEX_OPENCLAW_DYNAMIC_TOOL_NAMESPACE = "openclaw" ;
390408
@@ -490,6 +508,7 @@ export function createCodexDynamicToolBridge(params: {
490508 messagingToolSourceReplyPayloads : [ ] ,
491509 toolMediaUrls : [ ] ,
492510 toolAudioAsVoice : false ,
511+ acceptedSessionSpawns : [ ] ,
493512 quarantinedTools,
494513 } ;
495514 const middlewareRunner = createAgentToolResultMiddlewareRunner ( {
@@ -654,6 +673,14 @@ export function createCodexDynamicToolBridge(params: {
654673 result : middlewareResult ,
655674 } ) ;
656675 const resultIsError = rawIsError || isToolResultError ( result ) ;
676+ // A successful spawn is durable before presentation middleware can rewrite details.
677+ const acceptedSessionSpawn =
678+ toolName === "sessions_spawn" && ! rawIsError
679+ ? normalizeAcceptedSessionSpawn ( telemetryRawResult )
680+ : null ;
681+ if ( acceptedSessionSpawn ) {
682+ telemetry . acceptedSessionSpawns . push ( acceptedSessionSpawn ) ;
683+ }
657684 const finalResultFailureKind = resolveToolResultFailureKind ( result ) ;
658685 const resultFailureKind = rawResultFailureKind ?? finalResultFailureKind ;
659686 const observerResult =
0 commit comments