A Higher-Categorical Semantics of Terminal Multiplexers
Abstract
Two names can reach the same running build. Reading both yields two views, while typing through both can duplicate input. From a typed model of tmux we derive an alias-invariance criterion, a coherence theorem for concurrent batches, and a sharp bound of $n-1$ writes to identify sharing among $n$ handles. A sheaf glues simultaneous readings, while a separate criterion determines whether a single server state realizes the result. GNU Screen, Zellij, and dtach supply distinguishing traces for the general theory.
1. The incidence structure of tmux
Alice links a build window from session A into session B. Bob can inspect the compiler through B's index, even after Alice removes A's link. Representing each session by its own privately owned process tree would duplicate the computation in the model. Two identical screen images leave its sharing undetermined.
At a server instant write $C,S,L,W,P$ for clients, sessions, session-window links, windows, and panes. In the ordinary tiled fragment the incidence data are
$$ a:C\rightharpoonup S,\qquad S\xleftarrow{s}L\xrightarrow{w}W,\qquad o:P\to W. $$
A link has an index unique in its session. IDs identify server objects for their respective lifetimes. A nonempty session selects a current link $j(s_0)$ above $s_0$, and a nonempty window selects a pane $f(w_0)$ above $w_0$. Thus $sj=1$ and $of=1$ on their domains. The ordinary selected pane of an attached client $c$ is $f(w(j(a(c))))$. Command resolution also supports explicit IDs, indexed paths, relative selectors, and command-specific defaults. The active-pane client flag supplies a client-specific selection for applicable actions. Grouped sessions can select different current windows from their shared collection.
Pane occurrences form the pullback $H=L\times_W P$, whose pairs $(\ell,p)$ satisfy $w(\ell)=o(p)$. Projection to $p$ forgets the route. A live fixture may project further to its endpoint incarnation. A retained dead pane can lack a live endpoint, while respawn can reuse the pane ID with a fresh workload. A workload may contain several processes.
Link and nonfinal unlink add and remove routes. An ordinary successful shell split allocates a pane and endpoint and revises a shared window layout. Selection changes the target of relative input. Detachment changes attachment. Hooks, size policies, exits, and last-link behavior can produce further observable transitions. tmux 3.5a manual
2. From addresses to effects
A key binding can intercept a client key. Forwarded bytes on a PTY master can be buffered, echoed, or interpreted as signal-generating characters by the slave line discipline. Output bytes, a parser grid, and the image rendered with overlays also define different observations. At fixed geometry let $t$ include incomplete control sequences. A deterministic timeout-free parser gives a byte-monoid action $\delta(t,uv)=\delta(\delta(t,u),v)$ by folding its single-byte transition. Thus a split within a control sequence preserves interpretation when full parser state survives the boundary. Linux PTY interface · Terminal control sequences
Restrict $H$ to chosen handles of live panes and let $q:H_{\rm live}\to T$ resolve them onto the endpoint incarnations in its image. The relation $h\sim k$ iff $q(h)=q(k)$ presents $T$ as their quotient. A fibre-constant assignment factors uniquely through $q$ by taking the common value on each nonempty fibre. Factoring a handle assignment through this quotient requires it to depend only on the endpoint. For selected handles $D$, the image $q[D]$ is left adjoint to inverse image on power sets. This gives a canonical once-per-recipient interpretation. A per-client notification can legitimately count two handles reaching one pane.
Proposition 1 (alias multiplicity). In a product of local endpoint stores, each visit to $t$ applies a fixed endomap $F_t$ to its coordinate, including all observed effects. Traversing $m_t>0$ occurrences yields $F_t^{m_t}(x_t)$. This agrees with one visit for every positive multiplicity and every admissible initial state precisely when $F_t^2=F_t$ on that invariant domain.
Proof. Maps on different coordinates commute. Grouping the visits by endpoint gives the displayed power. Taking the multiplicity two gives necessity, and induction reduces every positive power of an idempotent to its first power. For an arbitrary endomap, a traversal over the set of distinct endpoints instead visits each once. This is a routing property. It gives no delivery guarantee after a crash, retry, or change of endpoint incarnation. ∎
Setting a flag to true is idempotent when only the flag is observed. Appending a byte generally is not. Logging every write can destroy idempotence even for the flag. To send once per endpoint for a general action, deduplicate after target resolution.
3. Paths, squares, and coherence
At a chosen observation boundary let $X=\prod_{r\in D}X_r$. A named event $e$ has read support $R_e$, write support $W_e$, and a guard determined by $R_e$. New values depend only on the read resources and data fixed in the event. Observable ordered channels count as resources.
Certify $e,f$ independent when $W_e\cap(R_f\cup W_f)=W_f\cap(R_e\cup W_e)=\varnothing$. If $ef$ executes, $f$ was already enabled and preserves $e$'s guard and inputs. Thus $fe$ reaches the same store. Separate pane parsers may pass this test. Selecting a pane and sending to the active pane can fail it. Recording both arrivals in one ordered log also removes a square.
In the resulting strict $(2,1)$-category, stores are objects, enabled event paths are 1-arrows, and certified swaps generate invertible 2-cells under whiskering and composition. Impose interchange for swaps in disjoint positions. For three independent occurrences impose $s_1s_2s_1=s_2s_1s_2$, where $s_i$ swaps adjacent positions $i,i+1$. These pastings compare the same opposite paths through a cube. Reversing a swap leaves each individual write irreversible where appropriate. Trace theory · Geometric concurrency
Theorem 2 (finite batches). Fix one executable word of distinctly named occurrences. Order each pair failing the support test by its order in that word. Add desired program orders consistent with the word and take transitive closure to obtain a poset $P$. Every linear extension of $P$ executes to the same store. In the groupoid of its schedules generated by swaps of adjacent incomparables modulo cancellation, interchange, and the cube equation, every two schedules have exactly one connecting arrow. Each order ideal determines a unique intermediate store.
Proof. Rank occurrences by a reference extension. Every unsorted extension has an adjacent inversion. Its events are incomparable because their reference order is reversed. A swap reduces the inversion count, so every extension sorts to the reference. Taking the original executable word as reference and reversing these swaps proves executability and endpoint equality. For uniqueness, disjoint first reductions close by interchange. Overlapping reductions have three strictly decreasing ranks, pairwise incomparable, and close by the cube equation. Induction on inversion count therefore equates all decreasing paths to the reference. Each generator equals normalization at its source followed by inverse normalization at its target, so all zigzags with common endpoints agree. Every order of an ideal extends to a full schedule, and the same argument applies inside its prefix. ∎
Two ordered chunks $a<c$ on pane $p$ and an independent chunk $b$ on $q$ admit $acb,abc,bac$. One representative suffices for the final parser state. Sampling $q$ after $a$ can distinguish these schedules. Observer reads, timers, and capacity constraints must be included before reordering.
4. What several views determine
Fix an epoch and finite canonical addresses $X$ with value sets $A_x$. An address can be a pane-row-column triple or a window-pane active flag. Client-specific overlays require a client coordinate. A chart maps local positions $D$ to addresses by $q:D\to X$ and returns $y(d)\in A_{q(d)}$. It defines a reading on $q(D)$ exactly when repeated addresses agree. Cropping, viewport offsets, and the common value alphabet must be specified.
On the subset site of $X$ with union covers, $E(U)=\prod_{x\in U}A_x$ is a sheaf because one can choose each value from any covering chart containing its address. This topos is equivalent to $X$-indexed families of sets. For nonempty admissible snapshots $B$ and observation map $o:B\to E(X)$, set $R=o(B)$ and $R_U=\pi_U R$. This image presheaf is separated.
Proposition 3 (snapshot realizability). On a cover $U=\bigcup_i U_i$, every compatible family of individually realizable restrictions has a common witness if and only if
$$ R_U=\{v\in E(U): v|_{U_i}\in R_{U_i}\text{ for every }i\}. $$
On the full subset site this holds on every cover precisely when $R$ is the product of its singleton projections.
Proof. The ambient sheaf identifies compatible local families with the right-hand side. Membership on the left says precisely that some $b\in B$ realizes the vector there. The singleton cover forces the product condition. Conversely a vector of permitted coordinates can be extended to the remaining addresses by taking values from any fixed element of $R$. Its observed value is unique, although the witnessing process state can be ambiguous. ∎ Sheaf axiom · Join dependencies
For a single ordinary window with selectable panes $p,q,r$, the attainable active flags are $100,010,001$. The charts $\{p,r\}$ and $\{q,r\}$ can each report $(1,0)$ and agree on $r$. Their amalgamation $110$ violates the window invariant. The same pattern drawn from two independently focused clients would have a different meaning because its addresses should include the clients.
For anonymous slots, take a graph of views with each edge $e:v\to w$ carrying a proposed permutation $t_e\in S_n$ between two enumerations of $n$ tracked slots. Reversal inverts the permutation. Vertex relabelings $h_v$ transform the edge to $h_wt_eh_v^{-1}$. This gives the groupoid of functors from the graph's free path groupoid to $BS_n$. It satisfies descent on union covers by subgraphs. Arrows glue at vertices. Given local objects and coherent overlap isomorphisms, choose a reference chart at each vertex and transport each local frame to it. The cocycle makes the transformed edge labels agree. A common numbering exists exactly when all loop products are identity. To check this, propagate frames along a spanning forest and test the remaining edges. A triangle with two identities and a transposition is trivializable edgewise but has no common numbering. Consistently using stable pane IDs forces trivial loop products. Descent in groupoids
5. Behavioral comparison and recovery of sharing
Fix actions $A$, observations $O$, and an adapter with deterministic partial transitions $d:X\times A\rightharpoonup X$. Supply scheduling decisions as inputs or control them. Each trial reaches an observation boundary or a recognizable refusal in finite time. Totalize by an absorbing refusal state with fresh observation. This Moore machine assigns $b_x(w)=o(d^*(x,w))$ to $w\in A^*$, with intermediate observations at prefixes. Two states have equal behaviors exactly when a relation containing them preserves observations and relates all corresponding successors. One direction follows by induction. Conversely equality of behaviors at the empty word gives the present observation, and equality at $aw$ for every suffix $w$ gives successor equality. Such comparisons compose by relational composition. Preserving specified interchange cells requires extra structure. Rutten, Universal Coalgebra
Theorem 4 (sharp probe complexity of sharing). In a quiescent fixture, $n\geq1$ named handles address an unknown partition of backing terminals. Initially every marker cell is blank. Writing a fresh marker through one handle changes the marker cells of precisely the handles in its block. All cells can be read freely. Exactly $n-1$ single-handle writes are necessary in the worst case and sufficient to identify the partition.
Proof. Write to an unclassified handle. The positions displaying the fresh marker give its entire block. Repeat until at most one handle remains, whose block is then determined. Each probe removes at least one handle. Conversely, run an exact adaptive tester on singletons. After fewer than $n-1$ writes two handles are untouched. Merging those two into one block preserves all previous reads and therefore all choices made by the tester. It cannot distinguish the two partitions. ∎
Broadcast input or an application that deliberately replicates markers can violate the intervention law. Canonical ID queries, when available, can reveal the relation without writing.
6. A common signature and distinguishing traces
At state $x$ use clients $C_x$, slots $V_x$, endpoints $E_x$, and incidence $I_x\subseteq(C_x\times V_x)\times E_x$. A slot may be blank and a live endpoint may have no viewer. Typed transitions govern attachment, bindings, focus, routing, lifetime, and optional image reconstruction. A command can combine allocation and layout changes before the next observation.
For a fixed event forwarded unchanged through two routing layers, represent route occurrences by finite spans $A\leftarrow H\to B$ and $B\leftarrow K\to D$. Their composite consists of pairs in $H\times_B K$ agreeing at the intermediate port. Its route-count matrix is $MN$. To compute it, partition compatible pairs from $a$ to $d$ by their intermediate port $b$ and sum $M_{ab}N_{bd}$. The nonzero entries compose by Boolean matrix multiplication. Multiple routes to one inner pane can therefore yield a single reachable recipient but several deliveries. Rebracketing a triple of compatible routes is the span associator. The pentagon holds because both rebracketings preserve the underlying four-tuple. A prefix intercepted by the outer multiplexer requires stepping its decoder before applying this fixed-route calculation. Bénabou, Introduction to bicategories
For a projection $U$ forgetting views, client bookkeeping is erasable on a schedule if each such step preserves $U$, and every remaining event has core-dependent enabledness and a deterministic projected update commuting with $U$. Induction deletes the bookkeeping and preserves the final projected state. A resize caused by attachment can reach the application, breaking the first hypothesis.
A translation between execution 2-categories sends states to states, generating events to paths, and generating swaps to invertible comparisons. It extends uniquely to a strict 2-functor exactly when the assignments respect the defining equations, since composition and pasting then descend to the quotient. Translating two independent events to writes to a shared visible ordered log can give different target states, preventing a comparison cell.
- GNU Screen. Start with one visible region displaying one of two live shell windows. Split the region, focus the new blank region, select the other existing window, then remove its region. The pairs (visible regions, live shell endpoints) run $(1,2),(2,2),(2,2),(1,2)$. An ordinary tmux shell split increases both visible pane and endpoint counts. A translation identifying the two split commands fails the endpoint-count test. Screen manual, Regions
- Zellij. Start two clients focused on $p$, disable synchronized input, move the first to $q$, then type through the second. With independent focus the second can still reach $p$. With mirrored focus it reaches $q$. Independent choices live in $P^2$, shared choices in its diagonal. Separately, session resurrection can rebuild a layout and reoffer recorded commands for execution. A program can retain a secret bit in memory after reading it with echo disabled, clear its display, and later answer a query. Identical saved layout, invocation, viewport, and scrollback for both bits cannot determine both future answers. Live reattachment supplies a different continuity guarantee. Zellij options · Resurrection
- dtach. Have one client receive an output marker, detach it, and attach a fresh terminal with redraw disabled while the application remains silent. The computation survives and the relay supplies no retained emulator grid to replay that marker. Thus live workload continuity alone does not ensure recovery of the old image. dtach project and manual
Reproducibility and authorship
Two fresh Linux guest boots ran an unmodified Debian tmux 3.5a-3 executable. Two different sessions exposed one pane with the same initial process ID within each run. Selecting the other window in the first session moved both of its control clients and left the second session's client on its prior window. A gated shell produced new output after all three control clients detached. Reattachment showed the same pane, process ID, and captured lines. Removing one link left the other operational. Reversing two renames on distinct windows preserved the final name pair. Reversing them through aliases changed the final name. An echo-disabled fixture gave one acknowledgment for one delivery to the distinct recipient and two when both aliases were traversed. Three focus interventions gave $100,010,001$. Projecting the first two rows on the prescribed overlapping charts gave an unrealizable amalgam $110$. The two runs' records differed only by the OS-assigned PID.
Separately, a Linux canonical-mode PTY withheld the three bytes of 'abc' until a newline, and changing a controlling PTY to 37 rows by 101 columns delivered SIGWINCH to its foreground child. The finite marker diagnostic recovered all 5,295 partitions on one through eight handles, with maximum write counts zero through seven. The scripts and recorded results accompany the full paper. GNU Screen, Zellij, and dtach comparisons derive from the cited manuals. The general bounds follow from the proofs.
This anonymous manuscript was developed with OpenAI Codex assistance in mathematical drafting, literature review, and computational checks. Responsibility for the statements, citations, and limitations rests with the submitting author.