← Back to Pull requests

fix(workflow): detect subflow reference cycles at publish and bound the run call chain (issue #273) #360

Closed
unknown closed this pull request without merging on Nov 08, 2026 14:35 UTC
View on GitHub
unknown unknown commented on Nov 08, 2026 08:02 UTC
Author

Describe what this PR does / why we need it

Issue #273 reported that subflow execution resolves the referenced definition and recurses into executeSteps with no cycle check and no depth bound — a self-referencing definition publishes fine and dies with a JVM StackOverflowError at run time. This PR adds a two-line defense at publish time and at run time, entirely inside the workflow module (no Graph/Loop, no new dependencies).

Publish-time cycle detection

WorkflowRegistry.publish now resolves the definition's subflow reference graph against the already published definitions and rejects cycles before storing anything. The graph nodes are id@version pairs, so referencing a different version of the same workflow is not a cycle. The rejection message carries the closed chain (a@1 -> b@2 -> a@1). A reference to a definition that is not published yet stays a legal forward reference — it does not block the publish, and an unresolved reference surfaces at run time as the usual "workflow version is not published" failure. This policy is documented in the registry javadoc.

Run-time call chain and depth bound

The run now carries a subflow call chain (id@version, caller first) on its run data: it survives suspensions through the continuation closures and is copied per parallel branch. Entering a subflow whose node is already on the chain closes a cycle and fails with a WorkflowSubflowRecursionException carrying the closed chain; a chain that has reached the configured depth limit fails with the same exception and a diagnosis that names the root definition and every level. Nothing exhausts the JVM stack — an overly deep but acyclic chain ends with a domain error.

The limit defaults to 16 and is configurable through Builder.subflowMaxDepth(int) — the explicit bound the issue asks for in place of an unconditional recursion ban.

Legitimate reuse stays legal

The chain is the current call path, not a set of already-used subflows: invoking the same subflow twice sequentially, or from two parallel branches, is not a cycle and keeps working. Deliberate recursion through the DSL is not supported in this PR — a cycle on the call chain is always refused — because the issue's requirement is a bounded policy, and the depth limit plus publish-time rejection covers the failure modes without extending the definition format.

Testing

New WorkflowSubflowBoundaryTest with 8 cases: self-reference rejected at publish with the closed chain in the message, an indirect cycle across definitions rejected when the last definition closes it (the earlier forward reference publishes), a forward reference publishing successfully and failing at run with the usual unresolved error, a 20-level acyclic chain ending with the domain error instead of a stack overflow, the configured depth limit taking effect, sequential and parallel reuse of the same subflow completing, and cancellation inside a subflow terminating normally. Run against the unmodified code, 4 cases fail (both publish rejections and both depth cases); with the fix the whole argi-workflow-core module is 46/46 green, checkstyle clean.

Fixes #273

Diff: 394 lines (+295 / -99) across 4 files Reviewer: yuluo-yx Review duration: 393m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 394 lines diff across 4 files
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.358
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #360"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 43.2% (MEDIUM) · Higher = larger blast radius
43.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.1% · Safe to merge
17.1%