fix(memory): wire memory-spaces table/bucket names onto app-api#588
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 setsDYNAMODB_MEMORY_SPACES_TABLE_NAMEorS3_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 throwsResourceNotFoundException, and the centralized AWS-ClientErrorhandler maps that to a generic 502.inference-apialready 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 onPlatformComputeRefsand IAM-granted to the app-api role) throughAppApiSsmParams→resolveAppApiParams→buildAppApiEnvironment, emitting both names next to the flag:The names are wired unconditionally (the service reads them lazily); only
MEMORY_SPACES_ENABLEDgates whether the routes mount, so flipping the switch on later needs no further env change — mirroring how inference-api does it.Tests
test/app-api-environment.test.tsguards the wiring (names present, flag independent of names).tsc --noEmitclean; full infra jest suite green (431 tests, +2).Deploy note
Takes effect on the next
platform.yml(CDK) deploy. Also note theMemorySpacesConstruct(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