Files
Maxim fddfcfe742 fix(agentcore): stop two .env.example entries parsing as their own comment text
25b4fecb rewrote the Stack block of docker/.env.example to say that ./up.sh
overwrites STACK_NAME and MEMORY_ID, and that you fill them in by hand only if
you drive `docker compose` directly. That newly blessed the plain-compose path
while leaving two entries whose value position is empty and whose explanation
sits after it on the same line.

Compose's env-file parser only treats a whitespace-separated `#` as starting a
comment when it follows a NON-empty value. With nothing between `=` and the
hash, leading whitespace is stripped and the rest of the line becomes the value.
Measured, not assumed — a probe env file through `docker compose config`:

  C1=       # explanatory comment   ->  '# explanatory comment'   (literal)
  C2=# explanatory comment          ->  '# explanatory comment'   (literal)
  C3=value       # explanatory ...  ->  'value'                   (stripped)
  C4=value# explanatory comment     ->  'value# explanatory ...'  (literal)
  C5="value"     # explanatory ...  ->  'value'                   (stripped)
  C6= # explanatory comment         ->  '# explanatory comment'   (literal)
  C7=""     # explanatory comment   ->  ''                        (stripped)

So the affected set is exactly the two empty-valued lines. STACK_NAME's
`# or -st for Strands` looks like the same defect but is not: it follows a
non-empty value and is stripped correctly (case C3). It moved to its own line
for consistency, not because it was broken.

Before, against the example's real docker-compose.yml:

  $ docker compose --env-file .env.example -f docker-compose.yml config
      AWS_SESSION_TOKEN: '# leave blank if using long-term creds'
      MEMORY_ID: '# MemoryArn last segment (after final /)'
      STACK_NAME: my-copilotkit-agentcore-lg

After:

  $ docker compose --env-file .env.example -f docker-compose.yml config
      AWS_SESSION_TOKEN: ""
      MEMORY_ID: ""
      STACK_NAME: my-copilotkit-agentcore-lg

Confirmed in a real container rather than only in `config`, via a busybox
service given the same two files:

  == container env BEFORE ==
  P_MEMORY_ID=# MemoryArn last segment (after final /)
  P_AWS_SESSION_TOKEN=# leave blank if using long-term creds
  == container env AFTER ==
  P_MEMORY_ID=
  P_AWS_SESSION_TOKEN=

Why ./up.sh never showed it: bash and Compose disagree on these lines. `source`
of the old file yields MEMORY_ID=[] and AWS_SESSION_TOKEN=[] because bash does
treat the trailing hash as a comment, and up.sh's `set -a && source` then exports
them, where the process environment outranks the env file. Running the same old
file through Compose with those exports in place gives MEMORY_ID: "" — the bug
is invisible on the up.sh path and reachable only on the path 25b4fecb
documented.

Audited the rest of the file against the same parser: no remaining inline hash
on an assignment line, no duplicate keys, no quoting, no trailing whitespace, no
CRLF, no BOM. All eleven keys now resolve to what a reader would predict.

up.sh and docker-compose.yml needed no change. up.sh's `cp .env.example .env`
hint and its "auto-fills .env with stack outputs" header stay accurate, and its
`^KEY=.*` rewrite still matches both keys in the new layout — with the added
benefit that own-line comments survive the rewrite, where the inline ones were
destroyed by it. docker-compose.yml's "use ./up.sh instead of docker compose
directly" still holds; .env.example only says what to fill in if you don't.
up.sh's own known defects (AGENT grep/cut, unguarded config read, silent source,
hardcoded region) are deferred and untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-24 19:24:57 +02:00
..