Skip to content

Fix: agent list owner filter not applied - #17410

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
euvre:fix/agent-owner-filter
Jul 27, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
euvre:fix/agent-owner-filter

Conversation

@euvre

@euvre euvre commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

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:

  • Python (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 unconditional OR user_id = <current user> always mixed in every canvas owned by the caller, regardless of the requested owner_ids.
  • Go (internal/dao/user_canvas.go, UserCanvasDAO.ListByTenantIDs): the DAO tried to add a guarding user_canvas.user_id IN (owner_ids) condition via Where(condDB, "user_canvas.user_id IN ?", ownerIDs). However, GORM's BuildCondition silently 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:

OLD:   WHERE ((user_id IN (?) AND permission = ?) OR user_id = ?) AND (permission = ? OR user_id = ?)  -- guard lost
FIXED: WHERE user_id IN (?) AND (permission = ? OR user_id = ?)

Fix: both backends now use the single predicate user_id IN (owner_ids) AND (permission = 'team' OR user_id = <current user>):

  • When no owner_ids are passed, the effective set is all authorized tenants plus the caller, so behavior is identical to before.
  • When specific owners are selected, results are correctly restricted to those owners (their team-shared canvases; the caller's own canvases only when the caller is among the selected owners).

Also deduplicated the repeated predicate in the Python keywords / non-keywords branches into a single owner_filter expression.

Validation: ruff check / ruff format --check pass; go vet ./internal/dao/ passes; SQL semantics verified via GORM DryRun.

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.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 27, 2026
@euvre euvre added the ci Continue Integration label Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Canvas 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.

Changes

Canvas visibility filtering

Layer / File(s) Summary
Service-level owner filter
api/db/services/canvas_service.py
Extracts a reusable tenant, permission, and ownership predicate and combines it with optional case-insensitive title matching.
DAO authorization predicate
internal/dao/user_canvas.go
Simplifies the base query to constrain owner IDs, then include team canvases or canvases owned by the current user.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: haruko386, ondery

Poem

I’m a rabbit with queries tucked neat,
Owner filters hop into their seat.
Team canvases join, titles softly glow,
Fewer tangled predicates below.
Squeak—clean paths make reviews sweet!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix to the agent owner filter.
Description check ✅ Passed The PR description matches the required Summary template and explains the bug, root cause, fix, and validation.
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.

@euvre
euvre requested a review from wangq8 July 27, 2026 04:22

@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 `@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

📥 Commits

Reviewing files that changed from the base of the PR and between 1571abd and 2c3d9b5.

📒 Files selected for processing (2)
  • api/db/services/canvas_service.py
  • internal/dao/user_canvas.go

Comment on lines +374 to +377
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))

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.

📐 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

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (53afc32) to head (2c3d9b5).
⚠️ Report is 2 commits behind head on main.

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.
📢 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.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@wangq8
wangq8 merged commit 6cc862f into infiniflow:main Jul 27, 2026
10 of 11 checks passed
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