Skip to content

fix: always write devcontainer.metadata label as JSON array#1199

Open
fechu wants to merge 3 commits intodevcontainers:mainfrom
fechu:fix/metadata-label-always-array
Open

fix: always write devcontainer.metadata label as JSON array#1199
fechu wants to merge 3 commits intodevcontainers:mainfrom
fechu:fix/metadata-label-always-array

Conversation

@fechu
Copy link
Copy Markdown

@fechu fechu commented Apr 9, 2026

The getDevcontainerMetadataLabel function wrote a bare JSON object when there was only one metadata entry (e.g. docker-compose devcontainer with no features), but an array when there were multiple entries

  • The spec states the label "can contain an array of json snippets"
  • Tools like Zed (parsing code) or envbuilder that follow the spec and expect an array fail

The reading side (internalGetImageMetadata0) already handles both formats, but the writing side was inconsistent. In this PR we propose to always write an array of objects for simplicity. For backwards compatibility we leave the parsing, which supports both. Changing this makes the code follow the robustness principle by being strict what is returned (always an array).

Test instructions

Create the following project:

/tmp/zed-devcontainer-repro
└── .devcontainer
    ├── devcontainer.json
    ├── docker-compose.yml
    └── Dockerfile

devcontainer.json:

{
  "name": "repro",
  "dockerComposeFile": "docker-compose.yml",
  "service": "app",
  "remoteUser": "root"
}

docker-compose.yml:

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    command: sleep infinity
    volumes:
      - ..:/workspace

Dockerfile

FROM ubuntu:24.04

With the latest release the metadata is:

> devcontainer up --workspace-folder /tmp/zed-devcontainer-repro
[...]
> docker inspect --format='{{index .Config.Labels "devcontainer.metadata"}}' \
    $(docker ps -q --filter "label=devcontainer.local_folder=/tmp/zed-devcontainer-repro")

{"remoteUser":"root"}

After this change:

[{"remoteUser":"root"}]

Fixes #1054

When there is only one metadata entry (e.g. docker-compose devcontainer
with no features), `getDevcontainerMetadataLabel` wrote a bare JSON
object instead of an array. This violates the spec which states the
label "can contain an array of json snippets" and causes tools like Zed
that expect an array to fail when attaching to an existing container.

Always wrap the metadata in an array regardless of the number of entries.

Spec reference: https://containers.dev/implementors/json_reference/
Fixes devcontainers#1054
@fechu fechu requested a review from a team as a code owner April 9, 2026 20:21
@fechu fechu marked this pull request as draft April 9, 2026 20:36
@fechu fechu marked this pull request as ready for review April 9, 2026 21:02
@fechu
Copy link
Copy Markdown
Author

fechu commented Apr 9, 2026

@microsoft-github-policy-service agree

fechu added a commit to fechu/zed that referenced this pull request Apr 9, 2026
The devcontainer CLI writes the `devcontainer.metadata` container label
as a bare JSON object when there is only one metadata entry (e.g.
docker-compose with a Dockerfile and no features). This causes
deserialization to fail because the current code only accepts a JSON
array.

Try parsing as an array first, then fall back to parsing as a single
object wrapped in a vec.

Upstream CLI fix: devcontainers/cli#1199
Related CLI issue: devcontainers/cli#1054
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.

Devcontainer.Metadata Label can be a Dictionary or List

2 participants