Skip to content

fix(_utils): scope is_caller annotation to caller's socket#22

Merged
tony merged 2 commits intomainfrom
fix/is-caller-socket-scope
Apr 19, 2026
Merged

fix(_utils): scope is_caller annotation to caller's socket#22
tony merged 2 commits intomainfrom
fix/is-caller-socket-scope

Conversation

@tony
Copy link
Copy Markdown
Member

@tony tony commented Apr 19, 2026

Summary

Pane serializers (_serialize_pane, snapshot_pane, search_panes) compared pane.pane_id == TMUX_PANE without consulting the tmux socket. A caller on socket A pane %0 was therefore flagged is_caller=True for any %0 on any other server — a false positive that polluted every read-path tool returning PaneInfo / PaneSnapshot / PaneContentMatch.

The 0.1.0a2 caller-identity-scoping work already shipped _caller_is_on_server (realpath comparison + macOS TMUX_TMPDIR basename fallback), but wired it into the self-kill guard only. This PR extends it to the informational annotation via a new _compute_is_caller(pane) helper in _utils.py, and migrates all three call sites. The now-dead _get_caller_pane_id helper and its two unit tests are removed.

Test plan

  • uv run ruff check . --fix --show-fixes
  • uv run ruff format .
  • uv run mypy
  • uv run py.test --reruns 0 -vvv
  • just build-docs

New regression test test_serialize_pane_is_caller_false_across_sockets spawns two libtmux servers via the TestServer fixture, points the caller at server A, and asserts pane %0 on server B (same pane_id, different socket) is flagged False. Sanity: pane %0 on server A is still True. The existing test_serialize_pane_is_caller parametrization continues to pass — the no-TMUX-set conservative branch is preserved for consistency with _caller_is_on_server.

Companion PRs

Part of a batch of post-0.1.0a2 smoke-test fixes. Each PR is independent and can land in any order:

Closes #19

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 19, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.62%. Comparing base (8e2e0c3) to head (02fef68).

Files with missing lines Patch % Lines
src/libtmux_mcp/_utils.py 71.42% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #22      +/-   ##
==========================================
- Coverage   86.78%   86.62%   -0.17%     
==========================================
  Files          38       38              
  Lines        1710     1719       +9     
  Branches      201      204       +3     
==========================================
+ Hits         1484     1489       +5     
- Misses        167      170       +3     
- Partials       59       60       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony
Copy link
Copy Markdown
Member Author

tony commented Apr 19, 2026

Code review

No issues found. Checked for bugs and AGENTS.md compliance (repo has AGENTS.md, no CLAUDE.md).

Scope:

  • AGENTS.md (namespace imports, test patterns).
  • Shallow bug scan on the diff — tri-state semantics of _compute_is_caller verified; 12 call sites of _serialize_pane accounted for; three migrated sites (_serialize_pane, snapshot_pane, search_panes) confirmed as complete.
  • Git blame / history — matches prior scoping work on the self-kill guard.
  • Prior PR review comments — no applicable guidance.
  • Code comments — _caller_is_on_server's conservative-True semantics at src/libtmux_mcp/_utils.py are inherited rather than tightened; this is intentional for parity with the self-protection gate, though reviewers may wish to note it as a trade-off (basename fallback and TMUX_PANE-only branches keep conservative-True behavior for the annotation).

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

tony added 2 commits April 19, 2026 15:21
Before: `_serialize_pane`, `snapshot_pane`, and `search_panes` compared
`pane.pane_id == TMUX_PANE` without consulting the tmux socket. A caller
on socket A pane `%0` therefore saw `is_caller=True` for any `%0` on any
other server — a false positive that polluted every read-path tool
surface returning `PaneInfo` / `PaneSnapshot` / `PaneContentMatch`.

The 0.1.0a2 caller-identity-scoping work already introduced
`_caller_is_on_server` (realpath + macOS TMUX_TMPDIR basename fallback),
but wired it into the self-kill guard only — the informational annotation
kept its bare-equality implementation.

This change centralizes the annotation via `_compute_is_caller(pane)` in
`_utils.py`, which reuses `_caller_is_on_server(pane.server, caller)`.
All three callers migrate; the now-dead `_get_caller_pane_id` helper is
removed along with its two unit tests.

Regression test `test_serialize_pane_is_caller_false_across_sockets`
spawns two libtmux servers, points the caller at server A, and asserts
a pane on server B with the same pane_id is flagged `False`.

Closes #19
@tony tony force-pushed the fix/is-caller-socket-scope branch from cb3566d to 02fef68 Compare April 19, 2026 20:21
@tony
Copy link
Copy Markdown
Member Author

tony commented Apr 19, 2026

Code review

Re-reviewed after force-push to 02fef68 (squashed fixups for the three concerns noted in the prior review).

No blocking issues found. Checked for bugs and AGENTS.md compliance.

Scope of the re-review:

The prior review's concern about conservative-True semantics leaking into the annotation is resolved.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@tony tony merged commit 22323a2 into main Apr 19, 2026
9 checks passed
@tony tony deleted the fix/is-caller-socket-scope branch April 19, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants