Repository: n8n-io/n8n
File: packages/@n8n/db/src/repositories/execution.repository.ts (TypeScript)

Code before:
		return await this.manager.transaction(async (manager) => {
			// Update status, set startedAt only if not already set (preserves original for resumed executions)
			await manager
				.createQueryBuilder()
				.update(ExecutionEntity)
				.set({
					status: 'running',
					startedAt: () => 'COALESCE(startedAt, :startedAt)',
				})
				.setParameter('startedAt', DateUtils.mixedDateToUtcDatetimeString(startedAt))
				.where('id = :id', { id: executionId })
				.execute();

			// Fetch the actual startedAt
			const { startedAt: actualStartedAt } = await manager.findOneOrFail(ExecutionEntity, {
				select: ['startedAt'],
				where: { id: executionId },
			});

			a.ok(actualStartedAt);
			return actualStartedAt;
		});
	}

	/**
	 * Update an existing execution in the database.
	 *
	 * @param executionId - The ID of the execution to update
	 * @param execution - Partial execution data to update
	 * @param requireStatus - Optional status requirement. If provided, update only succeeds if execution has this status
	 * @returns true if update succeeded, false if no execution was found or requireStatus condition was not met
	 */
	async updateExistingExecution(
		executionId: string,
		execution: Partial<IExecutionResponse>,
		requireStatus?: ExecutionStatus,
	): Promise<boolean> {
		const {
			id,
			data,
			workflowId,
			workflowData,
			createdAt, // must never change
			startedAt, // must never change
			customData,
			...executionInformation
		} = execution;

		const executionData: Partial<ExecutionData> = {};

		if (workflowData) executionData.workflowData = workflowData;

Review comment (bug):
Moved to `ExecutionPersistence` and expanded there

Code after:
			);
			this.logger.info('Marked executions as `crashed`', { executionIds });
			processed += batch.length;
		}
	}

	async setRunning(executionId: string) {
		const startedAt = new Date();

		return await this.manager.transaction(async (manager) => {
			// Update status, set startedAt only if not already set (preserves original for resumed executions)
			await manager
				.createQueryBuilder()
				.update(ExecutionEntity)
				.set({
					status: 'running',
					startedAt: () => 'COALESCE(startedAt, :startedAt)',
				})
				.setParameter('startedAt', DateUtils.mixedDateToUtcDatetimeString(startedAt))
				.where('id = :id', { id: executionId })
				.execute();

			// Fetch the actual startedAt
			const { startedAt: actualStartedAt } = await manager.findOneOrFail(ExecutionEntity, {
				select: ['startedAt'],
				where: { id: executionId },
			});

			a.ok(actualStartedAt);
			return actualStartedAt;
		});
	}

	/**
	 * Update an existing execution in the database.
	 *
	 * @param executionId - The ID of the execution to update
	 * @param execution - Partial execution data to update
	 * @param requireStatus - Optional status requirement. If provided, update only succeeds if execution has this status
	 * @returns true if update succeeded, false if no execution was found or requireStatus condition was not met
	 */
	async updateExistingExecution(
		executionId: string,
		execution: Partial<IExecutionResponse>,
		requireStatus?: ExecutionStatus,
	): Promise<boolean> {
		const {
			id,
			data,
			workflowId,
			workflowData,