loop inside a JOIN/RACE branch fails terminally on iteration ≥2 (continue_as_new restarts ExecuteSubtree with wrong input)
Summary
A df.loop() placed inside a df.join() / df.race() branch fails the instant the loop tries to continue into its second iteration. The hosting branch sub-orchestration dies with a terminal "Missing graph in ExecuteSubtree input" error, and the parent JOIN/RACE then parks forever — the instance sits in running indefinitely.
This is the inverse nesting of #230 (which is JOIN/RACE inside a loop). It has a different failure signature but shares the same root cause: continue_as_new is host-context-unaware. It was surfaced by the automated combinator-nesting test matrix in #232 (Phase 2).
| Nesting | Example shape | Failure signature |
|---|---|---|
| JOIN/RACE inside a loop (#230) | Loop(Join(...)) |
iteration ≥2 reuses a child id already Completed → parent loop await never resolves |
| loop inside a JOIN/RACE branch (this issue) | Join(…, Loop(…)), Race(Loop(…), …) |
inner loop's first continue_as_new restarts the branch orchestration (ExecuteSubtree) from root with the wrong input → terminal failure → parent JOIN/RACE hangs |
| loop at top level after a sibling (#227) | Seq(…, Loop(…)) |
continue_as_new restarts ExecuteFunctionGraph from root → silently re-runs the loop's preceding siblings (over-execution) |
All three trigger at the same ≥2-iteration boundary.
Mechanism
- The loop node calls
ctx.continue_as_new(...)once per continuing iteration (execute_loop_node,src/orchestrations/execute_function_graph.rs). continue_as_newrestarts whichever orchestration is currently executing, from its root. That is only correct when the loop is the root orchestration (ExecuteFunctionGraph).- When the loop runs inside a JOIN/RACE branch, the currently-executing orchestration is
ExecuteSubtree. Its input parser requires{graph, node_id, results}, butcontinue_as_newhands it the bareFunctionInputthe loop node produces. - Result: on the post-
continue_as_newexecution (execution_id=2),ExecuteSubtreefails to parse its input → terminal application failure (not a retry/spin). The sub-orchestration dies; the parent JOIN/RACE await on that branch never resolves → permanent stall.
Observed — Join(If(M,M), Loop(Seq(M,M)))
Worker log (~/.pgrx/17.log); inner-loop branch is ::sub::9:
INFO ExecuteSubtree: executing node … instance_id=…::sub::9 execution_id=1
WARN Orchestration failed (application error) instance_id=…::sub::9 execution_id=2
orchestration_name=pg_durable::orchestration::execute-subtree
error="Missing graph in ExecuteSubtree input"
execution_id=1 runs iteration 1 fine; execution_id=2 is the post-continue_as_new restart that dies.
Symptom / impact
- Any workflow with a
df.loop()inside a JOIN/RACE branch that iterates ≥2 times hangs after iteration 1. - The instance remains
runningforever (no completion, no failure); the caller'swait_for_completiontimes out.
Severity & blast-radius (measured)
To determine whether stuck instances can stall the durable subsystem or the cluster, I started 15 genuinely-distinct Join(…, Loop) instances (distinct trace keys so each actually hangs), let them park, and measured:
| Probe | Result | Interpretation |
|---|---|---|
| System-wide CPU over 6 s with 15 hangs parked | ≈0.28 s total across all processes | Parked hangs do not spin — no busy-loop |
| Healthy single-marker instance with 15 hangs stuck | 0.60–0.74 s, no degradation | Orchestration pool not starved |
| Durable worker DB connections | idle (ClientRead); none held by hangs |
No connection exhaustion |
| Stuck instances over time | remain running indefinitely; persist & re-park across worker restart |
Permanent leak |
This is not a cluster-level DoS. PostgreSQL keeps serving and the worker keeps processing new instances at full speed; a parked hang consumes ~0 CPU and holds no active connection. It is a high-severity liveness/correctness defect:
- Permanent stuck instances — never complete or fail.
- Zombie accumulation — stuck rows survive and replay on every worker restart; a workload repeatedly hitting these shapes leaks unboundedly and lengthens restart replay (a slow resource-leak availability concern, not an instant stall).
- Closely related to the silent over-execution in #227 (same root cause, no error at all).
Repro (illustrative)
df.join(
df.if('SELECT true', df.sql('...A...'), df.sql('...B...')),
df.loop(
df.seq(df.sql('...body1...'), df.sql('...body2...')),
'<while-condition that permits a 2nd iteration>'
)
)
In-repo: quarantined, known-failing E2E tests under tests/e2e/generated/quarantine/ (#232 Phase 2). The depth-2 matrix found 20 hang shapes in this family — loop-in-join (11), loop-in-race-winner (6), loop-body-combinator (3) — each asserting the correct expected behavior and expected to flip green once this is fixed.
Suggested fix direction
Make continue_as_new (or the loop node's use of it) host-aware: a loop that is not the root orchestration must restart the correct host orchestration (ExecuteSubtree) with the correct input, or avoid continue_as_new in that context entirely. A single host-aware fix is likely to resolve all three manifestations — this issue, #230, and the top-level over-count #227. Any fix must remain deterministic / replay-safe (orchestration code).
Related
- #230 — inverse nesting (JOIN/RACE inside a loop); sibling symptom, same root cause.
- #227 — top-level
Seq(…, Loop)over-execution; samecontinue_as_new-from-root mechanism. - #232 — automated DSL test matrix that surfaced this.
Please note that this should be fixed by #228, which should be extended to test this issue's scenario.