Skip to content

Conversation

@marleystipich2
Copy link
Collaborator

@marleystipich2 marleystipich2 commented Nov 10, 2025

Summary by Sourcery

Remove direct database receptor joins from getPlaybookRuns, return empty executor arrays by default, and shift executor population to the combineRuns function while updating tests and snapshots accordingly.

Enhancements:

  • Simplify getPlaybookRuns to drop playbook_run_executors and playbook_run_systems joins and always return an empty executors array
  • Initialize the executors array in combineRuns if missing so executors can be populated via the playbook-dispatcher API

Tests:

  • Update FiFi integration tests and snapshots to remove receptor-related fields and validate empty executors arrays and adjusted executor properties

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 10, 2025

Reviewer's Guide

Refactor getPlaybookRuns to remove receptor-specific joins and data, initialize executors in combineRuns, and adjust integration tests to expect empty or simplified executor arrays.

Sequence diagram for combineRuns executor initialization and population

sequenceDiagram
participant combineRuns
participant PlaybookRun
participant playbook-dispatcher

combineRuns->>PlaybookRun: Check if executors exists
alt executors not present
    combineRuns->>PlaybookRun: Initialize executors as []
end
combineRuns->>playbook-dispatcher: Fetch run details for PlaybookRun.id
playbook-dispatcher-->>combineRuns: Return direct/satellite host executor data
combineRuns->>PlaybookRun: Populate executors with dispatcher data
Loading

Class diagram for updated PlaybookRun and Executor data structure

classDiagram
class Remediation {
  +id
  +tenant_org_id
  +created_by
  +playbook_runs: PlaybookRun[]
}
class PlaybookRun {
  +id
  +executors: Executor[]
}
class Executor {
  +executor_id
  +executor_name
  +status
  +system_count
  +counts
}
Remediation "1" -- "*" PlaybookRun : has
PlaybookRun "1" -- "*" Executor : has
Loading

File-Level Changes

Change Details Files
Simplify getPlaybookRuns query by removing executor/system joins and aggregations
  • Dropped include of playbook_run_executors and playbook_run_systems
  • Removed COUNT/SUM casting, GROUP BY clauses, and filtering logic
  • Updated DB destructuring to only extract necessary columns
src/remediations/remediations.queries.js
Initialize executors array in combineRuns to support external population
  • Added guard to set run.executors to empty array when missing
  • Ensures downstream formatRHCRuns call can append executor data
src/remediations/fifi.js
Update integration tests and snapshots to reflect removed receptor executor data
  • Adjusted expected executor IDs, names, statuses, and counts
  • Removed assertions for multiple executors per run
  • Assert executors arrays are empty or only contain simplified 'running' counts
  • Regenerated snapshots accordingly
src/remediations/fifi.integration.js
src/remediations/__snapshots__/fifi.integration.js.snap

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
Contributor

@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 there - I've reviewed your changes - here's some feedback:

  • Consider assessing the performance impact of replacing the aggregated database executor counts with per-run calls to the playbook-dispatcher API, as this could introduce additional latency under load.
  • Since getPlaybookRuns now always returns an empty executors array, you could move that default initialization into the query layer to simplify combineRuns and ensure consistency.
  • There are many repetitive .executors.should.have.length(0) assertions in the integration tests—extract a helper or shared assertion to DRY up those checks.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider assessing the performance impact of replacing the aggregated database executor counts with per-run calls to the playbook-dispatcher API, as this could introduce additional latency under load.
- Since getPlaybookRuns now always returns an empty executors array, you could move that default initialization into the query layer to simplify combineRuns and ensure consistency.
- There are many repetitive `.executors.should.have.length(0)` assertions in the integration tests—extract a helper or shared assertion to DRY up those checks.

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.

return result;
};

// For now, we're returning an empty executors array because we no longer use playbook_run_executors or playbook_run_systems tables (receptor data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Something that might be useful for a lot of the queries that we're cleaning up...

We wouldn't need to make any API calls in formatRHCRuns for Direct or Satellite cases if we had a dispatcher_runs_hosts table. dispatcher_runs_hosts would store host-level execution status and counts that we get from Kafka Run Host events from playbook-dispatcher..
The dispatcher_runs table helps in a lot of cases but for endpoints like GET /remediations/id/playbook_runs, we need the host-level run data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant