Skip to content

fix(last): under Rex, Pi's last opens the focused session, not the newest in the folder - #156

Merged
backnotprop merged 1 commit into
mainfrom
review/pi-pid-registry
Nov 15, 2026
Merged

backnotprop merged 1 commit into
mainfrom
review/pi-pid-registry

Conversation

@backnotprop

Copy link
Copy Markdown
Contributor

With two Pi sessions in one folder, plannotator-tui last --pid (which the Rex launcher passes) ignored the pid and opened the most recently written transcript, so it could open the other session's reply.

A Pi running our extension already lists its pid and transcript in the Pi link registry. last now uses that entry when the pid matches, and keeps today's newest-in-folder choice otherwise, so Pi users without the extension see no change. The herdr and hc launchers get the same fix, since they pass --pid too.

Reported and diagnosed by @kaushikgopal in #145, credited as co-author.

Tests: a new tests/last.rs case with two fake Pi transcripts in one folder (the other one newer) and a fake registry entry. With the entry's pid it opens the focused session; with an unregistered pid it still opens the newest. It fails on main with the reported bug.

…west in the folder

With two Pi sessions in one folder, `last --pid` ignored the pid and opened the most
recently written transcript. A Pi running our extension lists its pid and transcript in
the Pi link registry; `last` now uses that entry when the pid matches, and keeps the
newest-in-folder choice otherwise.

Reported and diagnosed in #145.

Co-authored-by: KG <[email protected]>
@backnotprop
backnotprop added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 95218e0 Nov 15, 2026
3 checks passed
@backnotprop
backnotprop deleted the review/pi-pid-registry branch November 15, 2026 17:49
backnotprop added a commit to kaushikgopal/plannotator-tui that referenced this pull request Nov 22, 2026
…ocket

Main already has a Pi extension that lists each session in the Pi link
registry, and plannotator#156 uses its pid and transcript for `last --pid`. This
drops the parts of this branch that the registry already covers, and
keeps what it did not:

- Dropped: the second extension in pi/ (its Unix socket server, tests,
  package files), the root package.json, the CI Node jobs, the socket
  reader in rex/pi.rs, and the `--pi-leaf-id` flag that carried its
  answer to the pane. Pi users without our extension keep the folder's
  newest transcript, as on main, instead of an error.
- /tree position: `/tree` moves Pi's leaf in memory and writes nothing
  to the transcript, so `last` showed the reply at the end of the newest
  branch, not the one Pi was on. The extension now writes `leaf` (Pi's
  current entry) and `tip` (the newest entry) into its registry entry,
  and rewrites it on `session_tree`. While the transcript's newest entry
  is still `tip`, `last` reads the branch ending at `leaf`; once Pi has
  appended, the newest entry is the leaf again. This uses this branch's
  branch walk in the hosts crate, with its tests adapted. It applies to
  any Pi transcript a registry entry names, so it also covers `--session`
  from the Herdr and herdr-core launchers.
- Session check before Send: a Rex `last` review of a Pi records the
  session id the registry lists for its pid, and Send refuses when Pi
  has since moved to another session (`/new`, `/resume`) or the entry is
  gone, as this branch's guard did with the socket.
- No guessing for a registered Pi with no saved reply: when the entry
  for the pid has no transcript file yet (a new session before its first
  reply, or `--no-session`), `last` says so instead of opening the
  folder's newest transcript, which belongs to another session.

Tests: hosts tests on the two-branch fixture (moved to the other branch,
moved back along the same branch, appended since, empty, missing,
dangling and cyclic leaves); `tests/last.rs` cases through the binary
with a fake registry entry, by pid and by --session; Rex unit tests for
the session check; and the extension's e2e test (real pi in RPC mode,
fake model) now navigates the tree and checks the entry.

Co-authored-by: KG <[email protected]>
sebastianst pushed a commit to sebastianst/plannotator-tui that referenced this pull request Nov 23, 2026
* fix(rex): select the focused Pi session

* fix(pi): last follows /tree through the link registry, not a second socket

Main already has a Pi extension that lists each session in the Pi link
registry, and plannotator#156 uses its pid and transcript for `last --pid`. This
drops the parts of this branch that the registry already covers, and
keeps what it did not:

- Dropped: the second extension in pi/ (its Unix socket server, tests,
  package files), the root package.json, the CI Node jobs, the socket
  reader in rex/pi.rs, and the `--pi-leaf-id` flag that carried its
  answer to the pane. Pi users without our extension keep the folder's
  newest transcript, as on main, instead of an error.
- /tree position: `/tree` moves Pi's leaf in memory and writes nothing
  to the transcript, so `last` showed the reply at the end of the newest
  branch, not the one Pi was on. The extension now writes `leaf` (Pi's
  current entry) and `tip` (the newest entry) into its registry entry,
  and rewrites it on `session_tree`. While the transcript's newest entry
  is still `tip`, `last` reads the branch ending at `leaf`; once Pi has
  appended, the newest entry is the leaf again. This uses this branch's
  branch walk in the hosts crate, with its tests adapted. It applies to
  any Pi transcript a registry entry names, so it also covers `--session`
  from the Herdr and herdr-core launchers.
- Session check before Send: a Rex `last` review of a Pi records the
  session id the registry lists for its pid, and Send refuses when Pi
  has since moved to another session (`/new`, `/resume`) or the entry is
  gone, as this branch's guard did with the socket.
- No guessing for a registered Pi with no saved reply: when the entry
  for the pid has no transcript file yet (a new session before its first
  reply, or `--no-session`), `last` says so instead of opening the
  folder's newest transcript, which belongs to another session.

Tests: hosts tests on the two-branch fixture (moved to the other branch,
moved back along the same branch, appended since, empty, missing,
dangling and cyclic leaves); `tests/last.rs` cases through the binary
with a fake registry entry, by pid and by --session; Rex unit tests for
the session check; and the extension's e2e test (real pi in RPC mode,
fake model) now navigates the tree and checks the entry.

Co-authored-by: KG <[email protected]>

* fix(pi): trust only a running Pi's own entry; Send refusals copy nothing

Review follow-ups on the registry-based Pi session and tree position:

- The tree position comes from the entry of the pid `last` was given,
  not from whichever entry names the transcript last: two Pis can
  resume one session file, each at its own place. Without a pid (a
  plain --session or the folder), the entry written last.
- An entry counts only when its Pi answers a ping, as the agent picker
  already requires (`live_pi_sessions`, which deletes an entry whose
  port refuses). A crashed Pi's place no longer steers a read, and a
  reused pid no longer gets a stale entry's refusal.
- Clearer messages: a Pi moved with /tree to before its first reply is
  told so instead of "no assistant messages yet", and `pi --no-session`
  is told the session is not being saved.
- Rex Send refusals for a Pi that changed session, or whose link does
  not answer, are `Failed`, not `Unavailable`: nothing is copied and the
  notes stay pending for E (decision 13 as amended). The messages say
  what to do. /fork and /clone stay refused; the spec says why.
- The launcher hands the pane the registry root it found Pi in, and a
  pane that cannot read a registry at all sends without the check.
- The extension reads the session's entries inside its try, and its
  comment says how stale entries are found.
- README: run `plannotator-tui pi install` again after upgrading; the
  binary has no check for an older extension.

Tests: two Pis on one file, a Pi that is gone, --no-session, a move to
before the first reply, `deliver()` against a fake rex and a real
registry for each refusal, and the launcher's pin.

---------

Co-authored-by: Michael Ramos <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant