Skip to content

Fix race condition in new_session() by avoiding list-sessions query#625

Open
neubig wants to merge 3 commits intotmux-python:masterfrom
neubig:fix/new-session-race-condition
Open

Fix race condition in new_session() by avoiding list-sessions query#625
neubig wants to merge 3 commits intotmux-python:masterfrom
neubig:fix/new-session-race-condition

Conversation

@neubig
Copy link

@neubig neubig commented Feb 5, 2026

Fixes: #624

Previously, new_session() would:

  1. Run 'tmux new-session -P -F#{session_id}' to create session
  2. Immediately run 'tmux list-sessions' to fetch full session data

This created a race condition in some environments where list-sessions might not see the newly created session yet, causing TmuxObjectDoesNotExist errors.

The fix:

  • Expand the -F format string to include all Obj fields (except 'server')
  • Parse the output directly into a Session object
  • Eliminate the separate list-sessions query entirely

This is more efficient (one fewer subprocess call) and eliminates the race condition by making session creation atomic.

I tested this using the script in the original issue and it works in all three cases:

Environment Result
Python 3.12 + PyInstaller + Docker PASS ✓
Python 3.13 + PyInstaller + Docker PASS ✓
Python 3.13 + PyInstaller + Native PASS ✓

@CLAassistant
Copy link

CLAassistant commented Feb 5, 2026

CLA assistant check
All committers have signed the CLA.

Previously, new_session() would run 'tmux new-session -P -F#{session_id}'
then immediately query 'tmux list-sessions' to fetch full session data.
This created a race condition in PyInstaller + Python 3.13+ + Docker
environments where list-sessions might not see the newly created session.

The fix expands the -F format string to include all Obj fields, parsing
the output directly into a Session object without a separate query.

Co-authored-by: openhands <openhands@all-hands.dev>
@neubig neubig force-pushed the fix/new-session-race-condition branch from 0f803dd to e81a44f Compare February 5, 2026 05:46
@tony
Copy link
Member

tony commented Feb 5, 2026

@neubig Thank you. Can you sign the CLA?

Is there a CI or full traceback for this? Any tmux version you're trying with? Thanks for the details in #624.

@tony tony self-requested a review February 5, 2026 23:19
neubig and others added 2 commits February 6, 2026 07:16
Co-authored-by: Tony Narlock <tony@git-pull.com>
Co-authored-by: Tony Narlock <tony@git-pull.com>
@neubig
Copy link
Author

neubig commented Feb 6, 2026

Thanks @tony! Signed the CLA.

I checked and the version is tmux 3.5a.

And in terms of CI where this failed, the reason why we were able to identify this is because this CI run failed: https://github.com/OpenHands/software-agent-sdk/actions/runs/21638051841/job/62369267088

We were able to trace it back to the upgrade from Python 3.12 to 3.13, and after reverting to 3.12, the consistent failures due to the issue I cited here disappeared (although this particular run still has a few failures): https://github.com/OpenHands/software-agent-sdk/actions/runs/21710957108

@neubig neubig requested a review from tony February 6, 2026 13:42
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.

Race condition in new_session() in some environments (e.g. PyInstaller + Python 3.13+ + Docker)

4 participants