Repository navigation
fix: unable to open filter in agent page(no agent tags...) - #16531
Conversation
📝 WalkthroughWalkthroughAdds comma-aware tag filtering and a qualified order clause in the user_canvas DAO, returns a joined ChangesAgent tag filtering and listing
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant AgentHandler
participant AgentService
participant UserCanvasDAO
Client->>AgentHandler: GET /agents?tags=a,b
AgentHandler->>AgentService: ListAgents(..., tags)
AgentService->>UserCanvasDAO: ListByTenantIDs(..., tags)
UserCanvasDAO-->>AgentService: UserCanvasListItem rows
AgentHandler->>AgentService: ListAgentTags(userID, canvasCategory)
AgentService->>UserCanvasDAO: ListTags(ownerIDs, userID, canvasCategory)
UserCanvasDAO-->>AgentService: tag counts map
AgentHandler-->>Client: JSON response
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ 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: 3
🤖 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/dao/user_canvas.go`:
- Around line 363-366: The owner filtering in the UserCanvas DAO currently
broadens results by unconditionally re-adding the current user via the
`Or("user_canvas.user_id = ?", userID)` clause, which bypasses an explicit
`ownerIDs` filter. Update the query logic in the affected DAO method(s) like
`ListTags` and the matching canvas/agent listing path so the `ownerIDs`
constraint is applied first and the current-user permission exception is only
included when it does not violate the selected owner set; keep the same query
shape consistent across both methods.
- Around line 87-90: Keep tag listing and filtering consistent by matching the
same normalization used by ListTags. In applyUserCanvasTagFilter, the current
WHERE clause in the user_canvas tag matching logic only handles comma boundaries
without optional whitespace, so values like "foo, bar" won’t match when
filtering for "bar". Update the tag filter to trim/ignore surrounding delimiter
whitespace the same way ListTags does, or canonicalize stored tags before
querying, and ensure the matching logic in applyUserCanvasTagFilter uses the
same semantics as the tag parsing code.
In `@internal/service/agent.go`:
- Line 212: The Agent JSON output currently omits empty tags because the Tags
field uses omitempty, which can let tagless agents reach the frontend with tags
missing and trigger the crash. Update the Agent struct’s Tags field in agent.go
to always serialize the field, keeping tags present even when empty, and verify
any marshal paths using Agent still emit tags for tagless agents.
🪄 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: 88768b33-8932-468c-b8c5-6f403a05ac0c
📒 Files selected for processing (6)
internal/dao/user_canvas.gointernal/handler/agent.gointernal/handler/agent_test.gointernal/handler/agent_wait_for_user_test.gointernal/service/agent.gointernal/service/agent_sessions.go
There was a problem hiding this comment.
♻️ Duplicate comments (1)
internal/dao/user_canvas.go (1)
373-380: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winMake the selected-owner predicate a standalone
Where.Line 373 still starts from the broadened
(owner IN ... AND team) OR current usercondition, and Lines 376-377 pass the new owner predicate as extra args to that nested*gorm.DBcondition. Split it into two chainedWheres soownerIDsis guaranteed to constrain the permission/current-user exception; GORM documents chainedWhereclauses as ANDed conditions. (pkg.go.dev)Proposed fix
- Where( - DB.Where("user_canvas.user_id IN ? AND user_canvas.permission = ?", ownerIDs, "team"). - Or("user_canvas.user_id = ?", userID), - "user_canvas.user_id IN ?", - ownerIDs, - ).Where( - DB.Where("user_canvas.permission = ?", "team"). - Or("user_canvas.user_id = ?", userID)) + Where("user_canvas.user_id IN ?", ownerIDs). + Where( + DB.Where("user_canvas.permission = ?", "team"). + Or("user_canvas.user_id = ?", userID), + )#!/bin/bash # Verify the owner filter is no longer embedded as variadic args to a nested *gorm.DB condition. python - <<'PY' from pathlib import Path s = Path("internal/dao/user_canvas.go").read_text() print("standalone owner filter:", 'Where("user_canvas.user_id IN ?", ownerIDs).' in s) print("nested owner filter args still present:", 'DB.Where("user_canvas.user_id IN ? AND user_canvas.permission = ?", ownerIDs, "team").' in s and '"user_canvas.user_id IN ?",' in s) PY🤖 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/dao/user_canvas.go` around lines 373 - 380, The user_canvas query is still combining the selected-owner filter with the team/current-user exception inside one nested GORM condition, which can weaken the intended constraint. Update the chain in user_canvas query building so the ownerIDs predicate is its own standalone Where and the permission/current-user logic is a separate chained Where, using the existing GORM call sites around user_canvas.user_id and user_canvas.permission. Keep the conditions split so the owner filter always ANDs with the rest of the query.
🤖 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.
Duplicate comments:
In `@internal/dao/user_canvas.go`:
- Around line 373-380: The user_canvas query is still combining the
selected-owner filter with the team/current-user exception inside one nested
GORM condition, which can weaken the intended constraint. Update the chain in
user_canvas query building so the ownerIDs predicate is its own standalone Where
and the permission/current-user logic is a separate chained Where, using the
existing GORM call sites around user_canvas.user_id and user_canvas.permission.
Keep the conditions split so the owner filter always ANDs with the rest of the
query.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4fbbd12c-7692-4b37-b3ed-9ae3815aacb6
📒 Files selected for processing (2)
internal/dao/user_canvas.gointernal/service/agent.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/service/agent.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16531 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
As title:
Before:

fixed:
