Skip to content

fix(desktop): run an agent command on tmux that cannot tag its pane, untracked - #8705

Merged
waleedlatif1 merged 5 commits into
stagingfrom
fix/desktop-tmux-untagged-runs
Oct 7, 2026
Merged

waleedlatif1 merged 5 commits into
stagingfrom
fix/desktop-tmux-untagged-runs

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #8668. To stop only its own commands, an agent run inside tmux tags its pane with a pane option (set-option -p). Pane options need tmux 3.0 or later. #8668 refused the command whenever tagging failed, so on older tmux every agent run failed, even with the background executor off.

  • On tmux before 3.0, a run now goes ahead untracked. Such a tmux refuses set-option -p, and Sim recognises the refusal from the text real tmux 2.9a prints: its getopt's unknown option -- p, or illegal option -- p with BSD getopt on macOS, followed by set-option's usage line. A tmux that can tag panes but did not (it timed out, or failed otherwise) still gets the run refused, so no command starts that Stop and sign-out could never end.
  • Stop, sign-out and switching Terminal off leave an untracked run alone, because nothing could tell its pane from one of the user's. A call stopped mid-wait reports such a run as running rather than completed, and keeps its files.
  • An untracked run is reaped once it finishes or its pane is gone. Gone means tmux no longer has that pane, checked with #{pane_id}, a format every tmux knows; tmux 3.x answers for a missing pane with an empty line rather than an error. It is not kept as an orphan when its Sim terminal closes.
  • A finished run's pane is closed, including when a run finishes after its call returned and is reaped later, so dead panes kept by remain-on-exit do not pile up. An untracked run's pane is closed only when tmux reports its start command (#{pane_start_command}, which old tmux has too) as the run's own script, so a user's pane that took the id after a tmux restart is never closed.
  • Tagged runs behave as before. The start gate still holds every command until the tagging call has finished, so a tagged run's command never runs before a stop could recognise its pane.

The pane field in a run result

#8668 changed a run result's pane from the run's window id (@N) to its pane id (%N). I checked every consumer:

  • Sim's web UI: nothing renders the field.
  • The model: it may pass the value back as the pane argument of read, input, kill or close. All four hand it to tmux as -t, and tmux accepts a pane id there. A pane id is also more precise than a window id: @N meant whichever pane of that window was active, so a split could redirect the call.
  • Docs: the protocol docs now describe both values. The generated tool catalog describes the pane argument as a session:window.pane target from panes; a run's pane id is still a valid target, so nothing there breaks.

Format separator follow-up to #8720

  • The -F separator changes from |~sim~| to <~sim~>.
  • |~sim~| began and ended with the same character, so a field ending in |~sim~ (a cwd or a window name) was misread rather than dropped.
  • <~sim~> has no proper prefix that is also a suffix. It can only be found where Sim wrote it, or wholly inside a field, and that changes the line's field count, so the line is dropped.

Tests

  • Untagged run: on old tmux's real refusal (captured from tmux 2.9a, plus the BSD getopt wording), the run starts untracked, a stop sends tmux nothing, and the user's pane is untouched. Once the pane is gone (answered the 3.x way), it reads as gone.
  • Refused run: on a timeout or any other tagging failure, the run is refused.
  • Dead panes: a finished untracked run's pane is closed, and only once it has finished; a run reaped after it finished has its pane closed; a user's pane that took a finished run's id after a restart is left open.
  • Real commands: they run whether or not tmux could tag the pane (the fake tmux actually executes the script).
  • Gate: the fake tmux holds the tagging call until the test releases it. While it is held, the command has not run; once it is released, the command runs.
  • Stop on an untracked run: a Stop mid-wait reports the run as still running and keeps its files, and the run is reaped once its status lands. Once its pane disappears, it reads as gone.
  • Separator: a field that ends with all but the separator's last character parses intact, and a field holding the whole separator drops its line. The first test fails with |~sim~|.
  • Real tmux: with real 2.9a, runs go ahead untracked, the command runs, and Stop leaves it alone. With real 3.4, runs are tagged, and Stop ends the run and closes its pane. listPanes parses on both.
  • Red checks:
    • With the old refusal pattern, five tests fail on 2.9a's real text.
    • Against staging's tmux.ts, the first two tests fail.
    • With the gate loop removed, the gate test fails.
    • The gate test replaces a weak one, "never runs one it could not tag". That test passed because the run directory had been deleted, not because of the gate.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@vercel

vercel Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 7, 2026 4:18am UTC

Request Review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Handles tmux runs that cannot be tagged with pane identifiers.

The PR appears safe to merge; no new actionable issue was found.

What we checked:

  • Stop falsely reports completion: The stopped path uses pollRun unchanged for untracked runs, so an unfinished command remains running.
  • Cleanup closes a user's pane: A finished status alone is not enough. The pane's start command must also contain the run's unique script path.

Summary

Allows agent commands to run untracked when tmux rejects pane options, while still refusing other tagging failures.

  • Stop reports an unfinished untracked run as running and retains its files.
  • Finished runs close their panes during later cleanup. Untracked panes require a matching script path.
  • Updates pane-target docs and adds regression tests.
  • The four previous, unnumbered findings are addressed by the current code and tests.
  • waleedlatif1 explicitly describes leaving untracked commands running after Stop or terminal closure as intentional.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Open run pane behind gate] --> B[Try to tag pane]
  B -->|Success| C[Release gate: tracked run]
  B -->|Pane options unsupported| D[Release gate: untracked run]
  B -->|Other failure| E[Refuse command]
  C --> F[Stop checks pane tag]
  D --> G[Stop leaves command running]
  D --> H[Finished run]
  H --> I{Start command matches run script?}
  I -->|Yes| J[Close pane and remove files]
  I -->|No| K[Leave pane and remove files]
Loading

Reviews (5) · Last reviewed commit: "fix(desktop): recognise how real tmux be..." · Reviewed by Greptile

Comment thread apps/desktop/src/main/terminal/tmux.ts Outdated
Comment thread apps/desktop/src/main/terminal/tmux.ts Outdated
Comment thread apps/desktop/src/main/terminal/tmux.test.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Turn on auto-fix | Re-trigger cubic

Comment thread apps/desktop/src/main/terminal/index.ts
Comment thread apps/desktop/src/main/terminal/tmux.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

…untracked

Agent `run` inside tmux tagged its pane with a pane option (`set-option -p`,
tmux 3.0+) and refused the command when that failed, so on older tmux every
agent run failed, with the background executor off too.

A run whose pane cannot be tagged now goes ahead untracked: Stop, sign-out and
switching Terminal off leave it alone, since nothing could tell its pane from
one of the user's. Tagged runs are unchanged. The gate still holds every
command until the tagging call has finished.
…ap and close finished untracked panes

- Only tmux before 3.0, which refuses `set-option -p` as an unknown flag or
  invalid option, runs a command untracked. A tmux that can tag panes but did
  not (it timed out, or failed otherwise) gets the run refused, as before, so
  no command starts that Stop and sign-out could never end.
- tmux 3.x answers `display-message` for a pane that is gone with an empty line
  rather than an error, so an untracked run's pane is gone unless tmux echoes
  its id back.
- A finished untracked run's pane is closed, and a run that finishes after its
  call returned has its pane closed when it is reaped, so dead panes kept by
  `remain-on-exit` do not pile up.
…, and use a separator no field can straddle

- Real tmux 2.9a refuses `set-option -p` with its own getopt's
  `unknown option -- p` and set-option's usage line (BSD getopt on macOS:
  `illegal option -- p`). The untracked fallback only matched later wordings,
  so on real pre-3.0 tmux every run was refused. The fake tmux and the tests
  now use the text captured from real 2.9a.
- The `-F` separator `|~sim~|` began and ended with the same character, so a
  field ending in `|~sim~` was misread rather than dropped. `<~sim~>` has no
  proper prefix that is also a suffix, so it is only found where it was
  written or wholly inside a field, whose line is then dropped.
@waleedlatif1
waleedlatif1 force-pushed the fix/desktop-tmux-untagged-runs branch from 07697ce to 8dddbd7 Compare October 7, 2026 04:18
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 38942a7 into staging Oct 7, 2026
36 of 37 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/desktop-tmux-untagged-runs branch October 7, 2026 05:48

This branch was previously deployed

1 inactive deployment
Preview — 8dddbd7c Deployed Oct 7, 2026 by vercel[bot]
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