From ba0356adae347304dbfa04a10c5b9157ef9ea47b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 16 Nov 2026 16:23:45 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20principles=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20start=5Fwin?= =?UTF-8?q?dow=20fails=20only=20where=20it=20cannot=20mark=20a=20new=20ses?= =?UTF-8?q?sion=20as=20the=20checkout's,=20so=20a=20started=20chunk=20neve?= =?UTF-8?q?r=20reads=20as=20one=20that=20didn't=20start?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/loop_claude/tmux.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/loop_claude/tmux.py b/bin/loop_claude/tmux.py index 9b4f1a63..8eb1653e 100644 --- a/bin/loop_claude/tmux.py +++ b/bin/loop_claude/tmux.py @@ -66,7 +66,7 @@ def listed(session: str, run: Tmux) -> list[Listed]: def start_window(window: Window, cwd: str, env: typing.Mapping[str, str], command: list[str], first: bool, run: Tmux) -> Failure | None: - """Starts command in a new window of window's session, in cwd with env added to its environment, and leaves the client where it is. first makes the session too. A Failure says why tmux started none, or why it could not set the options of the window it started, which then runs without them.""" + """Starts command in a new window of window's session, in cwd with env added to its environment, and leaves the client where it is. first makes the session too. A Failure says why tmux started none, or why it could not mark a session it made as this checkout's.""" make = ["new-session", "-d", "-s", window.session] if first else ["new-window", "-d", "-t", f"={window.session}:"] variables = [flag for name, value in env.items() for flag in ("-e", f"{name}={value}")] # tmux reads a `;` that ends an argument as the end of the command, unless a backslash precedes it. @@ -76,10 +76,12 @@ def start_window(window: Window, cwd: str, env: typing.Mapping[str, str], comman return Failure(f"tmux could not start the window {window.target}: {done.stderr.strip() or f'it exited {done.returncode}'}") # set-option and show-options read a target as a pane's, so `=session` alone names no session. owned = run(["set-option", "-t", f"={window.session}:", OWNER, cwd]) if first else None - # By the ID, since a window of the same name may still be closing. A loop that fails before the option is set closes its window, and its stop is still sent as a DM. - kept = run(["set-option", "-w", "-t", done.stdout.strip(), "remain-on-exit", "failed"]) - unset = next((option for option in (owned, kept) if option is not None and option.returncode), None) - return Failure(f"tmux started the window {window.target} but could not set its options: {unset.stderr.strip() or f'it exited {unset.returncode}'}") if unset else None + # By the ID, since a window of the same name may still be closing. A loop that fails before the option is set closes its window, and its stop is still sent as a DM, so a failure here doesn't matter. + run(["set-option", "-w", "-t", done.stdout.strip(), "remain-on-exit", "failed"]) + # Without the owner, start_chunks cannot tell this checkout's session from another's, so no further chunk may start in it. + if owned is not None and owned.returncode: + return Failure(f"tmux started the session {window.session} but could not mark it as this checkout's: {owned.stderr.strip() or f'it exited {owned.returncode}'}") + return None def owner(session: str, run: Tmux) -> str: