Skip to content

feat: introduce ComputeStrategy interface and extract AgentCoreComputeStrategy#8

Open
MichaelWalker-git wants to merge 4 commits intomainfrom
feat/compute-strategy
Open

feat: introduce ComputeStrategy interface and extract AgentCoreComputeStrategy#8
MichaelWalker-git wants to merge 4 commits intomainfrom
feat/compute-strategy

Conversation

@MichaelWalker-git
Copy link
Copy Markdown

Summary

  • Introduces a ComputeStrategy interface (SessionHandle, SessionStatus, startSession/pollSession/stopSession) and a resolveComputeStrategy() factory that selects the strategy based on blueprintConfig.compute_type
  • Extracts AgentCore-specific session logic from orchestrator.ts into AgentCoreComputeStrategy class (src/handlers/shared/strategies/agentcore-strategy.ts)
  • Refactors the start-session durable execution step in orchestrate-task.ts to use the strategy pattern — state transitions remain in the handler, compute-specific work is delegated to the strategy
  • Pure refactor: no behavior change, no new CloudFormation resources, synthesized template is identical to main

This is PR 1 of 3 for wiring the Fargate compute backend through a strategy interface, as requested in PR #4 review.

Files changed

Action File
CREATE src/handlers/shared/compute-strategy.ts — interface, types, factory
CREATE src/handlers/shared/strategies/agentcore-strategy.ts — AgentCore implementation
MODIFY src/handlers/shared/orchestrator.ts — remove startSession(), agentCoreClient, related imports
MODIFY src/handlers/orchestrate-task.tsstart-session step uses resolveComputeStrategy()
CREATE test/handlers/shared/compute-strategy.test.ts
CREATE test/handlers/shared/strategies/agentcore-strategy.test.ts
MODIFY test/handlers/orchestrate-task.test.ts — remove old startSession tests (moved to strategy tests)

Test plan

  • npx projen build passes (509 tests, 37 suites, compile + synth + lint)
  • Synthesized CloudFormation template identical to main (git diff main -- cdk.out/ is empty)
  • Deployed to dev account — stack update successful
  • Submitted task via CLI — full lifecycle: SUBMITTED → HYDRATING → RUNNING → FAILED (GitHub token expiry, unrelated)
  • session_started event contains strategy_type: "agentcore" metadata confirming strategy pattern is active

@MichaelWalker-git MichaelWalker-git requested a review from a team as a code owner April 7, 2026 15:39
…AgentCore logic

Introduce ComputeStrategy interface with SessionHandle/SessionStatus types
and resolveComputeStrategy factory. Extract AgentCoreComputeStrategy from
orchestrator.ts. Refactor orchestrate-task handler to use strategy pattern
for session lifecycle (start/poll/stop). Pure refactor — no behavior change,
identical CloudFormation output.
The mise install step downloads tools (trivy) from GitHub releases.
Without GITHUB_TOKEN, unauthenticated requests hit the 60 req/hr
rate limit, causing flaky CI failures.
Mise uses GITHUB_API_TOKEN (not GITHUB_TOKEN) for authenticated
GitHub API requests when downloading aqua tools like trivy.
Trivy, grype, semgrep, osv-scanner, and gitleaks are only needed for
security scanning tasks, not for the build/test/synth pipeline. Disable
them via MISE_DISABLE_TOOLS to avoid GitHub API rate limits when mise
tries to download them on every PR build.
Copy link
Copy Markdown

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

Introduces a compute strategy abstraction for orchestrating agent sessions, extracting AgentCore-specific session invocation logic out of the shared orchestrator and updating the durable “start-session” step to delegate compute-specific work to the selected strategy.

Changes:

  • Added a ComputeStrategy interface plus resolveComputeStrategy() factory keyed off blueprintConfig.compute_type.
  • Extracted AgentCore session invocation/stop logic into AgentCoreComputeStrategy, and refactored orchestration to use it.
  • Added/updated unit tests for the new strategy + factory, and adjusted existing orchestrator-related tests accordingly.

Reviewed changes

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

Show a summary per file
File Description
cdk/src/handlers/shared/compute-strategy.ts Adds strategy interface/types and a factory for selecting a compute backend.
cdk/src/handlers/shared/strategies/agentcore-strategy.ts Implements AgentCore-specific session start/poll/stop behind the strategy interface.
cdk/src/handlers/shared/orchestrator.ts Removes AgentCore session start logic from the shared orchestrator.
cdk/src/handlers/orchestrate-task.ts Updates the durable start-session step to resolve and use a compute strategy.
cdk/test/handlers/shared/compute-strategy.test.ts Tests strategy resolution and unknown compute type behavior.
cdk/test/handlers/shared/strategies/agentcore-strategy.test.ts Tests AgentCore strategy session start/poll/stop behavior with SDK mocking.
cdk/test/handlers/orchestrate-task.test.ts Removes old startSession tests and adjusts mocks (now mostly orchestrator-focused).
.github/workflows/build.yml Updates CI environment variables and disables several security/scanning tools via MISE_DISABLE_TOOLS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AQUA_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MISE_DISABLE_TOOLS: "aqua:aquasecurity/trivy,grype,semgrep,osv-scanner,gitleaks"
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

This workflow change disables multiple security/scanning tools (trivy, grype, semgrep, osv-scanner, gitleaks) via MISE_DISABLE_TOOLS. That reduces CI coverage and can allow vulnerabilities/secrets to slip through unnoticed. If the goal is to mitigate rate limits, consider keeping gitleaks/osv-scanner enabled (or running scanners in a separate job with caching/backoff) and document the rationale in the workflow so the security tradeoff is explicit.

Suggested change
MISE_DISABLE_TOOLS: "aqua:aquasecurity/trivy,grype,semgrep,osv-scanner,gitleaks"
# Keep secret and dependency scanning enabled in CI; only disable the
# remaining tools that are intentionally skipped here.
MISE_DISABLE_TOOLS: "aqua:aquasecurity/trivy,grype,semgrep"

Copilot uses AI. Check for mistakes.
Comment on lines +130 to +133
await emitTaskEvent(taskId, 'session_started', {
session_id: handle.sessionId,
strategy_type: handle.strategyType,
});
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

The PR description says this is a pure refactor with no behavior change, but the session_started event metadata now includes strategy_type (previously only session_id). If consumers depend on a fixed schema, this is a behavior change; either update the PR description to note the additive event field or keep the emitted metadata identical to the previous shape.

Copilot uses AI. Check for mistakes.
Comment on lines 30 to 34
jest.mock('@aws-sdk/client-bedrock-agentcore', () => ({
BedrockAgentCoreClient: jest.fn(() => ({ send: mockAgentCoreSend })),
BedrockAgentCoreClient: jest.fn(() => ({ send: jest.fn() })),
InvokeAgentRuntimeCommand: jest.fn((input: unknown) => ({ _type: 'InvokeAgentRuntime', input })),
StopRuntimeSessionCommand: jest.fn((input: unknown) => ({ _type: 'StopRuntimeSession', input })),
}));
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

This test file still mocks @aws-sdk/client-bedrock-agentcore, but after extracting startSession out of shared/orchestrator the test suite no longer uses that SDK. Removing this mock will reduce noise and avoid accidentally masking real imports/usages in future tests.

Copilot uses AI. Check for mistakes.
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