Skip to content

Aio(feat): Add libtmux.aio and offline ReplayEngine tapes - #738

Open
tony wants to merge 12 commits into
engine-seam-minimalfrom
engine-ops-compatibility-dx
Open

tony wants to merge 12 commits into
engine-seam-minimalfrom
engine-ops-compatibility-dx

Conversation

@tony

@tony tony commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Note

Rebase alignment with v0.70.0 (0.74.0 milestone, #907): align AsyncSubprocessEngine child timeout and pipe-safe reaping with exc.TmuxCommandTimeout (#807), preserve structured logging and environment masking (#748), and check annotations with ty (uv run ty check) and Ruff ANN (#682) in place of mypy.

Summary

  • Add opt-in libtmux.aio (AsyncServer, AsyncSubprocessEngine, adispatch, adispatch_batch, AsyncCommandResult) built directly over libtmux.engine.AsyncTmuxEngine (Engine(feat): Add raw-byte libtmux.engine seam and capabilities #739), keeping asyncio out of sys.modules on synchronous import libtmux.
  • Add ReplayEngine, Exchange, and Tape in libtmux.test alongside RecordingEngine.tape / RecordingEngine.to_dict() and exc.UnscriptedCommand so recorded tmux traffic replays offline and fails closed on unscripted commands.

Changes

  • src/libtmux/aio.py:
    • AsyncSubprocessEngine: Awaits asyncio.create_subprocess_exec in binary mode, enforcing MSG_COMMAND limits, DaemonGuard generation fences, and child termination/reaping on TimeoutError and asyncio.CancelledError.
    • Async dispatch shares the classic argument renderer and decoded line view. The result retains the original bytes. Batched command vectors inherit the server timeout, while explicit requests keep their own.
    • AsyncServer.from_env() connects explicitly to the $TMUX server from a pane environment, and AsyncServer validates socket_name / socket_path length against AF_UNIX sun_path limits.
    • AsyncServer.list_sessions() probes the running daemon version before falling back to the client binary and uses the shared record parser, including when a session directory contains a newline.
  • src/libtmux/test/replay.py & src/libtmux/exc.py:
    • RecordingEngine pairs each completed request with its reply, including when threads finish out of order. JSON tapes retain binary outputs. Replay distinguishes request inputs and client options, and reports an unrecorded request with UnscriptedCommand.

Layer ownership (REVIEW.md)

  • Async dispatch (aio.py): owns opt-in AsyncServer, AsyncSubprocessEngine, adispatch/adispatch_batch, and shielded child reaping while keeping synchronous libtmux modules free of asyncio imports.
  • Test fixtures and helpers (test/replay.py): adds ReplayEngine, Tape, and Exchange alongside FakeEngine and RecordingEngine.

Test plan

  • Compare sync and async line endings, native command argv, batch deadlines, multiline paths, and binary JSON round trips. Reversed thread completion preserves both recorded replies.
  • Ruff format, Ruff lint, and ty (3.11 and 3.15)
  • Full pytest suite across supported tmux releases
  • Sphinx documentation build passes cleanly (just build-docs)

@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.43658% with 107 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.41%. Comparing base (f86d71f) to head (c741609).

Files with missing lines Patch % Lines
src/libtmux/aio.py 75.82% 38 Missing and 13 partials ⚠️
src/libtmux/test/replay.py 51.08% 42 Missing and 3 partials ⚠️
src/libtmux/test/fake_engine.py 57.89% 7 Missing and 1 partial ⚠️
src/libtmux/exc.py 71.42% 2 Missing ⚠️
src/libtmux/common.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                   @@
##           engine-seam-minimal     #738      +/-   ##
=======================================================
+ Coverage                59.94%   60.41%   +0.47%     
=======================================================
  Files                       37       39       +2     
  Lines                     6626     6955     +329     
  Branches                  1321     1356      +35     
=======================================================
+ Hits                      3972     4202     +230     
- Misses                    2218     2302      +84     
- Partials                   436      451      +15     

☔ View full report in Codecov by Harness.
📢 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
tony force-pushed the engine-ops-compatibility-dx branch from 1fa02d4 to c8e78bd Compare November 7, 2026 02:19
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 21e1fdc to 4be0c1f Compare November 20, 2026 23:52
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 4be0c1f to 50cadb3 Compare November 21, 2026 17:03
@tony tony changed the title Pluggable command engines: batching, async, and tmux-free tests Aio(feat): Add libtmux.aio and offline ReplayEngine tapes Nov 21, 2026
@tony
tony changed the base branch from master to engine-seam-minimal November 21, 2026 17:03
@tony
tony force-pushed the engine-seam-minimal branch from 48ba47c to 08fd87a Compare November 21, 2026 17:11
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 50cadb3 to 7e3aa7a Compare November 21, 2026 17:11
@tony
tony force-pushed the engine-seam-minimal branch from 08fd87a to 18045ea Compare November 22, 2026 02:43
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 7e3aa7a to 75b95d7 Compare November 22, 2026 02:43
@tony
tony force-pushed the engine-seam-minimal branch from 18045ea to adf517a Compare November 22, 2026 13:45
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 75b95d7 to dd1fbd6 Compare November 22, 2026 13:46
@tony
tony force-pushed the engine-seam-minimal branch from adf517a to 909b8de Compare November 22, 2026 15:21
@tony
tony force-pushed the engine-ops-compatibility-dx branch from dd1fbd6 to d77d4d6 Compare November 22, 2026 15:21
@tony
tony force-pushed the engine-seam-minimal branch from 909b8de to 240da60 Compare November 22, 2026 20:12
@tony
tony force-pushed the engine-ops-compatibility-dx branch from d77d4d6 to 626a690 Compare November 22, 2026 20:13
@tony tony added the area: engines Engine layer, deadlines, async, control mode, transports label Nov 24, 2026
@tony
tony force-pushed the engine-seam-minimal branch from 240da60 to c70c509 Compare November 25, 2026 08:12
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 626a690 to fcd2e82 Compare November 25, 2026 08:13
@tony tony mentioned this pull request Nov 25, 2026
46 of 79 tasks
@tony tony added this to libtmux Nov 25, 2026
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 94bccdd to b154176 Compare November 29, 2026 03:17
@tony
tony force-pushed the engine-seam-minimal branch from 79ab482 to c8717d3 Compare November 30, 2026 01:02
@tony
tony force-pushed the engine-ops-compatibility-dx branch from b154176 to 79bb713 Compare November 30, 2026 01:04
@tony
tony force-pushed the engine-seam-minimal branch from c8717d3 to ebde4a6 Compare December 4, 2026 03:13
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 79bb713 to 6f95bb9 Compare December 4, 2026 03:13
@tony tony modified the milestones: 0.73.0, 0.74.0 Dec 5, 2026
@tony
tony force-pushed the engine-seam-minimal branch from ebde4a6 to 0269c6c Compare December 5, 2026 16:52
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 6f95bb9 to 24dbb0f Compare December 5, 2026 16:54
@tony
tony force-pushed the engine-seam-minimal branch from 0269c6c to 3b6a7fc Compare December 5, 2026 17:53
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 24dbb0f to 37f0cc7 Compare December 5, 2026 17:53
tony added a commit that referenced this pull request Dec 5, 2026
why: Record AsyncServer, AsyncSubprocessEngine, and ReplayEngine notes.

what:
- Add unreleased 0.74.0 feature notes for #738.
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 37f0cc7 to 6dd08cd Compare December 5, 2026 18:22
@tony
tony force-pushed the engine-seam-minimal branch from 3b6a7fc to 4338fb6 Compare December 5, 2026 18:22
tony added a commit that referenced this pull request Dec 5, 2026
why: Record AsyncServer, AsyncSubprocessEngine, and ReplayEngine notes.

what:
- Add unreleased 0.74.0 feature notes for #738.
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 6dd08cd to 626ae6e Compare December 5, 2026 20:44
@tony
tony force-pushed the engine-seam-minimal branch from 4338fb6 to f86d71f Compare December 5, 2026 22:54
tony added 12 commits December 5, 2026 16:55
why: Async clients need cancellable subprocess calls. Recorded requests
and replies let tests exercise the same engine contract offline.

what:
- Add AsyncServer, AsyncSubprocessEngine, and async dispatch helpers.
- Record exchanges and reject unscripted commands during tape replay.
- Keep synchronous imports independent of asyncio.
why: Sync and async callers need the same line endings when reading a
command result.

what:
- Share line and diagnostic projection in the command-result adapter.
- Retain both original byte streams when decoding async replies.
why: A tuple passed to a batch could wait indefinitely even when
commands on the same server had a deadline.

what:
- Apply the configured timeout when constructing each command vector.
- Retain the policy on a caller-supplied request, including unbounded
  waits.
why: An embedded line feed split a native session record across lines
and made the async inventory unreadable.

what:
- Use the shared record parser for complete session inventories.
- Compare session paths on a private server with a multiline directory.
why: A second async argv renderer changed native argument boundaries and
could disagree with synchronous daemon-guard dispatch.

what:
- Use the command engine to prepare the request and child environment.
- Check native output with and without a live daemon guard.
why: JSON text decoding lost bytes. Pairing request and result lists
also exchanged replies when threads completed out of order.

what:
- Capture each completed request and reply together, including batches.
- Match explicit input, client flags and execution options during
  replay.
- Retain non-UTF-8 output in JSON and exercise a recorded example.
why: A failed has-session later in a native command group produced different decoded stdout in sync and async code, although tmux returned the same bytes.

what:
- Derive the compatibility projection once from the completed request and its diagnostics.
- Compare the native exit status, both raw streams, and both line views in one real grouped command.
why: A fixture may use an explicit path without a socket name. The async client must target the same isolated daemon for a valid comparison.

what:
- Build live async clients from the connection attached to the fixture's session.
- Let the synchronous recording wrapper retain its configured connection.
why: The native asyncio runner consumes the same arguments and
environment as the blocking subprocess runner. Using one launch
preparation path keeps socket selection and command limits consistent.

what:
- Build the async launch from the command engine’s resolved argv and
  environment.
why: AsyncServer needs parity with Server.from_env(), AF_UNIX length
preflights, daemon-probed session formats, and double-cancel reaping.

what:
- Add AsyncServer.from_env() and _check_socket_path preflight checks.
- Loop asyncio.shield(reap_task) until child reaping completes.
- Probe connected daemon version asynchronously for list_sessions().
why: Document AsyncServer/AsyncSubprocessEngine and ReplayEngine in
REVIEW.md's layer map.

what:
- Add the Async dispatch row for aio.py and keep synchronous modules
  free of asyncio imports
- Record ReplayEngine and Tape under Test fixtures and helpers
why: Record AsyncServer, AsyncSubprocessEngine, and ReplayEngine notes.

what:
- Add unreleased 0.74.0 feature notes for #738.
@tony
tony force-pushed the engine-ops-compatibility-dx branch from 626ae6e to c741609 Compare December 5, 2026 22:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: engines Engine layer, deadlines, async, control mode, transports

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant