From c245283582035d50bea915b921af379632c1a919 Mon Sep 17 00:00:00 2001 From: JeanCarlos_MartinsDa Date: Mon, 4 May 2026 12:38:24 -0300 Subject: [PATCH 1/5] Fix missing ParentInstanceID when creating a sub-orchestration --- backend/postgres/postgres.go | 14 ++++++++++---- backend/sqlite/sqlite.go | 10 ++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/backend/postgres/postgres.go b/backend/postgres/postgres.go index 10d8336..8baf93d 100644 --- a/backend/postgres/postgres.go +++ b/backend/postgres/postgres.go @@ -140,7 +140,7 @@ func (be *postgresBackend) AbandonOrchestrationWorkItem(ctx context.Context, wi } defer tx.Rollback(ctx) //nolint:errcheck // rollback after commit is a no-op - var visibleTime*time.Time = nil + var visibleTime *time.Time = nil if delay := wi.GetAbandonDelay(); delay > 0 { t := time.Now().UTC().Add(delay) visibleTime = &t @@ -497,6 +497,10 @@ func (be *postgresBackend) createOrchestrationInstanceInternal(ctx context.Conte } func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx pgx.Tx, e *backend.HistoryEvent, startEvent *protos.ExecutionStartedEvent) (int64, error) { + var parentInstanceID *string + if pi := startEvent.GetParentInstance(); pi != nil { + parentInstanceID = &pi.OrchestrationInstance.InstanceId + } res, err := tx.Exec( ctx, `INSERT INTO Instances ( @@ -506,8 +510,9 @@ func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx pgx.Tx, e *back ExecutionID, Input, RuntimeStatus, - CreatedTime - ) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT DO NOTHING`, + CreatedTime, + ParentInstanceID + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT DO NOTHING`, startEvent.Name, startEvent.Version.GetValue(), startEvent.OrchestrationInstance.InstanceId, @@ -515,6 +520,7 @@ func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx pgx.Tx, e *back startEvent.Input.GetValue(), "PENDING", e.Timestamp.AsTime(), + parentInstanceID, ) if err != nil { return -1, fmt.Errorf("failed to insert into Instances table: %w", err) @@ -769,7 +775,7 @@ func (be *postgresBackend) GetOrchestrationWorkItem(ctx context.Context) (*backe defer tx.Rollback(ctx) //nolint:errcheck // rollback after commit is a no-op now := time.Now().UTC() - newLockExpiration:= now.Add(be.options.OrchestrationLockTimeout) + newLockExpiration := now.Add(be.options.OrchestrationLockTimeout) // Place a lock on an orchestration instance that has new events that are ready to be executed. row := tx.QueryRow( diff --git a/backend/sqlite/sqlite.go b/backend/sqlite/sqlite.go index 1e1d1ea..5a76329 100644 --- a/backend/sqlite/sqlite.go +++ b/backend/sqlite/sqlite.go @@ -470,6 +470,10 @@ func (be *sqliteBackend) createOrchestrationInstanceInternal(ctx context.Context } func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx *sql.Tx, e *backend.HistoryEvent, startEvent *protos.ExecutionStartedEvent) (int64, error) { + var parentInstanceID *string + if pi := startEvent.GetParentInstance(); pi != nil { + parentInstanceID = &pi.OrchestrationInstance.InstanceId + } res, err := tx.ExecContext( ctx, `INSERT OR IGNORE INTO [Instances] ( @@ -479,8 +483,9 @@ func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx *sql.Tx, e *bac [ExecutionID], [Input], [RuntimeStatus], - [CreatedTime] - ) VALUES (?, ?, ?, ?, ?, ?, ?)`, + [CreatedTime], + [ParentInstanceID] + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, startEvent.Name, startEvent.Version.GetValue(), startEvent.OrchestrationInstance.InstanceId, @@ -488,6 +493,7 @@ func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx *sql.Tx, e *bac startEvent.Input.GetValue(), "PENDING", e.Timestamp.AsTime(), + parentInstanceID, ) if err != nil { return -1, fmt.Errorf("failed to insert into [Instances] table: %w", err) From cdcd99be9bb0af60f5830000730d61f34a2ebe90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean=20Carlos=20Magalh=C3=A3es?= Date: Thu, 28 May 2026 10:05:15 -0300 Subject: [PATCH 2/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- backend/sqlite/sqlite.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/sqlite/sqlite.go b/backend/sqlite/sqlite.go index 5a76329..86b62e9 100644 --- a/backend/sqlite/sqlite.go +++ b/backend/sqlite/sqlite.go @@ -472,7 +472,9 @@ func (be *sqliteBackend) createOrchestrationInstanceInternal(ctx context.Context func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx *sql.Tx, e *backend.HistoryEvent, startEvent *protos.ExecutionStartedEvent) (int64, error) { var parentInstanceID *string if pi := startEvent.GetParentInstance(); pi != nil { - parentInstanceID = &pi.OrchestrationInstance.InstanceId + if instanceID := pi.GetOrchestrationInstance().GetInstanceId(); instanceID != "" { + parentInstanceID = &instanceID + } } res, err := tx.ExecContext( ctx, From 11b1e5dff719ff206da7b8b0928eaf439384e9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean=20Carlos=20Magalh=C3=A3es?= Date: Thu, 28 May 2026 10:07:01 -0300 Subject: [PATCH 3/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- backend/postgres/postgres.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/postgres/postgres.go b/backend/postgres/postgres.go index 8baf93d..7d03000 100644 --- a/backend/postgres/postgres.go +++ b/backend/postgres/postgres.go @@ -499,7 +499,9 @@ func (be *postgresBackend) createOrchestrationInstanceInternal(ctx context.Conte func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx pgx.Tx, e *backend.HistoryEvent, startEvent *protos.ExecutionStartedEvent) (int64, error) { var parentInstanceID *string if pi := startEvent.GetParentInstance(); pi != nil { - parentInstanceID = &pi.OrchestrationInstance.InstanceId + if instanceID := pi.GetOrchestrationInstance().GetInstanceId(); instanceID != "" { + parentInstanceID = &instanceID + } } res, err := tx.Exec( ctx, From 3e92a48c00c12e4e6c71a466a33ff03a1d0a1e9f Mon Sep 17 00:00:00 2001 From: JeanCarlos_MartinsDa Date: Thu, 28 May 2026 10:13:08 -0300 Subject: [PATCH 4/5] avoid escaping to the heap --- backend/postgres/postgres.go | 5 +++-- backend/sqlite/sqlite.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/postgres/postgres.go b/backend/postgres/postgres.go index 7d03000..23ad205 100644 --- a/backend/postgres/postgres.go +++ b/backend/postgres/postgres.go @@ -2,6 +2,7 @@ package postgres import ( "context" + "database/sql" _ "embed" "errors" "fmt" @@ -497,10 +498,10 @@ func (be *postgresBackend) createOrchestrationInstanceInternal(ctx context.Conte } func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx pgx.Tx, e *backend.HistoryEvent, startEvent *protos.ExecutionStartedEvent) (int64, error) { - var parentInstanceID *string + var parentInstanceID sql.NullString if pi := startEvent.GetParentInstance(); pi != nil { if instanceID := pi.GetOrchestrationInstance().GetInstanceId(); instanceID != "" { - parentInstanceID = &instanceID + parentInstanceID = sql.NullString{String: instanceID, Valid: true} } } res, err := tx.Exec( diff --git a/backend/sqlite/sqlite.go b/backend/sqlite/sqlite.go index 86b62e9..d812a57 100644 --- a/backend/sqlite/sqlite.go +++ b/backend/sqlite/sqlite.go @@ -470,10 +470,10 @@ func (be *sqliteBackend) createOrchestrationInstanceInternal(ctx context.Context } func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx *sql.Tx, e *backend.HistoryEvent, startEvent *protos.ExecutionStartedEvent) (int64, error) { - var parentInstanceID *string + var parentInstanceID sql.NullString if pi := startEvent.GetParentInstance(); pi != nil { if instanceID := pi.GetOrchestrationInstance().GetInstanceId(); instanceID != "" { - parentInstanceID = &instanceID + parentInstanceID = sql.NullString{String: instanceID, Valid: true} } } res, err := tx.ExecContext( From c79aa9c9582248dfad7e0ef790617620263ad1d9 Mon Sep 17 00:00:00 2001 From: JeanCarlos_MartinsDa Date: Fri, 29 May 2026 10:01:10 -0300 Subject: [PATCH 5/5] revert copilot change --- backend/postgres/postgres.go | 5 ++--- backend/sqlite/sqlite.go | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/postgres/postgres.go b/backend/postgres/postgres.go index 23ad205..7d03000 100644 --- a/backend/postgres/postgres.go +++ b/backend/postgres/postgres.go @@ -2,7 +2,6 @@ package postgres import ( "context" - "database/sql" _ "embed" "errors" "fmt" @@ -498,10 +497,10 @@ func (be *postgresBackend) createOrchestrationInstanceInternal(ctx context.Conte } func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx pgx.Tx, e *backend.HistoryEvent, startEvent *protos.ExecutionStartedEvent) (int64, error) { - var parentInstanceID sql.NullString + var parentInstanceID *string if pi := startEvent.GetParentInstance(); pi != nil { if instanceID := pi.GetOrchestrationInstance().GetInstanceId(); instanceID != "" { - parentInstanceID = sql.NullString{String: instanceID, Valid: true} + parentInstanceID = &instanceID } } res, err := tx.Exec( diff --git a/backend/sqlite/sqlite.go b/backend/sqlite/sqlite.go index d812a57..86b62e9 100644 --- a/backend/sqlite/sqlite.go +++ b/backend/sqlite/sqlite.go @@ -470,10 +470,10 @@ func (be *sqliteBackend) createOrchestrationInstanceInternal(ctx context.Context } func insertOrIgnoreInstanceTableInternal(ctx context.Context, tx *sql.Tx, e *backend.HistoryEvent, startEvent *protos.ExecutionStartedEvent) (int64, error) { - var parentInstanceID sql.NullString + var parentInstanceID *string if pi := startEvent.GetParentInstance(); pi != nil { if instanceID := pi.GetOrchestrationInstance().GetInstanceId(); instanceID != "" { - parentInstanceID = sql.NullString{String: instanceID, Valid: true} + parentInstanceID = &instanceID } } res, err := tx.ExecContext(