Skip to content

feat: fail closed when a Building Block mock loads in a deployed environment - #1032

Merged
soberm merged 5 commits into
mainfrom
appsec/runtime-mock-guard
Oct 26, 2026
Merged

soberm merged 5 commits into
mainfrom
appsec/runtime-mock-guard

Conversation

@soberm

@soberm soberm commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

AWS Blocks selects a Building Block's implementation through npm conditional exports resolved at bundle time: cdk → the CDK construct, aws-runtime → the real AWS-backed implementation, and default → the local-dev mock (in-memory / on-disk stubs).

The cdk condition is already guarded at runtime by assertCdkConditionActive(), which fails closed when CDK synth runs without --conditions=cdk. The aws-runtime condition had no runtime counterpart. If a backend is bundled without the aws-runtime condition, module resolution falls back to each BB's default (mock) entry, and the deployed artifact runs the mocks with no error, warning, or log line.

The framework's own deploy tooling always passes the condition, so this only surfaces when a backend is deployed to a compute target the framework does not configure — a customer's own bundler, a container image, or another serverless platform.

Changes

  • Runtime guard (compute-agnostic). @aws-blocks/core/bb-utils now exports assertNotMockInDeployedEnv(bbName), the runtime counterpart of the --conditions=cdk synth check. It throws when a Building Block's mock (default) entry is loaded in a deployed environment. "Deployed" is detected from BLOCKS_CONFIG_BUCKET / BLOCKS_CONFIG_KEY — the same two variables Blocks sets on every compute it configures and that the config loader already uses to tell local-vs-deployed apart — so the check covers Lambda, container, AgentCore, and other compute targets alike. It deliberately does not key off AWS_LAMBDA_*, which would make it Lambda-only. It is a no-op in local dev and tests.
  • Wired into every BB mock entry. Each Building Block's mock entry calls the guard at module load, so a mis-bundled artifact throws at startup instead of running in-memory stubs. bb-auth-basic is intentionally excluded: it has no aws-runtime export, so its index.ts is its real deployed runtime rather than a mock.
  • AuthOIDC mock cookie secret. The mock runtime's cookie-signing secret is now a per-process random value (held on a globalThis symbol so duplicate module copies share one) instead of a fixed constant. Local sign-in is unchanged; sessions no longer persist across a dev-server restart.
  • Bundler conditions pinned. The @aws-blocks/hosting handler bundle and the AuthOIDC IdP-registration and distributed-table GSI-manager Lambda bundles now pin the aws-runtime condition (defense-in-depth; their graphs contain no @aws-blocks/* imports today).
  • Docs. docs/guides/extending-with-existing-aws-resources.md documents configuring your own bundler with the aws-runtime condition when deploying to a compute target Blocks doesn't configure, and is explicit that the runtime guard only fires where Blocks sets the config-location variables.

Validation

  • npm run build and npm run lint pass.
  • New unit tests for the guard (packages/core/src/common/runtime-guard.test.ts): both variables set throws; either one alone does not; neither set is a no-op.
  • New package-level test (packages/core/src/common/runtime-guard.e2e.test.ts) spawns a child node process importing a real built BB: with the config variables set and without --conditions=aws-runtime it exits non-zero naming the guard; with the condition it loads; with neither variable set it loads.
  • Existing suites pass (core 1695; bb-auth-oidc, bb-auth-cognito, bb-realtime, bb-kv-store, bb-file-bucket, bb-agent, bb-logger).

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…ronment

Add assertNotMockInDeployedEnv(bbName) to @aws-blocks/core (exported from
bb-utils), the runtime counterpart of assertCdkConditionActive. It throws when
a BB mock (default export) entry is loaded in a deployed environment, detected
compute-agnostically via BLOCKS_CONFIG_BUCKET/BLOCKS_CONFIG_KEY (not
AWS_LAMBDA_*), so it covers Lambda, container, AgentCore and other compute
targets. Wire it into every BB mock entry; bb-auth-basic is excluded because it
has no aws-runtime export (its index.ts is the real runtime). Replace the OIDC
mock cookie secret with a per-process random value, pin aws-runtime on three
esbuild bundles, and document the bundler-condition requirement.
@changeset-bot

changeset-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6101fc8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
@aws-blocks/core Minor
@aws-blocks/blocks Minor
@aws-blocks/bb-agent Minor
@aws-blocks/bb-app-setting Minor
@aws-blocks/bb-async-job Minor
@aws-blocks/bb-auth-cognito Minor
@aws-blocks/bb-auth-oidc Minor
@aws-blocks/bb-compute Minor
@aws-blocks/bb-container-compute Minor
@aws-blocks/bb-cron-job Minor
@aws-blocks/bb-dashboard Minor
@aws-blocks/bb-data Minor
@aws-blocks/bb-distributed-data Minor
@aws-blocks/bb-distributed-table Minor
@aws-blocks/bb-email-client Minor
@aws-blocks/bb-file-bucket Minor
@aws-blocks/bb-knowledge-base Minor
@aws-blocks/bb-kv-store Minor
@aws-blocks/bb-lambda-compute Minor
@aws-blocks/bb-logger Minor
@aws-blocks/bb-metrics Minor
@aws-blocks/bb-realtime Minor
@aws-blocks/bb-secret Minor
@aws-blocks/bb-tracer Minor
@aws-blocks/hosting Patch
@aws-blocks/create-block Minor
@aws-blocks/auth-common Patch
@aws-blocks/bb-auth-basic Patch
@aws-blocks/data-common Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@soberm
soberm marked this pull request as ready for review October 26, 2026 14:34
@soberm
soberm requested a review from a team as a code owner October 26, 2026 14:34
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
📖 Glossary & notes — scoring, indicators, per-metric thresholds (click to expand)
  • N = 1 — one rep per cell, so a small delta may be model variance, not a real change; re-run for certainty.
  • Indicators (change vs baseline, per metric): ✨ noticeably improved · ✅ OK / no significant change (within noise band) · ⚠️ slight regression (beyond 1× threshold) · ❌ serious regression (beyond 2× threshold) · 🆕 new — no baseline value yet (current value shown, tagged (new)) · — nothing to show this run · 🗑️ cell gone since the baseline. Each cell shows <indicator> <value> (<Δ vs main>) inline.
  • Columns: Tests (pass/denom) · Judge (overall 0-10 score with signed delta; per-dimension breakdown lives in the judge artifact JSON) · Cost · Turns (agent cycles) · Score · Stop reason.
  • Threshold definitions (per metric, DELTA_THRESHOLDS in overview.mjs):
    • composite/score: ±5 points — a change ≤5 pts is ✅; >5 improving is ✨; >5 worsening is ⚠️; >10 worsening is ❌.
    • judge (overall): ±0.3 — a shift ≤0.3 is ✅; >0.3 improving is ✨; >0.3 worsening is ⚠️; >0.6 worsening is ❌.
    • tests: ±1 pass — a ≤1 pass change is ✅; >1 improving is ✨; >1 worsening is ⚠️; >2 worsening is ❌.
    • cost: ±10% of baseline (floor $0.02) — within 10% is ✅; >10% cheaper is ✨; >10% more expensive is ⚠️; >20% more expensive is ❌.
    • turns: ±3 cycles — a ≤3 turn change is ✅; >3 fewer is ✨; >3 more is ⚠️; >6 more is ❌.
  • Directions: higher is better for tests, judge, and score; lower is better for cost and turns.
  • Composite (0-100) = round(60·test_rate + 4·judge·min(1, 4·test_rate), 1) — 60% objective pass-rate + 40% judge, the judge term gated below a 25% pass-rate.
  • Cost = builder token spend at Bedrock Claude Opus 4.8 rates ($5 in / $25 out per 1M tokens; BUILDER_PRICING in scoring.mjs).
  • SCORE = composite ÷ cost — composite points per dollar (higher = better). Cost, not raw token volume, is the denominator, so tokens can't dominate; a broken (composite 0) cell scores 0 no matter how cheap. Flip SCORE_PER_DOLLAR in scoring.mjs for cost-per-point (lower = better).
  • Baseline = the most recent main-branch bench (bench/runs/latest-main.json), NOT the PR base commit — the PR always diffs against the current state of main.
  • Excluded from the mean: harness_error cells (infra failures) and gradeable cells that ran no tests. agent_fail (agent produced no app in budget) and dead_server (built app never served / crashed) are BOTH included, as composite 0.
  • Run artifacts — per-cell source + full agent traces · 🕒 Last run: 2026-10-26T15:41:24Z · run #40346719071

Results — PR vs main baseline

Each metric shows its current value colored by the change vs the latest main baseline ee8e078. ✨ improved · ✅ within noise · ⚠️ slight regression · ❌ serious regression · 🆕 no baseline yet (value shown, tagged (new)).

  • Mean composite 0.0/100 across 1 scored cell(s) — ✅ 0.0 vs main.
  • Verdicts: 0 pass · 0 partial · 1 fail · 9 harness_error.
  • Totals: cost $76.16 · tokens 14.6M in / 133.7K out · 300 turns.
  • Config: baseline ee8e078.
  • ❌ Composite band 🔴 across 1 scored cell(s). Threshold 65 — FAIL.
Task Template Tests Judge Cost Turns Score Stop reason
async-word-counter bare — — ⚠️ $3.84 (+$0.4) ⚠️ 23 (+4) — endTurn
auth-notes demo — — ❌ $11.08 (+$4.85) ❌ 45 (+17) — endTurn
cognito-profile auth-cognito — — ✨ $3.26 (-$2.34) ✨ 15 (-10) ✅ 0 (0) error
collab-presence-board default — — ✅ $2.07 (-$0.04) ✅ 17 (+1) — endTurn
email-digest demo — — ⚠️ $5.53 (+$0.54) ✅ 28 (+2) — endTurn
file-gallery bare — — ✨ $1.91 (-$0.23) ✅ 15 (+2) — endTurn
kb-chat-agent demo — — ❌ $27.29 (+$5.44) ❌ 59 (+9) — endTurn
observability-api backend — — ✅ $4.4 (-$0.46) ✅ 24 (-1) — endTurn
oidc-dsql-notes react — — ✅ $9.34 (+$0.05) ✅ 38 (0) — endTurn
sql-kb-catalog nextjs — — ❌ $7.44 (+$2.21) ❌ 36 (+7) — endTurn

Merge verdict

❌ This bench run BLOCKS the PR.

  • ❌ Absolute floor — mean composite 0.0 is below the floor 65.
  • ✅ Regression vs main — mean composite delta +0.0 pts vs main is within the 10-pt limit.

The Δ vs base ball above is a fixed ±5-pt display band; the regression gate uses BENCH_MAX_REGRESSION. The ball is cosmetic — the gate threshold is what blocks.

Caveats & exclusions

  • 🧰 Excluded (harness_error, not scored) — 9: 9× isolation_unavailable. Cells: async-word-counter/bare, auth-notes/demo, collab-presence-board/default, email-digest/demo, file-gallery/bare, kb-chat-agent/demo, observability-api/backend, oidc-dsql-notes/react, sql-kb-catalog/nextjs

This was referenced Oct 28, 2026

This branch had an error being deployed

1 failed and 1 inactive deployments
agent-bench — 6101fc85 Deployed Oct 26, 2026 by soberm via bench / summary #3426
e2e — 6101fc85 Deployed Oct 26, 2026 by soberm via E2E Compute Smoke #4078
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