SELECT te.[Id],
       te.[ExecutionMode],
       te.[WorkKind],
       te.[ExecutionType],
       te.[AssignedAgent],
       te.[QueuedAt],
       te.[StartedAt],
       te.[FinishedAt],
       te.[Status],
       te.[InputDataJson],
       te.[OutputDataJson],
       te.[OutputDataRef],
       te.[ErrorMessage],
       te.[CorrelationId],
       te.[ReplayedFromTaskId],
       te.[WorkspaceId],
       te.[AssignmentType],
       te.[ConfidenceScore],
       te.[RetryCount],
       te.[LastRetryAt],
       te.[MaxRetryAttempts],
       te.[RetryReason],
       te.[Priority],
       te.[RetryOfTaskId],
       te.[SuggestionLogId],
       te.[CreatedAt],
       te.[SuggestedPatchJson],
       te.[AiReviewEvidenceManifestJson],
       te.[AiReviewStatus],
       te.[CreatedVia],
       te.[Language], te.[Domain], te.[RepositoryUrl], te.[Branch], te.[FilePath], te.[Prompt], te.[OutputFormat], te.[TriggerSource], te.[ExternalId], te.[ExternalSystem], te.[RowVersion], st.[Id] AS TransitionSplit, st.[Id], st.[TaskExecutionId], st.[Status], st.[Timestamp], st.[Message], parent.[ChildTaskId] AS ParentSplit, parent.[ChildTaskId], parent.[ParentTaskId], child.[ParentTaskId] AS ChildSplit, child.[ParentTaskId], child.[ChildTaskId]
FROM [dbo].[TaskExecutions] te
    LEFT JOIN [dbo].[StatusTransitions] st
ON st.[TaskExecutionId] = te.[Id]
    LEFT JOIN [dbo].[ParentTaskExecutions] parent
    ON parent.[ChildTaskId] = te.[Id]
    LEFT JOIN [dbo].[ParentTaskExecutions] child
    ON child.[ParentTaskId] = te.[Id]
WHERE te.[Id] = @Id;
