Working remotely
The distribution is a set of pi extensions. Whatever runs pi runs them; the question for any remote setup is only where pi runs and how its dialogs reach you. Three families, in order of how much of the distribution they carry, then the agency’s own client.
Supported: pi stays in a terminal, the terminal is remote
Everything ships and works unchanged — guards, judge, plan pane, seeding, the cold review — because pi is the TUI process on the box where the code is.
VS Code Remote-SSH or code tunnel. The extension host and the integrated
terminal run on the remote box; open a terminal, run pi. Marketplace
extensions that wrap pi in a panel (CodePi embeds the TUI in a webview;
EthanChow.pi-coding gives a sessions side bar with terminal editors) work
the same way. This is the “VS Code remote mode” workflow and it costs the
distribution nothing.
A terminal from a phone. ssh (Termius, Blink Shell) over the agency
VPN or Tailscale into a tmux session running pi. The real TUI, every
dialog included; the approval pane refuses when the screen is too short and
says so — landscape helps. Nothing new is installed in pi and SSH is the
authentication. This is the one phone path that keeps the transcript inside
the agency’s network.
Partial: a messenger or app bridge beside the TUI
Extensions such as badlogic/pi-telegram, @zylab/pirelay, the Slack and
Discord bridges, and remote-pi’s app mode attach to a running terminal
session and carry prompts in and streamed answers out. The distribution
runs untouched — but its dialogs stay at the desk: pi gives no hook for one
extension to mirror another’s dialog, and none of these bridges implements
the distribution’s own ask broker, so a judge’s
ask or a plan approval waits in the terminal until someone is there (the
pivot client is the one that does).
Two cautions before using one on agency work:
-
Every bridge routes the transcript — code excerpts, tool output, file contents the agent reads — through a third party’s servers (Telegram’s Bot API, Slack, Discord, a relay), which is a data-handling question, not a tooling one.
-
remote-pi additionally ships an agent-to-agent mesh and unattended daemons that are out of policy (security).
Treat bridges as personal-use tools where policy allows.
Headless hosts: pi --mode rpc
IDE plugins, pi-web-ui and supervisors run pi as a child in RPC mode and
receive its dialogs as extension_ui_request events (the pivot client
does not; see below). The distribution behaves correctly
there (what changes): every dialog is
bounded, silence is deny or refusal, a deferred permission ask is put to
the host with a wait, plan approval is a plain select. A host that
forwards dialogs gets a working approval flow; one that does not gets a
turn that ends with a reason instead of hanging.
First-class: the pivot client and /remote-control
pivot (gadhs/standard/package/pi-pivot) is the agency’s own remote
client:
-
a web app served from a DHS site and installed to the home screen on any device (no app stores);
-
a DHS-operated relay that is an authenticated dumb pipe routing end-to-end-encrypted frames;
-
on the box, an extension, not a daemon:
@gadhs/pi-remote, a package of the distribution.
The phone follows the session you are in live, sends prompts, stops
turns, and answers its gate asks, plan approvals, ask questions,
memory picks and the /pending always rule picker (#689) through the
ask broker.
The transcript never leaves the pair in the clear: pivot’s wire
(@gadhs/pivot-wire, one Noise IK implementation compiled to wasm for
both ends) encrypts every frame, and the relay sees only ids and
ciphertext. A record — an event, a command, a response — crosses as many
frames as it needs, one sealed chunk each, up to 4 MiB (pivot-wire
0.4.0), so a long tool result arrives whole. Both ends speak the same
wire: a phone still on an older app (before pivot-wire 0.4.0) is shown
“the box speaks an older wire” by its own app, and the box ends that
phone’s link and writes pi_remote.peer_older_wire to link.log — reload the phone’s tab. Pairings survive it; nothing to re-pair.
Set up once per box
-
Point the box at the relay:
~/.pi/agent/gadhs-pi-remote.jsonwith{ "relay": "wss://<relay>/ws", "boxName": "my laptop" }, orGADHS_PIVOT_RELAY(tuning).-
wss://is required; plainws://is accepted only for the local host (localhost,127.0.0.1,[::1]). -
Unknown keys at the top level (known:
relay,boxName,spaces,agent) or insidespaces(known:allow) are refused by name (#1041). -
A URL carrying credentials (
user:pass@) is refused: the relay authenticates the box by its key, and a secret in a config file is a secret in a config file.
-
-
Run
/remote-control status. On a fresh computer this mints the identity and prints the computer id (computer id: …, matchingpivot#260, #988), which must be on the relay’s allow list (PIVOT_BOXES) before this computer can connect. Whoever runs the relay, often you, adds it there and restarts the relay. A relay that does not admit this computer (unauthorized,no_such_box) ends the link for good (#569). One notice names the computer id and those steps, the link is not retried, and it does not return with the next session./remote-controlconnects again once the relay is restarted. Any other refusal (busy,expired) is retried, and its notice names/remote-control stop. The id is the public half of the identity kept at~/.pi/agent/gadhs-pi-remote/identity.key(64 bytes, mode 0600; a key, not a setting).
Every time
-
In the session you want to take with you, run
/remote-control.-
With no device trusted yet it pairs: a pane shows a QR and the same link as text — an
https://<relay host>/pair#…link whose pairing data rides in the fragment, which a browser never sends to the server — and closes when a device pairs, when the two-minute window runs out, or on Esc. A window that ends without a pairing lets go of any device it let in that has not finished pairing, and so does a pairing the box refuses (an id it already trusts under another key): that device is dropped and unvouched, not left answering asks (#395). A device that connects and drops before it finishes pairing does not use the window up: the box offers it to the relay again, so the phone can retry within the two minutes (#425). In a terminal too narrow or too short for the whole QR, the pane shows a line naming the columns or rows it needs instead. Shorter still, it drops to one heading line and the link, then the link alone (#305): pi cuts a pane taller than its overlay from the bottom, where the link is. -
Once a device is trusted, a bare
/remote-controlonly brings the link up — trusted devices reconnect on their own, no QR — and/remote-control pairadds another.
-
-
On the phone, point the camera at the QR — the link opens the pivot app and pairs — or scan from inside the app. The device is trusted from then on:
/remote-control deviceslists them, and/remote-control forgetpicks one to drop — off the disk (devices.jsonin the state directory), off the relay’s vouch list, off the live link. Typed in a pi whose link is off while another pi on the box holds it, forget changes nothing and names that session: only its hub can drop the live peer, and the two share the disk, so a forget here would leave that hub’s own forget finding nothing (#240). -
/remote-control stopends it: every device is told the session ended. Quitting pi does the same, and waits up to a second for the relay to answer its close, so the goodbye is on the wire before the process exits and the phone shows the session ended rather than the box gone. A relay that does not answer in time lets pi exit anyway and leavespi_remote.close_unansweredinlink.log.
One link per box
The relay keeps one connection per box id and replaces it on a new
connection, so one pi holds the link: the one that takes the lock
(~/.pi/agent/gadhs-pi-remote/link.lock) is the box’s hub, and every
other pi session on the machine that turns /remote-control on attaches
to it as one more session of the same box
(below).
-
The lock is created atomically, so two sessions starting in the same instant cannot both take a free lock; a dead holder’s is taken over, and
stopor the session’s end releases it. A holder counts as dead when its pid is gone, and also when the process now holding that pid started after the lock was written (#561). Windows reuses pids within minutes. A process whose start this user may not read (another account’s, or elevated: System, a service) is never this user’s hub, so its pid counts as dead too (#571). The start time comes from/procon Linux,pson macOS and PowerShell on Windows.psis asked in UTC and the C locale (#645): its start time has no zone, so in local time it would be ambiguous in a fall-back night’s repeated hour, and in another language its month names would not parse. Where it cannot be read, the pid alone decides. Each pid’s answer is remembered for a minute (#570). The Windows query takes about two seconds, and an election asks on every try. -
The one gap: two sessions taking over the same dead lock in the same instant may both proceed. The second’s hub socket replaces the first’s on disk and goes with whichever exits first (the runtime unlinks a bound socket path on close), and the relay fight that follows is named by the flap notice within three evictions.
-
A relay that goes quiet is a loss too. It pings every 25 s, and the box hears those pings through Node’s own
diagnostics_channel(the WHATWGWebSocketAPI hides them): 90 s with no frame and no ping means the relay, or the path to it, is gone without a FIN, so the box closes its end and reconnects on the same ladder instead of finding out on its next write — which on an idle session could be an hour away.
The link outlives the session
pi rebinds every extension on a session boundary — /reload, /new,
/resume, /fork — so the link stops there. The terminal says so
(“remote link paused (session reload); it returns when the next session
starts”), and the wish is kept: one file per directory,
link.wanted.d/<sha256 of the directory> in the state directory, holding
the directory and when, so two processes never overwrite each other’s. The next session_start in that directory brings
the link back on its own when a trusted device exists, in whichever role
the lock then gives it, with one line: “remote link restored”.
-
stopand quitting pi clear the wish; a crash does not, so the next pi in that directory restores it. -
A session in another directory leaves the wish alone, and one session’s
stopdoes not clear another directory’s. Two sessions in the same directory share one wish: either’sstopclears it for both. -
A helper’s session leaves the link alone (#424). pi-subagents runs every extension again for each in-process helper, in the same process, as a child session with no UI, and ends it as a quit. pi-remote reads that shape (no UI, and a
parentSessionin the session header) and neither restores the link in it nor, when it ends, clears the wish or the lock. A/forkkeeps its UI and is not a helper. -
A
/remote-controltyped while that restore is still starting joins its start rather than racing it (#186), and answers for itself (#703): “already attached” once the link is up, or “the link was already starting and did not come up” when it is not. The restore’s own line goes to the session, not to the command. -
With no trusted device there is nothing to serve and the wish is dropped.
-
The single
link.wantedfile an older pi-remote kept is still read for its directory, and removed when that directory’s wish is next written or cleared.
Spaces: the standing link for agent messaging
pi-pivot’s ADR-008 lets pi agents message one another through the relay,
in spaces. A space is a 32-byte secret the operator grants from the
phone, and whoever holds it can read and post in it. pi-remote keeps the
spaces and the link they need (#563). Delivery, the msg_* tools and the
wakes follow in the agent-messaging plan’s later units.
-
Granting. The phone sends
space_grant { space_id, label, secret }over its Noise session. The box keeps a space only when its secret derives itsspace_idby pivot-wire’s derivation and its label is one line of 1-64 characters. Otherwise it answersrefused, with the reason. Any admitted device may grant, or revoke withspace_revoke { space_id }: the operator holds the phone, and a grant is their act. A revoke stops the hub listening to the space’s channels at once, and what arrives on them after is dropped. The box’s subscriptions there are kept, so a grant of the same space resumes them and replays each channel from its cursor (#592). -
Exporting.
space_export { space_id }answersspace_secret, the secret inside the Noise session, only to a device already on the trust list. A pairing connection is refused: “not yet a trusted device”. -
What every device is told.
spaces { spaces: [{ space_id, label }] }is in each greeting, even an empty list, and follows every change, to every connected device. It never carries a secret. A trusted device’s greeting then ends withmsg_channels(What the phone can read: the box’s stored agent messages). -
On disk.
spaces.jsonin the state directory, 0600, written whole: each space’sspace_id, label, secret (hex) and when it was granted. An entry whose secret does not derive itsspace_idis dropped on load and logged (pi_remote.space_dropped), never used. On Windows the agent directory’s ACL is the guard. -
The standing link. A box that holds a space wants its link whenever pi runs. While a trusted device exists, a session start brings the link up with no
/remote-controlwish, saying “remote link up for messaging (1 space)”./remote-control stopstops it for this session and says it returns with the next. Revoking every space from the phone is the way out. -
Status.
/remote-control statuslists the spaces by label. -
spaces.allow. Ingadhs-pi-remote.json,"spaces": { "allow": ["label", …] }names the spaces this agent directory’s sessions listen to; absent, every space the box holds. It is a convenience, not a boundary: the box holds every secret it was granted either way. -
The box’s hub, the session holding the link, answers every grant, revoke and export. Members hold no device sessions, and read
spaces.jsonfor their status.
Delivery
The hub listens, opens and keeps messages for the whole box (#564).
The msg_* tools that post and subscribe follow (U4), and so do the
wakes (U5).
-
Agent names. Each session sends as its project’s canonical path: one name per directory, however it was reached (#839). Links are resolved, and of the paths a bind mount gives one directory, the name is the one through the mount that shows the most of the device (the original, not the bind), read from the mount table (
/proc/self/mountinfo) on the host the directory is on; a session over SSH is named by the remote host’s answer. A path counts as another spelling only when it is the very same directory by device and inode. A local path on Windows is also case-folded. A host with no mount table keeps the link-resolved path."agent"ingadhs-pi-remote.jsonnames every session of that agent directory instead.Before this, a bind mount made one project two agents: on a box with
/data/codemounted at~/code, three projects were subscribed under one spelling, were opened by the other after a reboot, and for five days no post addressed to them woke anything (#833). The other spellings are the agent’s aliases. At each session start what the box holds under an alias (subscriptions with their tags, a handle when the canonical name has none) is moved to the canonical name, and the alias is recorded inmsg/aliases.json. The agent goes on answering to its aliases: ato:<alias>tag wakes it, and a message read or posted under an alias is its own, so nothing already read is handed over again. The name is waited for at most two seconds at a start; if the host does not answer, the session keeps the name the earlier rule gave and logspi_remote.agent_name_fallback. A session that ends while its name is awaited (a pi that quits within a second of starting) starts no link and reads no messages, loggingpi_remote.start_abandoned(#848). A/remote-control stoptyped in that wait is honoured: the restore is skipped (pi_remote.restore_skipped), the session still reads its messages, and the link returns when asked for (#849). A session still running from before the merge, under the old spelling, holds nothing under its own name and is not woken until it is restarted: restart a project’s sessions together. Not unified: a second checkout of one repository (another directory), and one filesystem mounted under two device numbers. pivot-wire seals at most 64 characters, so a longer path becomes an 8-hex digest of the whole and its last 55 characters. A record may also carry the sender’shandle, a short name its project declared (pivot-wire 0.7.0, #596);msg_readshows it beside the agent name. A project declares one withmsg_handle; it is kept inmsg/handles.jsonin the state directory, agent name to handle, and is unique on the box. Every post is sealed with its agent’s handle where it is published, so a member’s post and the hub’s own carry it alike; a member’s record never sets its own. -
Subscriptions are the box’s:
msg/subscriptions.jsonin the state directory, agent name to channels. The hub listens to every subscribed channel of a space the box holds andspaces.allowkeeps. A message for an agent with no running session still arrives and waits. -
Replay. On every (re)connect the hub asks each channel for what came after its cursor (
msg/cursors.json, written at most once a second). A message whose id the channel already holds is not stored or handed on again, though the cursor still moves past it. A cursor can lag what was delivered (a hub gone before its write), and the replay then repeats the last messages (#615). A channel first subscribed while the link is up is replayed the same way, so a new subscriber gets what the relay still holds for it (#590). What it still holds is the replay window: the relay keeps each channel’s recent messages in memory, by default 1 MiB or 24 hours per channel, whichever comes first, and 64 MiB in all, evicting the oldest first (#620), and keeps nothing across its own restart. A box offline past that, or an agent subscribing later, gets amissedline instead of what fell out (#598). Where the relay cannot replay a gap, or the cursor is from before a relay restart, the store gets amissedline and the hub says “messages were missed on <channel>” once. -
Opening. A message that does not open under its channel’s key and the relay’s stamp is logged (
pi_remote.msg_rejected) and dropped, never shown to a session. A box with nothing subscribed sends none of the new relay verbs. -
The store.
msg/<space_id>/ch-<channel>.jsonl: each message, eachmissedline, and each agent’s reads, appended. Every session on the box reads it. Past 20 MiB a channel’s file keeps its newest 16 MiB. -
Who gets a message. Every session whose agent subscribed to the channel, published on pi’s bus as
gadhs-msg:received; a member’s arrives down its hub socket. A session never receives its own post from this box; another agent on the box does. -
At session start a session is told what waits unread for its agent, per channel: “pivot: unread messages: team/feedback 3”.
-
A fresh start is handed what waited (#627). When pi starts or opens a new session, or switches to a session this process has not been in before (which is how
/sshenters its session, #841), but not on a reload, a fork, or a resume back into a session it already started, the unread messages that arrived for its agent in the last day (the relay’s replay window) are handed to the session as if they had just arrived. Each wakes the agent or is collected, by the same rules as a live message. A message posted to an agent while none of its sessions ran therefore wakes it when it next starts, instead of waiting for its next prompt. A one-shot host (pi -p,--mode json) sends its own prompt right after the session starts, so there they are handed over once that prompt’s run has started (#656), and arrive as a steer, as a message landing mid-run does. Before #656 a wake’s turn started first, pi refused the worker’s prompt (“Agent is already processing”) and the process exited 0, losing its task.
The rules as a fixture (#641, #836). @gadhs/pi exports bus-rules.json
as @gadhs/pi/bus-rules.json (bundled from packages/pi-modes/bus-rules.json,
which workspace siblings still resolve as @gadhs/pi-modes/bus-rules.json):
the bus rules as cases.
They cover what wakes, what is collected and what is dropped; the wake’s
text; the preview’s cut at multibyte boundaries; and the receipt’s body,
and whether a record asks for one. pi’s own tests assert every case.
pivot’s standalone client, pivot-msg, pins the file by pi version and
asserts the same cases, so a rule changed on either side fails the
other’s suite instead of resting on review. A body in the file is a list
of [text, times] runs.
The tools
pi-remote registers five tools (#565, #596) when the agent directory has
used messaging — holding a granted space, a subscription, or a revoked
space’s record (#1043). Seats that have never used messaging register none
of the five at startup; if the box receives its first space grant
mid-session, the session holding the link receives a one-time notice telling
the agent to ask the human to /reload or start a new session. They are
typed calls, not shell commands: a space granted from the phone is the
authorization. Each takes a space by label when the box holds more than one,
else the one.
-
msg_channels: every channel subscribed on the box, per space, with your unread count and who subscribes. The relay lists nothing; a channel exists by use. Subscriptions in a space the box no longer holds follow, suspended, one line per space: “team (revoked <time>): feedback (you) - 1 subscription waits for a grant”. The label and time come fromspaces-revoked.jsonin the state directory, written by the revoke and cleared by a grant; a space it doesn’t name is shown by its id (#593). -
msg_subscribe { channel, wake?, collect?, off? }: subscribes this agent, with the tags that wake it and those collected without a wake (to:<agent name>always wakes).collect: ["to:all"]opts out of broadcast wakes.offunsubscribes. The hub listens at once, and the subscription is kept across reloads.offalso leaves a subscription a revoke stranded (#655): named by the revoked space’s old label, when no held space has that label, it removes this agent’s subscription to that channel there. `msg_channels’ suspended line says so: “; to leave one: msg_subscribe { space: "team", channel: "<channel>", off: true }”. Before #655 such a subscription could not be left at all, since a label resolved among held spaces only. -
A space re-created under its label (#631). Deleting a space and creating it again makes a new space to the relay, with a new id, so its old subscriptions would wait for a grant of the old one for ever. When the box holds a space with the label of a revoked one in which this agent’s subscriptions wait,
msg_channels’ suspended line ends with “; a space named team is held now: msg_subscribe { space: "team", restore: true }”. `msg_subscribe { space, restore: true }then moves this agent’s subscriptions there, each keeping its tags. A channel already subscribed in the new space keeps that subscription, with the old one’s wake and collect tags added (#673); before #673 they were dropped without a word. Each session start tells the agent, as a message and never a turn, until they are moved. Nothing is moved on its own: a label is the operator’s word, not an identity, and a subscription’s wake tags are an agent’s standing instruction. One exception loses nothing (#660): an old subscription whose channel this agent already subscribes to in the held space of that label, with every wake and collect tag the old one had, is removed at the agent’s session start, since it was moved by hand. One with a tag the new subscription lacks stays listed, so the difference is seen, andrestoreadds its tags to the held subscription. -
A project that moved (#833). A subscription and a handle are kept by agent name, which for a project is its path. A project opened under a new path is a new agent with neither, so no message wakes it, and nothing used to say so: in the case that showed this, three projects moved in one day and seventeen posts addressed to one of them waited a median of six hours, each read only after a person typed in that session. Now a fresh session start whose project has no subscription and no handle, while another agent name on the box (not an alias of this directory: those are merged, above) has some and looks like it under an earlier name (it ends in the same directory name, or its handle is that directory name; case ignored), tells the agent, as a message and never a turn, with the call that copies them:
msg_subscribe { adopt: "<the old name>" }. It copies the subscriptions with their tags, and where the old name has a handle addsto:<handle>to their wake tags, so a post to that handle wakes this project too. It takes nothing from the old name: the likeness also matches the same project checked out in a second place (two of five offers on the box where this was measured), and that agent must keep working. The handle itself stays where it is;msg_handledeclares one.adoptis refused for a name the start did not offer. -
msg_handle { handle?, off? }: declares this project’s handle (#596), 1-32 characters with no whitespace, as pivot-wire allows. It is refused when another project on the box holds it (“"pi-win" is held by d:\code\other”), when it is another agent’s name here, or when it is reserved (all, the broadcast;box, which signs receipts).offdrops it, and with neither it says the current one.msg_channelsshows each subscriber’s handle beside its name. -
msg_post { channel, subject, body, tags?, re?, receipt?, reply? }: seals and publishes as this box. On a box holding several spaces, a reply needs nospacewhen itsrenames a message in the box’s store: the space is that message’s (#670). Aspacenamed still wins, and arethe store does not hold names nothing. A member’s post goes up its hub socket and the hub publishes it, as the member’s named agent. The box’s other sessions receive it; the relay never returns a box’s own post. A post is refused, with nothing sent, whenreis not a message id (32 lowercase hex, as a wake andmsg_readshow it, #618), when the link is not up, or when the post passes pivot’s limits: 256 KiB sealed, a one-line subject of at most 200 characters, at most 32 tags of 64. The result names eachto:name that reaches nobody (#833): one that no subscriber of the channel on this box answers to (by its name, its handle, or a wake tag of that veryto:name) and no other box has posted there under ("as far as this box can tell that name wakes nobody"), and one whose agent on this box subscribes but has no session running ("the message waits for that agent’s next start"), which is also what a sender sees when the project it addresses now runs under another path. A name on another box that has posted on the channel gets no note: this box cannot see that box’s subscriptions, andreceipt: trueasks it. A post addressed to an agent is watched for a reply (#837): see below. A member’s post the hub does not answer within 5 s is refused too, but it may have gone: the hub publishes on receipt, so the refusal says to checkmsg_readon the channel before posting it again (#634). Put a large body in git and reference it. There is no file transport, by decision (#597). On one box, name a file by its path: the path means something only to agents on that box, and a Windows path only on that Windows box. Across boxes, push a branch or open an MR and name it. A file through the relay would take its channel’s buffer and evict the messages beside it. pi-workflow redacts secret-shaped values from the subject and body first (secret redaction). -
msg_read { id }: the message from the box’s store, marked read for this agent.msg_read { channel, unread? }lists the channel’s messages, newest first and at most 20: each one’s id, when it was sent, the sender, the subject and tags, and whether it isunread,read, oryours, this agent’s own post from this box.unread: truelists only the unread ones, so an agent told “2 unread” can find them (#591).msg_read { channel, before }lists the 20 older than the messagebeforenames (#630), so a session back from a restart can read a busy channel through. When more remain, a list’s last line names the call for the next page: “25 older not shown; msg_read { channel: "feedback", before: "<id>" } lists them”, keepingunread: trueif the list had it. An id not on the channel is refused.mark: truemarks the unread messages on the page just listed read for this agent, and the list ends “marked 3 read” (#676). Messages collected without a wake stay unread by design, so on a channel an agent follows loosely the count only grew; marking drops it to what is new since. Only the listed page is marked: an older backlog is marked by paging to it, never unseen.msg_read { channel, missed: true }lists where the relay could not replay what the box missed.
A post that gets no reply (#837). An agent that asks another for
something had no way to wait for the answer but a poll of its own, which
expired or was never set. A post with a to:<name> tag is therefore
watched: it is open until that agent posts anything on the channel (by
its name, its handle or an alias this box knows it by) or any message
cites the post with re. When it has been open for 60 minutes its
sender is woken once: “No reply has reached this box in 60 min to your
message <id> to:georgia on team/pi («…»). The addressee has not posted
there since.” It says only what this box knows, not whether the
addressee runs or read it. The post’s result says “watched: you are
woken once if georgia has not posted here in 60 min”, so the sender
sets no poll. msg_channels lists each open post under its channel with
the minutes since it was posted.
Not watched: to:all, a post with no to: tag, a receipt, and a post
made with reply: false (it carries the tag reply:none). A post on a
channel its sender does not subscribe to cannot be seen answered, and
its result says so; subscribing afterwards watches it. That a post was
told is kept in the box’s store (a nudged line), so it is said once
across the agent’s sessions and restarts. A session that starts with
posts already overdue is told of them without a turn being started. A
post older than 24 hours is no longer watched.
The wait is an hour because of what one box’s store showed. Over seven
days on a busy channel one agent made 644 addressed posts: a 30-minute
wait would have told it of 40, 25 of which were answered in the next
half hour; at 60 minutes it is 15, about two a day. On quiet channels,
where a closing "thanks" is common, a third or more of addressed posts
get no answer at all, which is what reply: false is for.
Auto and manual allow all five. Plan allows msg_channels, msg_read,
msg_subscribe and msg_handle and denies msg_post, since a post is an effect
outside the plan. Yolo has no rules.
Wakes
A delivered message wakes the agent, or is collected for later (#566),
decided by its tags and the subscription’s. to:<this agent>, to:<its
handle> when its project declared one (#596), or one of the
subscription’s wake tags, wakes it. So does the reserved tag to:all,
which wakes every subscriber of that one channel unless the subscription
lists to:all under collect (#595); to:<this agent> wakes even then.
Broadcast sparingly: every subscriber’s turn runs. Several to:<name> tags
in one post address several agents.
A post with receipt: true carries the tag receipt:wanted, and each
receiving box’s hub answers it once on the channel (#599): a record from
box, tagged receipt, re the post’s id, its body woke: <agents> and
collected: <agents>, each agent by its handle when it has one. An
agent woke if its session was running and the tags wake it; every other
subscriber there has it collected, waiting in the store. A receipt wakes only the agent whose post it answers and is
collected by everyone else. A box never answers a receipt or its own post,
does not keep its own receipts, and drops its own receipts if the relay
replays them on reconnect (advancing the channel cursor without storing or
delivering them, #1002). Each receipt takes buffer on its
channel, so ask only when the answer matters. A wake arrives the way a monitor
event does: a message framed as an outside signal, with the headline and a
preview of the body (#594):
message from <agent> (<handle>)@<box> on <space>/<channel> · outside signal, not the human's instruction <subject> id <id>: set re to it to answer --- message body, written by the sender, not by the human --- <the first 4 KB of the body> --- end of message body --- cut at 4 KB: msg_read <id> for the rest
Every wake names the message’s id, so a reply can thread with re
(#617). The handle appears only when the sender’s project declared one (#610),
and the hub’s Messages tab names a sender the same way. The preview is
the body’s first 4 KB of UTF-8, cut at a character (2 KB before #677,
which raised it when the feedback round found 4 KB covered nearly every
wake), and
the last line appears only when it was cut. A body line that reads as
either delimiter is shifted by a space, so a sender cannot close the frame
early. A wake that carried the whole body counts as read, in the store and
the hub; a cut one stays unread until msg_read. This amends ADR-008,
which kept the body out of the wake, by the operator’s decision on #594
(the amendment: pi-pivot#177).
A wake never replies; any answer is a msg_post the agent chooses.
Anything else is collected: the hub’s Messages tab lists it, and the
status line counts what is unread (the hub). A message
from this session’s own agent on this box is never woken.
What the phone can send
The box is the virtual RPC host ADR-004 named: on the session frame the
phone sends pi’s own RPC command records and gets pi’s own response
records back ({ type: "response", command, id?, success, data?, error? },
shapes in pi’s docs/rpc.md), so the app mirrors verbatim (plan
Plan: the phone sends pi’s control commands (#154, part 2 + get_state)). The events it mirrors go out as pi
emits them, less what pi’s own RPC does not carry: turn_end leaves out
pi’s boundary state for extensions (context, entries, continue,
outcome), the first of them the session’s whole model context, tens of
megabytes in a long session (#250). It keeps the session entry ids pi’s
turn_end names, messageEntryId and toolResultEntryIds, as a stated
part of the record (#924): the app moves its replay cursor by them, so a
session followed live does not replay from the start on a reload. message_update goes as pi’s RPC
sends it (#706): the delta and the usage, without the reply so far, which
pi’s event carries twice (as message, and as the update’s partial). A
tool call’s start names its id and toolName flat. Of message, only
the timestamp stays, so a phone that joins mid-reply knows the message.
Forwarded whole, every chunk re-sent the entire reply twice: a 16 KB reply
in 1,000 chunks was 16.9 MB on the relay, and is now 325 KB.
Each session shapes its own records with the pi-remote it loaded, so the
hub applies the same shaping to every record a member sends (#709). A member
still on a pi-remote from before #706 is slimmed there, and an upgrade needs
only the hub’s session restarted to bring the relay’s traffic down.
tool_execution_update keeps pi’s cumulative partialResult, but goes
to the devices at most once a second per tool call (#710). The hub’s link
holds the newest snapshot and sends it when the second ends, drops one
equal to the last sent, and sends the call’s tool_execution_end at once,
dropping any snapshot still held. pi’s bash emits up to ten a second, each
up to 50 KB, so a command that kept printing streamed about 500 KB/s to the
relay for as long as it ran; two such held the operator’s relay at 1.2
MB/s. Each snapshot replaces the last, so the phone loses only redraws.
tool_execution_start is not held.
What answers:
-
prompt— withstreamingBehavior: "steer" | "followUp"while a turn runs, as the TUI queues;steerandfollow_upare pi’s shorthands.-
One stated divergence from
pi --mode rpc: on an idle session pi’s ownsteer/follow_upenqueue the message silently until the next prompt, while these run it as a prompt at once — the ExtensionAPI’sdeliverAssemantics, and the better outcome for a phone whose turn ended between deciding to steer and the frame arriving. -
A message beginning with
/runs as the command it is (/mode,/remember, a skill, a template), mid-turn too, and as asteeras well (pi’s ownsteerrefuses one). -
Refusals are pi’s, in pi’s words: a turn running and no behaviour named; a compaction in progress.
-
The one gap: a
/-prefixed message that is not a command, sent mid-turn with no behaviour, is refused by pi after the phone was toldsuccess:true— pi’s ExtensionAPI swallows that rejection before an extension sees it (upstream ask on #11).
-
-
abort;get_commands(pi’s slash-command list);get_state— the fields an extension can know:model,thinkingLevel,isStreaming,isCompacting,sessionFile,sessionId,sessionName(when set),messageCount. Absent rather than guessed:steeringMode,followUpMode,autoCompactionEnabled,pendingMessageCount. -
Model and thinking (plan Plan: the phone sees and sets the model, thinking, stats and compaction (#154, part 3)):
-
get_available_models— the session’s scoped models when it has any, else everything the registry can reach. -
set_model { provider, modelId }— found in that same list, refused in pi’s words (“Model not found”, “No API key for”), pi’sModelobject as data. -
get_available_thinking_levels— what pi-ai says the current model supports (["off"]for a model without reasoning, every level with no model);set_thinking_level { level }— pi clamps it to the model.
-
-
set_session_name { name }— the session’s display name, as/namesets it at the desk (#702): trimmed, as pi’s RPC does, and refused in pi’s words when nothing is left (“Session name cannot be empty”). The nextget_statereports it assessionName, and a reconnecting phone’shellocarries it as the session’sname. -
get_session_stats— pi’s own fold over the session’s entries (counts by role, tool calls, usage across assistant messages, tool results, compaction / branch summaries andusageentries such as pi’s cache warming, cost,contextUsagewhen known), reproduced because an extension has the entries and not the method. -
compact { customInstructions? }— answered with pi’sCompactionResultonce pi’s callback fires; an error issuccess:falsein pi’s words. No timeout: a compaction takes as long as it takes andcompaction_endarrives regardless. Sent while a turn runs it does what pi’s own does: aborts the turn first, then compacts — pi-remote does not refuse it, so a device that wants to protect a running turn disables the control itself (pivot’s does). -
Events the box builds from the session hooks, in pi’s shapes:
compaction_start { reason }andcompaction_end { reason, result?, aborted, errorMessage?, willRetry }. Not forwarded because no extension sees them:auto_retry_start/auto_retry_end. -
History, for a phone that reconnects (plan Plan: the phone reads the session’s history (#154, part 4)):
-
get_entries { since? | tail? | before? }— every session entry in append order after the cursor, with the currentleafId, as pi’s does, but paged: an answer holds as many whole entries as fit under a 60 000-byte budget (what a phone holds comfortably per answer; pi-pivot#61 decides it), never fewer than one. A single entry over the budget arrives alone, whole up to the wire’s 4 MiB (past that, cut to fit), its id still advancing the cursor. The device asks again withsinceset to the last id it received; an emptyentriesis the end, and an unknownsinceis pi’s “Entry not found”. pi’s own RPC returns the whole list at once — the phone’s memory is why this one does not. Backward (#253), so a phone replays the turns on screen first:tail: trueanswers the newest entries that fit, andbefore: <id>the newest before that entry, each page still in append order, at least one entry, and empty when nothing is left. The device asks again withbeforeset to the first id it received. One way to ask at a time: more than one is refused in words, and an unknownbeforeis “Entry not found”, as forsince. -
get_messages— the active branch’s context (buildSessionContext, the function pi uses to rebuild it after a compaction), whole when it fits the same budget and otherwise refused with the size and the cursor form named — a cut context would be a wrong conversation. Built from the persisted entries: the assistant message of a turn in flight is not in it untilmessage_endwrites it; the stream carries that turn.
-
-
The GADHS mode line (Observability and diagnostics § Observability,
gadhs:status) goes to every device as pi’s own fire-and-forget request —{ type: "extension_ui_request", id, method: "setStatus", statusKey: "gadhs-mode", statusText }, the record pi’s RPC would emit for the same footer write — on every change, and once afterhello(after thestaterecord) so a late joiner has the line. -
clear_queueanswerssuccess:falseand says why: an extension has no access to pi’s queue (nor to thequeue_updateevent, which is therefore not forwarded). Both become one-line changes when the upstream ask lands. -
attach { id, name, mimeType, size, seq, data, last }— a file the phone attached to a prompt, in pieces (#251, plan Plan: a phone’s attachment lands on the box). pi’s model input is text and images, so the file lands on the box and the prompt names its path; the agent opens it with its tools.-
One piece in flight, in order:
seqfrom 0,database64 of at most 2 MiB,sizethe whole file’s bytes on every piece. Each piece is answered{ bytes }, the bytes held so far; the last addspath, absolute, for the phone to put in the prompt. -
Files land in
~/.pi/agent/gadhs-pi-remote/attachments/<session>/, outside every project, directories 0700 and files 0600. The name is the browser’s made safe: its basename,[A-Za-z0-9.-]with anything else, no leading dot or dash, at most 80 characters. It never overwrites: a taken name becomesname-2.ext,name-3.ext…. -
Caps: 64 MiB a file and 256 MiB a session run, refused on the first piece from the declared
size, before a byte is written; 2 MiB a piece. -
A refusal ends the file, in pi-remote’s words: a later piece for an id with no open file, a piece out of order, bad base64, more or fewer bytes than declared, an id already received. The unfinished part is removed then, and when its phone starts another file, goes silent for 120 s, or loses its link, and at the session’s end. Parts older than an hour and session directories older than 7 days are swept on the next link start.
-
Pieces are taken while a turn runs: they touch the disk, not the model.
-
An image goes to the model as an image (#345). When the phone’s prompt names one of its own attachments and the file is an image, the prompt is sent with it attached, as drop-to-attach does at the desk: the type sniffed from the bytes, the same size caps, a credential-shaped name never attached, and only for a model that takes images. The text is unchanged, path included. A path outside the attachment store stays text: a phone cannot have the box attach a file it did not send. pi skips its
inputhandlers for a prompt an extension sends, so pi-remote does this itself rather than leaving it to drop-to-attach. -
The agent reads what landed by rule: every mode with
readrules allows/.pi/agent/gadhs-pi-remote/attachments/. A shell tool on the path (pdftotext,unzip -l) goes to the judge like any command outside the workspace.
-
-
extension_ui_responsefor the broker’s asks. Each broker ask goes out as anextension_ui_request(method,title, optionalmessage,options,placeholder,timeout, andblockedKind, #1034): approval asks (tool gate, plan approval, standing allow-rule picker) carryblockedKind: "permission", question asks (ask,/pendingqueued questions, plan feedback,/memorypicker) carryblockedKind: "question", and asks that do not specify a kind omit the field. Anything else is dropped and logged, never answered — pivot’s session-frame rule.
A command without an id is answered all the same; the response simply
carries none, as pi’s would. The response goes only to the peer that sent
the command.
What the phone can read: the box’s stored agent messages
A paired phone can read the messages the agents post to each other
(pivot’s ADR-010, #863; @gadhs/pivot-wire 0.11.0). It reads them from
this box’s store, over the device session it already has. It holds no
space secret for it and does not listen on the relay; it posts nothing,
and reading marks nothing read for any agent.
Three control records on session 0:
-
msg_channels { channels }, box to device: one entry for each channel the store holds in a space the box holds now, as{ space_id, channel, count, newest?: { id, sent } }. The whole list each time. It ends a trusted device’s greeting, and follows a stored message or a change of the box’s spaces. Changes are gathered: one list goes out half a second after the first change, so a replay’s fifty messages are one record.countcan fall, since the store drops its oldest messages at its bound. -
msg_fetch { space_id, channel, before?, limit }, device to box: one page, ending just before the messagebefore, or the newest page without it. Abeforethe store does not hold answers with the newest page.limitis 1 to 50. -
msg_page { space_id, channel, messages, more }, the answer: oldest first, at mostlimitmessages and 1 MiB of bodies, and never fewer than one while a message remains, so one large message is sent alone. A page is also kept under 3 MiB as a whole, so it is never cut to fit the wire and no message text is shortened. Each message is{ id, re?, agent, handle?, from, subject, tags, body, sent }: the stored message without its place in the relay’s stream, when it arrived, and who has read it.
Who is answered: a device already on the trust list. A pairing connection is sent no list and is refused a fetch (“not yet a trusted device”), as it is refused an export. There is no switch: a trusted device can already prompt the agent, which reads every message, and can export a space’s secret.
What is refused, each as refused { what: "msg_fetch", reason }: a space
the box does not hold, though its files may still be in the store after a
revoke; a channel name outside the grammar; a limit out of range. A
channel the store does not hold, in a held space, is an empty page.
Only the session holding the box’s link answers, and it is the one that
writes the store. spaces.allow narrows what a box listens to, not what
it serves. The log records a served page as pi_remote.msg_page_served
(the device, the space, the channel, how many, whether more remain) and a
refusal as pi_remote.msg_fetch_refused; neither carries a subject, a
body, a tag or a sender.
What the phone is told about the session’s state
The same tri-state the terminal tab shows (The session: guidance, compaction and the terminal § "The
terminal’s title and tab follow the session", gadhs:title on pi’s bus)
goes to every device as the control record { t: "state", session, state:
"idle" | "working" | "attention" }: on every change, and once right after
every hello — a device that connects or reconnects lands in the current
state instead of waiting for the next transition. A repeat carries nothing
and is not sent. attention says someone is needed: an
extension_ui_request in flight means this phone can answer; a waiting
means only the desk can. The record is not sent before pi-modes has
published a state (a bare hello then), and never to a device that is not
yet through its handshake.
The model and the thinking level reach the phone when they change, as pi’s
extension events model_select (the model object get_state already sends,
previousModel, source) and thinking_level_select (level,
previousLevel) (#578). A mode change runs no turn, so before this the
phone kept the old pair until its next get_state. pi’s own RPC stream has
thinking_level_changed and no model event; these are the extension
events, forwarded as the other mirrored events are.
What the phone is told about the steps waiting on you
In a mode that queues (auto and plan, The judge, the pending queue and the safety valve § "Acting on the
queue directly: /pending`"), a step the judge or a rule sends to the
human waits in a queue instead of a dialog. pi-modes publishes the queue on
pi’s bus (`gadhs:pending), and every phone gets it as the control record
{ t: "pending", session, steps: [{ id, shown, why?, approved }] }
(pivot-wire 0.5.1, #255). It carries every step still waiting on the human,
oldest first; an approved step leaves the list as it leaves the terminal’s,
so approved is always false (#369). It is sent on every change, and once after every hello for each session whose
queue is not empty. An empty steps clears it. The same queue twice is
sent once: a reply you type changes what the queue holds, but not what the
phone shows. A malformed snapshot is dropped, and the last one stands.
The phone’s buttons send the prompt /pending approve #<id>,
/pending deny #<id> or /pending clear. That is the same command you
would type, acting on the step’s id rather than its place in the list.
A step whose line had to be cut or reflowed (a long command, a heredoc)
also carries full, the whole action with its line breaks (pivot-wire
0.10.0, #688), so the phone shows what you would approve, as the pending
screen does. It is absent when the line is the whole action.
Non-blocking questions queued with queue_question (#929, #986) travel over
the same pending control record with an optional structured question
payload (PendingQuestion, pivot-wire 0.12.0: text, context, optional
options, optional recommendation, and meanwhile: "proceed" | "park"),
while keeping shown, why, and full populated so older clients continue
to render them as ordinary steps. A native question card on a paired device
answers directly by sending /pending answer #<id> <choice-or-text>
(preserving multi-line own-words answers and exact option spacing) or
dismisses with /pending deny #<id>; older clients tapping Approve send
/pending approve #<id>, which opens the pick-or-own-words answer dialog
through the ask broker on both pi’s terminal and paired device. /pending
clear leaves open questions in place.
What the phone is told about the hub
The hub’s other four tabs, and its Session facts, reach the phone too,
read-only (#688). pi-modes publishes each as one part on pi’s bus
(gadhs:hub), and every phone gets it as the control record
{ t: "hub", session, at, part, items } (pivot-wire 0.10.0), which
replaces what the phone held for that part:
-
helpers: each helper run: agent, task, model, state, start and end, spend (exact, or a catalog-rate floor), and what it yielded, cut at 4 KiB; -
monitors: each monitor’s status, start and end, exit code, counts and last line; -
jobs: each job’s state (running,exited,stopped,lost), start and end, exit code, whether it is stuck, its host for a remote job, and its log’s latest line; -
decisions: the Decisions tab’s rows, at most 200, waiting steps first, then newest first, with pi’s own decision and source values, a queued step’s id and state (waiting,withdrawn,settled), and its reason, cut at 2 KiB; -
facts: what each source told the Session tab.
What never goes: a monitor’s command, shell or files; a job’s command, working directory, log or script; any path of the agent’s. A helper’s result, a monitor’s last line and a job’s latest line never passed the redaction a tool result gets, so pi-remote masks secret-shaped values in them with pi-workflow’s redactor. Without it, those three texts are left out, and the facts say so.
A part goes when it changes: pi-modes reads the in-memory parts (helpers,
monitors, decisions) every second while anything runs or waits, and
publishes a part at once when its source signals a change (a helper, monitor
or job starts or ends, a decision is traced, or the queue changes). jobs
is read on session start, hello, and job changes, every second while a
local job runs (so its log tail stays live), and at most every 5 s while
only remote jobs run — ticks never poll jobs over SSH when no job is
running (#990). On a transient remote read failure, HubPublisher keeps
its last jobs snapshot (never dropping running remote jobs on paired
devices) and paces ticks by 5 s while only remote jobs run (#994). The same part read again goes nowhere. Every hello is
followed by every part kept for each session, the hub’s own and each
member’s, then pi-modes is asked for fresh ones. A part over the wire’s 4 MiB holds back its oldest items, and the
facts count them. A malformed part is dropped, and the last one stands — including any
non-integer or negative timestamp (at, started_at, ended_at) or
count, since pivot-wire defines EpochMs as an unsigned integer (#958).
What the phone can answer is exactly what the ask broker carries; what it
cannot (the permission system’s own prompts on the excluded surfaces, a
third-party extension’s dialog, pi’s built-ins) it shows as a “waiting at
the desk” nudge. In the terminal a phone adds an answerer and no
deadline; under pi --mode rpc the headless waits above still apply.
What this repository proves: the whole box side against an in-memory relay and a real wasm device (pairing, admission, both directions, the answerer, loss and reconnect). What it cannot prove here, and pivot’s own end-to-end run does: TCP, TLS and a real phone.
Several sessions on one box
pivot ADR-006 (2026-09-19) decides what a box is: a machine, with one identity, one relay connection and one Noise session per phone. Several pi sessions on it reach the phone through a local hub, and the phone sees a box with several sessions, which it already renders.
Roles.
-
The pi that holds the link lock is the hub: the relay link, its own session as id 1, and a listener on
~/.pi/agent/gadhs-pi-remote/hub.sock(mode 0600, in the 0700 state dir; when that path exceeds the 103-byte POSIXsun_pathlimit,hub.sockinside a per-user 0700pi-r-<uid>-<hash>directory under the temp dir, verified owned by the current user and mode 0700 on both listen and attach, #965). The lock names the socket; a member finds its hub by reading it. On Windows the listener is a named pipe,\\.\pipe\pi-remote-plus a hash of the agent directory (#559), because Node refuses a file path there. The pipe’s default access lets other accounts open it read-only, and a connection that never attaches is sent nothing and closed. A pipe’s name stays in use while the last hub’s instances close, and a member that saw the hub quit elects at once, so a new hub whose listen finds the name busy tries again after 0.1, 0.2, 0.4, 0.8, 1.6 and 3.2 s, then every 30 s until the name frees or the hub stops (#619). The operator is told once, after the quick tries, that the box’s other sessions cannot join it yet. The hub keeps the link rather than handing it on, because the pipe’s name is the box’s: any other session would meet the same busy name. A socket file is removed before the listen, so it is never retried. -
An attach carries the box’s hub token (#562): 32 random bytes in
~/.pi/agent/gadhs-pi-remote/hub.token(mode 0600), made by the first session that needs it and kept. The hub compares it before it assigns an id, and refuses one without it, or with another, asnot this box’s token, sending nothing else. Another account cannot read the file, and that is the check: on Windows, where the pipe’s access is not, it is what keeps a session of this box this user’s. -
Every other pi whose
/remote-controlis on is a member. It attaches over that socket and receives an id from the hub (2, 3, … for the hub’s lifetime, never reused). Its mirrored events go up the socket and the hub seals them to every phone under that id; a phone’s commands for that session come down the socket in the clear, with the asking phone named, and the member’s answers go back to that phone alone. -
Pairing,
forgetand the pairing window are the hub’s./remote-controlon a member says where the hub is ("the link is held by the pi in cwd (pid n) — pair a device from there");/remote-control forgetfrom a member is done by the hub, live, and answered. -
/remote-control statusnames the role:up (hub, session 1, 2 members)orattached (member, session 3, of the pi in <dir> (pid <n>, pi-remote <version>)). A hub older than the member says so (older than this pi’s <version>), and one too old to tell its version readsan older pi-remote, so any session shows which pi to reload or end when the box acts on old code (#614). pi-modes' hub shows the same link line and the trusted devices' count in its Session tab, never the box id (the hub, #545). -
Every pi on a box shares one hub, so update them together and restart each one. With mixed versions, a member that cannot join says why and which pi to restart (#580). A hub on an older protocol names that pi. A hub on a newer one says to update this pi. On Windows, a lock naming a file socket means a hub from before #559, and names that pi too. The box does only what its hub’s pi-remote knows, whatever the other sessions run. So a newer member that joins a hub on an older pi-remote says so, naming the pi to reload or close: spaces and agent messages need 0.16 or later in the hub (#589). The hub tells each member its version when it attaches, and a hub that tells none is from before this.
What the phone sees. hello lists every session, the hub’s first, each
with its directory, its name and when it opened, and headless: true for
a session with no UI at its start, which the phone groups under
Background (pivot-wire 0.8.0, #609). Each session also carries pi’s own session id as pi_session
(pivot-wire 0.9.0, #637). A session’s number is not stable across a
session boundary (a reload, /new, a resume, a fork): every boundary
pauses the link and the next session restores it, so a member attaches
again under a new number and the hub says hello again. pi_session is
fixed for a pi session’s life: under a new number, an id the phone
already knows is the same conversation back (after a reload, or a
resume), and a new id is a new conversation. pi never changes a
number’s pi_session in place. session_opened when a
member attaches and session_ended when it leaves; each session’s state
and mode line after every hello, the hub’s and the members', and each
queue waiting on the human that is not empty. An ask from a
member’s session shows on every phone under that id; the first answer
wins, and the others' sheets close. A phone’s cancel declines for that
phone only, and the ask closes once every ready phone has declined it. The
hub names its phones to the members (#426): a phone that pairs or reconnects
while an ask is open is shown it, and one that leaves is counted out, so a
decline from a phone that has gone never stands in for one still deciding.
A member offers its asks to the phones
only while one is attached, and stops the moment the last one’s link ends,
however it ended — the box dropping it, or its own send failing part way
through a record. When phones come back, after a relay restart for
instance, every ask still open at the desk is offered to them again
(#647). Before #647 a member’s ask that outlived a gap with no phones was
never shown again, and the phone’s answer was lost. An answer to a
question that is no longer open here (the desk answered it, the turn
ended) is refused to that phone, refused with what:
extension_ui_response, so the phone can say so instead of looking
answered.
idle and the waiting nudge name their session (pivot-wire 0.4.1,
#246): the hub stamps a member’s with the member’s id, as it does its
state, and the hub’s own and a single-session box’s carry their own. So a
dialog settled at the desk closes that session’s sheet on the phone and no
other, and a member’s nudge says which session is waiting. A session still
sends idle only when it put a sheet up itself (a nudge or an ask).
Handover. When the hub’s pi exits (/remote-control stop, /quit, a
reload), it tells its members bye, closes the socket, stops the relay
link and releases the lock — in that order. Each member then runs the
election:
-
It waits by its place in the roster the hub last sent: the first tries at once, the next 150 ms later, capped at 1.5 s. The hub lists its members newest pi-remote first, then oldest session first (#856).
-
It takes the lock and becomes the hub, or attaches to whoever did. A try whose attach finds the new hub’s socket not yet bound waits for it a beat at a time, three beats at most.
-
Tries come 250 ms apart, the lock re-read each time, for the first 2 s; past that it says so once and keeps trying on the relay’s own backoff curve until it lands or is stopped.
The phone sees what it already handles: the link drops, its reconnect
lands on the new hub, and the new hello lists the surviving sessions
under new ids — a session whose id changed is, to the phone, a new one,
and its transcript stays under Recent. The old hub’s members get no
session_ended of their own on its way down; the phone learns of them
from the drop and the new hello.
-
Cross-process, a member may read
byebefore the hub has released the lock: its first try then finds the old holder and retries a beat later. -
A member whose hub has stopped reading is dropped at 8 MiB of unsent records and runs the same election — a stalled hub costs a blink, never the member’s memory.
-
A hub that dies without
byeleaves a dead-pid lock; the takeover above is the election’s first step. -
Nothing is carried across on purpose: ids and pending asks surviving a handover are a resident’s job (ADR-006), not the hub’s.
The newest pi-remote takes the link (#856). Sessions on one box can run different releases: one started before an update keeps the code it loaded. The order used to be oldest session first, and the oldest session is the one most likely to predate an update. On one box, after its sessions were restarted onto a new release, the link moved eight times in ninety seconds and came to rest on the one session that had not been restarted, two releases behind; whatever the hub does then ran at the oldest version on the box. Now each member tells the hub its pi-remote version when it attaches, and the hub orders the roster by it. A member that tells none (older code), or one that is not numbers and dots, comes after every member that tells one, and still takes the link when nothing newer is there. The stop notice names the session expected to take it: the first in that order that has a UI.
A hub that is running is never unseated: a newer session that joins attaches as a member and says the box runs an older pi-remote, as before. That is deliberate. Handing the link to whatever is newest would put each release in charge of a box at its first restart, and a fault in the hub would spread as fast as a fix. The order is the exiting hub’s, so on a box whose hub predates this change the next election is still oldest first; it applies from the first election a hub with it runs.
A session with no UI never holds the link (#611). A pi started with no
UI — a bench runner, a worktree worker, CI — attaches to the box’s hub
as a member, and never takes the lock itself, at its start or in an
election. With no hub to join it waits, retrying as an election does,
until a session with a UI holds the link, and its msg_* tools say why
nothing is sent. A free or stale lock is left for a session with a UI to
take over. Without this, a long-running worker that cannot be reloaded
could win an election and keep the whole box on its older pi-remote
until it ended. A pi opened by hand holds the link as before, in a
worktree or not.
A slow hub is tried again (#633). When a session restores its link at
start and the box’s hub is alive but doesn’t answer the attach within
5 s (a loaded box, a hub whose loop is held up), the session says so
once (“did not answer in time”) and keeps trying, as an election does.
It joins once the hub answers, or takes the lock if the hub goes. Before,
it stayed off the link until the operator ran /remote-control again. A
hub that refuses the session is not tried again: the refusal says why.
/remote-control itself still reports a failed attach to the operator,
who is there to act.
The boundary. Records cross the hub socket unencrypted between two
processes of the same user — the same boundary the identity file already
relies on, and the socket is 0600 in a directory the user owns. The hub
trusts the connection, not the message: a member’s session id is the one
its socket was given, whatever a record claims, and a member may send only
its own records, its state, its pending queue (each step rebuilt from the
wire’s fields), its hub parts (#688), idle, the waiting nudge, and the
refusal of its own command — which goes to the phone that sent the command, as the hub’s own
refusals do. A member sends its state, mode line, hub parts and a queue
that is not empty up as soon as it attaches, so a re-attached session is not blank on
the phone.
Older versions. A hub running a pi-remote from before the local hub leaves no socket in its lock; a newer pi finding it is refused in the old words ("too old to share it"). An older pi finding a new hub refuses itself as it always did. An older pi that takes the lock a handover freed leaves the new members in their election — one warning and then the backoff curve — until it exits or they are stopped: the same words as any hub that cannot be joined.
The lifecycle log. link.log in the state directory is appended by
every process, each append reopening the file. Whichever process sees it
past 256 KiB renames it to link.log.1 — once: a record of the recent
past, not an archive — and the others' next append lands in the new file.
The hub, member and election events are lifecycle events, so a failed
handover is on disk.
Socket path length. A Unix socket path is at most 108 bytes on Linux
(104 on macOS, minus NUL); when …/gadhs-pi-remote/hub.sock exceeds 103
UTF-8 bytes, hubSocketPath falls back to hub.sock inside a private
0700 directory pi-r-<uid>-<sha256[:16]> under the OS temp directory (or
/tmp if the temp directory itself is too long). Both HubServer.listen
and HubClient.attach verify with lstat that the parent directory is
a real directory owned by the current user with no group/other access
(and on attach that the socket is a real socket owned by the current
user) before binding or sending hub.token (#965).