Skip to content

fix: prevent recursion failure in data branch DAG cycles - #26139

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-26083-dag-cycle
Jul 24, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-26083-dag-cycle

Conversation

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #26083

What this PR does / why we need it:

Replace recursive Data Branch DAG depth calculation with a bounded iterative
parent walk. When corrupted branch metadata contains a parent cycle, all nodes
in that cycle are deterministically detached and treated as roots, while
non-cyclic descendants retain their valid parent edges.

This prevents cyclic mo_branch_metadata from exhausting the process stack and
also removes recursive stack growth for deep acyclic chains. The existing
NewDAG API and ordinary LCA behavior remain unchanged.

Adds a bounded child-process regression covering a two-node cycle, self-cycle,
non-cyclic descendant, and a 4,096-node acyclic chain.

Validation:

  • go test ./pkg/frontend/databranchutils -run '^(TestNewDAGCycle|TestDAGFunctionality)$' -count=10
  • go test ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=50
  • go test -race ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$' -count=1
  • go test ./pkg/frontend/databranchutils -count=1
  • go test ./pkg/frontend -run '^$' -count=1
  • git diff --check

@mergify mergify Bot added the kind/bug Something isn't working label Jul 24, 2026
@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Jul 24, 2026
@VioletQwQ-0
VioletQwQ-0 marked this pull request as ready for review July 24, 2026 08:25
@VioletQwQ-0
VioletQwQ-0 requested a review from XuPeng-SH as a code owner July 24, 2026 08:25
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete DAG construction and query closure. The iterative parent walk terminates for cycles and deep chains, deterministically detaches exactly the cycle members, preserves non-cyclic descendant edges, and leaves FindLCA invariants valid. Focused cycle/deep-chain tests, race tests, and an additional randomized functional-graph invariant test passed. No correctness, performance, compatibility, or lifecycle blocker found.

@mergify mergify Bot added the queued label Jul 24, 2026
@mergify

mergify Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-24 10:45 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-24 13:22 UTC · at 07d333db7821b762a0ae48a3121179f93aad3380

This pull request spent 2 hours 37 minutes 26 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

This pull request seems to come from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request, or update the branch manually.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review completed on 8723647b against the latest main integration state.

Additional verification beyond the existing PR tests:

  • Exhaustively enumerated all 126,125 functional parent graphs with 1-6 nodes, including every combination of roots, self-cycles, multi-node cycles, multiple disconnected cycles, and acyclic prefixes/descendants.
  • For every graph, verified that exactly the cycle members are detached, every retained edge preserves its original parent, all depths satisfy child.Depth == parent.Depth + 1, every parent walk terminates, and FindLCA plus PathFromAncestor match independent reference implementations for every node pair.
  • Merged the latest main in a detached worktree and reran the focused tests 10x plus race; all passed.
  • Benchmarked the defensive implementation against the base: a 4,096-node chain rises from about 0.20 ms to 0.31 ms and uses one additional O(N) visited map, while a 4,096-root forest remains at the same allocation count. This is the expected bounded-memory tradeoff for cycle detection and is not material on the branch-DAG construction path. An optional root/known-parent fast path could reduce constant CPU cost but is not a merge blocker.

No correctness, liveness, compatibility, or practical performance blocker found. Approval remains valid.

@XuPeng-SH
XuPeng-SH merged commit 7b4c81a into matrixorigin:main Jul 24, 2026
23 of 25 checks passed
@mergify mergify Bot added dequeued and removed queued labels Jul 24, 2026
@VioletQwQ-0
VioletQwQ-0 deleted the codex/issue-26083-dag-cycle branch July 27, 2026 02:58
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#26139)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26083

## What this PR does / why we need it:

Replace recursive Data Branch DAG depth calculation with a bounded
iterative
parent walk. When corrupted branch metadata contains a parent cycle, all
nodes
in that cycle are deterministically detached and treated as roots, while
non-cyclic descendants retain their valid parent edges.

This prevents cyclic `mo_branch_metadata` from exhausting the process
stack and
also removes recursive stack growth for deep acyclic chains. The
existing
`NewDAG` API and ordinary LCA behavior remain unchanged.

Adds a bounded child-process regression covering a two-node cycle,
self-cycle,
non-cyclic descendant, and a 4,096-node acyclic chain.

Validation:

- `go test ./pkg/frontend/databranchutils -run
'^(TestNewDAGCycle|TestDAGFunctionality)$' -count=10`
- `go test ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$'
-count=50`
- `go test -race ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$'
-count=1`
- `go test ./pkg/frontend/databranchutils -count=1`
- `go test ./pkg/frontend -run '^$' -count=1`
- `git diff --check`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#26139)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26083

## What this PR does / why we need it:

Replace recursive Data Branch DAG depth calculation with a bounded
iterative
parent walk. When corrupted branch metadata contains a parent cycle, all
nodes
in that cycle are deterministically detached and treated as roots, while
non-cyclic descendants retain their valid parent edges.

This prevents cyclic `mo_branch_metadata` from exhausting the process
stack and
also removes recursive stack growth for deep acyclic chains. The
existing
`NewDAG` API and ordinary LCA behavior remain unchanged.

Adds a bounded child-process regression covering a two-node cycle,
self-cycle,
non-cyclic descendant, and a 4,096-node acyclic chain.

Validation:

- `go test ./pkg/frontend/databranchutils -run
'^(TestNewDAGCycle|TestDAGFunctionality)$' -count=10`
- `go test ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$'
-count=50`
- `go test -race ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$'
-count=1`
- `go test ./pkg/frontend/databranchutils -count=1`
- `go test ./pkg/frontend -run '^$' -count=1`
- `git diff --check`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#26139)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26083

## What this PR does / why we need it:

Replace recursive Data Branch DAG depth calculation with a bounded
iterative
parent walk. When corrupted branch metadata contains a parent cycle, all
nodes
in that cycle are deterministically detached and treated as roots, while
non-cyclic descendants retain their valid parent edges.

This prevents cyclic `mo_branch_metadata` from exhausting the process
stack and
also removes recursive stack growth for deep acyclic chains. The
existing
`NewDAG` API and ordinary LCA behavior remain unchanged.

Adds a bounded child-process regression covering a two-node cycle,
self-cycle,
non-cyclic descendant, and a 4,096-node acyclic chain.

Validation:

- `go test ./pkg/frontend/databranchutils -run
'^(TestNewDAGCycle|TestDAGFunctionality)$' -count=10`
- `go test ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$'
-count=50`
- `go test -race ./pkg/frontend/databranchutils -run '^TestNewDAGCycle$'
-count=1`
- `go test ./pkg/frontend/databranchutils -count=1`
- `go test ./pkg/frontend -run '^$' -count=1`
- `git diff --check`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants