Skip to content

fix: cannot get query in agent-log - #16610

Merged
yuzhichang merged 4 commits into
infiniflow:mainfrom
Haruko386:main
Jul 3, 2026
Merged

yuzhichang merged 4 commits into
infiniflow:mainfrom
Haruko386:main

Conversation

@Haruko386

Copy link
Copy Markdown
Member

Summary

As title

bug:

fixed:
image

@Haruko386 Haruko386 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Jul 3, 2026
@Haruko386
Haruko386 marked this pull request as draft July 3, 2026 09:16
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 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: 39bb6ede-59cf-4ef5-8f16-a2be642b043d

📥 Commits

Reviewing files that changed from the base of the PR and between 118f4db and 01ba224.

📒 Files selected for processing (1)
  • internal/service/agent.go

📝 Walkthrough

Walkthrough

This PR adds sanitized node-input tracking to canvas scheduler node lifecycle events, persisting and reusing inputs across node_started and node_finished events. It also changes AgentService.RunAgent's tenant_id assignment to use userID directly, introducing a separate run_tenant_id field with updated resolution logic in tenantIDFromRoot.

Changes

Node Input Telemetry in Scheduler

Layer / File(s) Summary
Sanitize and persist node inputs at start
internal/agent/canvas/scheduler.go
Adds sanitizeNodeInputs to filter reserved keys, updates nodeStartedAt to accept and persist sanitized inputs into state.Sys and emit them in node_started events.
Reuse stored inputs at completion
internal/agent/canvas/scheduler.go
nodeFinishedNow reads previously stored sanitized inputs from state.Sys and includes them in NodeFinishedData instead of leaving it empty.
Update call sites
internal/agent/canvas/scheduler.go
Loop expansion path and normal node wrapper path pass node inputs to nodeStartedAt.

Agent RunAgent Tenant ID Resolution

Layer / File(s) Summary
Set tenant_id directly, populate run_tenant_id
internal/service/agent.go
RunAgent unconditionally sets root["tenant_id"] to userID, removing the prior DAO lookup, and best-effort sets root["run_tenant_id"] from the first tenant ID with a warning on failure.
Update tenant id resolution helper
internal/service/agent.go
tenantIDFromRoot now prefers root["run_tenant_id"], falling back to root["tenant_id"].

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

Sequence Diagram(s)

sequenceDiagram
  participant NodeWrapper
  participant Scheduler
  participant StateSys
  NodeWrapper->>Scheduler: nodeStartedAt(in)
  Scheduler->>Scheduler: sanitizeNodeInputs(in)
  Scheduler->>StateSys: store _node_inputs_<cpnID>
  Scheduler-->>NodeWrapper: emit node_started (with inputs)
  NodeWrapper->>Scheduler: nodeFinishedNow()
  Scheduler->>StateSys: read _node_inputs_<cpnID>
  Scheduler-->>NodeWrapper: emit node_finished (with inputs)
Loading

Poem

A rabbit hops through node and state,
Sanitized inputs, tucked in freight,
Tenant IDs now cleanly split,
run_tenant_id gets its own bit,
Hop hop hooray, the code's alright! 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The required Summary section is present, but it is too vague and lacks the background context the template asks for. Expand Summary with the problem context, what changed, and the user impact instead of 'As title'; keep the screenshot if useful.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main fix: retrieving the query in the agent-log view.
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.

@Haruko386
Haruko386 marked this pull request as ready for review July 3, 2026 09:20

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/service/agent.go (1)

776-785: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Stale comment describes removed tenant-lookup behavior.

The comment block above (lines 776-782) still documents the old best-effort DAO lookup ("The lookup is best-effort — a failure here (DAO down, user has no tenants) logs and continues with an empty tenant_id"), but the code now unconditionally assigns userID with no lookup, fallback, or logging. This is misleading for future readers investigating tenant_id behavior.

📝 Proposed comment fix
-	// Phase 4.4 V2.1 (v3.6.1): populate root["tenant_id"] so the
-	// RunTracker.Start call (in buildRunFunc) records the run
-	// under the right tenant. The lookup is best-effort — a
-	// failure here (DAO down, user has no tenants) logs and
-	// continues with an empty tenant_id rather than failing
-	// the run; the run still works, the only loss is the
-	// per-tenant filterability of the run-history log.
+	// Phase 4.4 V2.1 (v3.6.1): populate root["tenant_id"] so the
+	// RunTracker.Start call (in buildRunFunc) records the run
+	// under the right tenant. tenant_id is set directly to the
+	// caller's userID (no DAO lookup) — see PR discussion for why
+	// user-level scoping is used here instead of resolving an
+	// actual tenant record.
🤖 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 `@internal/service/agent.go` around lines 776 - 785, Update the stale comment
near the root["tenant_id"] assignment in agent.go so it matches the current
behavior in buildRunFunc/RunTracker.Start setup: remove the obsolete best-effort
DAO lookup and empty-tenant fallback description, and rewrite it to explain that
tenant_id is now populated directly from userID before the run starts. Keep the
comment concise and aligned with the surrounding Phase 4.4 V2.1 logic so future
readers are not misled about any lookup, logging, or fallback behavior.
🧹 Nitpick comments (2)
internal/agent/canvas/scheduler.go (2)

260-265: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicate sanitizeNodeInputs computation.

sanitizeNodeInputs(inputs) is called twice (Line 262 and Line 265) with the same argument, doing redundant work and allocating two maps. Compute once and reuse.

♻️ Proposed fix
+	sanitized := sanitizeNodeInputs(inputs)
 	if state.Sys != nil {
 		state.Sys["_node_start_"+cpnID] = now
-		state.Sys["_node_inputs_"+cpnID] = sanitizeNodeInputs(inputs)
+		state.Sys["_node_inputs_"+cpnID] = sanitized
 	}
 	nsData, _ := json.Marshal(NodeStartedData{
-		Inputs:        sanitizeNodeInputs(inputs),
+		Inputs:        sanitized,
🤖 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 `@internal/agent/canvas/scheduler.go` around lines 260 - 265, The
NodeStartedData setup in scheduler.go recomputes sanitizeNodeInputs(inputs)
twice, duplicating work and allocations. Update the logic around the
state.Sys["_node_inputs_"+cpnID] assignment and the NodeStartedData construction
to compute the sanitized inputs once, store them in a local variable, and reuse
that value in both places. Use the nearby NodeStartedData and state.Sys updates
as the anchor points when making the change.

233-326: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚖️ Poor tradeoff

Move node bookkeeping out of sys.*
CanvasState.Snapshot() only clones Outputs, so this does not leak into out["state"], but _node_inputs_* and _node_start_* still live in Sys, get copied by SnapshotNamespaces(), and are serialized with the run state. Keep that bookkeeping in a private per-run field instead of the public sys.* namespace to avoid unbounded growth and namespace pollution.

🤖 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 `@internal/agent/canvas/scheduler.go` around lines 233 - 326, The node
bookkeeping in nodeStartedAt and nodeFinishedNow is still being stored under
CanvasState.Sys keys like _node_start_* and _node_inputs_*, which leaks into
SnapshotNamespaces() and serialized run state. Move this per-node metadata into
a private per-run field on CanvasState (or another internal scheduler-only
store) and update nodeStartedAt/nodeFinishedNow to read and write there instead
of sys.* so Snapshot() and namespace serialization stay clean.
🤖 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 `@internal/service/agent.go`:
- Around line 783-785: The tenant identifier recorded in the agent run context
is currently using userID directly, which mixes user IDs and tenant IDs across
entrypoints. Update the tenant resolution logic in RunAgent so
root["tenant_id"], state.Sys["tenant_id"], and RunTracker.Start all receive the
resolved tenant ID consistently, regardless of whether the call comes from the
chat path or the bot path. Use the existing RunAgent flow and the tenant-related
fields in the state/root setup to locate and replace the userID-based assignment
with the proper resolved tenant value.

---

Outside diff comments:
In `@internal/service/agent.go`:
- Around line 776-785: Update the stale comment near the root["tenant_id"]
assignment in agent.go so it matches the current behavior in
buildRunFunc/RunTracker.Start setup: remove the obsolete best-effort DAO lookup
and empty-tenant fallback description, and rewrite it to explain that tenant_id
is now populated directly from userID before the run starts. Keep the comment
concise and aligned with the surrounding Phase 4.4 V2.1 logic so future readers
are not misled about any lookup, logging, or fallback behavior.

---

Nitpick comments:
In `@internal/agent/canvas/scheduler.go`:
- Around line 260-265: The NodeStartedData setup in scheduler.go recomputes
sanitizeNodeInputs(inputs) twice, duplicating work and allocations. Update the
logic around the state.Sys["_node_inputs_"+cpnID] assignment and the
NodeStartedData construction to compute the sanitized inputs once, store them in
a local variable, and reuse that value in both places. Use the nearby
NodeStartedData and state.Sys updates as the anchor points when making the
change.
- Around line 233-326: The node bookkeeping in nodeStartedAt and nodeFinishedNow
is still being stored under CanvasState.Sys keys like _node_start_* and
_node_inputs_*, which leaks into SnapshotNamespaces() and serialized run state.
Move this per-node metadata into a private per-run field on CanvasState (or
another internal scheduler-only store) and update nodeStartedAt/nodeFinishedNow
to read and write there instead of sys.* so Snapshot() and namespace
serialization stay clean.
🪄 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: 00c550ee-70de-42e3-8056-2583bdbce7e0

📥 Commits

Reviewing files that changed from the base of the PR and between 3cba34d and 118f4db.

📒 Files selected for processing (3)
  • internal/agent/canvas/scheduler.go
  • internal/handler/chunk_test.go
  • internal/service/agent.go

Comment thread internal/service/agent.go Outdated
Comment on lines +783 to +785

root["tenant_id"] = userID

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 | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect how tenant_id from RunAgent/root/state.Sys is consumed downstream,
# and whether GetTenantIDsByUserID / UserTenant model treats tenant_id as
# distinct from user_id elsewhere in the service layer.
rg -n -B2 -A5 'tenant_id' internal/agent/canvas internal/service internal/handler --type=go
rg -n -B3 -A8 'func.*GetTenantIDsByUserID' internal/dao --type=go
rg -n -B3 -A10 'runTracker\.Start|func.*RunTracker.*Start' internal --type=go

Repository: infiniflow/ragflow

Length of output: 50374


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- internal/service/agent.go (context around tenant_id assignment and run tracker handoff) ---'
sed -n '760,810p' internal/service/agent.go
echo

echo '--- internal/service/agent.go (state.Sys population and tenantIDFromRoot) ---'
sed -n '958,1005p' internal/service/agent.go
echo

echo '--- internal/service/agent.go (tenantIDFromRoot helper) ---'
sed -n '1178,1190p' internal/service/agent.go
echo

echo '--- internal/agent/canvas/run_tracker.go (tenant_id storage/filtering) ---'
sed -n '1,180p' internal/agent/canvas/run_tracker.go
echo

echo '--- internal/service/user.go (GetTenantIDsByUserID / user-tenant relation) ---'
rg -n -A20 -B5 'GetTenantIDsByUserID|type UserTenant|GetUserTenantRelationByUserID' internal/service/user.go internal/dao internal/entity --type=go

Repository: infiniflow/ragflow

Length of output: 22478


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- run tracker consumers / run-history filtering ---'
rg -n -A8 -B6 'RunTracker|tenant_id.*run|run history|agent:run|Get.*Run|List.*Run|Query.*Run' internal --type=go

echo
echo '--- tests that assert tenant_id behavior for agent runs ---'
rg -n -A6 -B4 'tenant_id.*tenant-|root\["tenant_id"\]|RunTracker.*tenant_id|tenantIDFromRoot' internal --type=go

echo
echo '--- any code that resolves tenant IDs from a user for agent runs ---'
rg -n -A6 -B4 'GetTenantIDsByUserID|tenantIDs :=|tenant_id.*userID' internal/service internal/dao internal/agent --type=go

Repository: infiniflow/ragflow

Length of output: 50375


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- RunAgent signature and nearby setup ---'
rg -n -A30 -B10 'func \(s \*AgentService\) RunAgent|func \(s \*AgentService\) RunAgentWithWebhook' internal/service/agent.go --type=go

echo
echo '--- RunAgent call sites ---'
rg -n -A4 -B4 '\.RunAgent\(' internal --type=go

echo
echo '--- user/tenant context around handlers that invoke agent runs ---'
rg -n -A8 -B8 'RunAgentWithWebhook|RunAgent\(' internal/handler internal/service --type=go

Repository: infiniflow/ragflow

Length of output: 50374


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- internal/service/agent.go: loadCanvasForUser and related tenant/user plumbing ---'
rg -n -A35 -B15 'func \(s \*AgentService\) loadCanvasForUser|userTenantDAO|GetTenantIDsByUserID|ErrUserCanvasNotFound|tenant_id' internal/service/agent.go --type=go

echo
echo '--- internal/service/bot.go: how tenantID is sourced for RunAgent ---'
sed -n '120,190p' internal/service/bot.go

echo
echo '--- internal/service/agent.go: root initialization block around tenant_id ---'
sed -n '748,800p' internal/service/agent.go

Repository: infiniflow/ragflow

Length of output: 33809


Use a resolved tenant ID here, not userID. In the chat path RunAgent is called with user.ID, while the bot path passes a tenant ID, so root["tenant_id"] / state.Sys["tenant_id"] / RunTracker.Start will record different meanings depending on the entrypoint. That makes tenant-scoped run-history filtering inconsistent and drops the shared-workspace tenant context for multi-tenant users.

🤖 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 `@internal/service/agent.go` around lines 783 - 785, The tenant identifier
recorded in the agent run context is currently using userID directly, which
mixes user IDs and tenant IDs across entrypoints. Update the tenant resolution
logic in RunAgent so root["tenant_id"], state.Sys["tenant_id"], and
RunTracker.Start all receive the resolved tenant ID consistently, regardless of
whether the call comes from the chat path or the bot path. Use the existing
RunAgent flow and the tenant-related fields in the state/root setup to locate
and replace the userID-based assignment with the proper resolved tenant value.

Haruko386 added 2 commits July 3, 2026 17:24
Removed TestChunkHandlerListChunksAcceptsAvailableFalse test case from chunk_test.go.
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit fd7fb66 into infiniflow:main Jul 3, 2026
3 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 3, 2026
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants