Skip to content

Conversation

bjeffries
Copy link

Description

This pull request addresses issues #3078 and #3079.

Currently there is a bug identified in #3078 that prevents the existing builder plugin from hooking the executor outside of the planning service. This is addressed by adding a similar check in the operations api manager.

Looking at the bigger picture, the executor hook check was specialized just for the builder plugin. The change below will parse through any hook that is added to the executor hook data structure allowing for other plugins to easily leverage this capability.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

How Has This Been Tested?

I have tested these changes on Caldera v5 with a plugin that leverages this hooking method to edit ability files before they are staged for an agent.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

@bjeffries bjeffries requested a review from a team as a code owner December 3, 2024 20:17
@mkultraWasHere mkultraWasHere self-assigned this Dec 6, 2024
@mkultraWasHere mkultraWasHere self-requested a review December 19, 2024 00:36
mkultraWasHere
mkultraWasHere previously approved these changes Dec 19, 2024
@deacon-mp deacon-mp requested a review from Copilot September 29, 2025 23:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes executor hook functionality for plugins by generalizing hook execution to work across different services and moving command encoding to occur after plugin hooks are called.

  • Refactored specific builder plugin hook check to support any plugin hooks through a generic _call_ability_plugin_hooks method
  • Added hook execution to the operations API manager to ensure plugins can modify abilities outside the planning service
  • Moved command encoding to occur after plugin hooks to ensure hooks can modify abilities before encoding

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
app/service/planning_svc.py Replaced specific builder plugin hook check with generic hook execution method
app/api/v2/managers/operation_api_manager.py Added plugin hook execution and moved command encoding after hooks

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 395 to 396
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

This code will fail with an AttributeError if executor.HOOKS is None or undefined. Add a null check before iterating: if executor.HOOKS: before the for loop.

Suggested change
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)
if executor.HOOKS:
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)

Copilot uses AI. Check for mistakes.

Comment on lines 177 to 178
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

This code will fail with an AttributeError if executor.HOOKS is None or undefined. Add a null check before iterating: if executor.HOOKS: before the for loop.

Suggested change
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)
if executor.HOOKS:
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)

Copilot uses AI. Check for mistakes.

Comment on lines 393 to 397
async def _call_ability_plugin_hooks(self, ability, executor):
"""Calls any plugin hooks (at runtime) that exist for the ability and executor."""
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)

Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The duplicated hook execution logic in both files should be extracted to a shared utility or base class to avoid code duplication and ensure consistent behavior.

Suggested change
async def _call_ability_plugin_hooks(self, ability, executor):
"""Calls any plugin hooks (at runtime) that exist for the ability and executor."""
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)
# _call_ability_plugin_hooks is now implemented in BasePlanningService

Copilot uses AI. Check for mistakes.

@deacon-mp
Copy link
Contributor

Can address the suggestions above and update the PR for approval

@deacon-mp deacon-mp requested a review from Copilot October 6, 2025 22:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

sonarqubecloud bot commented Oct 6, 2025

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.

3 participants