From 5e1f362d82f5e2f8a97dab059cd1e2fdd644335b Mon Sep 17 00:00:00 2001 From: Renan Hagiwara Date: Mon, 23 Nov 2026 17:11:34 -0300 Subject: [PATCH] fix(runs): strip leading dashes from task window names (#1061) A task id whose last 40 characters start with `-` was passed to `new-window -n` as an option: psmux exits 0 with no window and no id, and the session reads as crashed with an empty log. Strip the leading dashes in `task_window_name`, so the adapter and attach stay in step. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +++ src/bmad_loop/runs.py | 9 ++++++--- tests/test_runs.py | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eb59b78c..2b5625da4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -220,6 +220,9 @@ breaking changes may land in a minor release. ### Fixed +- Strip leading dashes from task window names. A task id whose last 40 characters + start with `-` was passed to `new-window -n` as an option, so psmux created no window + and the session read as crashed with an empty log (#1061). - Read BMAD v7's `quick_lenses`/`thorough_lenses` review sets in `validate` and the run preflight, so a v7 project is no longer required to install the deleted `bmad-review-adversarial-general` and `bmad-review-edge-case-hunter`. A `workflow.review` diff --git a/src/bmad_loop/runs.py b/src/bmad_loop/runs.py index 507203195..dee3a73bf 100644 --- a/src/bmad_loop/runs.py +++ b/src/bmad_loop/runs.py @@ -439,9 +439,12 @@ def session_name(run_id: str) -> str: def task_window_name(task_id: str) -> str: """Name of the window a task's agent session runs in, inside the run's - :func:`session_name` session: the task id's last 40 characters. The adapter - names the window with it, and an attach finds the task window by it.""" - return task_id[-40:] + :func:`session_name` session: the task id's last 40 characters, leading + dashes stripped. The adapter names the window with it, and an attach finds + the task window by it. A ``-``-leading name reads as an option to + ``new-window -n``: psmux then exits 0 with no window and no id, and the + session reads as crashed (#1061).""" + return task_id[-40:].lstrip("-") or task_id def attach_target_argv(target: str) -> list[str]: diff --git a/tests/test_runs.py b/tests/test_runs.py index aaf837b4f..a743f1c31 100644 --- a/tests/test_runs.py +++ b/tests/test_runs.py @@ -358,6 +358,29 @@ def test_write_pid(tmp_path): assert float(tokens[1]) > 0 +@pytest.mark.parametrize( + "task_id, expected", + [ + ("3-1-short-key-dev-1", "3-1-short-key-dev-1"), + ("x" * 50 + "-dev-1", ("x" * 50 + "-dev-1")[-40:]), + # The 40-char slice starts at a dash: psmux would read it as a flag (#1061). + ( + "3-2-aaaaaa-a-bbbbbbbbb-c-dd-eeeeeee-ff-ggggggg-dev-1", + "bbbbbbbbb-c-dd-eeeeeee-ff-ggggggg-dev-1", + ), + ( + "3-2-aaaaaa-a---bbbbbbb-c-dd-eeeeeee-ff-ggggggg-dev-1", + "bbbbbbb-c-dd-eeeeeee-ff-ggggggg-dev-1", + ), + ], +) +def test_task_window_name_never_starts_with_a_dash(task_id, expected): + name = runs.task_window_name(task_id) + assert name == expected + assert not name.startswith("-") + assert len(name) <= 40 + + @pytest.mark.usefixtures("force_tmux_backend") # attach_argv goes through the seam def test_attach_argv_outside_tmux(monkeypatch): monkeypatch.delenv("TMUX", raising=False)