feat: recover poll activations within original round budgets

This commit is contained in:
2026-09-18 05:40:08 +08:00
parent 1d1a441167
commit 56b9a2ccfe
32 changed files with 1051 additions and 65 deletions

View File

@@ -92,7 +92,7 @@ func readWorkflowResult(ctx context.Context, tx *sql.Tx, g *workflowGraph, c wor
if node.Poll != nil {
taskDefinition = &node.Poll.Task
var round uint32
err = tx.QueryRowContext(ctx, `SELECT r.round FROM weave_poll_rounds r JOIN weave_poll_states p ON p.namespace_id=r.namespace_id AND p.workflow_id=r.workflow_id AND p.activation_id=r.activation_id WHERE r.namespace_id=? AND r.workflow_id=? AND r.activation_id=? AND r.task_id=? AND r.round BETWEEN 1 AND p.used_rounds`, c.ns, c.workflow, source.activation, source.task).Scan(&round)
err = tx.QueryRowContext(ctx, `SELECT r.round FROM weave_poll_rounds r JOIN weave_poll_states p ON p.namespace_id=r.namespace_id AND p.workflow_id=r.workflow_id AND p.activation_id=r.activation_id WHERE r.namespace_id=? AND r.workflow_id=? AND r.activation_id=? AND r.task_id=? AND r.round BETWEEN p.first_round AND p.used_rounds`, c.ns, c.workflow, source.activation, source.task).Scan(&round)
if errors.Is(err, sql.ErrNoRows) || direct != nil {
return nil, workflowSourceError("RESULT_POLL_OWNER")
}
@@ -167,14 +167,13 @@ func (r *WorkflowRuntime) consume(ctx context.Context, tx *sql.Tx, g *workflowGr
}
node, _ := g.program.Step(row.view.Key)
if node.Poll != nil {
var used, max uint32
var deadline time.Time
var current *core.ID
var resolved *time.Time
if err := tx.QueryRowContext(ctx, `SELECT used_rounds,max_rounds,deadline_at,current_task_id,resolved_at FROM weave_poll_states WHERE namespace_id=? AND workflow_id=? AND activation_id=? FOR UPDATE`, c.ns, c.workflow, source.activation).Scan(&used, &max, &deadline, &current, &resolved); err != nil {
budget, lastTask, err := readWorkflowPollBudget(ctx, tx, g, row)
if err != nil {
return false, err
}
if resolved != nil || current == nil || *current != source.task {
used, max, deadline := budget.UsedRounds, budget.MaxRounds, budget.DeadlineAt
current := budget.CurrentTaskID
if budget.ResolvedAt != nil || current == nil || *current != source.task || lastTask != source.task {
return true, r.confirmWorkflowResult(ctx, tx, g, c, "PROCESSED", "STALE_POLL_ROUND", now)
}
if node.Poll.FinalSignal != nil {