Skip to content

fix(remote): keep host sessions attached to their project group - #2371

Closed
mybolide wants to merge 6 commits into
vastsa:mainfrom
mybolide:fix/remote-project-sidebar-rows
Closed

mybolide wants to merge 6 commits into
vastsa:mainfrom
mybolide:fix/remote-project-sidebar-rows

Conversation

@mybolide

@mybolide mybolide commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2370

Summary

Three defects in the sidebar's host project groups — the project surface
keyed by [hostKey, projectId] instead of a filesystem path — plus the
presentation gaps that made a host group read as a local one:

  1. A host project group had no disclosure and no group-body wrapper, so it
    could not be folded, and its rows sat flush with the header.
  2. .thread-item-source had no CSS rule at all, so the remote source tag was a
    bare flex item with no nowrap: in a narrow sidebar it shrank until its two
    glyph clusters stacked vertically.
  3. Opening a remote conversation moved its row out of the group. Once every row
    had been opened, the group itself disappeared from the sidebar.
  4. Host groups trailed the local project list with no heading and no stable
    order, and their header used the generic button primitive, whose padding and
    centering pulled the chevron off the rail every local group shares.

This pull request is the project-group scope only. The remote model catalog and
context-usage protocol feature was split into #2379 at review request, so this
diff stays landable on its own.

Root cause

host-core stores a session's project_path; RACP exposes a projectId.
apps/pi-host/src/host-operations.ts decorated session/list rows from the
projects table, but the Agent Host resolves the very same session through
createHostSessionPort (packages/host-runtime/src/host-ports.ts) for
session/attach, prompts, and configuration, and that port returned the raw
record. attach.snapshot.session therefore carried no projectId, and Electron
main replaces its cached summary with that snapshot when a conversation opens
(remote-history.read -> racpSessionToSummary). remoteProjectId became
undefined, so the row could no longer be matched to its host project, and the
group vanished once it had no rows left.

Group order had a second, independent cause: groupRemoteProjectSessions
returned the host's session-array order, so the project that was just opened
moved to the top while the retained local list stayed put.

Same session.get record, old code vs this branch:

base:   attach.snapshot.session.projectId = undefined
branch: attach.session.projectId          = "7"
        attach.snapshot.session.projectId = "7"
        workspaceLabel "713Air" arrives in both

Fix

  • packages/host-runtime/src/host-ports.ts — export withProjectIds and
    use it in createHostSessionPort.get, so every consumer of the same session
    reports the same project identity. A record that already carries the RPC field
    is authoritative and costs no lookup, so a host that reports ids pays nothing
    while a path-only host still resolves one. The path lookup is a per-record
    fallback, never a batch-wide override: a mixed page keeps each row's own id,
    and session/list cannot disagree with a single get of the same row.
  • apps/pi-host/src/host-operations.ts — drop the private copy of the
    decoration and reuse the shared helper; its hostError mapping stays.
  • apps/desktop/src/components/remote/RemoteProjectGroups.tsx — rebuild the
    group on the same section/header/body/clip/list structure as a local project
    group, with a chevron, aria-expanded/aria-controls, inert plus
    aria-hidden while folded, and the shared projectCollapsed state so the
    fold survives a restart. The catalog key never reaches openProjectPaths, so
    it cannot resurrect a group after the project is gone. The + action still
    creates a session and is not part of the toggle. The header now uses
    TooltipButton with the sidebar's own sidebar-session-group-title /
    sidebar-session-group-add classes, so the chevron and folder land on the
    same rail as a local group.
  • apps/desktop/src/lib/project-order.ts (new) — the project sort moved out
    of Sidebar.tsx into one helper used by both the local list and the host
    groups, so a host group's position follows the sidebar sort (recent,
    created, oldest, name) instead of session arrival order.
  • apps/desktop/src/components/Sidebar.tsx — host groups are emitted under
    their own Remote heading (data-sidebar-section="remote"), rendered only
    while at least one host group is visible, and rows inside that section no
    longer repeat a per-row Remote badge.
  • apps/desktop/src/styles/sessions.css — give .thread-item-source the
    fixed, single-line, muted badge treatment its neighbours already have, and add
    .sidebar-list-subheader for the second section heading.
  • Specs — 03-runtime/19-remote-agent-control-protocol.md section 5.1
    states the id is stable across session/list, session/get, and the attach
    snapshot; 04-ux/01-ui-ia.md states host groups share the local
    header/disclosure/inset treatment, sit under their own Remote heading, and
    follow the project sort; 06-delivery/e2e/live-and-remote.md E2E-231 expects
    the kept group and the fold.

Tests

Check Result
pnpm --filter @pi-desktop/host-runtime test 189 passed, 3 skipped (23 files)
node --test on the 4 touched desktop test files 38/38 pass
pnpm --filter @pi-desktop/desktop typecheck exit 0
pnpm check:pr-base head contains origin/main (29043af)

New coverage:

  • packages/host-runtime/src/host-ports.test.ts — get() keeps the project id
    for the attach path (session.get + projects.list), leaves a session whose
    project row is gone undecorated, skips the lookup when the record already
    reports an id, keeps each record's own id when the same batch also needs a
    lookup, and reports the same id from a single get and a mixed batch.
  • apps/desktop/test/remote-project-groups.test.mjs — renders the real
    component through the store and locale: header toggle with
    aria-expanded/aria-controls, the body/clip/list wrapper, inert +
    aria-hidden while folded, the + action still reachable on a folded group,
    the fold stored in shared project state without touching
    openProjectPaths, the Remote heading and its single-rail inset, the
    per-row badge being gone inside that section, and every locale naming it.
  • apps/desktop/test/remote-project-session.test.mjs — group order comes from
    the sort mode, so the same two host projects produce the same order whether
    the host lists the opened session first or last.

Not run

  • E2E-231 (live-and-remote.md) is not re-run as an automated suite on this
    head.
    Desktop and host versions must match exactly (HOST_VERSION_MISMATCH
    otherwise). A manual paired-host run on a macOS arm64 host built from the
    pre-split head covered the sidebar behaviour this pull request changes
    (fold, shared rail, Remote section, stable group order, existing sessions
    untouched); the only difference on this head is the mixed-batch id rule,
    which real host-core records never exercise because they carry a path and no
    projectId.
  • pnpm -r --if-present test: the pi-host suite fails on this Windows host at
    both revisions — config.test.ts expects /data, admin-socket.test.ts
    needs a Unix domain socket (ADMIN_UNAVAILABLE), and
    host-operations.test.ts asserts POSIX paths (17 failures, unchanged by this
    branch).
  • The desktop suite's 74 failing cases on Windows are the environment's existing
    failures, not this change: a baseline worktree at 2b279cf ran the same 29
    failing test files and produced exactly the same failure set (set
    difference 0): macOS notarization/signing, POSIX sh and SSH/socket
    transports, D:\ path assertions, Electron window fixtures that time out on
    this host, and one non-ASCII-path module-hook crash.

Scope

host-ports.ts + its tests, apps/pi-host/src/host-operations.ts,
RemoteProjectGroups.tsx, Sidebar.tsx, project-order.ts, sessions.css,
three spec/UX paragraphs. No protocol, persistence, or database change.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the original attach identity defect independently with the production createHostSessionPort: for a path-only session.get record and matching projects.list row, baseline returns projectId: undefined, while this head returns "7". The new renderer tests plus adjacent remote session/project tests pass 24/24; host-ports tests pass 8/8. Diff whitespace check passes, and this head contains current origin/main fad88dd.

One identity-consistency case still needs fixing in withProjectIds before landing:

  • Input records: [{id: "existing", projectId: "authoritative-id", projectPath: "/work/project"}, {id: "legacy", projectPath: "/work/project"}].
  • projects.list returns [{id: 7, path: "/work/project"}].
  • Executing the actual candidate helper returns projectId "7" for BOTH records. The existing authoritative ID is overwritten because the second record triggers the batch lookup and the final map unconditionally replaces any matching path.
  • Calling createHostSessionPort.get for the first record alone preserves "authoritative-id" (no lookup). Thus list and attach can still disagree for the same supported record shape, exactly the invariant this fix is intended to establish. This contradicts the documented rule that an already-reported ID is authoritative.

Please resolve the ID per record as record.projectId ?? pathLookup (using the same presence semantics as needsLookup), retaining the existing ID even when another record requires lookup. Add a mixed-batch regression that checks both the preserved explicit ID and the filled legacy ID, and list/get consistency. No persistence or protocol change is needed.

Live E2E-231 remains NOT RUN; I have not treated these unit/render checks as live paired-host or Electron acceptance. After the identity case is fixed, the matching-revision integration candidate still needs the relevant process/UI acceptance required by AGENTS.md §16. No remote CI checks were reported on this head at review time.

@mybolide mybolide changed the title fix(remote): keep host project groups collapsible and keep opening a session inside its group fix(remote): keep host project groups in their own section and let a remote session use the Host's model catalog Nov 16, 2026

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked head 4f732f9703cbdf8933f83ccc28ed74f9ea7ae71b by executing the actual updated withProjectIds and createHostSessionPort.get. The previous blocker still reproduces unchanged: the mixed batch containing an explicit authoritative-id record plus a path-only record for /work/project returns 7 for both, while get of the explicit record returns authoritative-id. The helper still unconditionally replaces the ID from the path map. Please preserve each record’s existing ID before falling back to the path lookup and add the mixed-batch/list-get regression requested in the previous review.

The new remote model catalog/usage functionality and manual paired-host evidence do not resolve this identity mismatch. Please split the model/usage protocol feature into a separate PR so the project-group identity fix can be validated and landed independently with the smallest coherent scope. No approval or merge on this head; broader landing checks were stopped at the independently reproduced root-cause blocker.

host-core keys a session by its project path, while RACP exposes the
project id. `session/list` decorates its rows from the projects table, but
`session/attach` resolves the same session through `createHostSessionPort`,
which returned the raw record. The attach snapshot therefore carried no
`projectId`, the renderer replaces its cached summary with that snapshot
when a conversation opens, and the session leaves its host project group
for the top-level session list.

Move the decoration into `withProjectIds` in host-runtime so both the
session catalog and the Agent Host port resolve project identity the same
way, and cover it with the attach path in the host-port tests.
A remote project group had no disclosure affordance and no group body
wrapper, so its rows could not be collapsed and every row sat flush with
the header. The session row's source tag had no CSS rule at all, which
left it as a bare shrinking flex item: in a narrow sidebar the two glyphs
folded into a vertical stack instead of reading as a horizontal badge.

Rebuild the host group on the same section/header/body/clip/list structure
as a local project group, reuse the shared `projectCollapsed` state so the
fold survives a restart and never leaks a catalog key into
`openProjectPaths`, and give `.thread-item-source` the fixed, single-line
treatment its neighbours already have.
The decoration added for attach snapshots asked the projects table on every
`session.get`, even when the record already carried the RPC field. That put
an extra host round-trip on the session-open path and broke hosts whose RPC
surface answers sessions but not projects — the desktop production harness
is one, and it started failing on an unexpected `projects.list`.

Only records that carry a path without an id need the lookup now. Nothing
changes for the remote host that motivated the fix: its records report the
path alone, so it still resolves an id, and a reported id stays
authoritative instead of being overwritten by a table read.
The host project group is the one sidebar surface keyed by
`[hostKey, projectId]` instead of a path, so the local group's checks never
reached it. Render the real component through the store and locale and
assert the parts that went missing: a header toggle that owns
`aria-expanded`/`aria-controls`, the body/clip/list wrapper the fold needs,
`inert` plus `aria-hidden` while collapsed, and the new-task action still
reachable on a folded group.

Against the previous component three of the four cases fail, so the suite
holds the shape rather than describing it.
Host-owned groups trailed the local project list with no heading, so a
host project read as a retained local one, and each of its conversations
repeated a "Remote" chip the heading now carries. The group header also
used the generic button primitive, whose padding and centering pulled the
chevron and folder off the rail every local group shares.

Groups now sort through the same project order the local list uses
instead of following whichever host session row arrived first, so opening
a conversation in one host project no longer moves that group above
another.
`withProjectIds` filled every row from the project-path lookup, so one
legacy row on the same page rewrote the id another row had already
reported: the batch returned `7` for a record whose single `get` returned
its own id, and `session/list` could disagree with `session/attach` about
which project a session belongs to.

The lookup is a fallback now, decided with the same presence rule that
decides whether a lookup is needed at all, so a mixed page and a single
read always resolve the same id for the same record.
@mybolide
mybolide force-pushed the fix/remote-project-sidebar-rows branch from 4f732f9 to 0932f9f Compare November 16, 2026 12:05
@mybolide mybolide changed the title fix(remote): keep host project groups in their own section and let a remote session use the Host's model catalog fix(remote): keep host sessions attached to their project group Nov 16, 2026
@mybolide

Copy link
Copy Markdown
Contributor Author

Both points are addressed.

1. The mixed-batch id override is fixed in 0932f9f.

withProjectIds now resolves each record as record.projectId || pathLookup,
using the same presence rule needsLookup already used, so the project-path map
is a per-record fallback and never a batch-wide override. Two regressions pin
it in packages/host-runtime/src/host-ports.test.ts:

  • keeps each record's own project id when the same batch also needs a lookup —
    [{id: "existing", projectId: "authoritative-id", projectPath: "/work/project"}, {id: "legacy", projectPath: "/work/project"}] against a projects.list row
    {id: 7, path: "/work/project"} now yields "authoritative-id" and "7".
  • reports the same project id from a single get and a mixed batch — the list
    path and createHostSessionPort.get for the explicit record both report
    "authoritative-id".

I ran both against the previous head first and they failed with your exact
symptom (expected '7' to be 'authoritative-id'), then fixed the helper.
pnpm --filter @pi-desktop/host-runtime test → 189 passed, 3 skipped;
apps/desktop and packages/host-runtime typecheck exit 0.

2. The model/usage protocol feature is split out into #2379.

This pull request is now the project-group scope only: the attach identity fix
plus the sidebar group disclosure/badge/section/order work that #2370 describes.
Head is 0932f9f, contains origin/main (29043af), and pnpm check:pr-base
passes. The model catalog, session/usage, the new Session fields and spec
§5.8 live in #2379 against the same base, so neither branch depends on the other.

On E2E-231: I have not claimed it as run on this head. A manual paired-host run
on a macOS arm64 Host built from the pre-split head covered the sidebar
behaviour here (fold, shared rail, Remote section, stable group order, existing
sessions untouched). The only behavioural delta introduced by 0932f9f is the
mixed-batch rule, which real host-core records never exercise because they carry
project_path and no projectId. I can rebuild this exact head into a matching
Desktop + Host pair for a fresh live pass if you want that evidence before
merge.

@vastsa

vastsa commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Rechecked 0932f9f with current main e17e5e7 in an isolated integration worktree. The mixed-batch/list-get identity blocker is resolved: production host-port tests pass 10/10, including authoritative ID preservation. Renderer/grouping tests pass 16/16 after building the candidate locale package. The model/usage feature has been split out as requested. Desktop build and diff check pass.

The adjacent Electron remote-mvp-ui acceptance fails at “Backdrop click did not close the dialog”; I ran the same suite on main and reproduced the identical failure, so this is not evidence of a regression in this PR. This suite also does not prove the matching-revision paired-host list → attach → group retention and restart/collapse acceptance required for E2E-231. That process/UI acceptance remains NOT RUN, and there are no remote CI checks on this head. Please provide a runnable matching-revision E2E covering that path (including persisted collapse and stable project ordering) so the now-correct identity fix can be landed with integration evidence. No new source defect is asserted by this comment.

@mybolide

Copy link
Copy Markdown
Contributor Author

Closing in favour of #2394, because #2370 was fixed on main by #2382.

That merge (27ec1a4) already carries the identity rule this branch implemented —
withSessionProjectIds with the authoritative-id fallback the review asked for —
plus the group fold under a remote:: collapse key and the
.thread-item-source nowrap rule. Keeping this pull request open would leave a
second copy of all three, and it no longer applies to main cleanly.

What was still missing after #2382 is the sidebar presentation the report also
described, and that is now #2394: host groups under their own Remote heading,
the same project sort as the local list, and no per-row chip inside that
section.

On the E2E request in your last comment: #2394 runs the paired-host journey at
the head being proposed, against a real pi-desktop-host-core on Windows, and
now asserts the ordering case as well:

ACCEPTANCE PASS: 30/30 checks
PASS group-order-follows-project-sort-not-session-arrival — first=["2","1"] last=["2","1"]
PASS negative-unsorted-arrival-order-would-differ — ["1","2"]

Thanks for the independent reproduction of the mixed-batch defect; that case is
what the main helper now encodes, and the two regressions I added for it are
in packages/host-runtime/src/host-ports.test.ts on main as well.

The remote model catalog and usage report stay in #2379, which is on current
main as well.

@mybolide mybolide closed this Nov 17, 2026
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.

Remote host project groups cannot collapse, stack their source tag, and lose rows after opening a conversation

2 participants