Skip to content

fix: unable to open filter in agent page(no agent tags...) - #16531

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
Haruko386:mono
Jul 1, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
Haruko386:mono

Conversation

@Haruko386

@Haruko386 Haruko386 commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

As title:

Before:
image


fixed:
image

@Haruko386 Haruko386 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Jul 1, 2026
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 1, 2026
@Haruko386
Haruko386 marked this pull request as draft July 1, 2026 08:37
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds comma-aware tag filtering and a qualified order clause in the user_canvas DAO, returns a joined UserCanvasListItem projection from ListByTenantIDs, adds ListAgentTags, and threads the new tags parameter through agent listing handlers and tests.

Changes

Agent tag filtering and listing

Layer / File(s) Summary
DAO tag filter helpers and order clause
internal/dao/user_canvas.go
Adds qualified ordering and comma-aware tag parsing/filtering helpers for user_canvas queries.
ListByTenantIDs projection and tag counts
internal/dao/user_canvas.go
Adds UserCanvasListItem, reworks ListByTenantIDs to select joined user fields and apply tag filtering, and updates ListTags to aggregate comma-separated tag counts.
AgentItem shape and mapping
internal/service/agent.go
Expands AgentItem, adds AgentTagCount, and maps UserCanvasListItem rows into the updated response shape.
ListAgentTags service method
internal/service/agent_sessions.go
Adds AgentService.ListAgentTags, collects owner IDs, converts DAO tag counts into sorted AgentTagCount rows, and returns service codes.
Handler wiring and test updates
internal/handler/agent.go, internal/handler/agent_test.go, internal/handler/agent_wait_for_user_test.go
Parses the tags query parameter in ListAgents, forwards it to the service, implements ListAgentTags, and updates test fakes for the new ListAgents signature.

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
Loading

Suggested labels: size:S

Poem

I sniff out tags in comma trails,
And sort the counts where each one pales.
With joins and lists, I bound and hop,
Then hand back rows that never stop.
🐇 Thump! The agents’ tags now pop.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main fix: the agent page filter no longer breaks when no agent tags are present.
Description check ✅ Passed The description follows the required Summary section and includes before/after screenshots that explain the fix.
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 1, 2026 08:37

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

📥 Commits

Reviewing files that changed from the base of the PR and between d770217 and ebd9dec.

📒 Files selected for processing (6)
  • internal/dao/user_canvas.go
  • internal/handler/agent.go
  • internal/handler/agent_test.go
  • internal/handler/agent_wait_for_user_test.go
  • internal/service/agent.go
  • internal/service/agent_sessions.go

Comment thread internal/dao/user_canvas.go Resolved
Comment thread internal/dao/user_canvas.go Resolved
Comment thread internal/service/agent.go Resolved

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

♻️ Duplicate comments (1)
internal/dao/user_canvas.go (1)

373-380: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Make the selected-owner predicate a standalone Where.

Line 373 still starts from the broadened (owner IN ... AND team) OR current user condition, and Lines 376-377 pass the new owner predicate as extra args to that nested *gorm.DB condition. Split it into two chained Wheres so ownerIDs is guaranteed to constrain the permission/current-user exception; GORM documents chained Where clauses 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

📥 Commits

Reviewing files that changed from the base of the PR and between ebd9dec and 17c4631.

📒 Files selected for processing (2)
  • internal/dao/user_canvas.go
  • internal/service/agent.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/agent.go

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (9bf5760) to head (17c4631).
⚠️ Report is 8 commits behind head on main.

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

@JinHai-CN
JinHai-CN merged commit 9eacbb4 into infiniflow:main Jul 1, 2026
3 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 2, 2026
@Haruko386
Haruko386 deleted the mono branch July 17, 2026 07:55
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants