Skip to content

Node state-transition model#263

Open
pinodeca wants to merge 3 commits into
copilot/fix-loop-restart-issuefrom
node-transition-model
Open

Node state-transition model#263
pinodeca wants to merge 3 commits into
copilot/fix-loop-restart-issuefrom
node-transition-model

Conversation

@pinodeca

Copy link
Copy Markdown
Contributor

Summary

Introduces a formal node & instance state-transition model for pg_durable, then implements it. This consolidates two related node-status gaps:

What's here now

The first commit adds the design proposal: docs/node-state-model.md. It defines:

  • Instance and node lifecycle states and their legal transitions (mermaid diagrams).
  • A coarse, stable status set (pending, running, completed, failed, skipped, cancelled) plus a nullable status_reason (upstream_failed, branch_not_taken, race_lost, scope_cancelled) — avoiding an ever-growing enum under the strict schema-upgrade contract.
  • Per-construct outcomes (THEN/IF/LOOP/JOIN/RACE/BREAK).
  • Loop iteration-scoping: how a single mutable df.nodes row behaves across continue_as_new, and the body-subgraph reset that prevents stale terminal marks leaking between iterations.
  • Prior-art alignment with Airflow (TaskInstance states), Temporal (event history + ContinueAsNew), BPMN 2.0 (withdrawn), and AWS Step Functions.
  • How the model resolves No "skipped" indication for downstream steps after a step fails #240 (pending → skipped terminal sweep) and df.instance_nodes leaves race-loser nodes running or pending after race completion #171 (running → cancelled subtree reconciliation at race resolution).

Plan

This PR starts as a design proposal for review. After incorporating colleague feedback, the implementation (status set additions, status_reason column, race-loser reconciliation, and loop-reset) will land on this same PR.

Upgrade & migration

The model is explicit about backward compatibility: new status/status_reason require install + upgrade DDL, and every reconciliation activity must no-op gracefully against schemas that predate the relevant column/status (the schema-probe pattern already used for skipped).

pinodeca and others added 2 commits June 12, 2026 21:05
…s_new

df.loop called continue_as_new inline in the main orchestration, so every
new generation restarted from graph.root_node_id, re-executing prefix nodes
on every iteration. Each df.loop() node now spawns a dedicated child
sub-orchestration (execute_loop) that owns continue_as_new; the parent awaits
it and runs any suffix nodes exactly once.

Relies on duroxide PR #31 (parent link preserved across continue_as_new),
pulled in as a git dependency until merged and released.

Co-authored-by: copilot-swe-agent <copilot@github.com>
Co-authored-by: pinodeca <32303022+pinodeca@users.noreply.github.com>
Nested loops and loop bodies containing JOIN/RACE branches hung forever
because duroxide auto-generated child instance IDs ({parent}::sub::{event_id})
reset their event counter on each continue_as_new generation, so every loop
generation re-derived the same child ID and collided with the previous
(now terminal) child.

Use schedule_sub_orchestration_with_id with a deterministic,
generation-qualified child ID ({instance}::e{execution_id}::{tag}::{node_id})
at all loop/join/race spawn sites.

Add nested-loop, loop-in-JOIN-branch, and non-root while-loop regression
tests, and a USER_GUIDE note that each df.loop runs as its own child
orchestration.
@pinodeca pinodeca changed the title Implement node state-transition model (#171, #240) Node state-transition model Jun 23, 2026
pinodeca added a commit that referenced this pull request Jun 23, 2026
The proposal previously framed the #240 skipped-node work as part of
'this PR'. That work landed earlier in PR #249; this PR (#263) defines
the consolidated state model and adds the remaining implementation
(cancelled, status_reason, race-loser reconciliation, loop reset).
@pinodeca pinodeca force-pushed the node-transition-model branch from 68283e0 to 44c171e Compare June 23, 2026 16:24
pinodeca added a commit that referenced this pull request Jun 23, 2026
Adds docs/node-state-model.md, a design proposal consolidating the
node-status work for issues #240 (skipped downstream nodes) and #171
(race-loser nodes left running/pending). Defines instance and node
lifecycle states, legal transitions, a coarse status set plus nullable
status_reason, loop iteration-scoping/reset semantics, and prior-art
alignment with Airflow/Temporal/BPMN/Step Functions.

The #240 skipped-node work shipped earlier in PR #249; this PR (#263)
defines the consolidated model and will add the remaining implementation
(cancelled, status_reason, race-loser reconciliation, loop reset) after
review.

Design only; implementation to follow on this PR.
@pinodeca pinodeca linked an issue Jun 26, 2026 that may be closed by this pull request
Squash of the node-state-model proposal, the execution-id proposal, and the
temporary exec-id implementation plan. Rebased onto the df.loop
sub-orchestration fix (PR #228, copilot/fix-loop-restart-issue).
@pinodeca pinodeca force-pushed the node-transition-model branch from 73d219d to 7ab6b3f Compare June 27, 2026 13:30
@pinodeca pinodeca changed the base branch from main to copilot/fix-loop-restart-issue June 27, 2026 13:30
@pinodeca pinodeca force-pushed the copilot/fix-loop-restart-issue branch from 3a4255f to b26327a Compare June 27, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No "skipped" indication for downstream steps after a step fails df.instance_nodes leaves race-loser nodes running or pending after race completion

1 participant