n8n 2.47.3 → 2.47.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -134,6 +134,7 @@ export declare class InstanceAiService {
134
134
  getActiveRunId(threadId: string): string | undefined;
135
135
  private stopRunsForQuotaExhaustion;
136
136
  cancelRun(threadId: string, reason?: string): void;
137
+ private settleCancelledSuspension;
137
138
  sendCorrectionToTask(threadId: string, taskId: string, correction: string): 'queued' | 'task-completed' | 'task-not-found';
138
139
  cancelBackgroundTask(threadId: string, taskId: string): void;
139
140
  private broadcastTaskControl;
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var InstanceAiService_1;
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.InstanceAiService = exports.QuotaExhaustedStreamError = exports.isAssistantCreditBalanceExhausted = void 0;
14
+ const agents_1 = require("@n8n/agents");
14
15
  const api_types_1 = require("@n8n/api-types");
15
16
  const backend_common_1 = require("@n8n/backend-common");
16
17
  const backend_services_1 = require("@n8n/backend-services");
@@ -86,6 +87,14 @@ function isTelemetryConfigurableAgent(agent) {
86
87
  agent !== null &&
87
88
  typeof Reflect.get(agent, 'telemetry') === 'function');
88
89
  }
90
+ function describeMemoryTaskOutcome(value) {
91
+ if (!(0, is_record_1.isRecord)(value) || typeof value.status !== 'string')
92
+ return {};
93
+ return {
94
+ outcome: value.status,
95
+ ...(typeof value.reason === 'string' ? { reason: value.reason } : {}),
96
+ };
97
+ }
89
98
  const WORKFLOW_SETUP_ROUTING_CLAIM_TTL_MS = 15 * 60 * 1000;
90
99
  const CONFIRMATION_EXPIRED_MESSAGE = 'This confirmation has expired. Send a new message to continue.';
91
100
  const RESUME_REJECTED_MESSAGE = 'I could not apply that confirmation. Send a new message to continue.';
@@ -408,13 +417,7 @@ let InstanceAiService = InstanceAiService_1 = class InstanceAiService {
408
417
  pendingCount: pendingTasks.length,
409
418
  ...(event.type === 'skipped' ? { reason: event.reason } : {}),
410
419
  ...(event.type === 'failed' ? { error: (0, get_error_message_1.getErrorMessage)(event.error) } : {}),
411
- ...(event.type === 'completed' &&
412
- event.value &&
413
- typeof event.value === 'object' &&
414
- 'status' in event.value &&
415
- typeof event.value.status === 'string'
416
- ? { outcome: event.value.status }
417
- : {}),
420
+ ...(event.type === 'completed' ? describeMemoryTaskOutcome(event.value) : {}),
418
421
  };
419
422
  this.logger.info(`Observational memory task ${event.type}`, logContext);
420
423
  };
@@ -714,6 +717,7 @@ let InstanceAiService = InstanceAiService_1 = class InstanceAiService {
714
717
  ...(suspended.modelId !== undefined ? { modelId: suspended.modelId } : {}),
715
718
  promptVersion: suspended.orchestrationContext?.promptConfiguration?.version,
716
719
  });
720
+ void this.settleCancelledSuspension(threadId, suspended.user.id);
717
721
  }
718
722
  else {
719
723
  void this.finalizeCancelledSuspendedRun(suspended, reason);
@@ -721,6 +725,17 @@ let InstanceAiService = InstanceAiService_1 = class InstanceAiService {
721
725
  }
722
726
  void this.suspendedThreads.dropPendingConfirmationsForThread(threadId);
723
727
  }
728
+ async settleCancelledSuspension(threadId, resourceId) {
729
+ try {
730
+ await (0, agents_1.settleAbandonedToolCallsInMemory)(this.agentMemory, { threadId, resourceId });
731
+ }
732
+ catch (error) {
733
+ this.logger.warn('Failed to settle the tool call of a cancelled suspended run', {
734
+ threadId,
735
+ error: (0, get_error_message_1.getErrorMessage)(error),
736
+ });
737
+ }
738
+ }
724
739
  sendCorrectionToTask(threadId, taskId, correction) {
725
740
  return this.backgroundTasks.queueCorrection(threadId, taskId, correction);
726
741
  }
@@ -2995,6 +3010,7 @@ let InstanceAiService = InstanceAiService_1 = class InstanceAiService {
2995
3010
  }
2996
3011
  }
2997
3012
  async finalizeCancelledSuspendedRun(suspended, reason = 'user_cancelled') {
3013
+ void this.settleCancelledSuspension(suspended.threadId, suspended.user.id);
2998
3014
  const runTimeout = reason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON
2999
3015
  ? this.liveness.consumeRunTimeout(suspended.runId)
3000
3016
  : undefined;