Skip to content

fix(pi): read the context window from the pane's own PI_CODING_AGENT_DIR - #1899

Merged
devswha merged 2 commits into
mainfrom
fix/pi-context-window-pane-agent-dir
Oct 24, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/pi-context-window-pane-agent-dir

Conversation

@devswha

@devswha devswha commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

What this fixes

On Linux, a pi pane started with its own PI_CODING_AGENT_DIR now draws its context ring against the windows in that directory's model catalogs (models.json, commandcode-models.json, models-store.json). Before, the window came from the catalogs of the server's own PI_CODING_AGENT_DIR, while the transcript itself was already found through the pane's pi process. A pi started with another agent directory showed the server's numbers, or none.

Fixes #1474

How

  • piTranscriptPath (server/pi.ts) returns the agent directory of the same pi process whose session store it resolved: the server's piAgentDir() when no pi process was identified (or its environment cannot be read), and none when the pane's pi processes name different directories. It follows pi's own normalizer: ~ against the process's HOME, a file:// URL decoded, a relative path against the process's cwd, and two names of one directory through a symlink are one directory.
  • The conversation reader passes it down transcriptPage -> liveTurns -> parseConversationMetadata -> piContextWindow. The page cache signature and the settled-turns reuse include it, so a pi restarted with another agent directory gets a new answer and version.
  • Second item of the issue: a new test hands the catalog reader a FIFO directly (as one swapped in after the stat would be), in a child process, so the non-blocking open and the descriptor's regular-file check are covered, not only the stat in front of them.

When the pane's profile cannot be told (no pi process identified, or its environment unreadable, as always on macOS and Windows), the server's catalogs are used only when the session sits in the store inside the server's own agent directory, which that profile wrote. A store shared through PI_CODING_AGENT_SESSION_DIR says nothing of the pane's profile, so no ring is drawn there rather than the server's number (the merge pass's gate review, 1ba532c).

Verification

  • server/pi.contract.test.ts on the isolated herdr (real pane, real HTTP): a pi pane whose profile's models.json states 400000 while the server's states 200000. On origin/main the new assertion fails (window: 200000); with this change 10/10 pass.
  • Unit: server/pi.test.ts, server/pi-models.test.ts, server/conversation-metadata.test.ts (61 pass with the cache test). Mutations each fail a test: ignoring the pane's dir, dropping the dir from the page signature, dropping the settled-turns check, not passing it through transcriptPage, not decoding file://, not resolving symlinks, and opening the catalog blocking (the FIFO child is killed at 10 s and the test fails).
  • bun run check fast: pass (6396 unit tests, typecheck, build; an earlier run failed only on the host's inotify limit in server/shell-agent.test.ts, which the lead freed)

Reviews

  • omo-native-code-reviewer: approve; LOW items fixed (unit coverage for the cache and pass-through, symlinked dirs, "Linux only" wording).
  • Codex (gpt-6.1-sol, xhigh): fixed the file:// URL and symlink findings. Declined: on POSIX, a pane with no HOME but a USERPROFILE expands ~ against USERPROFILE. That is the rule the session store already uses (pinned by pi.test.ts), so the catalogs and the transcript keep resolving from the same home.

Pre-existing, not changed here: editing a catalog file alone does not change the page signature, so a new window shows once the transcript next changes.

The chat's context ring for a pi pane looked its model's window up in the
catalogs of the server's own PI_CODING_AGENT_DIR, while the transcript
itself was already found through the pane's pi process environment. A pi
started with another agent directory got the server's numbers.

piTranscriptPath now returns the agent directory of the same pi process
whose store it resolved (the server's when no pi process was identified,
none when the pane's pi processes name different ones), and the
conversation reader passes it down to the metadata parser. Cached pages
and settled turns are keyed on it too.

A new test hands the catalog reader a FIFO, as one swapped in after the
stat would be, in a child process, so the non-blocking open and the
descriptor check are covered rather than the stat in front of them.

Fixes #1474
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between b04e1be and 1ba532c.

Files selected for processing: 9
  • changelog.d/pi-context-window-pane-agent-dir.md
  • server/conversation-metadata.test.ts
  • server/conversation-metadata.ts
  • server/conversation.ts
  • server/pi-models.test.ts
  • server/pi-models.ts
  • server/pi.contract.test.ts
  • server/pi.test.ts
  • server/pi.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass gate review of 758802a: one point to settle. It is not a regression, but the gate held on it.

When the pane's pi process environment can't be read, the ring falls back to the bridge's own catalogs, which can be wrong (server/pi.ts:116,175,198). The gate reproduced it with separate agent directories and one shared session store:

  • With the environment readable, the ring shows the pane's own window, 400000.
  • Make that environment unreadable, and the same transcript shows the bridge's window, 200000.
  • When no pi process is identified, the result is the same.

This matches what the PR describes, and it is how the ring worked before, so it is no regression. But a number the pane doesn't own is worse than no number. Please pick one:

  1. Show no window when the catalog's owner is unknown: an unreadable environment, or no process identified. Keep the transcript lookup as it is. This is what the merge pass recommends.
  2. Keep the fallback on purpose: say so in the PR description, with the reason, for example that most panes run as the bridge's own user with the bridge's own agent dir. The merge pass then merges on that.

Holds

  • 71 tests pass.
  • A wrong-directory mutant is caught: the test expects 400000 and gets 215000.
  • When the pane's processes name different directories, no window is shown.
  • ~, file:// and relative-path handling match the installed pi 0.86.0.

The merge pass's gate review: when the pane's pi environment cannot be
read (or no pi process is identified), the ring fell back to the
server's own catalogs. With separate agent directories sharing one
session store through PI_CODING_AGENT_SESSION_DIR, that showed the
server's window for a pane on another profile.

In that case the transcript lookup only accepts a session from the
server's own store, so the server's agent directory is the pane's
exactly when that store is the one inside it. The window now comes
from there only then, and is unknown (no ring) otherwise. A pane that
writes into the server's own profile keeps its ring, including on
macOS, where no process environment can be read.
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Thanks for the gate review. Settled with option 1, made precise, in 1ba532c:

  • When the pane's pi environment cannot be read, or no pi process is identified, the transcript lookup only accepts a session from the server's own store. So the server's agent directory is the pane's exactly when that store is the one inside it (realpath(<server agent dir>/sessions)). The window now comes from there only in that case. Otherwise it is unknown and no ring is drawn.
  • Your reproduction (separate agent directories, one store shared through PI_CODING_AGENT_SESSION_DIR, unreadable environment) now gives no window instead of the server's 200000.
  • A pi pane that writes into the server's own profile keeps its ring, including on macOS, where no process environment can be read.

Verification:

  • server/pi.test.ts: unreadable environment with a shared store gives agentDir: null; the store inside the server's agent dir gives that dir, both with and without an identified process. Replacing the rule with "always the server's dir" fails 2 tests.
  • server/pi.contract.test.ts (isolated herdr, HTTP): the shared store answers window: null, and the server's own store answers its catalog's 200000. 10/10 pass.
  • bun run check fast: pass (6396 unit tests, typecheck, build).
  • The changelog fragment says when no ring is drawn.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work report. Overall: PASSED.

Lane Verdict Confidence
Gate review of 758802a (another model; programming + remove-ai-slops applied directly) REJECT: an unreadable pi environment fell back to the bridge's catalogs HIGH
Merge pass re-check of 1ba532c (the fix) PASS -

The fix in 1ba532c takes the merge pass's recommended option.

  • When no pi process could be read (none was identified, or its environment is unreadable), the bridge's agent directory is used only when the session's store is the one inside that directory.
  • A store shared through PI_CODING_AGENT_SESSION_DIR says nothing about the pane's profile, so the ring shows no window.
  • Mutant: with the old fallback to piAgentDir() put back, 2 pi tests fail.
  • The pi, pi-models and conversation-metadata tests pass (61), and so does the typecheck.

Held from the gate

  • When the pane's pi processes name different directories, no window is shown.
  • ~, file:// and relative paths are handled the way pi 0.86.0 handles them.
  • A wrong-directory mutant is caught.

All required checks are green and no review thread is open.

CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it.

@devswha
devswha merged commit 001e8e3 into main Oct 24, 2026
30 of 36 checks passed
@devswha
devswha deleted the fix/pi-context-window-pane-agent-dir branch October 24, 2026 21:07
devswha added a commit that referenced this pull request Oct 25, 2026
## Change

Follow-ups from #1399's review (#1445), for Command Code (`cmd`) panes.
Per item:

- **2, the footer check was strict** (`server/dialogs/cmd.ts`,
`server/dialogs/live.ts`): a permission prompt now gets its card when
its footer wraps (split hint, word or character wrap) or uses the ctrl+e
/ ctrl+y variants. These are the shapes the published `command-code`
1.88.0 renderer draws (read statically from the npm package; the CLI was
never run or logged into). A stale or incomplete footer, or anything
drawn below it, still gives no card. Normal status chrome is hidden
while a permission dialog is open, so it cannot sit under the footer.
- **LOW, an ordinary numbered menu was labelled an approval card**: a
menu is an approval card only when its rows are Command Code's own Yes …
No choices, so a theme picker with the same footer is not one.
- **4, herdr's model stuck in the transcript cache**
(`server/conversation.ts`, cmd metadata branch only): the served model
follows the pane's current model, and the ETag changes with it. The
response is a new object, so the cached page is never mutated. herdr's
live model now also replaces a model recorded in the transcript, which
is what the item asks for. This branch is only reached where herdr
reports the pane's Command Code session, which no released herdr does
yet (#1647), so the changelog entry says so.
- **5, store validation copied from `server/pi.ts`**: both now use
`server/transcript-store.ts`. Behaviour is identical, and the old names
are re-exported.
- **6, test gaps**: tests for the cmd metadata branch, for the keys each
answer sends from every cursor position, and for refusing a stale card
over HTTP (409 `prompt_changed`, no keys sent). Session resolution and
the skills source were already covered.
- **LOW**: the unused `CmdTranscriptOptions.home` is removed.

**Not fixed**
- **1, the card id covers everything above the rows**, so a card goes
stale when output above an open dialog redraws, as before. Narrowing the
id to the dialog was tried and reverted: two review rounds showed that
command text (a heredoc) can imitate the dialog's frame, including its
real layout (rule, blank line, heading, subtitle). Then two different
commands got the same id, and a stale card could be answered. Doing this
safely needs Command Code to expose the dialog, or a capture proving a
boundary that command text cannot imitate. A test pins the safe
behaviour.
- **LOW, a multi-line command's title**: left as main draws it, for the
same reason (it would need the same boundary guess).
- **3, the shell's cwd won over the agent's**: already fixed on main by
#1745.
- **LOW, the comment saying the body is part of the id**: it is accurate
with main's id, which covers everything above the rows, the body
included.

Fixes #1445

## Verification

- New tests fail on origin/main and pass here: footer shapes, the Yes/No
menu check, the model and ETag refresh without a transcript append, and
the answer keys. Tests from the reviews are kept as regressions. Heredoc
and indentation changes give different ids, a quoted dialog frame in the
real layout gives different ids, and file-permission card bodies equal
main's. The stale-card route test gets 409 with no keys sent.
- Single-file runs after the rebase onto main: `server/cmd.test.ts` 56
pass, `server/prompt.test.ts` 357 pass,
`server/cmd-conversation.test.ts` 2 pass, `server/pi.test.ts` 31 pass,
`server/dialogs/registry.test.ts` 55 pass,
`server/dialogs/interaction-plan.test.ts` 23 pass,
`server/dialogs/claude.test.ts` 13 pass.
- Live check over HTTP, against a real headless herdr session of its own
(not a fake socket) and the server's `/api/pane/prompt` routes. A pane
reported as `cmd` drew Command Code's shell permission dialog at 80
columns, where the terminal wraps the footer mid-word (`… bypass all
perm` / `issions (Docs ↗)`):
- this branch: an approval card with Yes / Yes, don't ask again / No.
origin/main: only the generic fallback card (↑ ↓ Enter Esc).
- a theme picker with the same footer: this branch gives the generic
menu card; origin/main labels it an approval card titled "Theme".
- a line redrawn above the open dialog gives a new id; answering the old
id gets 409 `prompt_changed` and no byte reaches the pane; answering the
new id sends only Enter.
- Reviews:
- Round 1: omo-native-code-reviewer and Codex (gpt-6.1-sol, xhigh) each
found a HIGH in the narrowed card id (a heredoc hiding the command
prefix).
- Round 2: both found more ways around the narrowing, and file cards
showing the whole screen. That led to restoring main's id.
  - Round 3: both APPROVE with no HIGH or MEDIUM.
- After the rebase (one import conflict in `server/pi.ts`, where main's
#1899 added `fileURLToPath`): Codex (gpt-6.1-sol, xhigh) reviewed the
rebase against the new main (#1899's store and agent directory code,
#1893's cache ordering, #1890's dialog reader order) and APPROVED with
no findings.
- `bun run check fast` on this head: workflow syntax, generated types
and themes, typecheck, build and unit tests ok (6800 pass, 0 fail, 13
skip).

---------

Co-authored-by: mp <mp@local>
devswha added a commit that referenced this pull request Oct 25, 2026
…e pinned, and pi sessions over 16 MiB (#1936)

Fixes #1544
Fixes #1549
Fixes #1487

Follow-ups to the command outcomes (#1543, #1450) that Chat shows under
a command it sent. Seven commits: one per issue, the changelog fragment,
two rounds of review fixes, and a Hermes test brought up to date with
the shared snapshot.

## What changes for the user

- **#1487: pi sessions over 16 MiB.** A command sent from Chat to a pi
session larger than the 16 MiB window now shows its result. Before, it
stayed "Accepted" until "No result seen" whenever pi kept writing. The
first entry in a cut window was counted as a branch point, so almost
every append changed the transcript's identity, and each send bound to
the old identity was skipped from then on. On an append, the branch read
before is now kept while the new path runs on from its last entry with
no fork after it. That last entry may sit on the path or just before the
window's first entry. Any other append, such as a `/tree` switch or a
fork made since, names the branch afresh, as before.
- **#1487: cheaper changed polls.** A changed poll still checks every
byte the cached and new reads share; `validates the full overlapping
tail within budget when the window slides` pins that check against
in-place rewrites. Three things changed:
  - The check no longer sha256-hashes both sides.
- The window starts on a 64 KiB boundary, and the cache keeps an xxHash3
digest of each chunk instead of up to four raw 16 MiB windows.
- The read buffer is no longer zeroed first; a short read still gives
up.

With four 33 MiB pi transcripts cached, the memory held went from about
190 MiB to 65-95 MiB. On 33 MiB with 16 KiB appends, a changed poll's
median went from 34-49 ms on origin/main to 10-20 ms (busy host, 3 runs
each). Reading only the appended bytes would drop that pinned
full-overlap check, so it is left for #1879, with the rest of #1487's
low items.
- **#1544: herdr calls per poll.** While a command waits for its result,
each `GET /api/pane/prompt` poll of a Claude pane asked herdr for
`pane.process_info` up to four times and for `session.snapshot` twice.
The poll now reads the processes once and hands that answer and its
snapshot to the transcript lookup (Claude, pi, devin, unlabelled panes,
and the OmO check). A read that fails is no answer, so the lookup then
asks herdr itself as before; a `claude attach` client still leads to its
job's session. The Codex, omp, gjc and OmO store lookups still read on
their own, noted in #1879.
- **#1549**:
- Tests at 59 s (row kept) and 61 s (row hidden) after a session change
typed in the terminal now pin `STALE_SESSION_LAG_MS`. The old test
jumped to 11 minutes, so a 5-minute bound also passed. A mutation to 300
s or 30 s fails one of them.
- A send whose agent process could not be matched (native Windows lists
only the shell) now also adopts a session herdr reports under the label
herdr gave the pane at the send. An OmO send therefore keeps its row
when OmO's session appears under herdr's `pi` label.
- `docs/agent-commands.md` now states which session a row belongs to,
plus four limits: the minute is counted when Chat next asks, a
terminal-typed change in a resumed session within it, pid reuse outside
Linux, and repeat ownership trusting herdr's history rows (the F4
items).

## How it was verified

- Each new test fails before its fix and passes after:
  - the method-count test (4 `pane.process_info` calls before);
- the 61 s test, under a 5-minute bound (and the 59 s test under a 30 s
one);
  - the OmO adoption test, without the label;
- the sliding-window, branch-switch, later-fork, leaf-cut and fork-slide
pi tests, and the failed-read `claude attach` test, each against the
commit before its fix.

With the chunk-digest check forced to always match, five rewrite tests
fail, including the pinned one.
- **Real surface:** `server/outcome.contract.test.ts` starts the server,
uses the isolated `ovis-test` herdr and runs a stand-in `claude` in a
real pty. It sends `/context` from Chat over the WebSocket and reads
`GET /api/pane/prompt`. A copy of it counts herdr RPCs during the first
poll after the send: origin/main made 3 `pane.process_info`, 2
`session.snapshot` and 1 `agent.get` calls; this branch makes 1, 1 and
1. The outcome is `result-observed` in both.
- `server/outcome*`, `prompt*`, `conversation*` and `pi*`: 752 pass. The
one exception is `conversation.test.ts` "Devin pane identity > falls
back when the explicit store is inaccessible or malformed", which timed
out at 5.9 s on this busy host. It runs 4.1 s alone on origin/main and
does not touch this change. `bun run check fast` passes.
- **Reviews:** omo-native-code-reviewer and Codex (gpt-6.1-sol, xhigh)
reviewed this.
- Codex's two reproduced MEDIUMs, a branch switch at the cut and a
failed process read, are fixed in "keep a pi branch while the window
slides, and ask again after a failed process read".
- Its re-review found two more MEDIUMs, a fork after the cached leaf and
an append cutting the leaf out. Both are fixed in "carry a pi branch
only past no new fork, and keep chunk digests instead of the window" and
covered by tests.
- A branch that switches away and comes back still loses its send. Codex
reproduced that on the parent commit too, so it is not new here; it is
noted in #1879.
- omo's LOW stays: an OmO pane labelled `claude` while its Claude child
runs could adopt the child's session, which hides the row and never
shows a wrong result.

- **After the rebase onto main** (#1897's `claude attach` options and
#1899's pi agent directory meet this change in
`server/conversation.ts`): Codex reviewed the rebase delta and found
nothing. Its 19 scratch tests confirm that an attach client found
through the shared process read still leads to its job's session and
that pi's store and agent directory resolve the same with and without
the shared read. The live contract QA above was rerun and still counts 1
`pane.process_info`, 1 `session.snapshot` and 1 `agent.get`,
`result-observed`. `bun run check fast` passes on the rebased head.

No HTTP or WebSocket contract, auth or workflow changes.

---------

Co-authored-by: mp <mp@local>
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.

pi context window: use the pane own PI_CODING_AGENT_DIR (#1391 follow-up)

1 participant