Skip to content

fix(agent): Switch no longer matches an empty condition (all([]) is True) - #15644

Merged
yuzhichang merged 3 commits into
infiniflow:mainfrom
seekmistar01:fix/switch-empty-condition-all
Jun 28, 2026
Merged

yuzhichang merged 3 commits into
infiniflow:mainfrom
seekmistar01:fix/switch-empty-condition-all

Conversation

@seekmistar01

Copy link
Copy Markdown
Contributor

Summary

Fixes the agent Switch component matching an empty/all-skipped condition unconditionally because all([]) is True.

Root cause

res only accumulates for items with a non-empty cpn_id (blank ones continue). For a condition with empty items (or all-blank cpn_id), res == [], and if all(res): is True, so the Switch routes to that condition's to target before reaching the else/end_cpn_ids branch.

Fix

-            if all(res):
+            if res and all(res):

An empty result set no longer counts as a match; genuinely-satisfied "and" conditions still route (the real all(res) path is preserved).

Files changed

  • agent/component/switch.py
  • test/unit_test/agent/component/test_switch_empty_condition.py (new)

Verification

  • ruff check / ruff format --check — clean
  • Added unit tests (mirroring the existing _FakeCanvas component-test pattern): an empty/all-skipped "and" condition now falls through to end_cpn_ids; a genuinely-satisfied "and" condition still routes to its target.
  • Local full pytest not run (heavy RAG deps); CI validates.

Note

Implemented with LLM assistance (model: claude-opus-4-8).

Closes #15643

…rue)

res only accumulates for items with a non-empty cpn_id, so a condition with
empty/all-blank items left res == [], and 'if all(res):' is True in Python,
routing the Switch to that condition unconditionally before the else/end
branch. Guard with 'if res and all(res):'.

Closes infiniflow#15643

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 4, 2026
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR fixes a bug in the Switch component where empty conditions incorrectly matched because all([]) evaluates to True in Python. The condition guard now requires both non-empty results and all items to be truthy before routing to a matched target, with regression tests validating the fix and ensuring normal routing still works.

Changes

Empty condition routing fix

Layer / File(s) Summary
Fix and regression tests for empty AND condition routing
agent/component/switch.py, test/unit_test/agent/component/test_switch_empty_condition.py
The short-circuit condition in Switch._invoke now checks res and all(res) instead of just all(res), preventing empty result lists from unconditionally matching. Regression tests validate that conditions with all blank cpn_id items fall through to end_cpn_ids, while satisfied conditions still route correctly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A switch that fell for empty dreams,
Now knows that all([]) deceives, it seems!
With res and all(res) standing guard,
Empty conditions won't be so hard.
Tests confirm the flow runs true,
Routing fixed—fresh and new! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main bug fix: the Switch component now correctly rejects empty conditions by guarding all([]) with a non-empty check.
Description check ✅ Passed The description comprehensively covers the problem, root cause, fix, files changed, and verification steps, following the template structure with clear sections.
Linked Issues check ✅ Passed The code changes fully address all requirements from #15643: the fix guards against empty res, unit tests verify both empty conditions fall through and satisfied conditions still route correctly.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the Switch component bug: one-line fix in switch.py and new test file covering the regression and validation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

@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: 2

🤖 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 `@test/unit_test/agent/component/test_switch_empty_condition.py`:
- Around line 25-27: Add the required pytest priority marker(s) to this test
module by declaring a module-level pytestmark list that includes the appropriate
priority (e.g., pytest.mark.p1 or p2/p3 as per policy); locate the test module
test_switch_empty_condition.py (which imports Switch and defines the tests) and
add a top-level line like pytestmark = [pytest.mark.p1] so all tests in this
file are annotated—alternatively, annotate individual test functions with
`@pytest.mark.p1` if only specific tests need the marker.
- Around line 53-77: Add a regression test that covers the explicit empty-items
case for an "and" condition so it falls through to end; in
test_switch_empty_condition.py create a new test (similar to
test_empty_condition_falls_through_to_end) that uses conditions =
[{"logical_operator": "and", "items": [], "to": ["TARGET"]}] and calls
_make_switch(..., end_cpn_ids=["END"]) and asserts outputs["_next"] == ["END"];
place it alongside the existing tests to ensure the empty-list branch in the
switch evaluation (the code paths exercised by _make_switch) is locked down.
🪄 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: 837a2fc0-0f5b-4b72-aa3c-c16c570e8314

📥 Commits

Reviewing files that changed from the base of the PR and between b65b18b and d359324.

📒 Files selected for processing (2)
  • agent/component/switch.py
  • test/unit_test/agent/component/test_switch_empty_condition.py

Comment on lines +25 to +27
from types import SimpleNamespace

from agent.component.switch import Switch

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 | 🟠 Major | ⚡ Quick win

Add pytest priority marker(s) required by repo policy.

This file is missing p1/p2/p3 marker annotations for tests. Please add a module-level marker (or per-test markers) to match the test policy.

Suggested minimal change
+import pytest
 from types import SimpleNamespace
 
 from agent.component.switch import Switch
+
+pytestmark = pytest.mark.p2
As per coding guidelines: `test/**/*.py`: Use pytest with priority markers (p1/p2/p3) for Python testing.

Also applies to: 53-77

🤖 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/agent/component/test_switch_empty_condition.py` around lines
25 - 27, Add the required pytest priority marker(s) to this test module by
declaring a module-level pytestmark list that includes the appropriate priority
(e.g., pytest.mark.p1 or p2/p3 as per policy); locate the test module
test_switch_empty_condition.py (which imports Switch and defines the tests) and
add a top-level line like pytestmark = [pytest.mark.p1] so all tests in this
file are annotated—alternatively, annotate individual test functions with
`@pytest.mark.p1` if only specific tests need the marker.

Comment on lines +53 to +77
def test_empty_condition_falls_through_to_end():
# The only item is skipped (blank cpn_id) -> result list is empty.
conditions = [
{
"logical_operator": "and",
"items": [{"cpn_id": "", "operator": "contains", "value": "x"}],
"to": ["TARGET"],
}
]
outputs = _make_switch(conditions, end_cpn_ids=["END"])
assert outputs["_next"] == ["END"]


def test_satisfied_and_condition_still_routes():
# A genuinely satisfied "and" condition must still route to its target
# (the fix must not break the real all(res) path).
conditions = [
{
"logical_operator": "and",
"items": [{"cpn_id": "c@out", "operator": "contains", "value": "hello"}],
"to": ["TARGET"],
}
]
outputs = _make_switch(conditions, end_cpn_ids=["END"], refs={"c@out": "hello world"})
assert outputs["_next"] == ["TARGET"]

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

Add regression coverage for truly empty items in AND conditions.

Current tests cover the “all skipped because blank cpn_id” variant, but not the explicit items: [] variant described in the issue objective. Add one test to lock that path down too.

Suggested test addition
+def test_empty_items_and_condition_falls_through_to_end():
+    conditions = [
+        {
+            "logical_operator": "and",
+            "items": [],
+            "to": ["TARGET"],
+        }
+    ]
+    outputs = _make_switch(conditions, end_cpn_ids=["END"])
+    assert outputs["_next"] == ["END"]
🤖 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/agent/component/test_switch_empty_condition.py` around lines
53 - 77, Add a regression test that covers the explicit empty-items case for an
"and" condition so it falls through to end; in test_switch_empty_condition.py
create a new test (similar to test_empty_condition_falls_through_to_end) that
uses conditions = [{"logical_operator": "and", "items": [], "to": ["TARGET"]}]
and calls _make_switch(..., end_cpn_ids=["END"]) and asserts outputs["_next"] ==
["END"]; place it alongside the existing tests to ensure the empty-list branch
in the switch evaluation (the code paths exercised by _make_switch) is locked
down.

@yuzhichang
yuzhichang self-requested a review June 28, 2026 00:49
@yuzhichang yuzhichang added the ci Continue Integration label Jun 28, 2026
@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (f90be41) to head (8eaf34a).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15644      +/-   ##
==========================================
- Coverage   94.56%   93.16%   -1.40%     
==========================================
  Files          10       10              
  Lines         717      717              
  Branches      118      118              
==========================================
- Hits          678      668      -10     
- Misses         25       29       +4     
- Partials       14       20       +6     

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

@yuzhichang
yuzhichang merged commit 2589b6e into infiniflow:main Jun 28, 2026
6 checks passed
yuzhichang added a commit that referenced this pull request Jun 29, 2026
…rue) (#15644)

## Summary
Fixes the agent `Switch` component matching an **empty/all-skipped
condition** unconditionally because `all([]) is True`.

## Root cause
`res` only accumulates for items with a non-empty `cpn_id` (blank ones
`continue`). For a condition with empty `items` (or all-blank `cpn_id`),
`res == []`, and `if all(res):` is `True`, so the Switch routes to that
condition's `to` target before reaching the else/`end_cpn_ids` branch.

## Fix
```diff
-            if all(res):
+            if res and all(res):
```
An empty result set no longer counts as a match; genuinely-satisfied
"and" conditions still route (the real `all(res)` path is preserved).

## Files changed
- `agent/component/switch.py`
- `test/unit_test/agent/component/test_switch_empty_condition.py` (new)

## Verification
- `ruff check` / `ruff format --check` — clean
- Added unit tests (mirroring the existing `_FakeCanvas` component-test
pattern): an empty/all-skipped "and" condition now falls through to
`end_cpn_ids`; a genuinely-satisfied "and" condition still routes to its
target.
- Local full pytest not run (heavy RAG deps); CI validates.

## Note
Implemented with LLM assistance (model: claude-opus-4-8).

Closes #15643

---------

Co-authored-by: seekmistar01 <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: Zhichang Yu <[email protected]>
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md
Execution snapshot (all merged upstream) to the Go agent side.

Group 1 - tool ports
- infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and
  wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and
  empty host are rejected before any driver dispatch. Allowed hosts
  are dialed via the validated/resolved public IP (DNS-pin).
- infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare
  through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and
  jin10 is a stub. Added regression guard tests: default client
  timeout, stage timeouts, and AST scan for bare http.Get/Post calls
  outside the helper.

Group 2 - component ports
- infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper
  returning {"content": v} frame; add DeepL translation-failure
  regression test using rewriteHostTransport (avoids mutating
  package globals which raced TestDeepL_BuildRequest).
- infiniflow#15644 Switch no longer matches empty condition: evaluateGroup
  empty-clauses short-circuit now returns false (was true) so an
  "and" condition with no clauses falls through to the next
  condition or end_cpn_ids instead of routing to the empty
  group's "to" target. Mirrors the all([]) is True fix.

Group 4 - API ports
- infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces
  WHERE id = ? AND dialog_id = ? (stronger than the Python
  post-fetch check). Added 3 IDOR regression tests at the service
  level (Get/Get mismatch/Delete) confirming the binding holds.

Total: 32 new tests across 4 new test files. All agent/tool and
agent/component tests pass (320 + 331). All new service IDOR
tests pass (3/3). The one failing test in agent/component
(TestAgent_ReActExhaustsSteps) is a pre-existing flaky test that
also fails on the baseline without my changes.

Refs: .claude/plans/review-and-port-py-agent-changes.md
Refs: infiniflow#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md
Execution snapshot (all merged upstream) to the Go agent side.

Group 1 - tool ports
- infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and
  wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and
  empty host are rejected before any driver dispatch. Allowed hosts
  are dialed via the validated/resolved public IP (DNS-pin).
- infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare
  through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and
  jin10 is a stub. Added regression guard tests: default client
  timeout, stage timeouts, and AST scan for bare http.Get/Post calls
  outside the helper.

Group 2 - component ports
- infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper
  returning {"content": v} frame; add DeepL translation-failure
  regression test using rewriteHostTransport (avoids mutating
  package globals which raced TestDeepL_BuildRequest).
- infiniflow#15644 Switch no longer matches empty condition: evaluateGroup
  empty-clauses short-circuit now returns false (was true) so an
  "and" condition with no clauses falls through to the next
  condition or end_cpn_ids instead of routing to the empty
  group's "to" target. Mirrors the all([]) is True fix.

Group 4 - API ports
- infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces
  WHERE id = ? AND dialog_id = ? (stronger than the Python
  post-fetch check). Added 3 IDOR regression tests at the service
  level (Get/Get mismatch/Delete) confirming the binding holds.

Total: 32 new tests across 4 new test files. All agent/tool and
agent/component tests pass (320 + 331). All new service IDOR
tests pass (3/3). The one failing test in agent/component
(TestAgent_ReActExhaustsSteps) is a pre-existing flaky test that
also fails on the baseline without my changes.

Refs: .claude/plans/review-and-port-py-agent-changes.md
Refs: infiniflow#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md
Execution snapshot (all merged upstream) to the Go agent side.

Group 1 - tool ports
- infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and
  wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and
  empty host are rejected before any driver dispatch. Allowed hosts
  are dialed via the validated/resolved public IP (DNS-pin).
- infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare
  through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and
  jin10 is a stub. Added regression guard tests: default client
  timeout, stage timeouts, and AST scan for bare http.Get/Post calls
  outside the helper.

Group 2 - component ports
- infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper
  returning {"content": v} frame; add DeepL translation-failure
  regression test using rewriteHostTransport (avoids mutating
  package globals which raced TestDeepL_BuildRequest).
- infiniflow#15644 Switch no longer matches empty condition: evaluateGroup
  empty-clauses short-circuit now returns false (was true) so an
  "and" condition with no clauses falls through to the next
  condition or end_cpn_ids instead of routing to the empty
  group's "to" target. Mirrors the all([]) is True fix.

Group 4 - API ports
- infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces
  WHERE id = ? AND dialog_id = ? (stronger than the Python
  post-fetch check). Added 3 IDOR regression tests at the service
  level (Get/Get mismatch/Delete) confirming the binding holds.

Total: 32 new tests across 4 new test files. All agent/tool and
agent/component tests pass (320 + 331). All new service IDOR
tests pass (3/3). The one failing test in agent/component
(TestAgent_ReActExhaustsSteps) is a pre-existing flaky test that
also fails on the baseline without my changes.

Refs: .claude/plans/review-and-port-py-agent-changes.md
Refs: infiniflow#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md
Execution snapshot (all merged upstream) to the Go agent side.

Group 1 - tool ports
- infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and
  wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and
  empty host are rejected before any driver dispatch. Allowed hosts
  are dialed via the validated/resolved public IP (DNS-pin).
- infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare
  through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and
  jin10 is a stub. Added regression guard tests: default client
  timeout, stage timeouts, and AST scan for bare http.Get/Post calls
  outside the helper.

Group 2 - component ports
- infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper
  returning {"content": v} frame; add DeepL translation-failure
  regression test using rewriteHostTransport (avoids mutating
  package globals which raced TestDeepL_BuildRequest).
- infiniflow#15644 Switch no longer matches empty condition: evaluateGroup
  empty-clauses short-circuit now returns false (was true) so an
  "and" condition with no clauses falls through to the next
  condition or end_cpn_ids instead of routing to the empty
  group's "to" target. Mirrors the all([]) is True fix.

Group 4 - API ports
- infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces
  WHERE id = ? AND dialog_id = ? (stronger than the Python
  post-fetch check). Added 3 IDOR regression tests at the service
  level (Get/Get mismatch/Delete) confirming the binding holds.

Total: 32 new tests across 4 new test files. All agent/tool and
agent/component tests pass (320 + 331). All new service IDOR
tests pass (3/3). The one failing test in agent/component
(TestAgent_ReActExhaustsSteps) is a pre-existing flaky test that
also fails on the baseline without my changes.

Refs: .claude/plans/review-and-port-py-agent-changes.md
Refs: infiniflow#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md
Execution snapshot (all merged upstream) to the Go agent side.

Group 1 - tool ports
- infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and
  wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and
  empty host are rejected before any driver dispatch. Allowed hosts
  are dialed via the validated/resolved public IP (DNS-pin).
- infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare
  through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and
  jin10 is a stub. Added regression guard tests: default client
  timeout, stage timeouts, and AST scan for bare http.Get/Post calls
  outside the helper.

Group 2 - component ports
- infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper
  returning {"content": v} frame; add DeepL translation-failure
  regression test using rewriteHostTransport (avoids mutating
  package globals which raced TestDeepL_BuildRequest).
- infiniflow#15644 Switch no longer matches empty condition: evaluateGroup
  empty-clauses short-circuit now returns false (was true) so an
  "and" condition with no clauses falls through to the next
  condition or end_cpn_ids instead of routing to the empty
  group's "to" target. Mirrors the all([]) is True fix.

Group 4 - API ports
- infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces
  WHERE id = ? AND dialog_id = ? (stronger than the Python
  post-fetch check). Added 3 IDOR regression tests at the service
  level (Get/Get mismatch/Delete) confirming the binding holds.

Total: 32 new tests across 4 new test files. All agent/tool and
agent/component tests pass (320 + 331). All new service IDOR
tests pass (3/3). The one failing test in agent/component
(TestAgent_ReActExhaustsSteps) is a pre-existing flaky test that
also fails on the baseline without my changes.

Refs: .claude/plans/review-and-port-py-agent-changes.md
Refs: infiniflow#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 30, 2026
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md
Execution snapshot (all merged upstream) to the Go agent side.

Group 1 - tool ports
- infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and
  wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and
  empty host are rejected before any driver dispatch. Allowed hosts
  are dialed via the validated/resolved public IP (DNS-pin).
- infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare
  through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and
  jin10 is a stub. Added regression guard tests: default client
  timeout, stage timeouts, and AST scan for bare http.Get/Post calls
  outside the helper.

Group 2 - component ports
- infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper
  returning {"content": v} frame; add DeepL translation-failure
  regression test using rewriteHostTransport (avoids mutating
  package globals which raced TestDeepL_BuildRequest).
- infiniflow#15644 Switch no longer matches empty condition: evaluateGroup
  empty-clauses short-circuit now returns false (was true) so an
  "and" condition with no clauses falls through to the next
  condition or end_cpn_ids instead of routing to the empty
  group's "to" target. Mirrors the all([]) is True fix.

Group 4 - API ports
- infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces
  WHERE id = ? AND dialog_id = ? (stronger than the Python
  post-fetch check). Added 3 IDOR regression tests at the service
  level (Get/Get mismatch/Delete) confirming the binding holds.

Total: 32 new tests across 4 new test files. All agent/tool and
agent/component tests pass (320 + 331). All new service IDOR
tests pass (3/3). The one failing test in agent/component
(TestAgent_ReActExhaustsSteps) is a pre-existing flaky test that
also fails on the baseline without my changes.

Refs: .claude/plans/review-and-port-py-agent-changes.md
Refs: infiniflow#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374

Apply unstaged agent-go-port prep work

docker/.env
  - switch API_PROXY_SCHEME from python to go (Go server is the default)
  - enable SANDBOX_ENABLED=1 and extend COMPOSE_PROFILES with ragflow-go

web/CLAUDE.md
  - document frontend agent conventions: CSS/flex layout debugging,
    scope boundaries, i18n language files, query-key factory pattern,
    request layering (hook -> service -> next-request), shared UI lock,
    utility libs (dayjs, ahooks, lodash)

web/.agents/skills/tanstack-query-best-practices/
  - remove the full tanstack-query-best-practices skill set
    (SKILL.md + 21 rule files, 1,535 lines total)

Lefthook pre-commit was satisfied after stripping two pre-existing
trailing-whitespace lines from docker/.env comments.

chore(hooks): enable auto-fix for staged file checks

Convert lefthook pre-commit to B-mode (check + auto-fix in place)
for the four fixable jobs:

- end-of-file-fixer, trailing-whitespace, mixed-line-ending: these
  wrap tools/hooks/check_files.py, which gains a --fix mode that
  rewrites staged files in place. Lefthook re-stages the fixes via
  stage_fixed: true, so the next commit naturally includes the
  cleanup. The user no longer has to manually strip whitespace,
  append newlines, or normalize line endings.

- web-eslint: ESLint --fix is enabled; safe auto-fixes are applied,
  warnings still surface.

trailing-whitespace now uses a regex ([ \t]+(?=\r?\n|$)) so it
correctly detects/strips whitespace before a line terminator and
preserves CRLF when only stripping whitespace. A previous
splitlines-based rstrip pass would silently miss
whitespace-before-newline.

Checks that only validate (json, yaml) or detect states that need
human review (case-conflict, merge-conflict, broken symlinks)
remain check-only; their --fix flag is accepted but a no-op.

ruff check/format, gofmt, and web-prettier already auto-fixed in
the previous config and were left unchanged.

fix
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 30, 2026
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md
Execution snapshot (all merged upstream) to the Go agent side.

Group 1 - tool ports
- infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and
  wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and
  empty host are rejected before any driver dispatch. Allowed hosts
  are dialed via the validated/resolved public IP (DNS-pin).
- infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare
  through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and
  jin10 is a stub. Added regression guard tests: default client
  timeout, stage timeouts, and AST scan for bare http.Get/Post calls
  outside the helper.

Group 2 - component ports
- infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper
  returning {"content": v} frame; add DeepL translation-failure
  regression test using rewriteHostTransport (avoids mutating
  package globals which raced TestDeepL_BuildRequest).
- infiniflow#15644 Switch no longer matches empty condition: evaluateGroup
  empty-clauses short-circuit now returns false (was true) so an
  "and" condition with no clauses falls through to the next
  condition or end_cpn_ids instead of routing to the empty
  group's "to" target. Mirrors the all([]) is True fix.

Group 4 - API ports
- infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces
  WHERE id = ? AND dialog_id = ? (stronger than the Python
  post-fetch check). Added 3 IDOR regression tests at the service
  level (Get/Get mismatch/Delete) confirming the binding holds.

Total: 32 new tests across 4 new test files. All agent/tool and
agent/component tests pass (320 + 331). All new service IDOR
tests pass (3/3). The one failing test in agent/component
(TestAgent_ReActExhaustsSteps) is a pre-existing flaky test that
also fails on the baseline without my changes.

Refs: .claude/plans/review-and-port-py-agent-changes.md
Refs: infiniflow#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374

Apply unstaged agent-go-port prep work

docker/.env
  - switch API_PROXY_SCHEME from python to go (Go server is the default)
  - enable SANDBOX_ENABLED=1 and extend COMPOSE_PROFILES with ragflow-go

web/CLAUDE.md
  - document frontend agent conventions: CSS/flex layout debugging,
    scope boundaries, i18n language files, query-key factory pattern,
    request layering (hook -> service -> next-request), shared UI lock,
    utility libs (dayjs, ahooks, lodash)

web/.agents/skills/tanstack-query-best-practices/
  - remove the full tanstack-query-best-practices skill set
    (SKILL.md + 21 rule files, 1,535 lines total)

Lefthook pre-commit was satisfied after stripping two pre-existing
trailing-whitespace lines from docker/.env comments.

chore(hooks): enable auto-fix for staged file checks

Convert lefthook pre-commit to B-mode (check + auto-fix in place)
for the four fixable jobs:

- end-of-file-fixer, trailing-whitespace, mixed-line-ending: these
  wrap tools/hooks/check_files.py, which gains a --fix mode that
  rewrites staged files in place. Lefthook re-stages the fixes via
  stage_fixed: true, so the next commit naturally includes the
  cleanup. The user no longer has to manually strip whitespace,
  append newlines, or normalize line endings.

- web-eslint: ESLint --fix is enabled; safe auto-fixes are applied,
  warnings still surface.

trailing-whitespace now uses a regex ([ \t]+(?=\r?\n|$)) so it
correctly detects/strips whitespace before a line terminator and
preserves CRLF when only stripping whitespace. A previous
splitlines-based rstrip pass would silently miss
whitespace-before-newline.

Checks that only validate (json, yaml) or detect states that need
human review (case-conflict, merge-conflict, broken symlinks)
remain check-only; their --fix flag is accepted but a no-op.

ruff check/format, gofmt, and web-prettier already auto-fixed in
the previous config and were left unchanged.
yuzhichang added a commit that referenced this pull request Jun 30, 2026
)

Mirrors 14 merged upstream PRs into the Go agent port.

PRs ported:
  - #15609 ExeSQL SSRF guard + DNS pin
  - #15436 HTTP timeout on external API tools
  - #16363 be_output restore + DeepL error path
  - #15644 switch no longer matches empty condition
  - #15374 session_id bind to path agent_id (DAO idor guard)
  - #16169 sandbox artifact ownership gate
  - #15457 tenant ownership on agentbots
  - #15145 rerun agent document access check
- #15446 thinking switch (component portion; provider policy lives in
internal/llm)
  - #15426 Invoke URL/proxy SSRF + DNS pin + no-redirects
  - #15238 agentbot thinking-logs beta endpoint
  - #14589 UserFillUp SSE event propagation
  - #14890 anonymous webhook opt-in
- #15068 PipelineChunker new component (text/file_ref/parser_id
dispatch; file-format extraction is a follow-up)

40 files, +2355 / -58 lines. 33 new tests, all targeted package suites
pass (1721 + 4 skipped); 1 pre-existing flaky test unrelated.
yuzhichang added a commit to ondery/ragflow that referenced this pull request Jul 1, 2026
…sion/user + input/output to Langfuse for agent runs

Rebuilt on current upstream/main after force-push; cherry-pick of the 7
PR-original commits collapsed into a single net diff to avoid conflicts
with intervening commits pulled in by repeated merges of upstream/main.

Original PR work (commits dropped during rebuild because their content
already lives on upstream/main or was a merge of upstream/main):
  c7339ae Enhance LLMService with token usage reporting
  0266cf0 Implement token usage tracking and Langfuse integration
  ab2b267 Include session_id in run_kwargs
  8bf937c Implement token usage tracking in chat model
  c955988 Enhance token tracking with context variables and functions
  3e88ed5 fix(agent): address CodeRabbit review on token usage tracking
  74b8c8c fix(agent): address CodeRabbit follow-up review

Forced-upstream duplicates dropped (already merged to main):
  70546ea (infiniflow#16396), 5b09910 (infiniflow#16403), 5d7f0fd (infiniflow#16405),
  730f33b (infiniflow#16407), a06343e (infiniflow#16408), f90be41 (infiniflow#16410),
  c4fe68e (infiniflow#16409), d4a0e71 (infiniflow#14773), ef42fd7 (infiniflow#15436),
  ab1015d (infiniflow#16363), db188cc (infiniflow#15446), 56ece68 (infiniflow#15609),
  2589b6e (infiniflow#15644), 74c2944 (infiniflow#15374), 78832ff (infiniflow#14985),
  bf18b59 (infiniflow#15457), 6c87225 (infiniflow#14890), e16d1a0 (infiniflow#15426),
  4712fcb (infiniflow#16169), 0536233 (infiniflow#14589), 08c807a (infiniflow#15145)

Plus 18 'Merge branch main into main' commits dropped (polluted topology).
yuzhichang added a commit to ondery/ragflow that referenced this pull request Jul 1, 2026
…sion/user + input/output to Langfuse for agent runs

Rebuilt on current upstream/main after force-push; cherry-pick of the 7
PR-original commits collapsed into a single net diff to avoid conflicts
with intervening commits pulled in by repeated merges of upstream/main.

Original PR work (commits dropped during rebuild because their content
already lives on upstream/main or was a merge of upstream/main):
  c7339ae Enhance LLMService with token usage reporting
  0266cf0 Implement token usage tracking and Langfuse integration
  ab2b267 Include session_id in run_kwargs
  8bf937c Implement token usage tracking in chat model
  c955988 Enhance token tracking with context variables and functions
  3e88ed5 fix(agent): address CodeRabbit review on token usage tracking
  74b8c8c fix(agent): address CodeRabbit follow-up review

Forced-upstream duplicates dropped (already merged to main):
  70546ea (infiniflow#16396), 5b09910 (infiniflow#16403), 5d7f0fd (infiniflow#16405),
  730f33b (infiniflow#16407), a06343e (infiniflow#16408), f90be41 (infiniflow#16410),
  c4fe68e (infiniflow#16409), d4a0e71 (infiniflow#14773), ef42fd7 (infiniflow#15436),
  ab1015d (infiniflow#16363), db188cc (infiniflow#15446), 56ece68 (infiniflow#15609),
  2589b6e (infiniflow#15644), 74c2944 (infiniflow#15374), 78832ff (infiniflow#14985),
  bf18b59 (infiniflow#15457), 6c87225 (infiniflow#14890), e16d1a0 (infiniflow#15426),
  4712fcb (infiniflow#16169), 0536233 (infiniflow#14589), 08c807a (infiniflow#15145)

Plus 18 'Merge branch main into main' commits dropped (polluted topology).

Co-authored-by: yzc <[email protected]>
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 1, 2026
…iniflow#16455)

Mirrors 14 merged upstream PRs into the Go agent port.

PRs ported:
  - infiniflow#15609 ExeSQL SSRF guard + DNS pin
  - infiniflow#15436 HTTP timeout on external API tools
  - infiniflow#16363 be_output restore + DeepL error path
  - infiniflow#15644 switch no longer matches empty condition
  - infiniflow#15374 session_id bind to path agent_id (DAO idor guard)
  - infiniflow#16169 sandbox artifact ownership gate
  - infiniflow#15457 tenant ownership on agentbots
  - infiniflow#15145 rerun agent document access check
- infiniflow#15446 thinking switch (component portion; provider policy lives in
internal/llm)
  - infiniflow#15426 Invoke URL/proxy SSRF + DNS pin + no-redirects
  - infiniflow#15238 agentbot thinking-logs beta endpoint
  - infiniflow#14589 UserFillUp SSE event propagation
  - infiniflow#14890 anonymous webhook opt-in
- infiniflow#15068 PipelineChunker new component (text/file_ref/parser_id
dispatch; file-format extraction is a follow-up)

40 files, +2355 / -58 lines. 33 new tests, all targeted package suites
pass (1721 + 4 skipped); 1 pre-existing flaky test unrelated.
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 size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Switch matches an empty condition because all([]) is True

2 participants