diff --git a/packages/cli/src/test-utils/AppRig.tsx b/packages/cli/src/test-utils/AppRig.tsx index 548372a139..c1f5122d3d 100644 --- a/packages/cli/src/test-utils/AppRig.tsx +++ b/packages/cli/src/test-utils/AppRig.tsx @@ -609,13 +609,15 @@ export class AppRig { this.removeToolPolicy(pending.toolName); } - // eslint-disable-next-line @typescript-eslint/no-floating-promises - messageBus.publish({ + const p = messageBus.publish({ type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, correlationId: pending.correlationId, confirmed: outcome !== ToolConfirmationOutcome.Cancel, outcome, }); + if (p instanceof Promise) { + p.catch(() => {}); + } }); await act(async () => { diff --git a/packages/core/src/agents/local-invocation.ts b/packages/core/src/agents/local-invocation.ts index 2c522c04e4..7df118d6f2 100644 --- a/packages/core/src/agents/local-invocation.ts +++ b/packages/core/src/agents/local-invocation.ts @@ -90,13 +90,18 @@ export class LocalSubagentInvocation extends BaseToolInvocation< } private publishActivity(activity: SubagentActivityItem): void { - void this.messageBus - .publish({ + try { + const p = this.messageBus.publish({ type: MessageBusType.SUBAGENT_ACTIVITY, subagentName: this.definition.displayName ?? this.definition.name, activity, - }) - .catch(() => {}); + }); + if (p instanceof Promise) { + p.catch(() => {}); + } + } catch { + // Ignore errors in fire-and-forget activity update + } } /** diff --git a/packages/core/src/confirmation-bus/message-bus.test.ts b/packages/core/src/confirmation-bus/message-bus.test.ts index 4a05faa24a..4708c41d4c 100644 --- a/packages/core/src/confirmation-bus/message-bus.test.ts +++ b/packages/core/src/confirmation-bus/message-bus.test.ts @@ -293,13 +293,14 @@ describe('MessageBus', () => { MessageBusType.TOOL_CONFIRMATION_REQUEST, (msg) => { if (msg.subagent === subagentName) { - void messageBus - .publish({ - type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, - correlationId: msg.correlationId, - confirmed: true, - }) - .catch(() => {}); + const p = messageBus.publish({ + type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, + correlationId: msg.correlationId, + confirmed: true, + }); + if (p instanceof Promise) { + p.catch(() => {}); + } resolve(); } }, @@ -337,13 +338,14 @@ describe('MessageBus', () => { MessageBusType.TOOL_CONFIRMATION_REQUEST, (msg) => { if (msg.subagent === 'agent1/agent2') { - void messageBus - .publish({ - type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, - correlationId: msg.correlationId, - confirmed: true, - }) - .catch(() => {}); + const p = messageBus.publish({ + type: MessageBusType.TOOL_CONFIRMATION_RESPONSE, + correlationId: msg.correlationId, + confirmed: true, + }); + if (p instanceof Promise) { + p.catch(() => {}); + } resolve(); } }, diff --git a/packages/core/src/confirmation-bus/message-bus.ts b/packages/core/src/confirmation-bus/message-bus.ts index b57ee851f2..f64ec6f1d7 100644 --- a/packages/core/src/confirmation-bus/message-bus.ts +++ b/packages/core/src/confirmation-bus/message-bus.ts @@ -11,6 +11,7 @@ import { PolicyDecision } from '../policy/types.js'; import { MessageBusType, type Message } from './types.js'; import { safeJsonStringify } from '../utils/safeJsonStringify.js'; import { debugLogger } from '../utils/debugLogger.js'; +import { sanitizeToolArgs } from '../utils/agent-sanitization-utils.js'; export class MessageBus extends EventEmitter { private listenerToAbortCleanup = new WeakMap< @@ -78,12 +79,16 @@ export class MessageBus extends EventEmitter { async publish(message: Message): Promise { if (this.debug) { - debugLogger.debug(`[MESSAGE_BUS] publish: ${safeJsonStringify(message)}`); + debugLogger.debug( + `[MESSAGE_BUS] publish: ${safeJsonStringify(sanitizeToolArgs(message))}`, + ); } try { if (!this.isValidMessage(message)) { throw new Error( - `Invalid message structure: ${safeJsonStringify(message)}`, + `Invalid message structure: ${safeJsonStringify( + sanitizeToolArgs(message), + )}`, ); } diff --git a/packages/core/src/scheduler/state-manager.ts b/packages/core/src/scheduler/state-manager.ts index 3a852fe4d8..de5e35b937 100644 --- a/packages/core/src/scheduler/state-manager.ts +++ b/packages/core/src/scheduler/state-manager.ts @@ -244,13 +244,18 @@ export class SchedulerStateManager { const snapshot = this.getSnapshot(); // Fire and forget - The message bus handles the publish and error handling. - void this.messageBus - .publish({ + try { + const p = this.messageBus.publish({ type: MessageBusType.TOOL_CALLS_UPDATE, toolCalls: snapshot, schedulerId: this.schedulerId, - }) - .catch(() => {}); + }); + if (p instanceof Promise) { + p.catch(() => {}); + } + } catch { + // Ignore errors in fire-and-forget update + } } private isTerminalCall(call: ToolCall): call is CompletedToolCall { diff --git a/packages/core/src/tools/tools.ts b/packages/core/src/tools/tools.ts index 7533d80e7e..b1eb419355 100644 --- a/packages/core/src/tools/tools.ts +++ b/packages/core/src/tools/tools.ts @@ -242,14 +242,19 @@ export abstract class BaseToolInvocation< ) { if (this._toolName) { const options = this.getPolicyUpdateOptions(outcome); - void this.messageBus - .publish({ + try { + const p = this.messageBus.publish({ type: MessageBusType.UPDATE_POLICY, toolName: this._toolName, persist: outcome === ToolConfirmationOutcome.ProceedAlwaysAndSave, ...options, - }) - .catch(() => {}); + }); + if (p instanceof Promise) { + p.catch(() => {}); + } + } catch { + // Ignore errors in fire-and-forget update + } } } } @@ -363,10 +368,18 @@ export abstract class BaseToolInvocation< ); }; - this.messageBus.publish(request).catch(() => { + try { + const p = this.messageBus.publish(request); + if (p instanceof Promise) { + p.catch(() => { + cleanup(); + resolve('allow'); + }); + } + } catch { cleanup(); resolve('allow'); - }); + } }); }