[Bug]: WorkflowProfiler reports zero elapsed time on Windows with Python <= 3.12

未关闭
#2,599 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 5 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

Start with WorkflowProfiler in profiling.py, total_runtime in run_pipeline.py, and tests/unit/indexing/test_profiling.py; check how elapsed time is measured and run the profiling tests on Windows with Python 3.11 or 3.12. Done means short workflows report positive elapsed time and pipeline runtime remains monotonic. The issue author says a fix and regression test are ready and that they plan to open a pull request, so check for work already underway before starting.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

WorkflowProfiler (and the pipeline total_runtime in run_pipeline.py) measure elapsed time with time.time(). On Windows, time.time() has a 15.6 ms resolution with Python <= 3.12 (it uses GetSystemTimeAsFileTime); CPython 3.13 switched to GetSystemTimePreciseAsFileTime with a 1 microsecond resolution (What's New in Python 3.13 - time).

Since pyproject.toml declares requires-python = ">=3.11,<3.14" but the unit-test CI matrix only runs Python 3.13, this bug is invisible to CI and affects every Windows user on Python 3.11/3.12:

  1. context.stats.workflows[name] = profiler.metrics writes overall = 0.0 for any workflow body shorter than one scheduler tick, so stats.json reports 0 ms per workflow on Windows with Python 3.11/3.12.
  2. tests/unit/indexing/test_profiling.py::TestWorkflowProfiler::test_handles_exception_in_context fails deterministically (assert 0.0 > 0), because the test body is microsecond-scale.
  3. time.time() is also a wall clock, so NTP adjustments can make elapsed/total_runtime negative or inflated; time.perf_counter() is the documented clock for measuring elapsed durations.
Steps to reproduce

On Windows with Python 3.11 or 3.12:

uv sync --all-packages
uv run pytest tests/unit/indexing/test_profiling.py

test_handles_exception_in_context fails with assert 0.0 > 0 on both 3.11.15 and 3.12.4 (verified: 11/11 pytest runs across both versions). A 300-iteration measurement of the exact try/with/raise block used by the test reports 298/300 zero elapsed values (99.3%), median 0.0, max 1.0 ms. The same test passes on Python 3.13 (3/3), which is exactly why the CI matrix (Python 3.13 only x ubuntu/windows) stays green while the supported versions fail.

Minimal clock probe on Windows, Python 3.12.4:

import time
zero = sum(
    (lambda t0: ([0] * 1000, time.time() - t0)[1] == 0.0)(time.time())
    for _ in range(200)
)
# -> 200/200 zero samples for a microsecond-scale body
Expected Behavior

WorkflowProfiler.overall and pipeline.total_runtime must be positive and monotonic regardless of Python version or OS. Elapsed-time measurement should use time.perf_counter() (high-resolution monotonic clock), per the Python docs recommendation for benchmarking.

GraphRAG Config Used

Not config-dependent; reproducible with the unit test suite alone.

Logs and screenshots
FAILED tests/unit/indexing/test_profiling.py::TestWorkflowProfiler::test_handles_exception_in_context - assert 0.0 > 0
 +  where 0.0 = WorkflowMetrics(overall=0.0, peak_memory_bytes=8480, memory_delta_bytes=8480, tracemalloc_overhead_bytes=1104).overall
Additional Information
  • GraphRAG Version: main (5faaaf4f5, post-3.3.0)
  • Operating System: Windows 11 (24H2, x64)
  • Python Version: 3.11.15, 3.12.4 (failing), 3.13.x (passing)
  • Related Issues: none found for this failure mode

I have a minimal fix ready (time.perf_counter() in profiling.py + run_pipeline.py, plus a regression test guarding positive elapsed time for sub-tick bodies) and will open a PR referencing this issue.

主要语言
Python
星标
36.6k
派生
3.9k
平均合并
4 天 11 小时
30 天内合并 PR
1

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/graphrag 的其他 Issue

查看 microsoft/graphrag 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。