Repository navigation
Fix: agent list owner filter not applied - #17410
Conversation
Filtering agents by owner (team member) on the agents page had no effect in both backends: - Python: the WHERE clause unconditionally OR-ed 'user_id = current user', so the caller's own canvases were always returned regardless of the requested owner_ids. - Go: the DAO passed the 'user_canvas.user_id IN (owner_ids)' condition as extra args to Where(condDB, ...), which GORM silently drops when the first argument is a *gorm.DB, producing the same flawed predicate. Both backends now use 'user_id IN (owner_ids) AND (permission = team OR user_id = current user)', which matches the previous behavior when no owner filter is given and correctly restricts results when owners are selected.
📝 WalkthroughWalkthroughCanvas visibility query construction was simplified in the service and DAO layers by consolidating tenant, permission, and ownership predicates while preserving optional title filtering and downstream query behavior. ChangesCanvas visibility filtering
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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
🤖 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 374-377: Update the authorization comment near the query using
ownerIDs and userID to accurately describe that self-owned canvases are included
only when userID is present in ownerIDs, rather than claiming all canvases owned
by userID are included. Leave the predicate unchanged.
🪄 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 Plus
Run ID: 416bfcb3-ce96-4da9-a3a0-2b12e61dbb14
📒 Files selected for processing (2)
api/db/services/canvas_service.pyinternal/dao/user_canvas.go
| Where("user_canvas.user_id IN ?", ownerIDs). | ||
| 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)) | ||
| DB.Where("user_canvas.permission = ?", "team"). | ||
| Or("user_canvas.user_id = ?", userID)) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the nearby authorization comment.
Line 357 says all canvases owned by userID are included, but this predicate first restricts rows to ownerIDs; self-owned canvases are included only when userID is selected. As per coding guidelines, “keep package and doc comments aligned with the current runtime path.”
🤖 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 374 - 377, Update the authorization
comment near the query using ownerIDs and userID to accurately describe that
self-owned canvases are included only when userID is present in ownerIDs, rather
than claiming all canvases owned by userID are included. Leave the predicate
unchanged.
Source: Coding guidelines
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17410 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
wangq8
left a comment
There was a problem hiding this comment.
LGTM. Clean fix with a well-documented root cause analysis.
The Python side deduplication via owner_filter is tidy and the Go fix correctly splits the IN clause into its own Where call to work around GORM's BuildCondition behavior. The new predicate user_id IN (owner_ids) AND (permission = team OR user_id = current_user) is semantically correct for both backends.
One minor observation: the Go SELECT column indentation change (tabs → mixed) is purely cosmetic and could have been a separate commit, but it doesn't affect functionality.
Summary
Filtering agents by owner (team member) on the Agents page had no effect: selecting a teammate (e.g.
zzz) still returned all of the caller's own agents. Both the Python and Go backends produced a flawed visibility predicate.Root cause:
api/db/services/canvas_service.py,UserCanvasService.get_by_tenant_ids): the WHERE clause was(user_id IN (owner_ids) AND permission = 'team') OR user_id = <current user>. The unconditionalOR user_id = <current user>always mixed in every canvas owned by the caller, regardless of the requestedowner_ids.internal/dao/user_canvas.go,UserCanvasDAO.ListByTenantIDs): the DAO tried to add a guardinguser_canvas.user_id IN (owner_ids)condition viaWhere(condDB, "user_canvas.user_id IN ?", ownerIDs). However, GORM'sBuildConditionsilently drops the remaining string/value arguments when the first argument is a*gorm.DB, so the guarding condition never made it into the SQL and the query degenerated to the same flawed predicate as Python.Verified with a GORM DryRun:
Fix: both backends now use the single predicate
user_id IN (owner_ids) AND (permission = 'team' OR user_id = <current user>):owner_idsare passed, the effective set is all authorized tenants plus the caller, so behavior is identical to before.Also deduplicated the repeated predicate in the Python keywords / non-keywords branches into a single
owner_filterexpression.Validation:
ruff check/ruff format --checkpass;go vet ./internal/dao/passes; SQL semantics verified via GORM DryRun.