Skip to content

Refactor: enahnce retry and timeout - #14983

Merged
wangq8 merged 14 commits into
infiniflow:mainfrom
wangq8:feature/add-spacy-4
May 22, 2026
Merged

wangq8 merged 14 commits into
infiniflow:mainfrom
wangq8:feature/add-spacy-4

Conversation

@wangq8

@wangq8 wangq8 commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

  1. Enhance retry and timeout, and adjust the default timeout
  2. NER: spacy do not batch chunks
  3. extract _has_cancel_and_exit
  4. enhance log messages

Type of change

  • New Feature (non-breaking change which adds functionality)
  • Refactoring

@coderabbitai

coderabbitai Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 746927bf-0ba0-40d0-8a87-edc89e4be460

📥 Commits

Reviewing files that changed from the base of the PR and between 96c4dcc and 579c579.

📒 Files selected for processing (1)
  • test/testcases/configs.py

📝 Walkthrough

Walkthrough

Adds Graphrag retry/backoff and per-phase timeout/lock configuration, introduces orchestration helpers (_has_cancel_and_exit, _run_with_retry, _acquire_lock), and integrates them into run_graphrag_for_kb and phase functions with cancellation checkpoints and user-facing chunk numbering fixes.

Changes

GraphRAG Retry, Timeout, and Locking Orchestration

Layer / File(s) Summary
Configuration Schema and Default Values
api/utils/validation_utils.py, api/utils/api_utils.py, rag/svr/task_executor.py
GraphragConfig adds fields for retry attempts, backoff timing, per-phase timeouts, and lock acquire timeout; API utils and task executor provide matching defaults.
Orchestration Helpers and Constants
rag/graphrag/general/index.py
Adds min/max batch token constants, default retry/backoff/timeout constants, bounded config-parsing helpers, cancellation helper _has_cancel_and_exit, async retry-with-timeout/backoff _run_with_retry, and cancellable Redis lock acquisition _acquire_lock.
Main Orchestration Loop Integration
rag/graphrag/general/index.py
run_graphrag_for_kb parses bounded graphrag_config values, handles empty-doc early exit, adjusts chunk batching (NER no LLM batching), computes per-doc build timeouts, and runs subgraph generation with retries while collecting failures.
Merge, Resolution, and Community Phase Orchestration
rag/graphrag/general/index.py
Merges run under a merge lock using _acquire_lock with per-doc merge retries via _run_with_retry; post-merge resolution and community phases run under a second lock with configured retries/timeouts and phase-marker updates.
Subgraph Generation Cancellation Checkpoints
rag/graphrag/general/index.py
generate_subgraph adds cancellation checkpoints at entry, during entity/relationship processing, before tidying, and before persisting subgraph chunks.
Resolution and Community Cancellation Checkpoints
rag/graphrag/general/index.py
resolve_entities and extract_community add early and mid-phase cancellation checkpoints and save/index gating.
Progress Message Display Updates
rag/graphrag/general/graph_extractor.py, rag/graphrag/light/graph_extractor.py, rag/graphrag/ner/graph_extractor.py
Chunk progress callbacks now display 1-based chunk numbers (use chunk_seq + 1).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • infiniflow/ragflow#14972: Overlaps on GraphRAG batching and run_graphrag_for_kb refactor; this PR adds additional retry/timeout/lock controls.

Suggested reviewers

  • KevinHuSh

Suggested labels

lgtm

Poem

🐰 I hopped through chunks both small and tall,
With retries and timeouts I steadied the fall.
Locks kept the merges tidy and tight,
Cancellation checked each cautious bite,
Now chunks count one — hop, review, and delight!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title "Refactor: enahnce retry and timeout" contains a typo ("enahnce" instead of "enhance") and is vague about the specific changes; it doesn't clearly convey what aspects are being enhanced or why. Correct the typo and make the title more specific, e.g., "Refactor: enhance retry, timeout, and cancellation handling in GraphRAG pipeline."
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description covers the main objectives (retry/timeout enhancements, NER spacy changes, cancellation extraction, log improvements) and marks the type of change, but lacks detail on what problems these changes solve and how they improve the system.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@wangq8 wangq8 changed the title refactor: extract _has_cancel_and_exit refactor: enahnce retry and timeout May 21, 2026
@wangq8 wangq8 added the ci Continue Integration label May 22, 2026
@wangq8
wangq8 marked this pull request as ready for review May 22, 2026 03:19
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 22, 2026
@wangq8 wangq8 changed the title refactor: enahnce retry and timeout Refactor: enahnce retry and timeout May 22, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rag/graphrag/general/index.py`:
- Around line 175-180: The backoff sleep should be interruptible so cancellation
is responsive: replace the one-shot await asyncio.sleep(wait) at the end of the
retry block with a short-chunk loop that repeatedly sleeps for a small interval
(e.g., 0.1s or min(wait, 0.1)) and checks for cancellation (via
asyncio.current_task().cancelled() or by letting asyncio.CancelledError
propagate) between chunks; ensure you re-raise CancelledError so cancellation
isn't swallowed. Update the code around the variables backoff_max_seconds,
backoff_seconds, attempt, attempts, wait and the callback/logging section to use
the chunked sleep loop instead of await asyncio.sleep(wait).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aef2609b-d2bc-436e-8cb0-fce9b21ca545

📥 Commits

Reviewing files that changed from the base of the PR and between c5a46fd and 188d581.

📒 Files selected for processing (7)
  • api/utils/api_utils.py
  • api/utils/validation_utils.py
  • rag/graphrag/general/graph_extractor.py
  • rag/graphrag/general/index.py
  • rag/graphrag/light/graph_extractor.py
  • rag/graphrag/ner/graph_extractor.py
  • rag/svr/task_executor.py

Comment on lines +175 to +180
wait = min(backoff_max_seconds, backoff_seconds * (2 ** (attempt - 1)))
if callback:
callback(msg=f"[GraphRAG] {label} failed attempt {attempt}/{attempts}: {error_msg}; retrying in {wait:.1f}s")
logging.warning("GraphRAG %s failed attempt %s/%s: %s", label, attempt, attempts, error_msg)
if wait > 0:
await asyncio.sleep(wait)

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Check cancellation during retry backoff sleep.

Backoff currently sleeps in one shot, so cancellation can be delayed until the full wait elapses. Poll cancellation during sleep to keep stop behavior responsive.

Proposed fix
-        if wait > 0:
-            await asyncio.sleep(wait)
+        if wait > 0:
+            slept = 0.0
+            while slept < wait:
+                _has_cancel_and_exit(task_id, f"Task {task_id} cancelled during {label} backoff.", callback)
+                interval = min(1.0, wait - slept)
+                await asyncio.sleep(interval)
+                slept += interval
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/graphrag/general/index.py` around lines 175 - 180, The backoff sleep
should be interruptible so cancellation is responsive: replace the one-shot
await asyncio.sleep(wait) at the end of the retry block with a short-chunk loop
that repeatedly sleeps for a small interval (e.g., 0.1s or min(wait, 0.1)) and
checks for cancellation (via asyncio.current_task().cancelled() or by letting
asyncio.CancelledError propagate) between chunks; ensure you re-raise
CancelledError so cancellation isn't swallowed. Update the code around the
variables backoff_max_seconds, backoff_seconds, attempt, attempts, wait and the
callback/logging section to use the chunked sleep loop instead of await
asyncio.sleep(wait).

@codecov

codecov Bot commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (c5a46fd) to head (579c579).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14983   +/-   ##
=======================================
  Coverage   93.12%   93.12%           
=======================================
  Files          10       10           
  Lines         713      713           
  Branches      116      116           
=======================================
  Hits          664      664           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 requested a review from KevinHuSh May 22, 2026 04:41
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 22, 2026
@wangq8
wangq8 merged commit a9ec78c into infiniflow:main May 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants