Skip to content

fix(agent): add HTTP timeout to external API tools - #15436

Merged
yuzhichang merged 3 commits into
infiniflow:mainfrom
cleanjunc:fix/agent-tool-http-timeout
Jun 28, 2026
Merged

yuzhichang merged 3 commits into
infiniflow:mainfrom
cleanjunc:fix/agent-tool-http-timeout

Conversation

@cleanjunc

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Closes #15435

Several agent tools call external HTTP APIs through requests with no request timeout. When an upstream host accepts the connection but never responds (a slow or overloaded API, a half open connection, a stuck load balancer), the call blocks forever. These tools run inside agent canvas execution, so a single stalled socket freezes the entire agent run with no recovery.

Ten call sites were affected:

  • agent/tools/qweather.py (4 calls)
  • agent/tools/jin10.py (4 calls)
  • agent/tools/tushare.py (1 call)
  • agent/tools/github.py (1 call)

The github.py tool already carried the @timeout decorator from common/connection_utils.py, but that does not protect against this case. In the default configuration the decorator waits on its result queue with no timeout, and a daemon thread blocked inside a socket read cannot be killed, so the run still hangs. The per request timeout added here is what actually bounds the call.

This is the same bug class as the merged Go stream timeout fix, surfacing in the Python tool layer.

Changes:

  • Pass timeout=DEFAULT_TIMEOUT on all 10 calls, reusing the existing shared constant in common/http_client.py (configurable via HTTP_CLIENT_TIMEOUT) so there is one source of truth rather than scattered literals.
  • Add an AST based unit test at test/unit_test/agent/tools/test_http_timeout.py that scans every tool module and fails if any requests or httpx request call omits a timeout, guarding current and future call sites.

Verification:

  • Reproduced the indefinite block against a stalling local server, and confirmed that adding a timeout raises ReadTimeout promptly.
  • Confirmed the @timeout decorator does not interrupt a blocked no timeout request in its default configuration.
  • The new test flags exactly the 10 original call sites on the pre fix code and passes (22 modules) after the fix.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. labels May 29, 2026
@coderabbitai

coderabbitai Bot commented May 29, 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: 552bec3e-ebf3-459e-875b-062124c75965

📥 Commits

Reviewing files that changed from the base of the PR and between d12c48e and fb62b61.

📒 Files selected for processing (1)
  • test/unit_test/agent/tools/test_http_timeout.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/unit_test/agent/tools/test_http_timeout.py

📝 Walkthrough

Walkthrough

This PR applies a shared DEFAULT_TIMEOUT to all outbound HTTP calls in agent tools (GitHub, Jin10, QWeather, TuShare) and adds a pytest that enforces every HTTP call in agent/tools includes a timeout argument.

Changes

HTTP Timeout Enforcement

Layer / File(s) Summary
Apply DEFAULT_TIMEOUT to agent tool HTTP calls
agent/tools/github.py, agent/tools/jin10.py, agent/tools/qweather.py, agent/tools/tushare.py
Each tool imports DEFAULT_TIMEOUT from common.http_client and passes it as timeout=DEFAULT_TIMEOUT to their outbound requests.get(...) / requests.post(...) call sites (GitHub search; Jin10 flash/calendar/symbols/news; QWeather city/weather/indices/air-quality; TuShare POST).
Add validation test for HTTP timeout enforcement
test/unit_test/agent/tools/test_http_timeout.py
New AST-based pytest scans agent/tools/*.py for requests.* and httpx.* call sites and asserts each includes a timeout= keyword or an acceptable **kwargs spread; fails listing non-compliant file:line locations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size:M

Poem

🐰 I hopped through code to set a bound,
Timeouts now keep calls from being drowned,
AST guards each new network plea,
No more hangs — just swift reply, you see!
— A cheerful rabbit 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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
Title check ✅ Passed The PR title 'fix(agent): add HTTP timeout to external API tools' accurately and concisely describes the main change—adding HTTP timeouts to prevent indefinite blocking in agent API tools.
Description check ✅ Passed The PR description thoroughly addresses the template requirements, explaining the problem (no request timeouts causing indefinite blocks), the type of change (bug fix), solution details, affected modules, and verification steps.
Linked Issues check ✅ Passed All coding requirements from issue #15435 are met: timeout added to all 10 identified call sites (qweather.py, jin10.py, tushare.py, github.py), reusable DEFAULT_TIMEOUT constant applied, and defensive AST-based test added to prevent regressions.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving the hanging issue: timeout additions to four tool modules and a preventive test file, with no unrelated modifications.

✏️ 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: 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 `@test/unit_test/agent/tools/test_http_timeout.py`:
- Around line 56-69: _iter_request_calls currently only treats direct names in
_HTTP_NAMESPACES as HTTP roots, missing session/client instances; update it to
also detect (1) attribute calls that produce clients (e.g., when root is an
ast.Call whose func is an ast.Attribute whose value is an ast.Name in
_HTTP_NAMESPACES, covering expressions like requests.sessions.Session()) and (2)
common instance variable names by either expanding _HTTP_NAMESPACES or adding a
small _HTTP_INSTANCE_NAMES set (e.g., "session","client","session_client") and
checking if isinstance(root, ast.Name) and root.id in that set so calls like
session.get(...) or client.request(...) are yielded; keep references to
_REQUEST_METHODS and _HTTP_NAMESPACES/_HTTP_INSTANCE_NAMES and preserve the
existing chained-attribute unwrapping logic.
🪄 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: 7a6d1771-3cd5-493d-8413-c8e4d402a104

📥 Commits

Reviewing files that changed from the base of the PR and between cd18cfa and d12c48e.

📒 Files selected for processing (5)
  • agent/tools/github.py
  • agent/tools/jin10.py
  • agent/tools/qweather.py
  • agent/tools/tushare.py
  • test/unit_test/agent/tools/test_http_timeout.py

@cleanjunc

Copy link
Copy Markdown
Contributor Author

Hi @Haruko386 @JinHai-CN
Can you review this PR? Thank you!

1 similar comment
@cleanjunc

Copy link
Copy Markdown
Contributor Author

Hi @Haruko386 @JinHai-CN
Can you review this PR? Thank you!

@cleanjunc

Copy link
Copy Markdown
Contributor Author

Hi @Haruko386 @JinHai-CN Can you review this PR?

@cleanjunc

Copy link
Copy Markdown
Contributor Author

Hi @qinling0210
Thanks for your review my other 2 PRs. Can you please check this PR more? I really appreciate it a lot!

@cleanjunc

Copy link
Copy Markdown
Contributor Author

@yingfeng @qinling0210
Could you please review this PR? Thanks a lot!

@yingfeng yingfeng added the ci Continue Integration label Jun 25, 2026
@yingfeng
yingfeng marked this pull request as draft June 25, 2026 08:47
@yingfeng
yingfeng marked this pull request as ready for review June 25, 2026 08:47
@yingfeng
yingfeng requested a review from yuzhichang June 25, 2026 08:47
@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 (eb5a275).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15436      +/-   ##
==========================================
- 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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-reviewed the current head. The timeout additions are correct, and the AST regression test now already covers both namespace calls and common session/client instances, so I do not see any remaining actionable issue in the current diff. From my side this is ready to merge.

@yuzhichang
yuzhichang merged commit ef42fd7 into infiniflow:main Jun 28, 2026
3 checks passed
yuzhichang added a commit that referenced this pull request Jun 29, 2026
### What problem does this PR solve?

Closes #15435 

Several agent tools call external HTTP APIs through `requests` with no
request timeout. When an upstream host accepts the connection but never
responds (a slow or overloaded API, a half open connection, a stuck load
balancer), the call blocks forever. These tools run inside agent canvas
execution, so a single stalled socket freezes the entire agent run with
no recovery.

Ten call sites were affected:

- `agent/tools/qweather.py` (4 calls)
- `agent/tools/jin10.py` (4 calls)
- `agent/tools/tushare.py` (1 call)
- `agent/tools/github.py` (1 call)

The `github.py` tool already carried the `@timeout` decorator from
`common/connection_utils.py`, but that does not protect against this
case. In the default configuration the decorator waits on its result
queue with no timeout, and a daemon thread blocked inside a socket read
cannot be killed, so the run still hangs. The per request timeout added
here is what actually bounds the call.

This is the same bug class as the merged Go stream timeout fix,
surfacing in the Python tool layer.

Changes:

- Pass `timeout=DEFAULT_TIMEOUT` on all 10 calls, reusing the existing
shared constant in `common/http_client.py` (configurable via
`HTTP_CLIENT_TIMEOUT`) so there is one source of truth rather than
scattered literals.
- Add an AST based unit test at
`test/unit_test/agent/tools/test_http_timeout.py` that scans every tool
module and fails if any `requests` or `httpx` request call omits a
`timeout`, guarding current and future call sites.

Verification:

- Reproduced the indefinite block against a stalling local server, and
confirmed that adding a timeout raises `ReadTimeout` promptly.
- Confirmed the `@timeout` decorator does not interrupt a blocked no
timeout request in its default configuration.
- The new test flags exactly the 10 original call sites on the pre fix
code and passes (22 modules) after the fix.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [ ] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):

---------

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 🌈 python Pull requests that update Python code size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent external API tools can hang forever when an upstream HTTP request stalls

3 participants