Skip to content

fix: restore reasoning web search fallback - #17754

Closed
ffeus wants to merge 2 commits into
infiniflow:mainfrom
ffeus:fix/17638-reasoning-web-search
Closed

ffeus wants to merge 2 commits into
infiniflow:mainfrom
ffeus:fix/17638-reasoning-web-search

Conversation

@ffeus

@ffeus ffeus commented Aug 4, 2026

Copy link
Copy Markdown

Summary

Reasoning-enabled chats could not reliably reach Web search when no usable local knowledge-base evidence was available.

What problem does this PR solve?

The failure differed by reasoning mode:

  • Low only performed local hybrid search.
  • Medium decomposed claims but only searched locally.
  • High and Ultra could hide web_search through phase-based tool gating when local evidence was absent.

This caused Internet-enabled, web-only chats to skip the configured Web search provider.

What is changed?

  • Keep Low and Medium local-first, then fall back to Web search when local retrieval is empty.
  • Make Web search reachable in High/Ultra when the request starts without local evidence.
  • Preserve the initial local-evidence state separately from the shared evidence pool so later Web results do not incorrectly suppress Web search.
  • Deduplicate equivalent Web requests within one reasoning execution, including concurrent requests.
  • Include provider-affecting query and keyword input in the Web cache identity.
  • Preserve Internet-disabled behavior and shared evidence/citation indexing.

Testing

  • Focused reasoning Web-search regression suite: 22 passed
  • Scoped Ruff: passed
  • Ruff format check: passed
  • Targeted compile check: passed
  • git diff --check: passed

Local validation used Python 3.12.8 because Python 3.13 was unavailable in the local environment; the repository declares Python >=3.13,<3.14.

Closes #17638

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Reasoning modes now expose web search when local evidence is absent, fall back from empty hybrid retrieval, merge web evidence into the knowledge base, and cache equivalent requests. Tests cover enabled, disabled, failure, fallback, deduplication, and multi-claim scenarios.

Changes

Web reasoning support

Layer / File(s) Summary
Web search caching and request coalescing
rag/advanced_rag/harness/pipeline.py, test/unit_test/rag/advanced_rag/harness/test_web_only_reasoning.py
Pipeline normalizes cache keys, shares equivalent in-flight requests, caches successful results, and retries failed requests.
Tool availability and phase routing
rag/advanced_rag/harness/config.py, rag/advanced_rag/harness/tools/gating.py, rag/advanced_rag/harness/agent.py, rag/advanced_rag/harness/orchestrator/agentic.py, test/unit_test/rag/advanced_rag/harness/test_web_only_reasoning.py
Low and medium modes include web_search. Agentic modes use local-evidence state for phase routing and omit web search when it is unavailable.
Retrieval fallback and evidence merging
rag/advanced_rag/harness/orchestrator/direct.py, rag/advanced_rag/harness/orchestrator/decompose.py, test/unit_test/rag/advanced_rag/harness/test_web_only_reasoning.py
Direct and decomposed retrieval use web search after empty local results. Merging deduplicates chunks and returns evidence IDs for verified claims.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ReasoningOrchestrator
  participant Pipeline
  participant hybrid_search
  participant web_search
  participant KnowledgeBase
  ReasoningOrchestrator->>Pipeline: execute hybrid_search
  Pipeline->>hybrid_search: retrieve local chunks
  hybrid_search-->>Pipeline: empty or non-empty result
  alt local result is empty and web search is available
    ReasoningOrchestrator->>Pipeline: execute web_search
    Pipeline->>web_search: retrieve external evidence
    web_search-->>Pipeline: web chunks
  end
  Pipeline-->>ReasoningOrchestrator: search result
  ReasoningOrchestrator->>KnowledgeBase: merge deduplicated chunks
  KnowledgeBase-->>ReasoningOrchestrator: evidence IDs
Loading

Possibly related PRs

Poem

A rabbit checks the local ground,
Then web-search hops are found.
Chunks merge and claims gain IDs,
Cached requests share their rides.
With web disabled, no calls are made.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address the linked issue by enabling Web search fallback across reasoning modes while preserving disabled-internet behavior and evidence indexing [#17638].
Out of Scope Changes check ✅ Passed The implementation and regression tests are directly related to restoring Web search fallback and preventing duplicate requests.
Title check ✅ Passed The title clearly and concisely describes restoring Web search fallback for reasoning-enabled chats.
Description check ✅ Passed The description includes the required Summary section and provides clear problem, solution, testing, environment, and issue context.

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.

@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

🧹 Nitpick comments (1)
test/unit_test/rag/advanced_rag/harness/test_web_only_reasoning.py (1)

6-41: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Isolate the import stubs.

Lines 6-41 leave synthetic parent modules in sys.modules. Later tests can import the fake rag.advanced_rag package and skip the real package initializer.

Move this bootstrap into an isolated fixture. Restore every module entry that the fixture adds after the module tests finish.

🤖 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 `@test/unit_test/rag/advanced_rag/harness/test_web_only_reasoning.py` around
lines 6 - 41, Move the synthetic module setup currently at module scope into an
autouse fixture for the tests in this module, preserving the existing stubs for
rag.advanced_rag and infinity.rag_tokenizer. Track each sys.modules entry added
or replaced by the fixture and restore its prior value, or remove it when
absent, during fixture teardown so later tests can import the real package
initializer.

Source: Learnings

🤖 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/advanced_rag/harness/pipeline.py`:
- Around line 46-68: Add structured logs in _execute_web_search for cache hits,
creation of a new provider task, and joining an existing in-flight task; use the
cache key or other non-sensitive metadata, never raw queries. In
rag/advanced_rag/harness/orchestrator/decompose.py lines 40-49, log local-search
fallback to web search and web-cache reuse without including raw claim text.

---

Nitpick comments:
In `@test/unit_test/rag/advanced_rag/harness/test_web_only_reasoning.py`:
- Around line 6-41: Move the synthetic module setup currently at module scope
into an autouse fixture for the tests in this module, preserving the existing
stubs for rag.advanced_rag and infinity.rag_tokenizer. Track each sys.modules
entry added or replaced by the fixture and restore its prior value, or remove it
when absent, during fixture teardown so later tests can import the real package
initializer.
🪄 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 Plus

Run ID: 7af5c027-8232-4a4b-8d1b-9bdf8a2d698a

📥 Commits

Reviewing files that changed from the base of the PR and between 594a464 and 92a1a94.

📒 Files selected for processing (8)
  • rag/advanced_rag/harness/agent.py
  • rag/advanced_rag/harness/config.py
  • rag/advanced_rag/harness/orchestrator/agentic.py
  • rag/advanced_rag/harness/orchestrator/decompose.py
  • rag/advanced_rag/harness/orchestrator/direct.py
  • rag/advanced_rag/harness/pipeline.py
  • rag/advanced_rag/harness/tools/gating.py
  • test/unit_test/rag/advanced_rag/harness/test_web_only_reasoning.py

Comment thread rag/advanced_rag/harness/pipeline.py Resolved
@yingfeng yingfeng added the ci Continue Integration label Aug 4, 2026

@KevinHuSh KevinHuSh 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.

But CI faild. Could you fix it?

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 4, 2026
@KevinHuSh
KevinHuSh marked this pull request as draft August 4, 2026 03:53
@KevinHuSh
KevinHuSh marked this pull request as ready for review August 4, 2026 03:53
@KevinHuSh KevinHuSh added ci Continue Integration and removed ci Continue Integration labels Aug 4, 2026
@ffeus

ffeus commented Aug 4, 2026

Copy link
Copy Markdown
Author

Thanks for the review. I investigated the CI failure.

The two failing wiki tests pass in isolation on the CI merge ref, and they also pass on upstream main. This PR does not modify the wiki implementation or those tests.

I also tried to rerun the failed workflow, but GitHub requires repository admin permissions for the rerun. Could you please rerun the failed job once?

If the same failure reproduces, I’ll continue investigating the full-suite test ordering/import isolation under Python 3.13.

@ffeus

ffeus commented Aug 10, 2026

Copy link
Copy Markdown
Author

Thanks for the review. I see that #17789 has been merged and closes #17638, with overlapping Web-search changes in the same agentic-search paths.

Since this PR is now conflicting and superseded by the upstream implementation, I’m closing it to avoid duplicate work. Thanks again for the review and approval.

@ffeus ffeus closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration lgtm This PR has been approved by a maintainer 🌈 python Pull requests that update Python code size:L This PR changes 100-499 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Web search is unreachable across reasoning modes for web-only chats

3 participants