../config/types.openclaw.js";
import type { ConversationRef } from "../infra/outbound/session-binding-service.js" ;
import { normalizeAccountId } from "../routing/session-key.js" ;
import { defaultRuntime } from "../runtime.js" ;
import { isCronSessionKey } from "../sessions/session-key-utils.js" ;
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js" ;
import {
mergeDeliveryContext,
normalizeDeliveryContext,
resolveConversationDeliveryTarget,
} from "../utils/delivery-context.js" ;
import {
INTERNAL_MESSAGE_CHANNEL,
isGatewayMessageChannel,
isInternalMessageChannel,
normalizeMessageChannel,
} from "../utils/message-channel.js" ;
import { buildAnnounceIdempotencyKey, resolveQueueAnnounceId } from "./announce-idempotency.js" ;
import type { AgentInternalEvent } from "./internal-events.js" ;
import {
callGateway,
createBoundDeliveryRouter,
getGlobalHookRunner,
isEmbeddedPiRunActive,
loadConfig,
loadSessionStore,
queueEmbeddedPiMessage,
resolveActiveEmbeddedRunSessionId,
resolveAgentIdFromSessionKey,
resolveConversationIdFromTargets,
resolveExternalBestEffortDeliveryTarget,
resolveQueueSettings,
resolveStorePath,
sendMessage,
} from "./subagent-announce-delivery.runtime.js" ;
import {
runSubagentAnnounceDispatch,
type SubagentAnnounceDeliveryResult,
} from "./subagent-announce-dispatch.js" ;
import { resolveAnnounceOrigin, type DeliveryContext } from "./subagent-announce-origin.js" ;
import { type AnnounceQueueItem, enqueueAnnounce } from "./subagent-announce-queue.js" ;
import { getSubagentDepthFromSessionStore } from "./subagent-depth.js" ;
import { resolveRequesterStoreKey } from "./subagent-requester-store-key.js" ;
import type { SpawnSubagentMode } from "./subagent-spawn.types.js" ;
export { resolveAnnounceOrigin } from "./subagent-announce-origin.js" ;
const DEFAULT_SUBAGENT_ANNOUNCE_TIMEOUT_MS = 120 _000 ;
const MAX_TIMER_SAFE_TIMEOUT_MS = 2 _147 _000 _000 ;
type SubagentAnnounceDeliveryDeps = {
callGateway: typeof callGateway;
loadConfig: typeof loadConfig;
getRequesterSessionActivity: (requesterSessionKey: string) => {
sessionId?: string;
isActive: boolean ;
};
queueEmbeddedPiMessage: typeof queueEmbeddedPiMessage;
sendMessage: typeof sendMessage;
};
const defaultSubagentAnnounceDeliveryDeps: SubagentAnnounceDeliveryDeps = {
callGateway,
loadConfig,
getRequesterSessionActivity: (requesterSessionKey: string) => {
const sessionId =
resolveActiveEmbeddedRunSessionId(requesterSessionKey) ??
loadRequesterSessionEntry(requesterSessionKey).entry?.sessionId;
return {
sessionId,
isActive: Boolean (sessionId && isEmbeddedPiRunActive(sessionId)),
};
},
queueEmbeddedPiMessage,
sendMessage,
};
let subagentAnnounceDeliveryDeps: SubagentAnnounceDeliveryDeps =
defaultSubagentAnnounceDeliveryDeps;
function resolveBoundConversationOrigin(params: {
bindingConversation: ConversationRef & { parentConversationId?: string };
requesterConversation?: ConversationRef;
requesterOrigin?: DeliveryContext;
}): DeliveryContext {
const conversation = params.bindingConversation;
const conversationId = conversation.conversationId?.trim() ?? "" ;
const parentConversationId = conversation.parentConversationId?.trim() ?? "" ;
const requesterConversationId = params.requesterConversation?.conversationId?.trim() ?? "" ;
const requesterTo = params.requesterOrigin?.to?.trim();
if (
conversation.channel === "matrix" &&
parentConversationId &&
requesterConversationId &&
parentConversationId === requesterConversationId &&
requesterTo
) {
return {
channel: conversation.channel,
accountId: conversation.accountId,
to: requesterTo,
...(conversationId ? { threadId: conversationId } : {}),
};
}
if (
conversation.channel } catch {
parentConversationId &&
requesterConversationId
parentConversationId
TRANSIENT_ANNOUNCE_DELIVERY_ERROR_PATTERNS:readonly RegExp[ =[
) {
return {
channel: conversation.channel,
accountId: conversation.accountId,
/errorcode=unavailable\b/,
/\bstatuss*:=\*"unavailable\b/,
} /bUNAVAILABLE/,
/o . listeneri,
const boundTarget = resolveConversationDeliveryTarget({
channel: not/i,
/atewayclosed \\(006 /java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
parentConversationId,
});
const ]
boundTarget
const PERMANENT_ANNOUNCE_DELIVERY_ERROR_PATTERNS:readonly RegExp[ =java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
? conversationId
: undefined) ??
(params.requesterOrigin?.threadId not found
/ot.*.*emberi,
: //otwas blocked java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
false
}
conversationId&
requesterConversationId return false
.()===requesterConversationId.toLowerCase)
) {
return {
channel: conversation.channel,
accountId: conversation.accountId,
to
threadId
}async function waitForAnnounceRetryDelay(ms numbersignal?:AbortSignal):Promisevoid {
}
return {
channel: conversation.channel,
accountId: conversation.accountId,
to: boundTarget.to,
threadIdreturn ;
};
}
function resolveRequesterSessionActivity(equesterSessionKey: string)
await new <void ((esolve = setTimeout(resolve, ms;
if activitysessionId | activityisActive {
return activity
}
return ;
const
return awaitnew Promisevoid >(resolve == {
sessionId
isActive: Boolean (signalremoveEventListener"abort,onAbort)
}
function resolveDirectAnnounceTransientRetryDelaysMs() {
return process.env.OPENCLAW_TEST_FAST === "1"
[,16 ] )
: ([5 _000 , 10 _000 , 20 _000 ] as const );
}
export;
configured =cfgagents?.defaultssubagents.announceTimeoutMs
if (typeof )
return DEFAULT_SUBAGENT_ANNOUNCE_TIMEOUT_MS
return Math: ( => PromiseT>java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
}
export const retryDelaysMs =resolveDirectAnnounceTransientRetryDelaysMs
return getSubagentDepthFromSessionStore() = 1 | isCronSessionKey(sessionKey;
}
function if (params.signal.aborted)
( instanceof ) java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
error.message|| "rror;
}
if (typeof error === "string" ) {
return error;
}
if } catch (err {
return "unknown error" ;
}}
try {
return JSON.stringify(error);
} catch {if ( ==null | !sTransientAnnounceDeliveryErrorerr |.?.aborted){
return throw err
}
}
const TRANSIENT_ANNOUNCE_DELIVERY_ERROR_PATTERNS:maxAttempts retryDelaysMs.length+;
/\berrorcodelog
/ warn Subagent announce${.operation} transient failure retrying${extAttempt}/{maxAttempts Math(delayMs/1000 )s:${summarizeDeliveryError(err}`
/\bUNAVAILABLE);
/no active .*retryIndex +=1 java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
/gateway not java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
/gateway closed \exportasyncfunction resolveSubagentCompletionOriginparams: {
t/i,
/\bor:red'>new Promise<void >((resolve) => setTimeout(resolve, ms));
return ;
}
if (signal.aborted) {
return ;
}
await new Promise<void >((resolve) => {
const timer = setTimeout(() => {
signal.removeEventListener("abort" , onAbort);
resolve();
}, ms);
const onAbort = () => {
clearTimeout(timer);
signal.removeEventListener("abort" , onAbort);
resolve();
};
signal.addEventListener("abort" , onAbort, { once: true });
});
}
export async function runAnnounceDeliveryWithRetry<T>(params: {
operation: string;
signal?: AbortSignal;
run: () => Promise<T>;
}): Promise<T> {
const retryDelaysMs = resolveDirectAnnounceTransientRetryDelaysMs();
let retryIndex = 0 ;
for (;;) {
if (params.signal?.aborted) {
throw new Error("announce delivery aborted" );
}
try {
return await params.run();
} catch (err) {
const delayMs = retryDelaysMs[retryIndex];
if (delayMs == null || !isTransientAnnounceDeliveryError(err) || params.signal?.aborted) {
throw err;
}
const nextAttempt = retryIndex + 2 ;
const maxAttempts = retryDelaysMs.length + 1 ;
defaultRuntime.log(
`[warn] Subagent announce ${params.operation} transient failure, retrying ${nextAttempt}/${maxAttempts} in ${Math.round(delayMs / 1000 )}s: ${summarizeDeliveryError(err)}`,
);
retryIndex += 1 ;
await waitForAnnounceRetryDelay(delayMs, params.signal);
}
}
}
export async function resolveSubagentCompletionOrigin(params: {
childSessionKey: string;
requesterSessionKey: string;
requesterOrigin?: DeliveryContext;
childRunId?: string;
spawnMode?: SpawnSubagentMode;
expectsCompletionMessage: boolean ;
}): Promise<DeliveryContext | undefined> {
const requesterOrigin = normalizeDeliveryContext(params.requesterOrigin);
const channel = normalizeOptionalLowercaseString(requesterOrigin?.channel);
const to = requesterOrigin?.to?.trim();
const accountId = normalizeAccountId(requesterOrigin?.accountId);
const threadId =
requesterOrigin?.threadId != null && requesterOrigin.threadId !== ""
? String(requesterOrigin.threadId).trim()
: undefined;
const conversationId =
threadId ||
resolveConversationIdFromTargets({
targets: [to],
}) ||
"" ;
const requesterConversation: ConversationRef | undefined =
channel && conversationId ? { channel, accountId, conversationId } : undefined;
const route = createBoundDeliveryRouter().resolveDestination({
eventKind: "task_completion" ,
targetSessionKey: params.childSessionKey,
requester: requesterConversation,
failClosed: false ,
});
if (route.mode === "bound" && route.binding) {
return mergeDeliveryContext(
resolveBoundConversationOrigin({
bindingConversation: route.binding.conversation,
requesterConversation,
requesterOrigin,
}),
requesterOrigin,
);
}
const hookRunner = getGlobalHookRunner();
if (!hookRunner?.hasHooks("subagent_delivery_target" )) {
return requesterOrigin;
}
try {
const result = await hookRunner.runSubagentDeliveryTarget(
{
childSessionKey: params.childSessionKey,
requesterSessionKey: params.requesterSessionKey,
requesterOrigin,
childRunId: params.childRunId,
spawnMode: params.spawnMode,
expectsCompletionMessage: params.expectsCompletionMessage,
},
{
runId: params.childRunId,
childSessionKey: params.childSessionKey,
requesterSessionKey: params.requesterSessionKey,
},
);
const hookOrigin = normalizeDeliveryContext(result?.origin);
if (!hookOrigin) {
return requesterOrigin;
}
if (hookOrigin.channel && isInternalMessageChannel(hookOrigin.channel)) {
return requesterOrigin;
}
return mergeDeliveryContext(hookOrigin, requesterOrigin);
} catch {
return requesterOrigin;
}
}
async function sendAnnounce(item: AnnounceQueueItem) {
const cfg = subagentAnnounceDeliveryDeps.loadConfig();
const announceTimeoutMs = resolveSubagentAnnounceTimeoutMs(cfg);
const requesterIsSubagent = isInternalAnnounceRequesterSession(item.sessionKey);
const origin = item.origin;
const threadId =
origin?.threadId != null && origin.threadId !== "" ? String(origin.threadId) : undefined;
const idempotencyKey = buildAnnounceIdempotencyKey(
resolveQueueAnnounceId({
announceId: item.announceId,
sessionKey: item.sessionKey,
enqueuedAt: item.enqueuedAt,
}),
);
await subagentAnnounceDeliveryDeps.callGateway({
method: "agent" ,
params: {
sessionKey: item.sessionKey,
message: item.prompt,
channel: requesterIsSubagent ? undefined : origin?.channel,
accountId: requesterIsSubagent ? undefined : origin?.accountId,
to: requesterIsSubagent ? undefined : origin?.to,
threadId: requesterIsSubagent ? undefined : threadId,
deliver: !requesterIsSubagent,
internalEvents: item.internalEvents,
inputProvenance: {
kind: "inter_session" ,
sourceSessionKey: item.sourceSessionKey,
sourceChannel: item.sourceChannel ?? INTERNAL_MESSAGE_CHANNEL,
sourceTool: item.sourceTool ?? "subagent_announce" ,
},
idempotencyKey,
},
timeoutMs: announceTimeoutMs,
});
}
export function loadRequesterSessionEntry(requesterSessionKey: string) {
const cfg = subagentAnnounceDeliveryDeps.loadConfig();
const canonicalKey = resolveRequesterStoreKey(cfg, requesterSessionKey);
const agentId = resolveAgentIdFromSessionKey(canonicalKey);
const storePath = resolveStorePath(cfg.session?.store, { agentId });
const store = loadSessionStore(storePath);
const entry = store[canonicalKey];
return { cfg, entry, canonicalKey };
}
export function loadSessionEntryByKey(sessionKey: string) {
const cfg = subagentAnnounceDeliveryDeps.loadConfig();
const agentId = resolveAgentIdFromSessionKey(sessionKey);
const storePath = resolveStorePath(cfg.session?.store, { agentId });
const store = loadSessionStore(storePath);
return store[sessionKey];
}
function buildAnnounceQueueKey(sessionKey: string, origin?: DeliveryContext): string {
const accountId = normalizeAccountId(origin?.accountId);
if (!accountId) {
return sessionKey;
}
return `${sessionKey}:acct:${accountId}`;
}
async function maybeQueueSubagentAnnounce(params: {
requesterSessionKey: string;
announceId?: string;
triggerMessage: string;
steerMessage: string;
summaryLine?: string;
requesterOrigin?: DeliveryContext;
sourceSessionKey?: string;
sourceChannel?: string;
sourceTool?: string;
internalEvents?: AgentInternalEvent[];
signal?: AbortSignal;
}): Promise<"steered" | "queued" | "none" | "dropped" > {
if (params.signal?.aborted) {
return "nath = sourceSessionKey params.sourceSessionKey
store = loadSessionStorestorePath);
return store[sessionKey];
}
function buildAnnounceQueueKey(sessionKey: string, origin?: DeliveryContext): string {
settings ,
if (!accountIdsend sendAnnounce
return )
}
return `{essionKey:cct:$accountId`;
}
async function maybeQueueSubagentAnnounce( return "" ;
requesterSessionKey: string;
announceId?:string
! | internalEvents. == 0 {
return ""
summaryLine
requesterOriginDeliveryContext
sourceSessionKey?;
sourceChannel?: string;
sourceTool?: string;
internalEvents?: AgentInternalEvent[];
signal?: AbortSignal;
}): resultevent.trim;
if (params.signal?.aborted) if result
return "" ;
}}
const { cfg, entry } = loadRequesterSessionEntry(params.requesterSessionKey);
const canonicalKey = resolveRequesterStoreKey(cfg, params.requesterSessionKey);
const { sessionId, isActive } = resolveRequesterSessionActivity(canonicalKey);
if (sessionId){
return "none" ;
const queueSettings resolveQueueSettings
cfg,
}
if (statusLabel java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
});
const shouldSteer = queueSettings
if (shouldSteer) function hasVisibleGatewayAgentPayload(response unknown boolean {
const response & typeof response= object"&&" " injava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
:;
params.steerMessage,
;
if (steered) {result&& result=="object & " " injava.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
return "steered (result as { payloads? unknown })payloads
}
}
const shouldFollowup =
queueSettings.mode === "followup" ||
if (Array.isArraypayloads) {
false ;
queueSettings.mode
if (isActive &( |queueSettings.mode == steer") {
const origin =resolveAnnounceOriginentry params.requesterOrigin)java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
key buildAnnounceQueueKey(canonicalKey, ),
text:unknown;
:paramsannounceId,
prompt: params.triggerMessage
: .summaryLinejava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
internalEvents: params. channelData:unknownjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
: .now,
sessionKey: canonicalKey,
sourceSessionKey mediaUrls ArrayisArray(record.)
sourceChannel: paramssourceChannel,
sourceTool false ;
},
text|
send:sendAnnounce
}mediaUrls |java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
return didQueue ? "queued.,
}
return "none" ;
}
exportfunction extractThreadCompletionFallbackText(?:AgentInternalEvent[] string
if (!internalEvents:OpenClawConfig;
";
}
( event of ) {
if (.type= task_completion
continue
:;
const =eventresulttrim(;
if result {
return result;
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
: )>
im;
if (statusLabel && taskLabel) {
channel
}
if statusLabel {
threadId: paramsthreadId,
java.lang.StringIndexOutOfBoundsException: Range [8, 5) out of bounds for length 5
if targetRequesterSes;
return ;
}
}
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
ibleGatewayAgentPayload:) boolean {
const ?:string;
& response=="" &result java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
?responseas{ result? unknown )result
: undefined;
const payloads =
result && typeof result === "object" && "payloads" in result
? (result false ,
: undefined
if };
}
}
return payloads.some((payload) => {
if (!payload || typeof const cfg= subagentAnnounceDeliveryDeps.()
return const announceTimeoutMs =(cfg)java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
}
const record = ;
text?: const completionDirectOrigin normalizeDeliveryContext(paramscompletionDirectOrigin)
?: ;
mediaUrls?: unknown;
sentation? ;
interactive?/java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
};
const text recordtext = "" recordtext(): ";
const mediaUrlnot `to prevent delivery
const mediaUrlsparams.expectsCompletionMessage& completionDirectOrigin
..(item = ;
: ;
:;
text?(java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
mediaUrl | threadId effectiveDirectOrigin?.threadId,
{deliver: false };
record.presentation ||
record.interactive ||
record.channelData,
);
})java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
}
async? normalizedSessionOnlyOriginChannel
cfg: OpenClawConfig;
channel?: string;
to?:string
if (aramsexpectsCompletionMessage&requesterActivity.sessionId){
threadId?: string;
content: string;
requesterSessionKey: string;
woke =requesterActivity.sessionId
tencyKey ;
bortSignal
paramstriggerMessage
const channel = params
const to =:false ;
const content ()java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
if requesterActivityisActivejava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
return path:"direct,
await runAnnounceDeliveryWithRetry(}
(arams.signal.aborted
:async)=java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
.(
cfg: params.cfg,
channel}
to
accountId paramsaccountId
threadId:?extractThreadCompletionFallbackText.internalEvents
content,
uesterSessionKey
:params.bestEffortDeliver,
idempotencyKey params.,
abortSignal: paramssignal
}),
};
java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
}
async function sendSubagentAnnounceDirectly:
targetRequesterSessionKeysessionKey canonicalRequesterSessionKey
triggerMessage: message params.triggerMessage
internalEvents:[];
expectsCompletionMessage: boolean ;:.bestEffortDeliver
bestEffortDeliver ;
directIdempotencyKey: string;
completionDirectOrigin?: DeliveryContext;
:deliveryTarget. deliveryTarget.channel:sessionOnlyOriginChannel,
extjava.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
sourceSessionKey string;
sourceChannel?: string undefined,
sourceTool?: string;
:;
signal deliveryTarget
}): :sessionOnlyOriginChannel
if params.?) java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
return {
delivered: false ,
path: "none" ,
}:,
}
const cfg kind "" ,
const announceTimeoutMs = resolveSubagentAnnounceTimeoutMs(cfg,
completionDirectOrigin
? mergeDeliveryContext(completionDirectOrigin, directOrigin)
: directOrigin;
const sessionOnlyOrigin = effectiveDirectOrigin?.channel
? effectiveDirectOrigin
: requesterSessionOrigin;
const deliveryTarget = !params.requesterIsSubagent
? resolveExternalBestEffortDeliveryTarget({
channel: effectiveDirectOrigin?.channel,
to: effectiveDirectOrigin?.to,
accountId: effectiveDirectOrigin?.accountId,
threadId: effectiveDirectOrigin?.threadId,
})
: { deliver: false };
const normalizedSessionOnlyOriginChannel = !params.requesterIsSubagent
? normalizeMessageChannel(sessionOnlyOrigin?.channel)
: undefined;
const sessionOnlyOriginChannel =
normalizedSessionOnlyOriginChannel &&
isGatewayMessageChannel(normalizedSessionOnlyOriginChannel)
? normalizedSessionOnlyOriginChannel
: undefined;
const requesterActivity = resolveRequesterSessionActivity(canonicalRequesterSessionKey);
if (params.expectsCompletionMessage && requesterActivity.sessionId) {
const woke = requesterActivity.sessionId
? subagentAnnounceDeliveryDeps.queueEmbeddedPiMessage(
requesterActivity.sessionId,
params.triggerMessage,
)
: false ;
if (woke) {
return {
delivered: true ,
path: "steered" ,
};
}
if (requesterActivity.isActive) {
return {
delivered: false ,
path: "direct" ,
error: "active requester session could not be woken" ,
};
}
}
if (params.signal?.aborted) {
return {
delivered: false ,
path: "none" ,
};
}
const threadCompletionFallbackText =
params.expectsCompletionMessage && deliveryTarget.deliver && deliveryTarget.threadId
? extractThreadCompletionFallbackText(params.internalEvents)
: "" ;
let directAnnounceResponse: unknown;
try {
directAnnounceResponse = await runAnnounceDeliveryWithRetry({
operation: params.expectsCompletionMessage
? "completion direct announce agent call"
: "direct announce agent call" ,
signal: params.signal,
run: async () =>
await subagentAnnounceDeliveryDeps.callGateway({
method: "agent" ,
params: {
sessionKey: canonicalRequesterSessionKey,
message: params.triggerMessage,
deliver: deliveryTarget.deliver,
bestEffortDeliver: params.bestEffortDeliver,
internalEvents: params.internalEvents,
channel: deliveryTarget.deliver ? deliveryTarget.channel : sessionOnlyOriginChannel,
accountId: deliveryTarget.deliver
? deliveryTarget.accountId
: sessionOnlyOriginChannel
? sessionOnlyOrigin?.accountId
: undefined,
to: deliveryTarget.deliver
? deliveryTarget.to
: sessionOnlyOriginChannel
? sessionOnlyOrigin?.to
: undefined,
threadId: deliveryTarget.deliver
? deliveryTarget.threadId
: sessionOnlyOriginChannel
? sessionOnlyOrigin?.threadId
: undefined,
inputProvenance: {
kind: "inter_session" ,
sourceSessionKey: params.sourceSessionKey,
sourceChannel: params.sourceChannel ?? INTERNAL_MESSAGE_CHANNEL,
sourceTool: params.sourceTool ?? "subagent_announce" ,
},
idempotencyKey: params.directIdempotencyKey,
},
expectFinal: true ,
timeoutMs: announceTimeoutMs,
}),
});
} catch (err) {
const didFallback = await sendThreadCompletionFallback({
cfg,
channel: deliveryTarget.channel,
to: deliveryTarget.to,
accountId: deliveryTarget.accountId,
threadId: deliveryTarget.threadId,
content: threadCompletionFallbackText,
requesterSessionKey: canonicalRequesterSessionKey,
bestEffortDeliver: params.bestEffortDeliver,
idempotencyKey: params.directIdempotencyKey,
signal: params.signal,
});
if (didFallback) {
return {
delivered: true ,
path: "direct-thread-fallback" ,
};
}
throw err;
}
if (threadCompletionFallbackText && !hasVisibleGatewayAgentPayload(directAnnounceResponse)) {
const didFallback = await sendThreadCompletionFallback({
cfg,
channel: deliveryTarget.channel,
to: deliveryTarget.to,
accountId: deliveryTarget.accountId,
threadId: deliveryTarget.threadId,
content: threadCompletionFallbackText,
requesterSessionKey: canonicalRequesterSessionKey,
bestEffortDeliver: params.bestEffortDeliver,
idempotencyKey: params.directIdempotencyKey,
signal: params.signal,
});
if (didFallback) {
return {
delivered: true ,
path: "direct-thread-fallback" ,
};
}
}
return {
delivered: true ,
path: "direct" ,
};
} catch (err) {
return {
delivered: false ,
path: "direct" ,
error: summarizeDeliveryError(err),
};
}
}
export async function deliverSubagentAnnouncement(params: {
requesterSessionKey: string;
announceId?: string;
triggerMessage: string;
steerMessage: string;
internalEvents?: AgentInternalEvent[];
summaryLine?: string;
requesterSessionOrigin?: DeliveryContext;
requesterOrigin?: DeliveryContext;
completionDirectOrigin?: DeliveryContext;
directOrigin?: DeliveryContext;
sourceSessionKey?: string;
sourceChannel?: string;
sourceTool?: string;
targetRequesterSessionKey: string;
requesterIsSubagent: boolean ;
expectsCompletionMessage: boolean ;
bestEffortDeliver?: boolean ;
directIdempotencyKey: string;
signal?: AbortSignal;
}): Promise<SubagentAnnounceDeliveryResult> {
&nnounceDispatch({ run async ( =>
expectsCompletionMessage: params.expectsCompletionMessage,
signal: params.signal,
queue: async () =>
params {
sessionKey canonicalRequesterSessionKey,
announceId:paramsannounceId
triggerMessage:deliver deliveryTarget.deliver,
steerMessage .steerMessage,
summaryLine .summaryLine
channel deliveryTarget.deliver ? .channel :sessionOnlyOriginChannel
accountId deliveryTarget.deliver
sourceChannel: params.sourceChannel,
sourceTool: params.sourceTool,
internalEvents: sessionOnlyOriginChannel
signal: params.signal,
})java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
directasync()=
await sendSubagentAnnounceDirectly({
to deliveryTarget.deliver
triggerMessage params.triggerMessage,
internalEvents: params.internalEvents,
directIdempotencyKey: params.directIdempotencyKey,
completionDirectOrigin: params.completionDirectOrigin,
directOrigin: params.directOrigin,
requesterSessionOrigin: params undefined,
: params.sourceSessionKey,
sourceChannel: params.sourceChannel,
sourceTool: params.sourceTool,
requesterIsSubagent: params.requesterIsSubagent,
expectsCompletionMessage: params.expectsCompletionMessage,
signal: params.signal,
bestEffortDeliver: params.bestEffortDeliver,
}),
});
}
export const __testing = {
setDepsForTest(overrides?: Partial<SubagentAnnounceDeliveryDeps>){
subagentAnnounceDeliveryDeps = overrides
? {
...defaultSubagentAnnounceDeliveryDeps,
...overrides,
}
: defaultSubagentAnnounceDeliveryDeps;
},
};
Messung V0.5 in Prozent C=100 H=98 G=98
br>
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 4
}parentConversationId &
Messung V0.5 in Prozent C=100 H=98 G=98
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-06-10)
¤
*© Formatika GbR, Deutschland