fix: cron sessions inherit allowAgents from parent agent config (#1771)

When a cron job runs in isolated mode, the sessions_spawn tool now correctly
inherits the allowAgents permissions from the parent agent's config.

The fix adds a requesterAgentIdOverride parameter that flows through the
tool creation chain:
- resolveEffectiveToolPolicy() extracts the correct agentId from the session key
- This agentId is passed to sessions_spawn and agents_list tools
- The tools use this override instead of re-parsing the session key

This fixes #1767
This commit is contained in:
/noctivoro-x
2026-01-25 06:10:48 -07:00
committed by GitHub
parent f618859761
commit abedc8bf7f
4 changed files with 17 additions and 4 deletions

View File

@@ -54,6 +54,8 @@ export function createClawdbotTools(options?: {
hasRepliedRef?: { value: boolean }; hasRepliedRef?: { value: boolean };
/** If true, the model has native vision capability */ /** If true, the model has native vision capability */
modelHasVision?: boolean; modelHasVision?: boolean;
/** Explicit agent ID override for cron/hook sessions. */
requesterAgentIdOverride?: string;
}): AnyAgentTool[] { }): AnyAgentTool[] {
const imageTool = options?.agentDir?.trim() const imageTool = options?.agentDir?.trim()
? createImageTool({ ? createImageTool({
@@ -105,7 +107,10 @@ export function createClawdbotTools(options?: {
agentSessionKey: options?.agentSessionKey, agentSessionKey: options?.agentSessionKey,
config: options?.config, config: options?.config,
}), }),
createAgentsListTool({ agentSessionKey: options?.agentSessionKey }), createAgentsListTool({
agentSessionKey: options?.agentSessionKey,
requesterAgentIdOverride: options?.requesterAgentIdOverride,
}),
createSessionsListTool({ createSessionsListTool({
agentSessionKey: options?.agentSessionKey, agentSessionKey: options?.agentSessionKey,
sandboxed: options?.sandboxed, sandboxed: options?.sandboxed,
@@ -129,6 +134,7 @@ export function createClawdbotTools(options?: {
agentGroupChannel: options?.agentGroupChannel, agentGroupChannel: options?.agentGroupChannel,
agentGroupSpace: options?.agentGroupSpace, agentGroupSpace: options?.agentGroupSpace,
sandboxed: options?.sandboxed, sandboxed: options?.sandboxed,
requesterAgentIdOverride: options?.requesterAgentIdOverride,
}), }),
createSessionStatusTool({ createSessionStatusTool({
agentSessionKey: options?.agentSessionKey, agentSessionKey: options?.agentSessionKey,

View File

@@ -313,6 +313,7 @@ export function createClawdbotCodingTools(options?: {
replyToMode: options?.replyToMode, replyToMode: options?.replyToMode,
hasRepliedRef: options?.hasRepliedRef, hasRepliedRef: options?.hasRepliedRef,
modelHasVision: options?.modelHasVision, modelHasVision: options?.modelHasVision,
requesterAgentIdOverride: agentId,
}), }),
]; ];
const coreToolNames = new Set( const coreToolNames = new Set(

View File

@@ -19,7 +19,11 @@ type AgentListEntry = {
configured: boolean; configured: boolean;
}; };
export function createAgentsListTool(opts?: { agentSessionKey?: string }): AnyAgentTool { export function createAgentsListTool(opts?: {
agentSessionKey?: string;
/** Explicit agent ID override for cron/hook sessions. */
requesterAgentIdOverride?: string;
}): AnyAgentTool {
return { return {
label: "Agents", label: "Agents",
name: "agents_list", name: "agents_list",
@@ -37,7 +41,7 @@ export function createAgentsListTool(opts?: { agentSessionKey?: string }): AnyAg
}) })
: alias; : alias;
const requesterAgentId = normalizeAgentId( const requesterAgentId = normalizeAgentId(
parseAgentSessionKey(requesterInternalKey)?.agentId ?? DEFAULT_AGENT_ID, opts?.requesterAgentIdOverride ?? parseAgentSessionKey(requesterInternalKey)?.agentId ?? DEFAULT_AGENT_ID,
); );
const allowAgents = resolveAgentConfig(cfg, requesterAgentId)?.subagents?.allowAgents ?? []; const allowAgents = resolveAgentConfig(cfg, requesterAgentId)?.subagents?.allowAgents ?? [];

View File

@@ -67,6 +67,8 @@ export function createSessionsSpawnTool(opts?: {
agentGroupChannel?: string | null; agentGroupChannel?: string | null;
agentGroupSpace?: string | null; agentGroupSpace?: string | null;
sandboxed?: boolean; sandboxed?: boolean;
/** Explicit agent ID override for cron/hook sessions where session key parsing may not work. */
requesterAgentIdOverride?: string;
}): AnyAgentTool { }): AnyAgentTool {
return { return {
label: "Sessions", label: "Sessions",
@@ -129,7 +131,7 @@ export function createSessionsSpawnTool(opts?: {
}); });
const requesterAgentId = normalizeAgentId( const requesterAgentId = normalizeAgentId(
parseAgentSessionKey(requesterInternalKey)?.agentId, opts?.requesterAgentIdOverride ?? parseAgentSessionKey(requesterInternalKey)?.agentId,
); );
const targetAgentId = requestedAgentId const targetAgentId = requestedAgentId
? normalizeAgentId(requestedAgentId) ? normalizeAgentId(requestedAgentId)