Skip to content

fix(bulk-actions): return per-item success/failed ids (EVO-1011)#58

Merged
dpaes merged 1 commit into
developfrom
fix/EVO-1011
May 13, 2026
Merged

fix(bulk-actions): return per-item success/failed ids (EVO-1011)#58
dpaes merged 1 commit into
developfrom
fix/EVO-1011

Conversation

@marcelogorutuba
Copy link
Copy Markdown
Member

@marcelogorutuba marcelogorutuba commented May 12, 2026

Summary

  • BulkActionsJob#bulk_conversation_update now collects success_ids and failed_ids per conversation using a rescue clause inside the iteration
  • BulkActionsController#create captures the job result and includes it in the API response payload
  • Frontend can now show accurate per-item failure toasts (e.g., "8 resolved, 2 failed")

Validation

  • evo-ai-crm-community: bundle exec ruby -c app/jobs/bulk_actions_job.rb
  • evo-ai-crm-community: bundle exec ruby -c app/controllers/api/v1/bulk_actions_controller.rb

Changed Files

  • app/jobs/bulk_actions_job.rb
  • app/controllers/api/v1/bulk_actions_controller.rb

Related PRs

Linked Issue

  • EVO-1011

Summary by Sourcery

Report per-item success and failure IDs from bulk conversation updates and expose them in the bulk actions API response.

New Features:

  • Return success and failure conversation IDs from bulk conversation updates in the bulk actions job.
  • Include bulk action result metadata (success and failure IDs) in the bulk actions create API response payload.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 12, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

BulkActionsJob and BulkActionsController were updated so that bulk conversation updates now track per-conversation successes and failures and return this result from the job, which the controller includes in the API response for the frontend to surface per-item failure information.

Sequence diagram for bulk conversation update result propagation

sequenceDiagram
  actor Frontend
  participant BulkActionsController as Api_V1_BulkActionsController
  participant BulkActionsJob

  Frontend->>BulkActionsController: create
  BulkActionsController->>BulkActionsController: type_matches?
  alt type_matches
    BulkActionsController->>BulkActionsJob: perform_now(user, params)
    BulkActionsJob->>BulkActionsJob: bulk_update
    BulkActionsJob->>BulkActionsJob: bulk_conversation_update
    loop each conversation
      BulkActionsJob->>BulkActionsJob: bulk_add_labels(conversation)
      BulkActionsJob->>BulkActionsJob: bulk_snoozed_until(conversation)
      BulkActionsJob->>BulkActionsJob: conversation.update!(params)
      alt update succeeds
        BulkActionsJob->>BulkActionsJob: success_ids << display_id
      else update fails
        BulkActionsJob->>BulkActionsJob: failed_ids << display_id
      end
    end
    BulkActionsJob-->>BulkActionsController: { success_ids, failed_ids }
    BulkActionsController->>BulkActionsController: success_response(data: result)
    BulkActionsController-->>Frontend: 201 Created with result
  else type does not match
    BulkActionsController-->>Frontend: error response
  end
Loading

File-Level Changes

Change Details Files
Return per-item success/failed conversation IDs from bulk_conversation_update and propagate them through bulk_update.
  • Initialize success_ids and failed_ids arrays at the start of bulk_conversation_update.
  • Wrap per-conversation operations in a rescue block to capture failures and push display_id into either success_ids or failed_ids.
  • Return a hash containing success_ids and failed_ids from bulk_conversation_update.
  • Return a placeholder success/failed hash in bulk_update when handling Contact type bulk updates.
app/jobs/bulk_actions_job.rb
Capture BulkActionsJob result in the bulk actions API and include it in the response payload.
  • Assign the result of BulkActionsJob.perform_now to a local variable in BulkActionsController#create.
  • Pass the job result as the data field in success_response instead of nil.
app/controllers/api/v1/bulk_actions_controller.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In bulk_update, the Contact branch now always returns an empty { success_ids: [], failed_ids: [] } hash, which is inconsistent with the conversation branch and may mislead the caller/front-end; consider either returning a meaningful result for contacts or returning nil/a distinct structure and handling that explicitly in the controller.
  • In bulk_conversation_update, the rescue StandardError inside the loop swallows all exceptions without any logging or context; consider at least logging the exception (with conversation ID) so operational issues can be traced while still allowing the bulk job to continue.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `bulk_update`, the Contact branch now always returns an empty `{ success_ids: [], failed_ids: [] }` hash, which is inconsistent with the conversation branch and may mislead the caller/front-end; consider either returning a meaningful result for contacts or returning `nil`/a distinct structure and handling that explicitly in the controller.
- In `bulk_conversation_update`, the `rescue StandardError` inside the loop swallows all exceptions without any logging or context; consider at least logging the exception (with conversation ID) so operational issues can be traced while still allowing the bulk job to continue.

## Individual Comments

### Comment 1
<location path="app/jobs/bulk_actions_job.rb" line_range="21" />
<code_context>
   def bulk_update
     if @params[:type] == 'Contact'
       bulk_contact_update
+      { success_ids: [], failed_ids: [] }
     else
       bulk_remove_labels
</code_context>
<issue_to_address>
**issue (bug_risk):** The Contact branch now returns an always-empty result, which is inconsistent with conversation updates and likely breaks result reporting.

For the Contact path, `bulk_update` now always returns `{ success_ids: [], failed_ids: [] }`, while the conversation path returns real IDs from `bulk_conversation_update`. As a result, the client will see empty arrays even when Contact updates succeed or fail. Either have `bulk_contact_update` return a similar success/failed ID structure and propagate it, or return `nil` and let the controller branch by type so it doesn’t promise per-record results for contacts.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

def bulk_update
if @params[:type] == 'Contact'
bulk_contact_update
{ success_ids: [], failed_ids: [] }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): The Contact branch now returns an always-empty result, which is inconsistent with conversation updates and likely breaks result reporting.

For the Contact path, bulk_update now always returns { success_ids: [], failed_ids: [] }, while the conversation path returns real IDs from bulk_conversation_update. As a result, the client will see empty arrays even when Contact updates succeed or fail. Either have bulk_contact_update return a similar success/failed ID structure and propagate it, or return nil and let the controller branch by type so it doesn’t promise per-record results for contacts.

… ids (EVO-1011)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dpaes dpaes merged commit fc1626f into develop May 13, 2026
1 check passed
@dpaes dpaes deleted the fix/EVO-1011 branch May 13, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants