Skip to content

[fix] Vermeer: make bounded cycle detection correct and allocation-safe - #31

Closed
imbajin wants to merge 2 commits into
masterfrom
fix/vermeer-triangle-cycle-runtime-20261105
Closed

imbajin wants to merge 2 commits into
masterfrom
fix/vermeer-triangle-cycle-runtime-20261105

Conversation

@imbajin

@imbajin imbajin commented Nov 5, 2026 •

Copy link
Copy Markdown

背景

cycle_detection 当前在 Hubble/Vermeer 上容易出现长时间运行,且存在确定性正确性问题:

  • 每层 DFS 都重新构造 visited map,单个 root 的分配量随深度重复增长;
  • 环长使用 len(stack),但 stack 不包含 root,导致三角环按长度 2 判断,min_length=3 时会漏掉合法 3 环;
  • cycle.max_length、min_length、max_cycles 缺少边界校验;
  • boolean 模式输出实际为 uint8,但属性类型声明为 TEXT;
  • 全局 cycle 计数使用 int32,大结果存在溢出风险。

方案

Before
每个 root
  └─ DFS level 1: 重建 visited map
      └─ DFS level 2: 再重建 visited map
          └─ ...
环长 = 不含 root 的 stack 长度

After
每个 root
  └─ 1 个 visited set + 1 个可回退 path
      ├─ push next
      ├─ DFS
      └─ pop/delete
环长 = 包含 root 的 path 长度
  • 抽取 searchBoundedCycles(),用单个 visited set 原地 push/pop;
  • closure 返回 root 时,以包含 root 的 path 长度判断真实环长;
  • all 模式保持不限数量,limit 严格按 max_cycles 停止,boolean 首个合法环立即停止;
  • 继续保持现有输出形状:root 由输出顶点隐含,cycle list 中不重复写 root;
  • all/limit 继续使用最小外部顶点 ID 作为 canonical root,避免同一环重复输出;
  • 参数在图规模分配前校验;
  • boolean 输出类型修正为 INT,cycle 总数升级为 int64。

测试

新增覆盖:

  • 3 环在 min_length=max_length=3 下可被识别;
  • 3 环不会错误通过 max_length=2;
  • 2 环、limit 提前停止、重复顶点拒绝;
  • canonical root 去重;
  • 非法远端 ID 防御;
  • 参数边界与 boolean 输出类型。

范围

  • 2 个文件;
  • 349 additions / 129 deletions;
  • 不改变框架 API;
  • 低于 2,000 行拆分上限。

性能边界

这次消除了递归层级重复 map 分配,并修复有界搜索语义。all 模式在稠密图上枚举全部简单环仍可能指数增长,这是输出规模本身决定的;生产环境需要受控结果时应使用 limit 或 boolean。

ASF 上游 PR 会使用同一 head 分支同步提交。

ASF upstream: apache#378

@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a6f37582-71df-452e-9a60-29f1c341a8bc
Commits

Reviewing files that changed from the base of the PR and between d06a23b and 741ef9c.

Files selected for processing: 2

  • vermeer/algorithms/cycle_detection.go
  • vermeer/algorithms/cycle_detection_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T15:05:08.080359Z 741ef9c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

imbajin commented Nov 5, 2026

Copy link
Copy Markdown
Author

已完成与 #33 的逐文件、语义和测试对比,保留 #33 作为主方案:

因此关闭本 PR 以减少两套实现并行审查;没有丢失独有测试或有效语义。

@imbajin imbajin closed this Nov 5, 2026
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.

1 participant