Skip to content

docs(adr): env transport for session and parked-window panes (#730, #731) - #1

Closed
dracic wants to merge 7 commits into
mainfrom
docs/730-731-mux-env-transport-design
Closed

dracic wants to merge 7 commits into
mainfrom
docs/730-731-mux-env-transport-design

Conversation

@dracic

@dracic dracic commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Review mirror of bmad-code-org#850 for Codex review. Not for merge here.

Design record for bmad-code-org#730 and bmad-code-org#731, which bmad-code-org#537 left as needs-design: how the state root reaches a pane child when environment inheritance cannot carry it. This happens in two ways: PSMUX_BARE_ENV=1 clears the env, and a stale multiplexer server substitutes its own BMAD_LOOP_STATE_DIR. Coding-CLI windows are already immune; the exposure is the TUI's parked engine windows and window-0 shells.

Docs only. No file under src/ or tests/ changes.

What the ADR decides (docs/adr/0001-mux-env-transport.md, status Accepted)

Evidence

Also in this PR

  • Starts docs/adr/ with an index; the repo had no ADR convention.
  • Links the index from docs/README.md.

Refs bmad-code-org#730 bmad-code-org#731 bmad-code-org#660

Summary by CodeRabbit

  • Documentation
    • Added an accepted architecture decision record on carrying the state root into session and parked-window panes, including environment handling, launcher warnings, and compatibility considerations.
    • Added links and guidance to help readers find and understand the project’s architecture decision records.

dracic added 2 commits October 2, 2026 20:20
…dow panes

Add ADR 0001 for bmad-code-org#730 and bmad-code-org#731: how the state root reaches a pane child
when inheritance cannot carry it (PSMUX_BARE_ENV clears the env; a stale
multiplexer server substitutes its own BMAD_LOOP_STATE_DIR).

Accepted, in three stages:
- Stage 1: a tmux-only inherited_env query plus a launcher warning when a
  pane would resolve a different state root. psmux stays Unknown, because
  its show-environment cannot see inherited values.
- Stage 2: carry the state root to parked engine windows in argv (a
  hidden --state-root option), with no seam change, on every backend.
- Stage 3: a versioned verb pair, specified but not scheduled.

Also starts docs/adr/ with an index, linked from docs/README.md.

Known gap: the round-3 review findings (the passwd fallback when HOME is
absent, and absent vs empty HOME) were patched and checked against
runs.state_root by hand, not re-reviewed.

Refs bmad-code-org#730 bmad-code-org#731
No stage of ADR 0001 is implemented yet. Say so in the summary and above the staged plan, label Stages 1 and 2 as planned, and word the approver's answer on --state-root as the contract Stage 2 will introduce.
@dracic

dracic commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T07:03:03.399204Z c222a11 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee698b824a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/adr/0001-mux-env-transport.md Outdated
- Add a hidden top-level `--state-root` option, applied in `cli.main` before `relay` dispatch and `_configure_mux`.
- It must be absolute. Otherwise `main` exits `USAGE` with one message, the same rule as `BMAD_LOOP_STATE_DIR`'s own validation.
- `tui.launch.start_detached` inserts it from `runs.state_root()`, and raises `LaunchError` on `StateRootError` (see Option D). The other `cli_argv` caller is a captured `subprocess.run` that inherits the launcher's own env directly, so it needs no flag.
- The bare-env warning's text, and Stage 1's, narrow to window-0 and other already-running shells. Per Stage 1, the wording says that a matching query cannot vouch for a shell that is already running.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the bare-env warning for coding-CLI panes

Do not narrow this warning to window-0 and existing shells after Stage 2. When PSMUX_BARE_ENV=1 is enabled, Stage 2 transports only the state root to the parked engine process; subsequently created coding-CLI panes can still lose ambient credentials or configuration that are not explicitly included in their env dict. The ADR itself acknowledges this remaining limitation under Option D, so implementing this instruction would misleadingly imply that bare mode is safe everywhere except shells.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 22d2196. The bare-env warning is no longer narrowed: Stage 2 carries only the state root, so a coding-CLI pane in bare mode can still miss other variables (Option D, Cons). Only Stage 1's stale-root warning narrows to window-0 shells; the bare-env warning drops just its parked-window clause.

Stage 2 carries only the state root, so a coding-CLI pane in bare mode can still miss variables its env dict does not name. Only Stage 1's stale-root warning narrows to window-0 shells; the bare-env warning stays and drops just the parked-window clause.
@dracic

dracic commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22d2196302

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/adr/0001-mux-env-transport.md Outdated
Comment on lines +246 to +247
- For **future panes**: `tmux set-environment -t =<ctl> BMAD_LOOP_STATE_DIR <root>`. The session scope matters, because a session value overrides the global one (§3.2), so a global-only fix can leave a stale session value in force. Add `-g` as well to cover new sessions, or use `tmux kill-server` to restart clean.
- For **already-running shells**, including window 0: no query can see them, and `set-environment` cannot change them. They need an in-shell `export BMAD_LOOP_STATE_DIR=<root>` or recreating.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Quote state-root paths in the suggested shell commands

In Stage 1's warning, render the root with shell-safe quoting in both suggested commands. The documented tmux syntax accepts a single value argument for set-environment (tmux manual), so a valid root such as /home/me/state dir is split into extra arguments and the remedy fails; shell metacharacters can also change what a copied command executes. The adjacent export BMAD_LOOP_STATE_DIR=<root> has the same problem, so the ADR and its warning tests should require quoting rather than interpolating the path verbatim.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 14a1a3e: the ADR now requires both remedy commands to render the root (and the ctl target) with shlex.quote, never verbatim, and Stage 1's tests to assert it with a root containing a space and a metacharacter. The Stage 1 implementation (bmad-code-org#854) already shell-quotes the remedy.

A valid state root may contain spaces or shell metacharacters; set-environment takes a single value. The suggested commands must render the root with shlex.quote, and Stage 1's tests must assert it.
@dracic

dracic commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 14a1a3e386

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Stage 1's remedy now states that tmux's control session is shared by every project on the server, offers set-environment only where no other state root uses it, and names the cost of kill-server. Stage 2 also carries the registry root (--registry-root) for the honor_ambient_psmux_data_dir opt-in, demotes the stale-root warning to an informational note, and re-surfaces the bare-env warning in the TUI. The CLI, test and Stage 3 specs are corrected, the E2E gate moves to its own module, and section 8 names the approver and records every amendment after acceptance as re-approved.

Refs bmad-code-org#730 bmad-code-org#731
@dracic

dracic commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ntact

Under the pre-7.3 PowerShell native-argument algorithm, a psmux parked argument that ends in a backslash and contains whitespace merges with the next one (measured on Windows PowerShell 5.1; pwsh 7.6.6 delivers it intact in both Windows and Legacy modes). Stage 2 now must either make the psmux transport safe for that case or refuse PowerShell older than 7.3 on every psmux launch path, with a live test for whichever route it takes.

Refs bmad-code-org#730 bmad-code-org#731
@dracic

dracic commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 7ba8abe694

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Section 8 promised a test on the pre-7.3 runtime for whichever route Stage 2 takes, but the refusal route only faked the version probe. It now also points the probe at Windows PowerShell 5.1 and asserts the refusal, with the faked-probe unit test kept as a supplement.

Refs bmad-code-org#730 bmad-code-org#731
@dracic

dracic commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: c222a1127f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dracic

dracic commented Oct 6, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR merged; closing this review mirror.

@dracic dracic closed this Oct 6, 2026
@dracic
dracic deleted the docs/730-731-mux-env-transport-design branch October 6, 2026 05:00
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