Repository navigation
fix: cannot get query in agent-log - #16610
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis 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. ChangesNode Input Telemetry in Scheduler
Agent RunAgent Tenant ID Resolution
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)
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
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 winStale 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
userIDwith 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 valueDuplicate
sanitizeNodeInputscomputation.
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 tradeoffMove node bookkeeping out of
sys.*
CanvasState.Snapshot()only clonesOutputs, so this does not leak intoout["state"], but_node_inputs_*and_node_start_*still live inSys, get copied bySnapshotNamespaces(), and are serialized with the run state. Keep that bookkeeping in a private per-run field instead of the publicsys.*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
📒 Files selected for processing (3)
internal/agent/canvas/scheduler.gointernal/handler/chunk_test.gointernal/service/agent.go
|
|
||
| root["tenant_id"] = userID | ||
|
|
There was a problem hiding this comment.
🗄️ 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=goRepository: 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=goRepository: 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=goRepository: 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=goRepository: 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.goRepository: 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.
Removed TestChunkHandlerListChunksAcceptsAvailableFalse test case from chunk_test.go.
|
LGTM |
### Summary As title bug: fixed: <img width="1827" height="1286" alt="image" src="https://github.com/user-attachments/assets/0cdc391c-43d7-4330-bc34-3aefe5d4f4ee" />
### Summary As title bug: fixed: <img width="1827" height="1286" alt="image" src="https://github.com/user-attachments/assets/0cdc391c-43d7-4330-bc34-3aefe5d4f4ee" />
Summary
As title
bug:
fixed:
