Skip to content

Conversation

fregataa
Copy link
Member

@fregataa fregataa commented Sep 4, 2025

resolves #5313 (BA-1950)

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Installer updates including:
    • Fixtures for db schema changes
    • New mandatory config options
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)
  • Test case(s) to:
    • Demonstrate the difference of before/after
    • Demonstrate the flow of abstract/conceptual models with a concrete implementation
  • Documentation
    • Contents in the docs directory
    • docstrings in public interfaces and type annotations

@fregataa fregataa added this to the 25Q2 milestone Sep 4, 2025
@fregataa fregataa self-assigned this Sep 4, 2025
@Copilot Copilot AI review requested due to automatic review settings September 4, 2025 13:05
@github-actions github-actions bot added size:L 100~500 LoC comp:manager Related to Manager component labels Sep 4, 2025
@fregataa fregataa changed the title feat: Action Processor to handle various types of targets feat(BA-1950): Action Processor to handle various types of targets Sep 4, 2025
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 PR implements an Action Processor system to handle various types of targets in the AI Backend manager. It introduces a modular architecture with specialized processors for different action types (single entity, scope, and batch operations) along with corresponding validators.

  • Refactors the action processing system with type-specific processors and validators
  • Adds specialized action classes for single entity, scope, and batch operations
  • Moves validation logic to a dedicated validator module structure

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.

File Description
src/ai/backend/manager/actions/validators/auth_validator.py Updates import path for ActionValidator
src/ai/backend/manager/actions/validator/*.py Introduces specialized validator classes for different action types
src/ai/backend/manager/actions/processor/*.py Implements type-specific action processors with common processing logic
src/ai/backend/manager/actions/action/*.py Defines base action classes and specialized action types for different targets

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

Comment on lines 37 to 92
async def _run(self, action: TSingleEntityAction) -> TSingleEntityActionResult:
started_at = datetime.now()
status = OperationStatus.UNKNOWN
description: str = "unknown"
result: Optional[TSingleEntityActionResult] = None
error_code: Optional[ErrorCode] = None

action_id = uuid.uuid4()
action_trigger_meta = BaseActionTriggerMeta(action_id=action_id, started_at=started_at)
for monitor in self._monitors:
try:
await monitor.prepare(action, action_trigger_meta)
except Exception as e:
log.warning("Error in monitor prepare method: {}", e)
try:
for validator in self._validators:
await validator.validate(action, action_trigger_meta)
result = await self._func(action)
except BackendAIError as e:
log.exception("Action processing error: {}", e)
status = OperationStatus.ERROR
description = str(e)
error_code = e.error_code()
raise
except BaseException as e:
log.exception("Unexpected error during action processing: {}", e)
status = OperationStatus.ERROR
description = str(e)
error_code = ErrorCode.default()
raise
else:
status = OperationStatus.SUCCESS
description = "Success"
return result
finally:
ended_at = datetime.now()
duration = ended_at - started_at
entity_id = action.entity_id()
if entity_id is None and result is not None:
entity_id = result.entity_id()
meta = BaseActionResultMeta(
action_id=action_id,
entity_id=entity_id,
status=status,
description=description,
started_at=started_at,
ended_at=ended_at,
duration=duration,
error_code=error_code,
)
process_result = ProcessResult(meta=meta)
for monitor in reversed(self._monitors):
try:
await monitor.done(action, process_result)
except Exception as e:
log.warning("Error in monitor done method: {}", e)
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

This entire _run method is duplicated across all three processor classes (single_entity.py, scope.py, batch.py). Consider extracting this common logic into a base class or shared utility function to eliminate code duplication.

Copilot uses AI. Check for mistakes.

Comment on lines +7 to +10
class BaseBatchAction(BaseAction):
@override
def entity_id(self) -> Optional[str]:
return None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the entity_id for backward compatibility?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it overrides BaseAction method

@fregataa fregataa force-pushed the feat/add-processors-based-on-action-types branch from bfdd80a to 2cf1a22 Compare September 5, 2025 09:45
@fregataa fregataa force-pushed the feat/add-processors-based-on-action-types branch from 2cf1a22 to 4db5743 Compare September 16, 2025 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:manager Related to Manager component size:L 100~500 LoC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Action Processors to handle various Action target types
2 participants