Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ pushes, because a tag triggers the publish workflow. See
[Release commits](WRITING.md#release-commits).

libtmux is pre-1.0: a minor version bump may include breaking API
changes, so downstream projects should pin `>=0.x,<0.y`.
changes, so downstream projects should pin `>=0.x,<0.y`. Warning
floors, escape hatches, `MIGRATION` entries, and hard-break recipes
follow [BREAKING_CHANGES.md](CONTRIBUTING/BREAKING_CHANGES.md).

1. Add the release's entries to `CHANGES`, following
[The changelog](WRITING.md#the-changelog).
Expand All @@ -245,7 +247,10 @@ belongs in its own commit, and usually in its own pull request.

Discuss a substantial change via an issue before making it.

Update the docs when a change touches the public interface.
Update the docs when a change touches the public interface. Compare
trunk against the pull request and document how callers obtain prior
behavior per [BREAKING_CHANGES.md](CONTRIBUTING/BREAKING_CHANGES.md)
when runtime behavior or public signatures change.

A pull request merges once it has the sign-off of one other developer.
If you don't have permission to merge it yourself, ask a maintainer to
Expand Down
177 changes: 177 additions & 0 deletions .github/CONTRIBUTING/BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Behavioral changes and API breakages

How `libtmux` evaluates, stages, and documents changes to observable behavior
and public APIs. Read this alongside [CONTRIBUTING.md](../CONTRIBUTING.md),
[WRITING.md](../WRITING.md), and [REVIEW.md](../../REVIEW.md) before opening a
behavioral or API pull request.

## Documented contracts and de facto behavior

Most downstream Python packages depend on `libtmux` without an upper version
bound, so minor releases reach users on reinstall. Downstream callers and test
suites depend on observable runtime behavior — return values, exceptions,
`__repr__` formatting, argument escaping, `$TMUX` inheritance, and `.cmd()`
return attributes — even when that behavior was undocumented or accidental.

Before changing runtime behavior, separate two cases:

- Unreachable or dead-code defects, where the existing code path never produced
a working result for any caller.
- De facto or documented behavior, where callers, scripts, or unit-test doubles
can observe and rely on the old output or side effect.

## Graduation sequence

When a change alters de facto or documented behavior, graduate it across
releases rather than flipping behavior unannounced.

### 1. Single-release warning floor

Keep existing default behavior for at least one minor release while emitting a
warning when the old path runs:

- Emit `FutureWarning` when a call remains valid syntax while its default
runtime semantics will change (for example, bare `Server()` ignoring `$TMUX`,
or `{Session, Window, Pane}.__exit__()` preserving unowned targets). Python
displays `FutureWarning` by default to end users.
- Emit `DeprecationWarning` when retiring a function, method, property, or
parameter in favor of another public API.
- Ship the public replacement before or alongside the warning. Never emit a
warning message that points callers to `libtmux._internal.*`.
- Add `MIGRATION` notes with `# Before` and `# After` code blocks plus
`warnings.filterwarnings`, `[tool.pytest.ini_options]`, and `PYTHONWARNINGS`
recipes so `pytest -Werror` suites have a documented transition step.

### 2. Default flip and escape hatches

Flip the default in a subsequent minor release. When callers cannot migrate
every call site in a single upgrade, keep an explicit escape hatch across a
documented deprecation window:

- Add a keyword parameter or alternate constructor when the choice belongs at
the call site, such as `kill_on_exit=True`, `raises=False` (returning `[]`
instead of raising), or `Server.from_env()`.
- Add an environment variable (`LIBTMUX_*`) when feasible for ambient defaults
where downstream users invoke `libtmux` indirectly through a CLI, plugin, or
test runner and cannot thread a keyword argument through intermediate layers.
- Promote the option to a permanent public parameter when the old behavior
serves a legitimate use case (for example, lenient non-raising inventory
reads or explicit `$TMUX` attachment). Retire temporary escape hatches only
after their window in `MIGRATION` closes.

### 3. Hard API breaks

Some defects and protocol boundaries cannot stage behind a warning or an
environment variable — for instance, repairing a filter that unconditionally
returned `[]`, escaping trailing command separators on the wire, or removing a
destructive side effect.

When an API requires a hard break:

- Provide a concrete way to obtain the prior behavior on the public API — a
parameter (`raises=False`, `check=False`), an alternate public method or
property (`server.sessions.filter(...)`, `server.clients`), or a runnable
code example — in both the pull request description and `MIGRATION`.
- Omit an old-behavior recipe only when you prove from source that the prior
behavior was unreachable dead code, and include that trace in the pull
request description.
- Place breaking changes under `### Breaking changes` at the top of the
`CHANGES` release entry per [WRITING.md](../WRITING.md#the-changelog), and
update the summary tables in `MIGRATION`.

## Pull request comparison layout

Every behavioral or API pull request fills out `### 2. Behavioral comparison`
in [PULL_REQUEST_TEMPLATE.md](../PULL_REQUEST_TEMPLATE.md) with three parts:

1. Trace what trunk actually does: cite the baseline release tag or `<base>`
commit, quote the exact expression, and walk through what happens at
runtime, including silent exception catches, type coercion, or accidental
outputs.
2. Compare what the pull request does: quote the replacement logic and compare
trunk against the pull request in a dimension table covering missing or
unreachable servers, primary and boundary inputs, runtime return values or
exceptions, static type annotations, and subprocess or timeout side effects.
3. Show how to get the old behavior and its graduation path: name the stage
(`bug fix on unreachable/dead path`, `warning release`, `default flip with
escape hatch`, or `hard break`) and give the exact parameter, environment
variable, alternate public call, or code snippet that reproduces each
plausible interpretation of the prior behavior.

## Worked example: `Server.attached_sessions`

The comparison below shows the expected level of detail using
`Server.attached_sessions` ([PR #949](https://github.com/tmux-python/libtmux/pull/949))
against [`v0.70.0`](https://github.com/tmux-python/libtmux/releases/tag/v0.70.0).

### 1. What trunk (`v0.70.0`) actually does

In [`src/libtmux/server.py` lines 1144-1158](https://github.com/tmux-python/libtmux/blob/v0.70.0/src/libtmux/server.py#L1144-L1158),
`v0.70.0` runs:

```python
return self.sessions.filter(session_attached__noeq="1")
```

Two interacting defects make `server.attached_sessions` return `QueryList([])`
for every server state:

1. `"noeq"` is absent from [`LOOKUP_NAME_MAP`](https://github.com/tmux-python/libtmux/blob/v0.70.0/src/libtmux/_internal/query_list.py#L335-L349).
2. `QueryList.filter()` raises [`OpNotFound(op="noeq")`](https://github.com/tmux-python/libtmux/blob/v0.70.0/src/libtmux/_internal/query_list.py#L363-L372),
a `ValueError` subclass, and the surrounding [`except ValueError:`](https://github.com/tmux-python/libtmux/blob/v0.70.0/src/libtmux/_internal/query_list.py#L578-L593)
meant for `path.rsplit("__", 1)` catches it and falls back to
`lhs = "session_attached__noeq"` with `op = "exact"`.
3. `keygetter(session, "session_attached__noeq")` reads a non-existent
attribute on `Session`, receives `None`, and returns `False` for every item.
4. Even if `noeq` existed, tmux's `#{session_attached}` format variable reports
the decimal client count (`"0"`, `"1"`, `"2"`, …), so `!= "1"` would match
detached sessions (`"0"`) while excluding single-client sessions (`"1"`).

### 2. What the PR does

```python
return self.sessions.filter(
lambda session: session.session_attached not in (None, "", "0"),
)
```

| Dimension | Trunk (`v0.70.0`) | PR `#949` |
| --- | --- | --- |
| Missing or unreachable server | `QueryList([])` | `QueryList([])` (unchanged; delegates to `self.sessions`) |
| Detached session (`session_attached == "0"`) | Omitted (`[]`) | Omitted (`[]`) |
| 1 attached client (`session_attached == "1"`) | Omitted (`[]`) | Included once |
| 2+ attached clients (`session_attached == "2"`, …) | Omitted (`[]`) | Included once (not duplicated per client) |
| Runtime return type | `QueryList[Session]` (`list` subclass) | `QueryList[Session]` (unchanged) |
| Static type annotation | `list[Session]` | `QueryList[Session]` (subtype-compatible with `list[Session]`; `.get()` and `.filter()` type-check) |
| Subprocess and timeout behavior | One `list-sessions` call via `self.sessions` | Identical |

### 3. How to get the old behavior and graduation path

Stage: bug fix on an unreachable dead-code path; ships without a deprecation
warning or environment flag because `Server.attached_sessions` returning `[]`
when clients were attached never worked. Callers wanting any adjacent session
or client filter can express it directly on the public API:

Single-client sessions only (`session_attached == "1"`):

```python
server.sessions.filter(session_attached="1")
```

Detached sessions (`session_attached == "0"`):

```python
server.sessions.filter(session_attached="0")
```

Sessions where `session_attached != "1"` literally:

```python
server.sessions.filter(lambda s: s.session_attached != "1")
```

One entry per attached client rather than one per session:

```python
server.clients
```
28 changes: 24 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Open an issue before sending behavioral or API pull requests. Read REVIEW.md,
.github/CONTRIBUTING.md, and:
.github/CONTRIBUTING.md, .github/CONTRIBUTING/BREAKING_CHANGES.md, and:
- https://github.com/tmux-python/.github/blob/HEAD/AI_POLICY.md
- https://github.com/tmux-python/.github/blob/HEAD/WRITING.md
Use N/A where a prompt does not apply (docs-only, lockfile bump, pure refactor).
Expand All @@ -14,13 +14,33 @@ Closes # <!-- or N/A for docs, lockfile bump, or pure refactor -->
- Sibling entry points checked (`sync`/`async`, CLI/API, single/batch, or `N/A`):
- Why this belongs here (owner fix, boundary adapter, or single-PR ownership transfer):

### 2. Failure before the fix (`N/A` for docs, lockfile bumps, or pure refactors)
### 2. Behavioral comparison (`N/A` for docs, lockfile bumps, or pure refactors)

- Baseline (`<base>` commit, or `<pre_fix_head>` SHA if fixing a defect introduced in this PR):
- Failing input or command and observed failure before the fix:
<!-- Follow .github/CONTRIBUTING/BREAKING_CHANGES.md for graduation rules and a worked example. -->

#### What trunk (`<base>` / latest release) actually does

- Baseline (`<base>` commit and latest release tag, or `<pre_fix_head>` SHA if fixing a defect introduced in this PR):
- Failing input or code path and observed runtime behavior (including accidental or de facto behavior):

#### What this PR does

| Dimension | Trunk | This PR |
| --- | --- | --- |
| Missing or unreachable server | | |
| Primary and boundary inputs | | |
| Runtime return value or exception | | |
| Static type annotation | | |
| Subprocess, state, or timeout side effects | | |

#### How to get the old behavior and graduation path

- Stage (`bug fix on unreachable/dead path`, `warning release`, `default flip with escape hatch`, or `hard break`):
- Warning, keyword parameter (`raises=False`, `kill_on_exit=True`), constructor, environment variable (`LIBTMUX_*`), or code snippet that reproduces the prior behavior:

### 3. Verification and tool disclosure

- Gates run (plus production-only revert check for behavioral fixes, or `N/A`):
- `.github/workarounds.toml` updates (`None` if none):
- `MIGRATION` and `CHANGES` updates (`None` if none):
- Tool use:
2 changes: 1 addition & 1 deletion REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Posture: `experimental` (pre-1.0 typed Python API over `tmux`; align observable

[Posture](https://github.com/tmux-python/.github/blob/HEAD/CONTRIBUTING.md#posture) defines `experimental`, `stable` and `private`.

Review the complete change against `<base>`, including untracked files. Report all findings in one pass without editing files. [Writing conventions](.github/WRITING.md) · [Contributing gates](.github/CONTRIBUTING.md) · [AI policy](https://github.com/tmux-python/.github/blob/HEAD/AI_POLICY.md).
Review the complete change against `<base>`, including untracked files. Report all findings in one pass without editing files. [Writing conventions](.github/WRITING.md) · [Contributing gates](.github/CONTRIBUTING.md) · [Breaking changes](.github/CONTRIBUTING/BREAKING_CHANGES.md) · [AI policy](https://github.com/tmux-python/.github/blob/HEAD/AI_POLICY.md).

## 1. Layer ownership

Expand Down
Loading