Fix tmux.createSession env vars not reaching launch command process#191
Merged
Conversation
`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.
ab8b85a to
dc8b79b
Compare
This was referenced May 21, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lib/tmux.js:createSessionwas runningtmux set-environmentAFTER spawning the launch command, so engine overrides withlaunch.env(e.g.~/.tangleclaw/engines/aider.jsonsettingOPENAI_API_KEYfor LiteLLM routing) silently delivered nothing to the spawned process.tmux new-session -e KEY=VALUE(tmux ≥ 2.8) so env is set at session-create time BEFORE the initial command spawns.test/tmux.test.js— file had zero coverage foroptions.envbefore.Fixes #190.
Already deployed locally
The fix is live on this host — TC server was restarted via
launchctl kickstart -k gui/$UID/com.tangleclaw.serverwith the patchedlib/tmux.jsalready 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 "
-eper-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 pinsnode --test 'test/*.test.js'— 2226/2226 pass (was 2224 at end of Chunk 10; +2)[Unreleased]boundary preservedaider --versioncomes up, trivial prompt routes through LiteLLM, non-zero spend row taggedmodel=qwen2.5-coder-32b-fp16lands in/spend/logs.Blast radius
Any
launch.envin 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).