Skip to content

Match chat sessions to sites by site id instead of path#4131

Open
bcotrim wants to merge 2 commits into
trunkfrom
match-chat-sessions-by-site-id
Open

Match chat sessions to sites by site id instead of path#4131
bcotrim wants to merge 2 commits into
trunkfrom
match-chat-sessions-by-site-id

Conversation

@bcotrim

@bcotrim bcotrim commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Related issues

  • Related to STU-1985 (one slice of the sidebar-redesign split — matching semantics only)

How AI was used in this PR

Claude implemented the change end-to-end from a scoped brief: traced the placement/matching flow, made the code changes, and extended the unit tests. I reviewed the diff via a guided code tour and steered the follow-up (extending id-matching to all call sites through a shared helper).

Proposed Changes

Chat sessions are bound to local sites via placements in ~/.studio/app.json, which have always stored a validated siteId — but the actual matching (sidebar grouping, empty-draft reuse, session header/preview owner lookup, and the main process' owner-server resolution) compared filesystem paths. Since site paths are name-derived and get reused, deleting a site and creating a new one at the same folder made the new site silently inherit the dead site's chat history.

This PR switches matching to the site id, consistent with everything else per-site in app.json (e.g. siteMetadata). All matching now routes through one shared, dependency-free helper (packages/common/ai/sessions/owner-site.ts) used by the renderer, the router, and the main process:

  • A recreated site at the same path starts clean; chats from the deleted site show under Unassigned instead of leaking into the new site.
  • "New chat" no longer reuses an empty draft that belonged to a different (deleted) site at the same path.
  • Session header, dashboard preview, initial-route redirect, and environment switching resolve the owner site by id too, so a stale path can never rebind a session to the wrong site.
  • A session whose owner site no longer exists is orphaned visibly (Unassigned / plain site-name header), never adopted by another site and never dropped.
  • ownerSitePath/ownerSiteName are kept for display, and path matching remains as a defensive fallback for placements written before siteId existed (placements are read from user-editable JSON without schema validation), so no existing chats are dropped.

Testing Instructions

In Agentic UI:

  1. Create a site and start a chat in it — it groups under that site in the sidebar.
  2. Delete the site, then create a new one with the same name (same folder path).
  3. The new site should show "No active chats"; the old chat should appear under Unassigned — previously it leaked into the new site.
  4. Open the old chat from Unassigned — the header shows the stored site name as plain text (no site dropdown), and prompting it does not target the new site.
  5. Draft reuse: open "New chat" for a site twice without prompting — the empty draft is reused. Recreate a site at the same path — the new site gets a fresh draft, not the old site's.
  6. Legacy fallback: remove siteId from one entry in aiSessionPlacements in ~/.studio/app.json — that chat should still group under its site via the path.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

🤖 Generated with Claude Code

@bcotrim bcotrim self-assigned this Jul 8, 2026
@bcotrim bcotrim marked this pull request as ready for review July 10, 2026 11:14
@bcotrim bcotrim requested review from a team, katinthehatsite and youknowriad July 10, 2026 11:14
@youknowriad

Copy link
Copy Markdown
Contributor

In the other PRs, we're deleting the AI sessions when we delete the site, which means the issue being fixed here won't matter anymore. That said, I agree with the change here conceptually, it's better to match the id but my understanding is that this requires a change in the JSONL of the sessions right? In which case, what happens to old sessions?

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.

2 participants