Skip to content

test(agent): de-flake TestAgent_Session_EnvironmentVariables#26638

Draft
dylanhuff-at-coder wants to merge 2 commits into
mainfrom
dylan/plat-310-flake-testagent_session_environmentvariables
Draft

test(agent): de-flake TestAgent_Session_EnvironmentVariables#26638
dylanhuff-at-coder wants to merge 2 commits into
mainfrom
dylan/plat-310-flake-testagent_session_environmentvariables

Conversation

@dylanhuff-at-coder

Copy link
Copy Markdown
Contributor

De-flakes TestAgent_Session_EnvironmentVariables, which failed only on Windows CI with every subtest erroring at 0.00s with "EOF".

Root cause

The test drove one long-lived shell (cmd.exe/sh) through a single shared stdin/stdout and a single shared bufio.Scanner across every subtest. On Windows the shell's channel half-closes early; the next subtest's stdin write then returns io.EOF and fails immediately, cascading to all subtests. The old scanner guard also let a clean EOF pass without ever asserting the value was found.

Fix

Give each variable its own short-lived ssh.Session and read it with session.Output, re-applying the two session-scoped vars via Setenv, and assert each value with require.Contains. This removes the shared mutable state that caused the cascade and closes the silent false-negative, matching the one-shot pattern already used by the sibling env-var tests. TestAgent_Session_SecretInjection shared the same anti-pattern and gets the identical refactor. Test-only; no production behavior changes.

Closes https://linear.app/codercom/issue/PLAT-310/flake-testagent-session-environmentvariables

Diagnosis and decisions
  • Why "EOF": bufio.Scanner.Err() maps a clean io.EOF to nil and the ssh read path returns only the io.EOF sentinel, so the scan guard could never emit it. The real failure was the unguarded stdin write in echoEnv hitting a dead shared channel (line 433 at the failing commit 550aa6d).
  • Env precedence is re-applied per session by the agent (updateCommandEnv), so fresh sessions are safe. Only MY_SESSION and MY_SESSION_MANIFEST need a per-session Setenv, and MY_SESSION_MANIFEST still asserts false to prove manifest-overrides-session.
  • Verified locally on linux: stable under -count=100 and -race, and make pre-commit is clean. The Windows cmd.exe branch mirrors the already-passing sibling tests, so test-go-pg windows-2022 is the real proof of the de-flake.
  • Deferred: optional product hardening for the Windows cmd.exe fallback (usershell_windows.go ComSpec) and the broader CI PATH/mise work are tracked separately.

This PR was generated by Coder Agents on behalf of @dylanhuff-at-coder.

@linear-code

linear-code Bot commented Jun 23, 2026

Copy link
Copy Markdown

PLAT-310

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