Skip to content

Commit 5561501

Browse files
handle missing action results gracefully in test mode
1 parent d1b9251 commit 5561501

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

shared.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16278,8 +16278,28 @@ func handleAgentDecisionStreamResult(workflowExecution WorkflowExecution, action
1627816278
}
1627916279

1628016280
if foundActionResultIndex < 0 {
16281-
log.Printf("[ERROR][%s] Action '%s' was NOT found with any result in the execution (yet)", workflowExecution.ExecutionId, actionResult.Action.ID)
16282-
return &workflowExecution, false, errors.New(fmt.Sprintf("ActionResultIndex: Agent node ID for decision ID %s not found", decisionId))
16281+
// In test mode, Singul doesn't create sub-executions, so we need to handle this gracefully
16282+
if os.Getenv("AGENT_TEST_MODE") == "true" {
16283+
log.Printf("[DEBUG][%s] AGENT_TEST_MODE: Action '%s' not found in results, creating placeholder", workflowExecution.ExecutionId, actionResult.Action.ID)
16284+
16285+
// Create a placeholder result for the agent action
16286+
placeholderResult := ActionResult{
16287+
Action: actionResult.Action,
16288+
ExecutionId: workflowExecution.ExecutionId,
16289+
Result: `{"status":"RUNNING","decisions":[]}`,
16290+
StartedAt: time.Now().Unix(),
16291+
CompletedAt: 0,
16292+
Status: "EXECUTING",
16293+
}
16294+
16295+
workflowExecution.Results = append(workflowExecution.Results, placeholderResult)
16296+
foundActionResultIndex = len(workflowExecution.Results) - 1
16297+
16298+
log.Printf("[DEBUG][%s] Created placeholder result at index %d", workflowExecution.ExecutionId, foundActionResultIndex)
16299+
} else {
16300+
log.Printf("[ERROR][%s] Action '%s' was NOT found with any result in the execution (yet)", workflowExecution.ExecutionId, actionResult.Action.ID)
16301+
return &workflowExecution, false, errors.New(fmt.Sprintf("ActionResultIndex: Agent node ID for decision ID %s not found", decisionId))
16302+
}
1628316303
}
1628416304

1628516305
mappedResult := AgentOutput{}
@@ -16291,6 +16311,28 @@ func handleAgentDecisionStreamResult(workflowExecution WorkflowExecution, action
1629116311
return &workflowExecution, false, err
1629216312
}
1629316313

16314+
// In test mode, if the placeholder has no decisions, we need to add the incoming decision
16315+
if os.Getenv("AGENT_TEST_MODE") == "true" && len(mappedResult.Decisions) == 0 {
16316+
log.Printf("[DEBUG][%s] AGENT_TEST_MODE: Placeholder has no decisions, parsing incoming decision", workflowExecution.ExecutionId)
16317+
16318+
// Parse the incoming decision from actionResult
16319+
incomingDecision := AgentDecision{}
16320+
err = json.Unmarshal([]byte(actionResult.Result), &incomingDecision)
16321+
if err != nil {
16322+
log.Printf("[ERROR][%s] Failed unmarshalling incoming decision: %s", workflowExecution.ExecutionId, err)
16323+
} else {
16324+
// Add the decision to the mapped result
16325+
mappedResult.Decisions = append(mappedResult.Decisions, incomingDecision)
16326+
mappedResult.Status = "RUNNING"
16327+
16328+
// Update the workflow execution result with the new decision
16329+
updatedResult, _ := json.Marshal(mappedResult)
16330+
workflowExecution.Results[foundActionResultIndex].Result = string(updatedResult)
16331+
16332+
log.Printf("[DEBUG][%s] Added decision %s to placeholder (total decisions: %d)", workflowExecution.ExecutionId, incomingDecision.RunDetails.Id, len(mappedResult.Decisions))
16333+
}
16334+
}
16335+
1629416336
// FIXME: Need to check the current value from the workflowexecution here, instead of using the currently sent in decision
1629516337

1629616338
// 1. Get the current result for the action

0 commit comments

Comments
 (0)