Skip to content

Fix tmux.createSession env vars not reaching launch command process#191

Merged
Jason-Vaughan merged 1 commit into
mainfrom
fix/tmux-env-before-launch-command
May 21, 2026
Merged

Fix tmux.createSession env vars not reaching launch command process#191
Jason-Vaughan merged 1 commit into
mainfrom
fix/tmux-env-before-launch-command

Conversation

@Jason-Vaughan
Copy link
Copy Markdown
Owner

Summary

  • Fixes the engine-override env-injection bug surfaced by today's Aider/LiteLLM smoke test ([bug] tmux.createSession sets env AFTER launch command spawns, so launch.env never reaches engine processes #190).
  • lib/tmux.js:createSession was running tmux set-environment AFTER spawning the launch command, so engine overrides with launch.env (e.g. ~/.tangleclaw/engines/aider.json setting OPENAI_API_KEY for LiteLLM routing) silently delivered nothing to the spawned process.
  • Switch to tmux new-session -e KEY=VALUE (tmux ≥ 2.8) so env is set at session-create time BEFORE the initial command spawns.
  • +2 regression pins in test/tmux.test.js — file had zero coverage for options.env before.

Fixes #190.

Already deployed locally

The fix is live on this host — TC server was restarted via launchctl kickstart -k gui/$UID/com.tangleclaw.server with the patched lib/tmux.js already on disk so the Monad-1 ↔ LiteLLM smoke test could re-run without waiting for merge. PR captures the change in git history.

Independent corroboration

Monad-1 session diagnosed the same root cause from their side without seeing this patch — their hypothesis was tmux server/session env caching, with the proposed fix being "-e per-session at spawn time, instead of relying on the tmux server's inherited env." That's exactly what shipped here. Two independent bisections converging on the same patch is a good signal the diagnosis is right.

Test plan

  • node --test 'test/tmux.test.js' — 43/43 pass including new env-injection regression pins
  • node --test 'test/*.test.js' — 2226/2226 pass (was 2224 at end of Chunk 10; +2)
  • CHANGELOG [Unreleased] boundary preserved
  • Owed by Monad-1 session: re-run the Aider/LiteLLM smoke test against the live server (already patched). Expected: aider --version comes up, trivial prompt routes through LiteLLM, non-zero spend row tagged model=qwen2.5-coder-32b-fp16 lands in /spend/logs.

Blast radius

Any launch.env in an engine override file was silently no-op. In TC's current world only the Aider override exercises this path, but the bug would have re-bitten every future env-keyed engine integration. Fix is a one-line ordering change in tmux session construction; risk surface is the env-string escaping (covered by the metacharacter regression test).

@Jason-Vaughan Jason-Vaughan added the bug Something isn't working label May 19, 2026
`lib/tmux.js:createSession` was calling `tmux set-environment` AFTER
`tmux new-session -d -s <name> <command>`, so the spawned launch
command inherited the parent's process env without the supplemented
values. `set-environment` only affects subsequently-spawned children
— the launch command itself was already running.

Net effect: every `~/.tangleclaw/engines/<id>.json` `launch.env`
silently did nothing for the launched process.

Surfaced via Aider override → LiteLLM smoke test: OPENAI_API_KEY
never reached the spawned aider process, producing
`litellm.AuthenticationError: OpenAIException - The api_key client
option must be set either by passing api_key to the client or by
setting the OPENAI_API_KEY environment variable`.

Fix: use `tmux new-session -e KEY=VALUE` flags (tmux ≥ 2.8) so env
is set at session-creation BEFORE the initial command spawns. Each
`-e VALUE` is wrapped via `_escapeArg` so shell metacharacters survive
intact. Post-create `set-environment` loop removed (redundant once
`-e` is in place).

+2 regression tests in test/tmux.test.js — launch command actually
inherits the env vars; tricky values survive escaping.

2226/2226 tests pass (+2 from 2224).

Fixes #190.
@Jason-Vaughan Jason-Vaughan force-pushed the fix/tmux-env-before-launch-command branch from ab8b85a to dc8b79b Compare May 21, 2026 16:25
@Jason-Vaughan Jason-Vaughan merged commit 039df60 into main May 21, 2026
@Jason-Vaughan Jason-Vaughan deleted the fix/tmux-env-before-launch-command branch May 21, 2026 16:26
Jason-Vaughan added a commit that referenced this pull request May 23, 2026
Eats its own dogfood: invokes the new `lib/wrap-steps/version-bump.js`
handler (shipped in PR #202 a few hours ago) programmatically against
this repo, then flushes the two staged writes via the same
`commit._flushStagedWrites` the V2 wrap pipeline would use.

Handler output:

  - oldVersion: 3.16.2
  - newVersion: 3.17.0
  - bumpLevel: minor (subsections: Changed, Fixed, Added)
  - detail: 3.16.2 → 3.17.0 (minor)

Highlights of this release (full notes in CHANGELOG.md):

- **#139 Methodology-aware single-button session wrap (series closed).**
  12 chunks across the May 14–19 window. `wrapV2: true` is now the
  default. Full server-side pipeline (`pr-check` → `critic-check` →
  `version-bump` → `ai-content` × 3 → `priming-roll` → `commit`)
  replaces the legacy NL-prompt-via-tmux flow. ADR 0002 is the
  durable home.

- **Open-queue #2 (PR #200): prawduct ai-content prompts populated.**
  Three placeholder steps (`changelog-update` / `learnings-capture` /
  `memory-update`) gain real prompts. V2 wraps now produce CHANGELOG
  entries / `learnings.md` entries / MEMORY.md session blocks
  instead of three SKIPPED rows.

- **Open-queue #3 (PR #202): real version-bump handler.** The handler
  that cut THIS release. Last #139-era no-op stub replaced.

- **PR #191: tmux env-ordering hotfix.** Engine `launch.env` now
  reaches the spawned engine process (was silently dropped pre-fix).
  Surfaced via Aider / LiteLLM `OPENAI_API_KEY` integration.

- **#168 CHANGELOG structural-invariants test.** Pinned post-PR #166
  regression class.

CHANGELOG `[Unreleased]` heading retained at the top with an empty
body (per the handler's promote contract) so the next session has
somewhere to accumulate entries.

Banner emoji NOT auto-injected — to be added manually as `> 🚀` (this
is a feature release, not a bug-fix) in a follow-on commit or
release-notes edit per the project's banner convention.

The UTC-vs-local-date bug in the version-bump handler (surfaced
cutting this release: handler stamped 2026-05-23 in UTC; manually
patched to 2026-05-22 to match the local-zoned convention used by
every prior CHANGELOG entry) is filed as #205. Future releases pick
up the fix when that lands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] tmux.createSession sets env AFTER launch command spawns, so launch.env never reaches engine processes

1 participant