diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/hooks/use-copilot-initialization.ts b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/hooks/use-copilot-initialization.ts index 809263a18..48a3ead80 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/hooks/use-copilot-initialization.ts +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/hooks/use-copilot-initialization.ts @@ -105,10 +105,10 @@ export function useCopilotInitialization(props: UseCopilotInitializationProps) { isSendingMessage, ]) - /** Load auto-allowed tools once on mount */ + /** Load auto-allowed tools once on mount - runs immediately, independent of workflow */ const hasLoadedAutoAllowedToolsRef = useRef(false) useEffect(() => { - if (hasMountedRef.current && !hasLoadedAutoAllowedToolsRef.current) { + if (!hasLoadedAutoAllowedToolsRef.current) { hasLoadedAutoAllowedToolsRef.current = true loadAutoAllowedTools().catch((err) => { logger.warn('[Copilot] Failed to load auto-allowed tools', err) diff --git a/apps/sim/stores/panel/copilot/store.ts b/apps/sim/stores/panel/copilot/store.ts index cc9d90cca..fd7552e12 100644 --- a/apps/sim/stores/panel/copilot/store.ts +++ b/apps/sim/stores/panel/copilot/store.ts @@ -1481,7 +1481,10 @@ const sseHandlers: Record = { // Check if tool is auto-allowed - if so, execute even if it has an interrupt const { autoAllowedTools: classAutoAllowed } = get() const isClassAutoAllowed = name ? classAutoAllowed.includes(name) : false - if ((!hasInterrupt || isClassAutoAllowed) && (typeof inst?.execute === 'function' || typeof inst?.handleAccept === 'function')) { + if ( + (!hasInterrupt || isClassAutoAllowed) && + (typeof inst?.execute === 'function' || typeof inst?.handleAccept === 'function') + ) { if (isClassAutoAllowed && hasInterrupt) { logger.info('[toolCallsById] Auto-executing class tool with interrupt (auto-allowed)', { id, @@ -2719,6 +2722,9 @@ export const useCopilotStore = create()( // Load sensitive credential IDs for masking before streaming starts await get().loadSensitiveCredentialIds() + // Ensure auto-allowed tools are loaded before tool calls arrive + await get().loadAutoAllowedTools() + let newMessages: CopilotMessage[] if (revertState) { const currentMessages = get().messages @@ -3782,10 +3788,7 @@ export const useCopilotStore = create()( const { id, name, params } = toolCall // Guard against double execution - skip if already executing or in terminal state - if ( - toolCall.state === ClientToolCallState.executing || - isTerminalState(toolCall.state) - ) { + if (toolCall.state === ClientToolCallState.executing || isTerminalState(toolCall.state)) { logger.info('[executeIntegrationTool] Skipping - already executing or terminal', { id, name,