Repository navigation
Fix: no more @token_required - #15562
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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)
📝 WalkthroughWalkthroughMoves agent session deletion logic into ChangesAgent Session Management Migration
Chunk API Authentication Update
Sequence Diagram(s)sequenceDiagram
participant Client
participant delete_agent
participant UserCanvasService
participant check_duplicate_ids
participant API4ConversationService
Client->>delete_agent: DELETE /agents/<agent_id>/sessions { ids | delete_all }
delete_agent->>UserCanvasService: query(agent_id) for ownership
UserCanvasService-->>delete_agent: agent record / ownership
delete_agent->>delete_agent: normalize targets (ids or all)
delete_agent->>check_duplicate_ids: deduplicate ids
check_duplicate_ids-->>delete_agent: deduped_ids + duplicate_messages
loop per id
delete_agent->>API4ConversationService: query(id, dialog_id) to verify ownership
API4ConversationService-->>delete_agent: session record / ownership
delete_agent->>API4ConversationService: delete_by_id(id)
API4ConversationService-->>delete_agent: deletion success/failure
end
delete_agent-->>Client: get_result / get_error_data_result with counts and errors
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: 2
🧹 Nitpick comments (1)
api/apps/restful_apis/agent_api.py (1)
451-498: 💤 Low valueConsider adding logging for this new deletion flow.
The endpoint lacks logging statements. Per coding guidelines, new flows should include logging. Consider adding log entries for successful bulk deletions and error conditions.
🤖 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 `@api/apps/restful_apis/agent_api.py` around lines 451 - 498, Add structured logging for the new deletion flow: log at start of operation (include tenant/agent_id and incoming ids/delete_all flag from get_request_json), log each per-session outcome inside the loop (success when API4ConversationService.delete_by_id succeeds and error when conv is None or deletion fails), and log final summary before each return (use success_count, errors, duplicate_messages). Reference the existing symbols get_request_json, UserCanvasService.query, check_duplicate_ids, API4ConversationService.delete_by_id and ensure logs include identifying context (tenant_id, agent_id, session_id) and use the module's logger for info/warn/error as appropriate.
🤖 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 `@api/apps/restful_apis/agent_api.py`:
- Around line 446-450: The delete_agent_session handler is defined async but
decorated with `@_require_canvas_access_sync` which does synchronous I/O and can
block the event loop; replace that decorator with `@_require_canvas_access_async`
(the same async access decorator used on create_agent_session) so the access
check runs without blocking, keeping the async signature of delete_agent_session
and preserving `@login_required` and `@add_tenant_id_to_kwargs` order.
- Around line 483-496: When both errors (from ownership checks) and
duplicate_messages (from check_duplicate_ids) can be present the current early
return in the if errors: branch hides duplicate_messages; update the logic in
the deletion response handling to merge duplicate_messages into the errors list
(or vice versa) before returning so both are reported. Concretely, in the block
using errors and duplicate_messages, build a single combined_errors list and use
get_result or get_error_data_result with that combined list and correct
success_count, ensuring both sources are included in the message; update
references around errors, duplicate_messages, get_result and
get_error_data_result accordingly.
---
Nitpick comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 451-498: Add structured logging for the new deletion flow: log at
start of operation (include tenant/agent_id and incoming ids/delete_all flag
from get_request_json), log each per-session outcome inside the loop (success
when API4ConversationService.delete_by_id succeeds and error when conv is None
or deletion fails), and log final summary before each return (use success_count,
errors, duplicate_messages). Reference the existing symbols get_request_json,
UserCanvasService.query, check_duplicate_ids,
API4ConversationService.delete_by_id and ensure logs include identifying context
(tenant_id, agent_id, session_id) and use the module's logger for
info/warn/error as appropriate.
🪄 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: 63d4c2b3-7880-4a01-8466-ecd2ac7b6134
📒 Files selected for processing (3)
api/apps/restful_apis/agent_api.pyapi/apps/restful_apis/bot_api.pyapi/apps/restful_apis/chunk_api.py
| if errors: | ||
| if success_count > 0: | ||
| return get_result(data={"success_count": success_count, "errors": errors}, | ||
| message=f"Partially deleted {success_count} sessions with {len(errors)} errors") | ||
| else: | ||
| return get_error_data_result(message="; ".join(errors)) | ||
|
|
||
| if duplicate_messages: | ||
| if success_count > 0: | ||
| return get_result( | ||
| message=f"Partially deleted {success_count} sessions with {len(duplicate_messages)} errors", | ||
| data={"success_count": success_count, "errors": duplicate_messages}) | ||
| else: | ||
| return get_error_data_result(message=";".join(duplicate_messages)) |
There was a problem hiding this comment.
Duplicate messages silently lost when deletion errors exist.
If both errors (from sessions not owned by the agent) and duplicate_messages (from check_duplicate_ids) exist, the if errors: block returns early and duplicate_messages are never reported to the caller.
🐛 Proposed fix: Combine errors and duplicate messages
+ all_errors = errors + duplicate_messages
+
- if errors:
+ if all_errors:
if success_count > 0:
- return get_result(data={"success_count": success_count, "errors": errors},
- message=f"Partially deleted {success_count} sessions with {len(errors)} errors")
+ return get_result(data={"success_count": success_count, "errors": all_errors},
+ message=f"Partially deleted {success_count} sessions with {len(all_errors)} errors")
else:
- return get_error_data_result(message="; ".join(errors))
-
- if duplicate_messages:
- if success_count > 0:
- return get_result(
- message=f"Partially deleted {success_count} sessions with {len(duplicate_messages)} errors",
- data={"success_count": success_count, "errors": duplicate_messages})
- else:
- return get_error_data_result(message=";".join(duplicate_messages))
+ return get_error_data_result(message="; ".join(all_errors))
return get_result()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if errors: | |
| if success_count > 0: | |
| return get_result(data={"success_count": success_count, "errors": errors}, | |
| message=f"Partially deleted {success_count} sessions with {len(errors)} errors") | |
| else: | |
| return get_error_data_result(message="; ".join(errors)) | |
| if duplicate_messages: | |
| if success_count > 0: | |
| return get_result( | |
| message=f"Partially deleted {success_count} sessions with {len(duplicate_messages)} errors", | |
| data={"success_count": success_count, "errors": duplicate_messages}) | |
| else: | |
| return get_error_data_result(message=";".join(duplicate_messages)) | |
| all_errors = errors + duplicate_messages | |
| if all_errors: | |
| if success_count > 0: | |
| return get_result(data={"success_count": success_count, "errors": all_errors}, | |
| message=f"Partially deleted {success_count} sessions with {len(all_errors)} errors") | |
| else: | |
| return get_error_data_result(message="; ".join(all_errors)) | |
| return get_result() |
🤖 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 `@api/apps/restful_apis/agent_api.py` around lines 483 - 496, When both errors
(from ownership checks) and duplicate_messages (from check_duplicate_ids) can be
present the current early return in the if errors: branch hides
duplicate_messages; update the logic in the deletion response handling to merge
duplicate_messages into the errors list (or vice versa) before returning so both
are reported. Concretely, in the block using errors and duplicate_messages,
build a single combined_errors list and use get_result or get_error_data_result
with that combined list and correct success_count, ensuring both sources are
included in the message; update references around errors, duplicate_messages,
get_result and get_error_data_result accordingly.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
api/apps/restful_apis/agent_api.py (1)
450-498: ⚡ Quick winAdd audit logging to the new bulk-delete flow.
This new destructive endpoint has no request/outcome logging, which makes owner denials, partial deletes, and bulk
delete_alloperations hard to trace in production. Please log the mode (delete_allvs explicit ids), requested count, and final success/error counts without dumping raw session IDs.🪵 Suggested logging points
async def delete_agent_session(tenant_id, agent_id): errors = [] success_count = 0 req = await get_request_json() + logging.info( + "Bulk agent session delete requested: tenant_id=%s agent_id=%s delete_all=%s ids_count=%d", + tenant_id, + agent_id, + bool(req and req.get("delete_all") is True), + len((req or {}).get("ids") or []), + ) cvs = await thread_pool_exec(UserCanvasService.query, user_id=tenant_id, id=agent_id) if not cvs: + logging.warning( + "Bulk agent session delete denied: tenant_id=%s agent_id=%s reason=not_owner", + tenant_id, + agent_id, + ) return get_error_data_result(f"You don't own the agent {agent_id}") @@ if errors: + logging.warning( + "Bulk agent session delete completed with ownership/missing errors: tenant_id=%s agent_id=%s success_count=%d error_count=%d", + tenant_id, + agent_id, + success_count, + len(errors), + ) if success_count > 0: return get_result(data={"success_count": success_count, "errors": errors}, message=f"Partially deleted {success_count} sessions with {len(errors)} errors") @@ if duplicate_messages: + logging.info( + "Bulk agent session delete completed with duplicate ids: tenant_id=%s agent_id=%s success_count=%d duplicate_count=%d", + tenant_id, + agent_id, + success_count, + len(duplicate_messages), + ) if success_count > 0: return get_result( message=f"Partially deleted {success_count} sessions with {len(duplicate_messages)} errors", data={"success_count": success_count, "errors": duplicate_messages}) else: return get_error_data_result(message=";".join(duplicate_messages)) + logging.info( + "Bulk agent session delete succeeded: tenant_id=%s agent_id=%s success_count=%d", + tenant_id, + agent_id, + success_count, + ) return get_result()As per coding guidelines, "Add logging for new flows".
🤖 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 `@api/apps/restful_apis/agent_api.py` around lines 450 - 498, In delete_agent_session, add audit logs that record the delete mode (set a variable when you check req.get("delete_all") vs explicit ids), the requested_count (len of conv_list before deduplication), and final success_count and error counts (len(errors) and len(duplicate_messages)) but never log raw session IDs; log an owner-denial event when you append to errors (inside the loop where you check API4ConversationService.query) and log a summary after the deletion loop before each return path that currently returns get_result/get_error_data_result, so callers and ops can see whether the request was delete_all or explicit ids, how many were requested, how many succeeded, and how many failed. Use the existing function name delete_agent_session and services (UserCanvasService.query, API4ConversationService.delete_by_id, check_duplicate_ids) to locate insertion points.
🤖 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.
Nitpick comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 450-498: In delete_agent_session, add audit logs that record the
delete mode (set a variable when you check req.get("delete_all") vs explicit
ids), the requested_count (len of conv_list before deduplication), and final
success_count and error counts (len(errors) and len(duplicate_messages)) but
never log raw session IDs; log an owner-denial event when you append to errors
(inside the loop where you check API4ConversationService.query) and log a
summary after the deletion loop before each return path that currently returns
get_result/get_error_data_result, so callers and ops can see whether the request
was delete_all or explicit ids, how many were requested, how many succeeded, and
how many failed. Use the existing function name delete_agent_session and
services (UserCanvasService.query, API4ConversationService.delete_by_id,
check_duplicate_ids) to locate insertion points.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2e8d29e6-3adf-406f-8220-4823e11ceadf
📒 Files selected for processing (2)
api/apps/restful_apis/agent_api.pyapi/apps/restful_apis/bot_api.py
💤 Files with no reviewable changes (1)
- api/apps/restful_apis/bot_api.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15562 +/- ##
=======================================
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 Sentry. 🚀 New features to boost your workflow:
|
…flow into bugfix/no-more-token-required
Fix: no more @token_required