Plan: /ssh says when the directory has a more recent conversation under another name

Closes: #876. Relates to: #842 (two anchors for one remote directory; stays open, the merge is not planned), #839 (the bind mount behind it), #524 (/ssh continues the latest conversation). Branch: feat/ssh-other-anchor-notice. Status: Done (2026-11-21) — as planned, with the errata below; not run: more than 64 anchors, the same machine under another host name

Erratum (2026-11-21): the measured rows. With real processes on both boxes every row of "Measured before merge" held but one prediction: the session file /ssh enters is never byte-equal after, since pi writes to a session it enters; the history not entered is. The time added: nothing measurable on the Linux box (median 504 ms without, 496 with); on the Windows box 14 to 27 ms measured in-process, nearly all of it the read of the other anchor’s history.

Erratum (2026-11-21): a risk the table lacks, found in measurement: reading the other anchor’s history to date it is a local read of its session files, whole, at every /ssh, outside D2’s bound (silent). It is 2 to 5 ms per MiB; 10 to 23 ms for the pairs measured. Stated in ssh.adoc; the read itself is older than this plan and is #877.

Erratum (2026-11-21): the count in Context is corrected by the seat that made it: the host directory holds 17 anchors, both destination spellings among them, so D1’s reach is as stated. latestSession is replaced by lastConversation rather than kept beside it: /ssh was its only caller.

Context

/ssh <destination>:<path> keeps a remote project’s sessions under a local directory, the anchor, named by a hash of the destination and the path as typed (anchorFor in packages/pi-ssh/anchor.ts). One remote directory typed two ways is two anchors and two histories, and /ssh continues only its own.

Counted on the Windows box (2026-11-21, #842): 18 anchors, 13 remote directories, 5 of them with two anchors. In each pair one anchor is luchs with /data/code/X (last written 2026-11-10 to 11-12) and the other bitskrieg@luchs with /home/bitskrieg/code/X (in use). Each idle anchor holds one conversation the sessions in use do not continue. Every pair differs in both the destination’s spelling and the path; in none does the host part differ (luchs in all ten).

The operator was offered three ways and did not choose; he then said to do all the open items. This plan is the one recommended to him: a notice, and nothing moved. Assumption named: warn only.

Design

D1. The other anchors of a host. packages/pi-ssh/anchor.ts gains otherAnchors(agentDir, spec): the anchors beside this one’s in its host directory (remotes/<host>/, the destination’s part after @), each with its remote.json read; this spec’s own anchor, a directory with no record and one with a broken record are left out. At most MAX_OTHER_ANCHORS (64), by name order. It reads local files only.

D2. Which of them are this directory. packages/pi-ssh/commands.ts gains sameDirectoryElsewhere(ws, agentDir, spec, waitMs), called in probe after the mirror is written, on the probe’s own connection. It asks the remote for the identity (device and inode, links followed: Workspace.identity) of this root and of each other anchor’s root, all at once, and keeps the anchors whose identity equals this root’s. A root that is gone, or that this user may not look at, is not kept. The whole is waited for OTHER_ANCHORS_WAIT_MS (2,000 ms); past it the answer is none and ssh.others_failed is logged. One anchor’s call that fails drops that anchor only. CommandDeps gains an optional otherAnchorsWaitMs, the wait, for the tests. probe returns them beside the anchor and the spec.

D3. When it is said. anchor.ts gains lastConversation(anchor, sessionDir): the latest session under an anchor that holds a conversation, with when it was last written (latestSession becomes its path). In open, an anchor from D2 is named only when its last conversation is newer than this anchor’s, or this anchor has none. So the notice appears when the session about to be entered is not the directory’s most recent history, with --new or without, and stops once this anchor’s own history is the newer one. No state is kept for it.

D4. What is said. One warning, before the switch, where the "continuing your last session" notice is given:

pi-ssh: this directory has a more recent conversation under another name: luchs:/data/code/app (last used 2026-11-12). /ssh luchs:/data/code/app continues that one; this session is a separate history.

Several are joined with ; ` in the first sentence and the second names the most recent. `ssh.elsewhere is logged with how many.

D5. Unchanged. How an anchor is named, remote.json, the helper and its protocol, where sessions are filed. No file is moved, renamed or deleted. Only /ssh says it; a session resumed straight into an anchor does not.

Scope

In: packages/pi-ssh/anchor.ts, packages/pi-ssh/commands.ts, packages/pi-ssh/test/anchor.test.ts, packages/pi-ssh/test/session.test.ts, docs/modules/ROOT/pages/ssh.adoc, CHANGELOG.adoc.

Out:

  • One anchor per directory, and moving the five idle histories (#842 as filed). Not planned.

  • The same host under another name (an address, a Host alias): its anchors are in another host directory and are not looked at. 0 of the 5 measured pairs differ this way. Stated in ssh.adoc; a host identity kept in remote.json would cover it and is not built.

  • Telling the five idle histories on the Windows box: the anchors in use there are the newer ones, so D3 says nothing when they are opened. They are listed on #842.

Risks

Risk Mode Mitigation

Another directory is named as this one

fail-open

Kept only on equal device and inode, asked on the connected host (D2). Test: a sibling directory with a newer conversation is not named. A wrong hint moves nothing.

Two machines share a host name, and the other’s recorded path is this directory here

fail-open

Accepted: the hint names a command the operator can read and ignore. Stated in ssh.adoc.

The lookup hangs and /ssh with it

fail-open

Bounded at 2 s, then no notice (D2). Concurrency test: an identity call that never answers; /ssh switches at the bound, says nothing, logs the failure.

A split is missed: another host name, a root this user cannot stat, more than 64 anchors on a host

silent

Stated in ssh.adoc as limits, with the measured count.

The notice at every /ssh to a directory with an old idle anchor

silent

Said only when the other history is the newer one (D3). Test: this anchor’s conversation newer, nothing said.

File times misorder the two histories (an agent directory copied or restored)

silent

Accepted: at most one hint too many or too few; nothing is decided by it.

The notice is lost because the session is replaced right after

silent

Given before the switch, as the existing notice is. Measured with real processes: it is on the RPC stream.

Tests

Unit (anchor.test.ts): otherAnchors lists an anchor of the same host under another destination spelling and another path; leaves out this one, another host’s, a directory with no record, one with a broken record, and a helper’s anchor nested inside an anchor; stops at 64. lastConversation gives the newest session that holds a conversation and its time, and nothing when none does.

Regression, the measured shape (session.test.ts, the real helper over a pipe): a conversation under unit:<a path through a linked parent>, then /ssh dev@unit:<the real path>: the warning with its exact text; the session entered is this anchor’s own; the other anchor’s session file is byte for byte as it was.

Each condition of D2 and D3, same file: this anchor’s conversation the newer one, nothing said; the other anchor with no conversation, nothing; a sibling directory with a newer conversation, nothing; the other anchor’s root deleted on the remote, nothing and /ssh proceeds; --new with a newer other, said.

Concurrency (session.test.ts): an identity call that never answers (the wait injected through CommandDeps), as in the Risks table; one anchor’s identity call rejecting while another’s answers: the second is still named.

Measured before merge, prediction on file first:

  • luchs, real pi processes over RPC, a scratch agent directory, a scratch directory under the repository’s .pi/scratch (one directory, two paths through the real bind mount): /ssh localhost:/data/code/… with a conversation, then /ssh bitskrieg@localhost:/home/bitskrieg/code/…: the notice on the stream; the other order: none.

  • The time the lookup adds to /ssh with 0, 1 and 15 other anchors on the host, locally, and over the Windows box’s real link.

  • The Windows seat: the pi-ssh suite; otherAnchors over a copy of its 18 real anchors names each of the five pairs; if the host name resolves there, one real /ssh to an idle spelling on the copy (predicted: the notice naming the spelling in use) and one to a spelling in use (predicted: none).

Not tested: macOS; a remote with more than 64 anchors.

Delivery

  1. One branch, one MR: D1 to D4 with their tests.

  2. Canonical doc: ssh.adoc, in "Start a remote session" (what the notice means and when it appears) and in "Limitations" (what it does not see).

  3. CHANGELOG, under Unreleased, Added.

  4. node tools/task.mjs validate, full consumer-sim, the measurements above; the Windows rows before merge; MR closing #876, squash off; the merge SHA on it and a line on #842.

  5. Released with the next release, a minor: @gadhs/pi-ssh and @gadhs/pi move.

Edit this page · latest