Skip to content

Fix: Adjust ExecutionStrategy of THINKING_MODES. - #17862

Merged
yingfeng merged 3 commits into
infiniflow:mainfrom
KevinHuSh:refine/agentic_search2
Aug 5, 2026
Merged

yingfeng merged 3 commits into
infiniflow:mainfrom
KevinHuSh:refine/agentic_search2

Conversation

@KevinHuSh

Copy link
Copy Markdown
Contributor

Summary

Adjust ExecutionStrategy of THINKING_MODES.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change expands search tools in harness modes, conditionally preserves closing reasoning markers in tool-result history, and stores tokenized fields for refined wiki pages.

Changes

Harness mode configuration

Layer / File(s) Summary
Search tools and execution settings
rag/advanced_rag/harness/config.py
Low and medium modes permit web_search and bm25_search. High mode includes bm25_search and does not require the agent loop.

Tool-result reasoning markers

Layer / File(s) Summary
Conditional reasoning marker preservation
rag/llm/chat_model.py
LiteLLMBase._append_history_batch removes existing closing markers and appends </think> when tool-result content contains <think>.

Wiki token metadata

Layer / File(s) Summary
Wiki page tokenization
rag/advanced_rag/knowlege_compile/wiki_incremental.py
_wiki_refine_page tokenizes generated content and persists tokenized title, full-content, and fine-grained content fields.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: 🐞 bug, 🌈 python

Poem

A rabbit hops through search and thought,
BM25 joins the trails sought.
Wiki pages gather tokens bright,
Think markers close their loop just right,
Three small changes land tonight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change to the ExecutionStrategy of THINKING_MODES.
Description check ✅ Passed The description includes the required Summary section and briefly states the purpose of the change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

🤖 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/config.py`:
- Line 18: Add informational logging at the selected-tool dispatch boundary in
Pipeline.execute, recording non-error tool calls, and add an informational log
when a selected tool executes without producing chunks; preserve the existing
error logging for unknown executors and exceptions.
🪄 Autofix

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: 6ecec06b-8ab1-4349-aa95-bb53851031e5

📥 Commits

Reviewing files that changed from the base of the PR and between a55a438 and 23461e9.

📒 Files selected for processing (1)
  • rag/advanced_rag/harness/config.py

max_agent_cycles=0,
max_parallel_agents=1,
available_tools=["hybrid_search"],
available_tools=["hybrid_search", "web_search", "bm25_search"],

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n -C 8 'available_tools|web_search|bm25_search|requires_agent_loop|logger|logging' --glob '*.py' .

Repository: infiniflow/ragflow

Length of output: 50375


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate config.py candidates =="
fd -a '^config\.py$' . | sed 's#^\./##' | rg 'rag/advanced_rag/harness/config.py|advanced_rag|dispatcher|harness' || true

echo "== inspect target config.py =="
if [ -f rag/advanced_rag/harness/config.py ]; then
  nl -ba rag/advanced_rag/harness/config.py | sed -n '1,120p'
fi

echo "== focused search for dispatcher / modes / new tools =="
rg -n --glob '*.py' 'class .*Dispatcher|dispatcher|dispatch|requires_agent_loop|available_tools|hybrid_search|web_search|bm25_search|logger|logging\b' rag/advanced_rag rag/advanced_rag/harness || true

echo "== list advanced_rag harness =="
git ls-files rag/advanced_rag/harness

Repository: infiniflow/ragflow

Length of output: 315


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== inspect target config.py =="
awk '{printf "%6d\t%s\n", NR, $0}' rag/advanced_rag/harness/config.py | sed -n '1,140p'

echo "== focused search for dispatcher / modes / new tools =="
rg -n --glob '*.py' 'class .*Dispatcher|dispatcher|dispatch|requires_agent_loop|available_tools|hybrid_search|web_search|bm25_search|logger|logging\b' rag/advanced_rag rag/advanced_rag/harness || true

echo "== list advanced_rag harness files =="
git ls-files rag/advanced_rag/harness

Repository: infiniflow/ragflow

Length of output: 49112


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== orchestrator implementation =="
awk '{printf "%6d\t%s\n", NR, $0}' rag/advanced_rag/harness/orchestrator/__init__.py | sed -n '1,220p'

echo "== direct implementation =="
awk '{printf "%6d\t%s\n", NR, $0}' rag/advanced_rag/harness/orchestrator/direct.py | sed -n '1,80p'

echo "== tool pipeline implementation =="
awk '{printf "%6d\t%s\n", NR, $0}' rag/advanced_rag/harness/pipeline.py | sed -n '1,180p'

echo "== route implementation =="
awk '{printf "%6d\t%s\n", NR, $0}' rag/advanced_rag/harness/route.py | sed -n '1,220p'

echo "== inspecting logging calls in dispatching modules =="
python3 - <<'PY'
from pathlib import Path
for path in [
    Path("rag/advanced_rag/harness/orchestrator/__init__.py"),
    Path("rag/advanced_rag/harness/orchestrator/direct.py"),
    Path("rag/advanced_rag/harness/pipeline.py"),
    Path("rag/advanced_rag/harness/route.py"),
]:
    text = path.read_text()
    lines = text.splitlines()
    print(f"\n--- {path} ---")
    for i, line in enumerate(lines, 1):
        l = line.strip()
        if l.startswith(("logging.", "_LOG.", "print(")) or "selective" in l.lower() or "dispatch" in l.lower() or "tool" in l.lower() or "mode" in l.lower() or "available" in l.lower():
            print(f"{i}: {l}")
PY

Repository: infiniflow/ragflow

Length of output: 21348


Add logging at the tool execution boundary.

orchestrator_loop logs the selected strategy, and Pipeline.execute logs unknown/missing executors and exceptions, but selected tool execution is not logged. Add an info/log at dispatch for non-error selected calls, and an info/log for tools that run with no chunks.

🤖 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/advanced_rag/harness/config.py` at line 18, Add informational logging at
the selected-tool dispatch boundary in Pipeline.execute, recording non-error
tool calls, and add an informational log when a selected tool executes without
producing chunks; preserve the existing error logging for unknown executors and
exceptions.

Source: Coding guidelines

@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)
rag/llm/chat_model.py (1)

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

Add debug logging for the new marker-normalization path.

This change introduces a new tool-history rewrite path without a diagnostic event. Add a debug-level log with marker counts. Do not log the raw tool content.

As per coding guidelines, new Python flows must add logging.

🤖 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/llm/chat_model.py` at line 2002, Add a debug-level log in the
tool-history rewrite path around the hist.append logic in chat_model.py so the
new marker-normalization flow is observable. Update the nearby normalization
branch to emit marker counts or other summary metrics from content processing,
and keep the log free of raw tool content while preserving the existing append
behavior.

Source: Coding guidelines

🤖 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/llm/chat_model.py`:
- Line 2002: The tool-message normalization in the history append logic must
stop removing every </think> marker. Update the surrounding chat-model handling
to preserve valid closing markers, append only the missing number needed to
balance existing <think> markers, and keep nested markers balanced; add tests
covering complete, missing, and nested marker cases.

---

Nitpick comments:
In `@rag/llm/chat_model.py`:
- Line 2002: Add a debug-level log in the tool-history rewrite path around the
hist.append logic in chat_model.py so the new marker-normalization flow is
observable. Update the nearby normalization branch to emit marker counts or
other summary metrics from content processing, and keep the log free of raw tool
content while preserving the existing append behavior.
🪄 Autofix

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: 19d08382-c189-4447-8bc2-14a3dfdaf36f

📥 Commits

Reviewing files that changed from the base of the PR and between 23461e9 and c6d3923.

📒 Files selected for processing (1)
  • rag/llm/chat_model.py

Comment thread rag/llm/chat_model.py
else:
content = str(result)
hist.append({"role": "tool", "tool_call_id": tc.id, "content": content.replace("</think>", "")})
hist.append({"role": "tool", "tool_call_id": tc.id, "content": content.replace("</think>", "") + ("</think>" if content.find("<think>") >= 0 else "")})

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve valid closing markers and append only missing markers.

For content = "<think>reason</think>answer", this expression produces <think>reasonanswer</think>. It moves normal output into the reasoning section. Nested markers can also become unbalanced because all closing markers are removed and only one is appended.

Use marker-aware balancing. Preserve existing closing markers. Add tests for complete, missing, and nested marker cases.

Suggested normalization
-            hist.append({"role": "tool", "tool_call_id": tc.id, "content": content.replace("</think>", "") + ("</think>" if content.find("<think>") >= 0 else "")})
+            missing_closers = max(0, content.count("<think>") - content.count("</think>"))
+            if missing_closers:
+                content += "</think>" * missing_closers
+            hist.append({"role": "tool", "tool_call_id": tc.id, "content": content})

If marker text can occur as ordinary tool data, use a parser or escape that data before counting markers.

This matches the marker behavior covered by test/unit_test/common/test_think_stream_parser.py:257-270 and agent/component/agent_with_tools.py:130-134.

🤖 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/llm/chat_model.py` at line 2002, The tool-message normalization in the
history append logic must stop removing every </think> marker. Update the
surrounding chat-model handling to preserve valid closing markers, append only
the missing number needed to balance existing <think> markers, and keep nested
markers balanced; add tests covering complete, missing, and nested marker cases.

@yingfeng yingfeng added the ci Continue Integration label Aug 5, 2026
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Aug 5, 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.

🧹 Nitpick comments (1)
rag/advanced_rag/knowlege_compile/wiki_incremental.py (1)

1672-1679: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add logging for the new wiki tokenization flow.

This flow adds tokenization but records no completion or output metadata. Add a structured debug log with safe metadata such as page version and field lengths. Do not log content, page_title, or token text.

As per coding guidelines, **/*.py: Add logging for new flows.

🤖 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/advanced_rag/knowlege_compile/wiki_incremental.py` around lines 1672 -
1679, Add a structured debug log after the new tokenization flow completes, near
rag_tokenizer.tokenize and embedding dimension derivation, recording safe
metadata such as page version and content, summary, and tokenized-field lengths.
Do not include content, page_title, or token text in the log, and use the
module’s existing logger.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@rag/advanced_rag/knowlege_compile/wiki_incremental.py`:
- Around line 1672-1679: Add a structured debug log after the new tokenization
flow completes, near rag_tokenizer.tokenize and embedding dimension derivation,
recording safe metadata such as page version and content, summary, and
tokenized-field lengths. Do not include content, page_title, or token text in
the log, and use the module’s existing logger.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 95361a18-030b-412d-8d81-e805b73e4943

📥 Commits

Reviewing files that changed from the base of the PR and between c6d3923 and ea33443.

📒 Files selected for processing (1)
  • rag/advanced_rag/knowlege_compile/wiki_incremental.py

@KevinHuSh
KevinHuSh marked this pull request as draft August 5, 2026 10:05
@KevinHuSh
KevinHuSh marked this pull request as ready for review August 5, 2026 10:05
@codecov

codecov Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (510e119) to head (ea33443).
⚠️ Report is 25 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17862   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

☔ View full report in Codecov by Harness.
📢 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.

@yingfeng yingfeng added ci Continue Integration and removed ci Continue Integration labels Aug 5, 2026
@yingfeng
yingfeng merged commit d2183e6 into infiniflow:main Aug 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants