psmux: retire the per-window option channel (`__blw@N` keys) once a psmux release gives windows their own user options (psmux master f720eddc)

Abierto
#921 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
15/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
powershell, python
Área
devtools

Línea de trabajo

Start with tests/test_psmux_live.py::test_premise_window_scoped_option_write_lands_at_session_scope and the @ branches in src/bmad_loop/adapters/psmux_backend.py (lines 824-1225 hold the channel). Do not begin until a psmux release ships the per-window user-option change, and first settle the floor bump, the session_options readers and the parked-trailer override listed in the issue. Done means the premise test is inverted into a regression test, the channel and its unit tests are removed, and the docs and CHANGELOG are updated.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

psmux master gives user options the scope of their flags (4eb94983, "user options take the scope of their flags"): set-option -w -t S:@N @k v now stores on window @N's own table, and show-options -wqv -t S:@N @k reads it back. bmad-loop's psmux backend routes every @ window option through a substitute channel, session-scoped keys named <option>__blw@<N>, because on the installed psmux v3.4.0 (20aa1d7) a -w user-option write lands in the session map (#310). On master the existing option channel continues to work in the measured paths, and the base-class -w path it replaces now works too, so the channel becomes retirable behind a floor bump. As checked on 2026-10-14, the latest published release is v3.4.0, released 2026-10-13; the tested change is on unreleased master. This issue tracks the retirement, as #914 does for _transportable's --leading clause; it tracks a future retirement rather than a reproduced production regression.

Environment

psmux master f720eddc (built from source, unreleased) and the control psmux 3.4.0 (20aa1d7), Windows 11 build 26200, PowerShell 7.6.6 (launching shell; SHELL removed), PSMUX_NO_WARM=1; bmad-loop 45bac91c.

The trigger

tests/test_psmux_live.py::test_premise_window_scoped_option_write_lands_at_session_scope fails on master, 3 of 3 runs (and in a separate 2 of 2), with its own message: psmux now has real per-window option storage — the @opt_@N scoped-option channel in psmux_backend is droppable (assert 'v' == ''). On 3.4.0 it passes. In one full-file run on master it was one of exactly two premise failures (the other is #914's tripwire). The weekly psmux-canary run against the latest release is where it will show first.

Measured (observed, both binaries, through bmad-loop's code)

The channel keeps working on master. Through PsmuxMultiplexer bound to each binary: set_window_option / show_window_option / unset_window_option, the @ column of list_windows, _scoped_options, and kill_window's key cleanup give identical results on master and 3.4.0 (two windows, two tags, each reads its own; the unset reads "" with no warning; a killed window's keys are freed). In one measurement, writes followed immediately by reads from a second client missed 0 times in 1200 pairs (100 per path per binary per warm-pool setting). No regression was observed in the exercised option-channel paths on f720eddc.

The base-class path the channel replaces is correct on master (BaseTmuxBackend.set_window_option / show_window_option / unset_window_option / list_windows, called on a PsmuxMultiplexer instance):

step psmux master f720eddc psmux 3.4.0 (control)
-w tag tag-a on S:@2, tag-b on S:@3, then base show_window_option each tag-a, tag-b '', ''
base list_windows(S, ["window_id", "@bmad_project"]) @1 '', @2 tag-a, @3 tag-b every row tag-b (the #310 bleed)
@-lines in show-options -q -t S (the session map) none from the base writes @bmad_project "tag-b"
base unset_window_option on S:@2, then read @2 / @3 '' / tag-b '' / ''
show-options -wqv on an unset name rc 0, empty rc 0, empty
show-options -wv (no -q) on an unset name rc 1, psmux: invalid option: @bmad_project rc 0, empty line

What retires

In src/bmad_loop/adapters/psmux_backend.py: the @ branches of set_window_option, unset_window_option and show_window_option; _option_scope, _window_id_for_name, _SCOPE_MARKER, _scoped_option_key, _KEY_SUFFIX, _read_scoped, _warn_unroutable, _scoped_options, _free_scoped_key, _sweep_orphan_keys (and its call in new_parked_window), the key cleanup in kill_window, and the @-column substitution in list_windows (its window_id qualification stays). Also the module docstring's "Per-window user options do not exist at all" sentence, the "Window options" paragraph of docs/multiplexer-backends.md, and the channel's unit tests in tests/test_psmux_backend.py.

What must stay or change (preconditions, each measured or marked)

  1. The parked trailer keeps its pane pin. BaseTmuxBackend._parked_trailer reads show-options -wqv <opt> with no -t. Measured on master from inside two real panes, with focus on the other window, in every run of three independent measurements: the target-less read answered the active window's value, while show-options -wqv -t $env:TMUX_PANE @k answered the pane's own. This is the same psmux trait #669 pinned for display-message (test_premise_target_less_display_message_ignores_tmux_pane). So PsmuxMultiplexer._parked_trailer stays an override; it changes its read to show-options -wqv -t $env:TMUX_PANE <opt> and drops its $wid probe, the key splice and the set-option -u $key free. That replacement is not yet implemented or validated end to end: the measurements validate its read target, not an attached client's return action.
  2. list-sessions -F '#{@bmad_project}' sees window tags. On master, after base-class -w tags on a session's windows, session_options("@bmad_project") answered tag-b, the active window's tag, for a session with no session-level tag: #{@k} resolves through the active window before the session. Once control-session windows carry real -w tags, every session_options(PROJECT_OPTION) reader that meets a control session gets a window's tag back. superseded_ctl_may_be_run in runs.py rests on the opposite premise ("no release ever set one on a control session (its windows carry the tag)"); it answers True for any non-empty tag, which is the direction that withholds an attach command, so the failure mode there is a withheld command rather than a wrong kill (source-derived; no superseded-control-session cleanup was driven). prunable_sessions skips control sessions only by name and needs the same re-check. Re-check those readers before retiring. With only channel-backed window tags in these runs, session_options returned no project tag on either tested binary.
  3. The floor moves first. As in #914: set _LAST_UNSUPPORTED to the last release without 4eb94983 (the gate is exclusive) and move the CI pin. On 3.4.0 the base path brings back the #310 bleed (measured above: every row reads the last tag written). A control session served by a pre-floor psmux server that outlived the upgrade is the same case. That is source-derived, not observed: the version gate checks the client binary, and the write is applied by the server. Mixed client and server builds were not tested.
  4. Windows parked before bmad-loop removes the channel (source-derived; migration not exercised). Their trailer is baked in at creation and still reads the session-scoped __blw@N key. If a later bmad-loop attach writes its return target only to a native -w option, that write does not arm the old trailer; an absent old key can leave the return action unarmed, while an old retained key can supply a stale target. Existing channel-backed project tags also do not appear in native -w reads until migrated or retagged (the prune then falls back to run-dir evidence, as the channel's own comment describes for pre-marker keys). Restart the affected control server and recreate its windows as part of adopting the removal. Upgrading psmux alone is not shown to cause this failure: the unchanged channel still works on master.
  5. The premise test turns into an adopted row: -w writes are per window, and the session map holds no @ key afterwards. Add a regression test that fails when the old v3.4.0 storage behaviour is substituted. Add a CHANGELOG entry (an upgrade item for the floor, plus Removed for the channel).

Repro

Run from PowerShell 7 (pwsh) with SHELL removed, in a bmad-loop checkout at 45bac91c after uv sync --all-extras; $Bin is the psmux to test, by full path; the registry is a throwaway directory under %TEMP%; remove it and probechan.py afterwards.

Remove-Item Env:SHELL -ErrorAction SilentlyContinue
$env:PSMUX_NO_WARM = '1'; $env:PYTHONUTF8 = '1'
$Bin = 'C:\path\to\psmux.exe'      # master build; then the installed 3.4.0 as the control
$Data = "$env:TEMP\psmux-chan-probe"; New-Item -ItemType Directory -Force $Data | Out-Null
@'
import sys
from pathlib import Path
from bmad_loop.adapters.psmux_backend import PsmuxMultiplexer
from bmad_loop.adapters.tmux_base import BaseTmuxBackend as B
binary, data = sys.argv[1], sys.argv[2]
mux = type("M", (PsmuxMultiplexer,), {"_BINARY": binary})(registry_root=data)
S = "probe-chan"; cwd = Path(data)
mux.new_session(S, cwd)
park = "pwsh -NoProfile -Command 'Start-Sleep 300'"
a = mux.new_window(S, "a", cwd, {}, park); b = mux.new_window(S, "b", cwd, {}, park)
mux.set_window_option(a, "@t", "chan-a"); mux.set_window_option(b, "@t", "chan-b")
print("channel:", mux.show_window_option(a, "@t"), mux.show_window_option(b, "@t"))
B.set_window_option(mux, a, "@bmad_project", "tag-a"); B.set_window_option(mux, b, "@bmad_project", "tag-b")
print("base -w:", repr(B.show_window_option(mux, a, "@bmad_project")), repr(B.show_window_option(mux, b, "@bmad_project")))
print("base list_windows:", B.list_windows(mux, S, ["window_id", "@bmad_project"]))
print("session_options:", mux.session_options("@bmad_project"))
mux.kill_session(S)
'@ | Set-Content "$env:TEMP\probechan.py"
uv run python "$env:TEMP\probechan.py" $Bin $Data
$env:PSMUX_DATA_DIR = $Data; & $Bin kill-server; Remove-Item Env:PSMUX_DATA_DIR

Master prints channel: chan-a chan-b, base -w: 'tag-a' 'tag-b', a list_windows with each window's own tag, and session_options naming the active window's tag (tag-b). 3.4.0 prints the same channel line, base -w: '' '', every list_windows row tag-b, and session_options tag-b (from the session map).

Source

psmux at f720eddc, src/server/options.rs:104-106 (the write now admits @ names):

pub(crate) fn is_window_scoped_write(name: &str) -> bool {
    is_window_option(name) || name.starts_with('@')
}

At v3.4.0 (src/server/options.rs:105-107, with its comment at :97-104) the same function excluded them ("User options (@...) are deliberately NOT included ... set -wg @k v and set -g @k v therefore remain the way to set one"). The causing commit is 4eb94983 (the psmux/psmux#795 follow-up, "user options take the scope of their flags"), which also routes #{@name} through the window (pane_user_option(app, window, pane, name): pane, window, global window table, then the session store). The psmux commits after f720eddc on the touched files, as of 2026-10-14, leave the user-option stores unchanged; the measurements stay pinned to f720eddc.

bmad-loop at 45bac91c: the channel block src/bmad_loop/adapters/psmux_backend.py:824-1225 and the trailer psmux_backend.py:545-600.

Impact on bmad-loop

No regression observed in the exercised option-channel paths on f720eddc. Retiring the channel removes the channel block (about 400 lines) and the two or three extra listing round-trips each psmux kill_window pays, and stops the control server accumulating keys, under the five preconditions above.

Lenguaje dominante
Python
Estrellas
196
Forks
78
Merge medio
9 h 24 min
PR fusionados (30 d)
44

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bmad-code-org/bmad-loop

Todos los issues de bmad-code-org/bmad-loop

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.