Skip to content

fix(app): restore per-session agent selection when switching between sessions - #3475

Open
PriyeshPandey2000 wants to merge 2 commits into
different-ai:devfrom
PriyeshPandey2000:fix/per-session-agent-memory
Open

fix(app): restore per-session agent selection when switching between sessions#3475
PriyeshPandey2000 wants to merge 2 commits into
different-ai:devfrom
PriyeshPandey2000:fix/per-session-agent-memory

Conversation

@PriyeshPandey2000

Copy link
Copy Markdown
Contributor

Summary

  • Agent selection lived in one global slot (local.prefs.selectedAgent) shared by every session, so picking an agent in one conversation overwrote it for all of them
  • Adds session-agent-store.ts, a localStorage store keyed by session ID, mirroring the existing session-model-store.ts
  • session-route.tsx reads/writes the active session's agent; the new-task composer still uses the global pref

Why

  • Returning to a conversation silently changed its agent, so the next message ran under the wrong one
  • Per-session model choice already works this way; agent selection was the outlier

Issue

Scope

  • session-agent-store.ts (new): per-session agent map under openwork.sessionAgents.v1, capped at 200 entries, tolerant of missing or malformed storage
  • session-route.tsx: selectedAgent derives from the active session; setSelectedAgent writes per-session, or to the global pref when no session is selected

Out of scope

  • local.prefs.selectedAgent stays as the new-task composer's source of truth, preserving the reload persistence from #2101
  • New sessions start at the default agent rather than inheriting the composer's choice — session-model-store.ts behaves the same way today, so this keeps the two consistent rather than changing one in a bugfix
  • No server, schema, or sync changes — local UI state only

Testing

Ran

  • pnpm typecheck
  • bun test --isolate tests/ (apps/app unit suite)
  • pnpm test:session-switch
  • pnpm test:sessions
  • pnpm test:health

Result

  • pass/fail: pass
  • if fail, exact files/errors: tests/message-list-loading.test.tsx has 2 failures (Invalid hook call / TypeError: null is not an object (evaluating 'resolveDispatcher().useState') in renderToStringImpl). These are pre-existing on dev — I re-ran that file with this branch's two files reverted to their dev state and got the identical 2 failures, so they are unrelated to this change. Everything else is green: 600 pass in the unit suite, 7/7 steps in test:session-switch, ok: true for test:sessions and test:health.

CI status

  • pass: typecheck, session-switch, sessions, health
  • code-related failures: none from this change
  • external/env/auth blockers: none

Manual verification

  1. Set the build agent on session A and plan on session B
  2. Switch back to session A — the picker shows build (before this change it showed plan)
  3. Reload the app and switch between both sessions — each still restores its own agent
  4. With no session selected, pick an agent in the new-task composer and reload — the choice is restored
  5. Clear a session's agent back to default — the entry is removed and the session falls back to the default agent

…ader comment

The getSessionAgent helper was exported and imported into session-route.tsx
but never called — the send path reads the agent from the render-scope
selectedAgent value instead. Remove the dead export and its import.

Also correct the file header, which claimed sessions without a stored agent
fall back to the global agent preference. They do not: the store simply has
no entry and the session uses the default agent. The global preference is
only read in session-route.tsx when no session is selected.
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-landing Ready Ready Preview, v0 Aug 3, 2026 6:17pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
openwork-diagnostics Skipped Skipped Aug 3, 2026 6:17pm

@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics August 3, 2026 18:15 Inactive
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@PriyeshPandey2000 is attempting to deploy a commit to the Different AI Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Bug]: Chosen agent per session keep being overwritten by the latest chat

1 participant