diff --git a/internal-packages/run-engine/src/engine/errors.ts b/internal-packages/run-engine/src/engine/errors.ts index 9e7c4c40c8..e4ff702ee0 100644 --- a/internal-packages/run-engine/src/engine/errors.ts +++ b/internal-packages/run-engine/src/engine/errors.ts @@ -59,7 +59,8 @@ export function runStatusFromError(error: TaskRunError): TaskRunStatus { export class ServiceValidationError extends Error { constructor( message: string, - public status?: number + public status?: number, + public metadata?: Record ) { super(message); this.name = "ServiceValidationError"; diff --git a/internal-packages/run-engine/src/engine/index.ts b/internal-packages/run-engine/src/engine/index.ts index 7657431140..20ef7d53e8 100644 --- a/internal-packages/run-engine/src/engine/index.ts +++ b/internal-packages/run-engine/src/engine/index.ts @@ -1155,7 +1155,6 @@ export class RunEngine { } ); - await this.worker.ack(`heartbeatSnapshot.${runId}`); return; } diff --git a/internal-packages/run-engine/src/engine/systems/checkpointSystem.ts b/internal-packages/run-engine/src/engine/systems/checkpointSystem.ts index 5c6cf2aa57..bec173d960 100644 --- a/internal-packages/run-engine/src/engine/systems/checkpointSystem.ts +++ b/internal-packages/run-engine/src/engine/systems/checkpointSystem.ts @@ -270,11 +270,25 @@ export class CheckpointSystem { const snapshot = await getLatestExecutionSnapshot(prisma, runId); if (snapshot.id !== snapshotId) { - throw new ServiceValidationError("Snapshot ID doesn't match the latest snapshot", 400); + throw new ServiceValidationError( + "Snapshot ID doesn't match the latest snapshot in continueRunExecution", + 400, + { + snapshotId, + latestSnapshotId: snapshot.id, + } + ); } if (!isPendingExecuting(snapshot.executionStatus)) { - throw new ServiceValidationError("Snapshot is not in a valid state to continue", 400); + throw new ServiceValidationError( + "Snapshot is not in a valid state to continue in continueRunExecution", + 400, + { + snapshotId, + snapshotStatus: snapshot.executionStatus, + } + ); } // Get the run and update the status diff --git a/internal-packages/run-engine/src/engine/systems/executionSnapshotSystem.ts b/internal-packages/run-engine/src/engine/systems/executionSnapshotSystem.ts index a9d5600aea..4e5628d2de 100644 --- a/internal-packages/run-engine/src/engine/systems/executionSnapshotSystem.ts +++ b/internal-packages/run-engine/src/engine/systems/executionSnapshotSystem.ts @@ -361,7 +361,6 @@ export class ExecutionSnapshotSystem { runnerId, }); - await this.$.worker.ack(`heartbeatSnapshot.${runId}`); return executionResultFromSnapshot(latestSnapshot); } diff --git a/internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts b/internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts index e8c78b2174..942c22f6be 100644 --- a/internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts +++ b/internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts @@ -318,9 +318,16 @@ export class RunAttemptSystem { //if there is a big delay between the snapshot and the attempt, the snapshot might have changed //we just want to log because elsewhere it should have been put back into a state where it can be attempted this.$.logger.warn( - "RunEngine.createRunAttempt(): snapshot has changed since the attempt was created, ignoring." + "RunEngine.createRunAttempt(): snapshot has changed since the attempt was created, ignoring.", + { + snapshotId, + latestSnapshotId: latestSnapshot.id, + } ); - throw new ServiceValidationError("Snapshot changed", 409); + throw new ServiceValidationError("Snapshot changed inside startRunAttempt", 409, { + snapshotId, + latestSnapshotId: latestSnapshot.id, + }); } const taskRun = await prisma.taskRun.findFirst({ diff --git a/packages/core/src/logger.ts b/packages/core/src/logger.ts index 7b0de5db09..1e7a811bcb 100644 --- a/packages/core/src/logger.ts +++ b/packages/core/src/logger.ts @@ -147,6 +147,7 @@ function extractStructuredErrorFromArgs(...args: Array | message: error.message, stack: error.stack, name: error.name, + metadata: "metadata" in error ? error.metadata : undefined, }; } @@ -157,6 +158,7 @@ function extractStructuredErrorFromArgs(...args: Array | message: structuredError.error.message, stack: structuredError.error.stack, name: structuredError.error.name, + metadata: "metadata" in structuredError.error ? structuredError.error.metadata : undefined, }; }