Server(fix[sessions,clients]): Return empty on tmux errors#677
Merged
Conversation
why: A change in 0.57.0 made Server.sessions and Server.clients propagate LibTmuxException on any tmux failure (socket permission errors, subprocess crashes, malformed output). That broke the contract Server.sessions had carried since 0.17.0 and the one Server.clients was born with: a list-shaped accessor returns an empty QueryList when tmux cannot answer, and callers reach for Server.is_alive() / Server.raise_if_dead() when they need an explicit connectivity signal. Restore that contract for both accessors. Server.search_sessions, Server.search_windows, and Server.search_panes still raise; they take a caller-supplied filter, so a tmux failure there is signal, not noise. what: - Wrap Server.sessions and Server.clients bodies in try/except LibTmuxException → QueryList([]). Both now call fetch_objs directly instead of routing through _fetch_or_empty — the broader try/except already absorbs the daemon-not-up case the helper exists for. - Drop the Raises clause on Server.sessions; add prose pointing at is_alive/raise_if_dead for connectivity checks.
why: Lock in the lenient-by-default contract restored in the preceding commit. A tmux failure under Server.sessions or Server.clients yields an empty QueryList; connectivity checks go through Server.is_alive() / Server.raise_if_dead(). what: - Replace test_server_sessions_propagates_errors, test_server_clients_propagates_errors, and test_server_sessions_permission_error_propagates with test_server_sessions_returns_empty_on_tmux_error, test_server_clients_returns_empty_on_tmux_error, and test_server_sessions_permission_error_returns_empty. - Leave the daemon-not-up and missing-socket tests unchanged.
why: Surface the revert in the unreleased section so the user-facing release notes reflect the restored contract when the next version ships. what: - Add a "Lenient Server.sessions and Server.clients accessors" deliverable under the unreleased entry placeholder. - Add a "Stricter search_* methods" deliverable noting that the newer search_* accessors continue to raise. - Leave the 0.57.0 entry intact — it accurately records what 0.57.0 shipped.
why: 0.57.0's brief detour into raise-on-tmux-error for Server.sessions and Server.clients (reverted in the preceding commits) showed the convention isn't written down anywhere. Make it explicit so future list-returning accessors don't drift toward loud-failure by default. what: - Add a "List-returning accessors: empty by default on tmux errors" subsection under tmux-Specific Considerations. States the contract for Server.sessions / Server.clients / Server.attached_sessions, points at Server.is_alive() / Server.raise_if_dead() as the explicit-check primitives, and asks any future loud-failure mode to be a scoped opt-in instead of a baked-in raise on a new accessor.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #677 +/- ##
==========================================
+ Coverage 51.26% 51.37% +0.11%
==========================================
Files 25 25
Lines 3482 3488 +6
Branches 686 686
==========================================
+ Hits 1785 1792 +7
+ Misses 1403 1401 -2
- Partials 294 295 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Server.sessionsandServer.clients: tmux failures (socket permission errors, subprocess crashes, missing daemon, malformed output) once again yield an emptyQueryList, matching the contractServer.sessionshas carried since 0.17.0.LibTmuxException. Code written for 0.57.0 withtry/except LibTmuxExceptionaround these accessors keeps working — theexceptclause just becomes unreachable.Server.search_sessions,Server.search_windows, andServer.search_panesraising — they take a caller-supplied filter, where a tmux error carries meaningful signal.AGENTS.mdso future list-returning accessors don't drift toward loud-failure by default.Behavior
Before (0.57.0):
After (this PR):
For an explicit connectivity signal, callers use
Server.is_alive()orServer.raise_if_dead()— both available since 0.17.0.Scope
Server.sessionsQueryList(restored)Server.clientsQueryList(restored)Server.search_sessionsLibTmuxException(unchanged from 0.57.0)Server.search_windowsLibTmuxException(unchanged from 0.57.0)Server.search_panesLibTmuxException(unchanged from 0.57.0)Test plan
test_server_sessions_returns_empty_on_tmux_error—Server.sessionsreturnsQueryList([])on simulatedLibTmuxExceptiontest_server_clients_returns_empty_on_tmux_error— same forServer.clientstest_server_sessions_permission_error_returns_empty— connection errors absorbed into the empty contracttest_server_sessions_missing_socket_returns_empty— freshServer(socket_path=...)against a non-existent path returns empty (unchanged)test_server_search_sessions_propagates_errors—search_*methods still raise (unchanged)uv run ruff check .uv run mypyuv run pytest --reruns 0just build-docs