From 8deec279fb18e3f3bba65a21a328e222ea68e301 Mon Sep 17 00:00:00 2001 From: vr-varad Date: Wed, 1 Oct 2025 00:22:36 +0530 Subject: [PATCH 1/4] Fix: Register WorkflowHandle for gob encoding automatically --- dbos/dbos.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dbos/dbos.go b/dbos/dbos.go index b290bec..685a1c8 100644 --- a/dbos/dbos.go +++ b/dbos/dbos.go @@ -322,6 +322,8 @@ func NewDBOSContext(ctx context.Context, inputConfig Config) (DBOSContext, error gob.Register(ws) var si []StepInfo gob.Register(si) + var h baseWorkflowHandle + gob.Register(h) // Initialize global variables from processed config (already handles env vars and defaults) initExecutor.applicationVersion = config.ApplicationVersion From e5ecdff4c3acb1f3f888e3124be8de163c272c05 Mon Sep 17 00:00:00 2001 From: vr-varad Date: Wed, 1 Oct 2025 00:27:50 +0530 Subject: [PATCH 2/4] Fix: Update --- dbos/dbos.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dbos/dbos.go b/dbos/dbos.go index 685a1c8..5c6544f 100644 --- a/dbos/dbos.go +++ b/dbos/dbos.go @@ -322,8 +322,12 @@ func NewDBOSContext(ctx context.Context, inputConfig Config) (DBOSContext, error gob.Register(ws) var si []StepInfo gob.Register(si) - var h baseWorkflowHandle + var bh baseWorkflowHandle + gob.Register(bh) + var h workflowHandle[any] gob.Register(h) + var ph workflowPollingHandle[any] + gob.Register(ph) // Initialize global variables from processed config (already handles env vars and defaults) initExecutor.applicationVersion = config.ApplicationVersion From d42c5a92bc39ae098ebf2068ef50f61d9c601535 Mon Sep 17 00:00:00 2001 From: vr-varad Date: Wed, 1 Oct 2025 08:08:09 +0530 Subject: [PATCH 3/4] Fix: Update --- dbos/dbos.go | 2 -- dbos/dbos_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/dbos/dbos.go b/dbos/dbos.go index 5c6544f..75dad9f 100644 --- a/dbos/dbos.go +++ b/dbos/dbos.go @@ -322,8 +322,6 @@ func NewDBOSContext(ctx context.Context, inputConfig Config) (DBOSContext, error gob.Register(ws) var si []StepInfo gob.Register(si) - var bh baseWorkflowHandle - gob.Register(bh) var h workflowHandle[any] gob.Register(h) var ph workflowPollingHandle[any] diff --git a/dbos/dbos_test.go b/dbos/dbos_test.go index 43dbcee..37b2a10 100644 --- a/dbos/dbos_test.go +++ b/dbos/dbos_test.go @@ -719,3 +719,38 @@ func TestCustomPool(t *testing.T) { assert.False(t, systemDB.(*sysDB).launched) }) } + +func TestWorkflowHandlerRegistration(t *testing.T) { + databaseURL := getDatabaseURL() + ctx, err := NewDBOSContext(context.Background(), Config{ + DatabaseURL: databaseURL, + AppName: "test-initialize", + }) + require.NoError(t, err) + defer func() { + if ctx != nil { + Shutdown(ctx, 1*time.Minute) + } + }() // Clean up executor + + require.NotNil(t, ctx) + + wf := func(ctx DBOSContext, input string) (string, error) { + return input, nil + } + + RegisterWorkflow(ctx, wf) + + // Launch a workflow + err = Launch(ctx) + require.NoError(t, err) + defer Shutdown(ctx, 1*time.Minute) + + // Run a workflow + handle, err := RunWorkflow(ctx, wf, "test-input") + require.NoError(t, err) + + result, err := handle.GetResult() + require.NoError(t, err, "failed to get result from workflow") + assert.Equal(t, "test-input", result) +} From 45a4a20ac8ec904a7a1761fd2075f17626db1ce2 Mon Sep 17 00:00:00 2001 From: vr-varad Date: Fri, 3 Oct 2025 17:16:47 +0530 Subject: [PATCH 4/4] Fix: Update --- dbos/dbos.go | 1 + dbos/dbos_test.go | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/dbos/dbos.go b/dbos/dbos.go index c69165c..2c080a5 100644 --- a/dbos/dbos.go +++ b/dbos/dbos.go @@ -360,6 +360,7 @@ func NewDBOSContext(ctx context.Context, inputConfig Config) (DBOSContext, error var ws []WorkflowStatus safeGobRegister(ws, initExecutor.logger) var si []StepInfo + safeGobRegister(si, initExecutor.logger) var h workflowHandle[any] safeGobRegister(h, initExecutor.logger) var ph workflowPollingHandle[any] diff --git a/dbos/dbos_test.go b/dbos/dbos_test.go index 37b2a10..2840335 100644 --- a/dbos/dbos_test.go +++ b/dbos/dbos_test.go @@ -735,10 +735,20 @@ func TestWorkflowHandlerRegistration(t *testing.T) { require.NotNil(t, ctx) - wf := func(ctx DBOSContext, input string) (string, error) { - return input, nil + childWf := func(ctx DBOSContext, input string) (string, error) { + return "child-" + input, nil + } + + wf := func(ctx DBOSContext, input string) (WorkflowHandle[string], error) { + childHandle, err := RunWorkflow(ctx, childWf, input) + if err != nil { + var emptyHandle WorkflowHandle[string] + return emptyHandle, err + } + return childHandle, nil } + RegisterWorkflow(ctx, childWf) RegisterWorkflow(ctx, wf) // Launch a workflow @@ -746,11 +756,17 @@ func TestWorkflowHandlerRegistration(t *testing.T) { require.NoError(t, err) defer Shutdown(ctx, 1*time.Minute) - // Run a workflow - handle, err := RunWorkflow(ctx, wf, "test-input") + parentHandle, err := RunWorkflow(ctx, wf, "test-input") require.NoError(t, err) - result, err := handle.GetResult() - require.NoError(t, err, "failed to get result from workflow") - assert.Equal(t, "test-input", result) + // The result of the parent workflow should itself be a workflow handle + childHandle, err := parentHandle.GetResult() + require.NoError(t, err, "failed to get child handle from parent workflow") + + // Now we can use the child handle to get the final result + result, err := childHandle.GetResult() + require.NoError(t, err, "failed to get result from child workflow") + + // Assert final child workflow result + assert.Equal(t, "child-test-input", result) }