Skip to content

feat: AGENT_RUNTIME feature flag — Lambda/Fargate/both compute selection#19

Open
tobigs wants to merge 9 commits intoserithemage:mainfrom
tobigs:pr/lambda-runtime
Open

feat: AGENT_RUNTIME feature flag — Lambda/Fargate/both compute selection#19
tobigs wants to merge 9 commits intoserithemage:mainfrom
tobigs:pr/lambda-runtime

Conversation

@tobigs
Copy link
Copy Markdown

@tobigs tobigs commented Mar 26, 2026

Summary

Adds an AGENT_RUNTIME environment variable (fargate | lambda | both, default fargate) that controls which compute backend handles agent requests:

  • fargate (default): existing Fargate path, no change
  • lambda: skips all Fargate infrastructure (NetworkStack/VPC not created, no ECS SSM lookups, watchdog/prewarm early-return)
  • both: smart routing — Lambda by default, Fargate reuse when already running, /heavy//fargate hint for Fargate, Lambda failure fallback to Fargate

Changes

  • ApiStack: conditionally reads Fargate SSM params (cluster-arn, task-definition-arn, etc.) and skips ECS IAM grants when AGENT_RUNTIME=lambda
  • telegram-webhook.ts / identity.ts: guard Fargate task-state checks behind agentRuntime !== "lambda"
  • watchdog.ts / prewarm.ts: early-return when AGENT_RUNTIME=lambda
  • cdk/bin/app.ts: skip NetworkStack creation for lambda-only mode
  • MonitoringStack: exclude Fargate dashboard widgets (cold start, ECS CPU/Memory, pre-warming) in lambda-only mode
  • .env.example: documents AGENT_RUNTIME with valid values
  • E2E tests: 10 new preservation and bug-condition test cases

Dependencies

Note: This branch is based on pr/misc-fixes (PR #18) and will be rebased onto main once that is merged. The misc-fixes PR includes Korean→English string translations that some of these tests depend on.

Test plan

  • Unit tests: all 259 pass
  • E2E tests: 46 CDK synth tests pass (including 10 new AGENT_RUNTIME-specific cases)
# Lambda-only mode — no NetworkStack VPC resources, no Fargate env vars
AGENT_RUNTIME=lambda npx cdk synth

# Fargate-only (default)
AGENT_RUNTIME=fargate npx cdk synth

# Both — all stacks present
AGENT_RUNTIME=both npx cdk synth

🤖 Generated with Claude Code

Tobias and others added 9 commits March 26, 2026 17:38
The Telegram bot system prompt in bridge.ts was in Korean, causing the
AI to respond in Korean. Also translated all other user-facing Korean
strings across gateway handlers, identity service, container startup
notifications, monitoring dashboard descriptions, web UI, and tests.
ComputeStack is not deployed in lambda mode, so the SSM parameters it
writes (cluster-arn, task-definition-arn, etc.) don't exist. ApiStack
now conditionally reads them and skips Fargate IAM grants (ecs:RunTask,
iam:PassRole) when agentRuntime is 'lambda'.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- identity.ts: guard Fargate task-state lookup in verifyOtpAndLink behind
  agentRuntime !== "lambda" to avoid spurious DynamoDB reads
- telegram-webhook.ts: skip cold-start task-state check when Lambda runtime;
  pass agentRuntime to verifyOtpAndLink and routeMessage; add structured
  console logging throughout for observability
- ws-message.ts: pass agentRuntime, invokeLambdaAgent, and
  lambdaAgentFunctionArn to routeMessage
- telegram-webhook.test.ts: update verifyOtpAndLink call expectation to
  include agentRuntime option

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- watchdog/prewarm handlers: early-return when AGENT_RUNTIME=lambda
- E2E test: remove stale cluster/taskDefinition props from ApiStack
- .env.example: document AGENT_RUNTIME with valid values
- message.ts: add onLambdaResponse callback to RouteDeps so callers
  handle delivery after a successful Lambda invocation
- ws-message.ts: push each payload as a WebSocket message + send
  status:running before invoke and status:Idle after
- telegram-webhook.ts: send each payload text back via Telegram
- stacks.e2e.test.ts: fix unused variable in PREWARM_SCHEDULE test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…bda-only mode

- Make ApiStack vpc/fargateSecurityGroup props optional
- Conditionally include Fargate env vars (ECS_CLUSTER_ARN, TASK_DEFINITION_ARN,
  SUBNET_IDS, SECURITY_GROUP_IDS) only when fargateEnabled
- Skip NetworkStack creation when AGENT_RUNTIME=lambda
- Add agentRuntime prop to MonitoringStack, exclude Fargate dashboard
  widgets (Cold Start, Pre-Warming, ECS CPU/Memory) in lambda-only mode
- Add bug condition exploration and preservation E2E tests
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.

1 participant