Skip to content

[Bug]: --workspace-env values containing = are truncated in lifecycle hooks #1692

Closed

Description

@wsmoak

Before submitting

  • I have searched existing issues to confirm this is not a duplicate
  • I am running the latest version of Devsy

What happened?

When a --workspace-env (or --workspace-env-file) value contains =, devcontainer lifecycle hooks (postCreateCommand, postStartCommand) receive only the text before the next =. For ONE_EQ=a=b the hook sees a.

The full value is intact everywhere else. /etc/envfile.json and devsy workspace ssh sessions both see a=b. Only the lifecycle hook environment is affected, and nothing is logged.

The cause is patchEnvVars in pkg/devcontainer/config/prepareprobe.go:

t := strings.Split(v, "=")
newEnv[t[0]] = t[1]

This keeps only the text between the first and second =. It is applied to the environment of the userEnvProbe command, which feeds the hooks. Replacing it with strings. Cut and re-running the repro above makes every value come through intact in both hooks.

What did you expect to happen instead?

Hooks see the same value as every other path: everything after the first =.

devsy env set already keeps additional = characters in values (see #1431), so this looks like an inconsistency rather than a documented limit.

Steps to reproduce

  1. Create ws/.devcontainer/devcontainer.json and ws/.devcontainer/dump.sh (below), and an

envfile:

FILE_ONE_EQ=k=v

dump.sh:

#!/usr/bin/env bash
out=/tmp/env-repro-$1.txt
for v in PLAIN ONE_EQ TWO_EQ COMMA_EQ TRAILING_EQ FILE_ONE_EQ; do
  printf '%s=[%s]\n' "$v" "${!v-<unset>}"
done > "$out"
export DEVSY_HOME=$HOME/.devsy-envrepro DEVSY_DISABLE_TELEMETRY=true
devsy provider add docker
devsy workspace up ./ws --provider docker --id env-repro --ide none \
  --workspace-env "PLAIN=hello" \
  --workspace-env "ONE_EQ=a=b" \
  --workspace-env "TWO_EQ=a=b=c" \
  --workspace-env "COMMA_EQ=x=1,y=2" \
  --workspace-env "TRAILING_EQ=z=" \
  --workspace-env-file ./envfile
  1. In the container, read /tmp/env-repro-postCreate.txt and /tmp/env-repro-postStart.txt, and compare with /etc/envfile.json and devsy workspace ssh env-repro.

devcontainer.json

{
  "name": "env-repro",
  "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
  "postCreateCommand": "bash .devcontainer/dump.sh postCreate",
  "postStartCommand": "bash .devcontainer/dump.sh postStart"
}

Error output / logs

No error is logged.

Variable      Passed     Hooks      /etc/envfile.json  workspace ssh
PLAIN         hello      hello      hello              hello
ONE_EQ        a=b        a          a=b                a=b
TWO_EQ        a=b=c      a          a=b=c              a=b=c
COMMA_EQ      x=1,y=2    x          x=1,y=2            x=1,y=2
TRAILING_EQ   z=         z          z=                 z=
FILE_ONE_EQ   k=v        k          k=v                k=v

How often does this happen?

Every time

Operating system

macOS

Linux distribution (if applicable)

No response

Architecture

ARM64

Desktop app or CLI?

CLI only

Devsy version

v1.24.0

Devsy provider

Docker

Provider version

v1.0.0

Screenshots

No response

Anything else?

Workaround: percent-encode = before passing the value and decode it in the hook, or read the full value from /etc/envfile.json.

Suggested fix:

 func patchEnvVars(env []string, patches map[string]string) []string {
        newEnv := map[string]string{}
        for _, v := range env {
-               t := strings.Split(v, "=")
-               newEnv[t[0]] = t[1]
+               name, value, ok := strings.Cut(v, "=")
+               if !ok {
+                       continue
+               }
+               newEnv[name] = value
        }

Activity

  1. skevetter commented on Oct 31, 2026

    @skevetter
    Contributor

    Cleanup audit and remaining delivery plan

    Status: the reported parser bug is fixed in source and included in a published prerelease. The remaining work is artifact verification and stable delivery, not another parser implementation.

    Reviewed 30 October 2026 against main 9bc12ee041ca854c6f81de95fd8c6e49d7cc028c. This audit inspected code, PR metadata, tests and release ancestry; it did not run the customer's Docker workload.

    1. What has already been completed

    Evidence Result
    PR #1719, merged 26 October as c9a7e55e3e936c34492e297a140309d1a16fe5d6 Implements the requested first-separator parsing fix.
    patchEnvVars Uses strings.Cut(v, "="), retains the complete value, ignores entries without a separator or with an empty name, and applies explicit patches afterward.
    Unit regression Covers additional/leading/trailing equals signs, empty values, literal whitespace/newlines/quotes/Unicode, duplicate keys, malformed entries, patch precedence and input immutability.
    Docker lifecycle regression Exercises both CLI input sources, post-create/post-start, SSH, selected persisted JSON values, and a real stop/start.
    v1.25.0-beta.5 and merge-to-release comparison The fix is included; the comparison's merge base is the fix commit. Later beta.8 also includes it.
    Latest stable v1.24.0 Predates this fix. The customer's stated stable version remains affected.

    The root cause is the inherited environment preparation for the user probe. Splitting at every = discarded all segments after the first value segment. The current implementation preserves everything after the first separator. The fix is in the Linux container agent path even when the launching client runs on macOS or Windows.

    Keep the existing behavior around environment precedence. In particular, the test deliberately separates config-level containerEnv/remoteEnv precedence from an explicit conflicting --workspace-env assignment. This issue does not change those contracts or the CLI's existing empty-assignment removal semantics.

    2. Exact remaining work

    D1. Verify the published candidate, using the existing regression

    • Select a fixed published core candidate, currently v1.25.0-beta.8, and record its resolved source commit, package/CLI SHA-256 and printed version. Record the Docker provider version and container agent version too.
    • In a disposable Linux GitHub Actions environment, stage the published standalone CLI at the existing framework path e2e/bin/devsy-linux-amd64. Run the existing Ginkgo spec named lifecycle hooks preserve equals signs in environment values. Invoke the test runner without a preceding build task that replaces this file with a development binary. The framework constructs the binary path in framework.go.
    • Repeat with the CLI extracted from that release's actual Desktop package, recording the package digest and the extracted binary digest/version. If the CLI bytes are identical, record the comparison explicitly; this establishes the packaged CLI contents, not native Desktop GUI acceptance.
    • Use the release's normal agent-delivery path and verify the executing container agent matches the fixed release. Keep development DEVSY_AGENT_URL, DEVSY_AGENT_BINARY and transport overrides out of this release run. A passing new host CLI with an unverified old container agent is insufficient.
    • Retain the fixture e2e/tests/up/testdata/docker-workspace-env-equals, its loginInteractiveShell user probe, and waitFor: postStartCommand. Do not replace the hook checks with an assertion only against workspace ssh; that was already working in the report.
    • Keep the fresh test home/context and cleanup behavior. Do not print the complete environment or /etc/envfile.json; the existing test selects only fixture keys inside the container.

    Expected exact values in both lifecycle hook files, SSH output and the selected persisted keys:

    Name Value
    PLAIN hello
    ONE_EQ a=b
    TWO_EQ a=b=c
    COMMA_EQ x=1,y=2
    TRAILING_EQ z=
    FILE_ONE_EQ k=v
    REMOTE_EQ in the existing precedence fixture remote=a=b

    The restart assertion must delete only the fixture's previous post-start output, perform a normal stop/start, and observe a newly produced correct file. Do not recreate the workspace to make the restart assertion pass.

    D2. Confirm the customer-facing upgrade path

    • Run the issue's macOS ARM64/Docker scenario with a fixed published CLI and the actual packaged Desktop CLI. Verify the installed version and executing container agent before comparing results.
    • Record which artifacts contain the fix in the issue and stable release notes. If stable has not been published, label the available fix as a prerelease.
    • Confirm that upgrading and normally restarting a workspace delivers the fixed agent and reruns post-start correctly. A historical post-create output file is not rewritten by an upgrade. Use a fresh disposable workspace to validate post-create; do not instruct users to rebuild production data merely to regenerate a diagnostic file.
    • Attach the test run and the bounded value comparison. Obtain reporter confirmation when available.

    D3. Only if a fixed artifact still fails

    • Locate the first divergent boundary using the fixture keys: CLI parsing, persisted environment, probe input, probe output, merged hook environment, then hook process environment.
    • If the actual running agent is older, fix the delivery/version-selection problem rather than modifying patchEnvVars again.
    • If a different boundary truncates a value, add its failing regression and a narrow fix in a signed Draft PR, linking back here. Keep any confirmed separate defect scoped separately.

    3. Completion criteria

    Implementation is complete. Keep this issue as the existing delivery tracker until the published CLI/Desktop candidate passes the customer-value checks and the fixed supported release is identified. No duplicate implementation ticket is needed. Close as fixed once the release and validation evidence are recorded; retain any unrelated follow-up under its own issue.

  2. skevetter commented on Oct 31, 2026

    @skevetter
    Contributor

    Completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions