Skip to content

fix(memory): wire memory-spaces table/bucket names onto app-api#588

Merged
philmerrell merged 2 commits into
developfrom
fix/memory-spaces-app-api-env-wiring
Jul 7, 2026
Merged

fix(memory): wire memory-spaces table/bucket names onto app-api#588
philmerrell merged 2 commits into
developfrom
fix/memory-spaces-app-api-env-wiring

Conversation

@philmerrell

Copy link
Copy Markdown
Contributor

The bug

GET /memory/spaces (and every other Memory Spaces read) returns 502 {"detail":"Upstream service error."} in any environment where the feature is enabled.

Root cause: app-api's container environment sets only MEMORY_SPACES_ENABLED — it never sets DYNAMODB_MEMORY_SPACES_TABLE_NAME or S3_MEMORY_SPACES_BUCKET_NAME. The backend repository falls back to the default table name "memory-spaces" (which doesn't exist — the real table is {prefix}-memory-spaces), so DynamoDB throws ResourceNotFoundException, and the centralized AWS-ClientError handler maps that to a generic 502.

inference-api already sets the identical trio (inference-agentcore-construct.ts:346-348), but per the service-boundary rule it's app-api that owns the /memory/spaces/* CRUD surface — so app-api is exactly where the names were missing. This was a wiring gap in the A1 data-layer PR (#582).

The fix

Thread the typed refs (refs.memorySpacesTable / refs.memorySpacesBucket, already present on PlatformComputeRefs and IAM-granted to the app-api role) through AppApiSsmParamsresolveAppApiParamsbuildAppApiEnvironment, emitting both names next to the flag:

MEMORY_SPACES_ENABLED
DYNAMODB_MEMORY_SPACES_TABLE_NAME   ← added
S3_MEMORY_SPACES_BUCKET_NAME        ← added

The names are wired unconditionally (the service reads them lazily); only MEMORY_SPACES_ENABLED gates whether the routes mount, so flipping the switch on later needs no further env change — mirroring how inference-api does it.

Tests

  • New test/app-api-environment.test.ts guards the wiring (names present, flag independent of names).
  • tsc --noEmit clean; full infra jest suite green (431 tests, +2).

Deploy note

Takes effect on the next platform.yml (CDK) deploy. Also note the MemorySpacesConstruct (table + bucket) has to actually be deployed to the target account — as of this writing it isn't present in dev-ai yet, so a platform deploy is needed there regardless of this fix.

🤖 Generated with Claude Code

philmerrell and others added 2 commits July 7, 2026 15:40
app-api owns the Memory Spaces CRUD surface (`/memory/spaces/*`) but its
container environment only set MEMORY_SPACES_ENABLED — never the table or
bucket names the service reads (DYNAMODB_MEMORY_SPACES_TABLE_NAME /
S3_MEMORY_SPACES_BUCKET_NAME). Without them the repository falls back to the
default "memory-spaces" table name, which doesn't exist, so every read throws
a boto3 ResourceNotFoundException that the centralized handler maps to a
502 "Upstream service error." (inference-api already sets the identical trio,
but per the service-boundary rule it isn't the one serving these routes.)

Thread `refs.memorySpacesTable`/`.memorySpacesBucket` through AppApiSsmParams
and emit both names next to the flag in buildAppApiEnvironment. Names are
always wired (read lazily); only MEMORY_SPACES_ENABLED gates route mounting,
so flipping the switch on later needs no env change. New unit test guards the
wiring; tsc + 431 infra jest tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Fold the lesson from the app-api env-wiring fix into the cdk-infrastructure
skill so the next construct-author sees it while wiring, not after a 502.
Adds a "Cross-Construct References" subsection: set a resource's name env var
on every compute that reads it (one doesn't imply the other), the silent-502
failure mode (default-name fallback → ResourceNotFoundException → generic 502,
invisible to synth/CI), and the env-map test guard + service-boundary caveat.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@philmerrell philmerrell merged commit 0944e73 into develop Jul 7, 2026
4 checks passed
@philmerrell philmerrell deleted the fix/memory-spaces-app-api-env-wiring branch July 7, 2026 21:56
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