Issue Checklist
Platform
All platforms
Version
latest (main branch)
Bug Description
useUpdateSession uses the global mutate(listKey, ...) from swr to update the session list cache after editing a session. However, useSessions uses useSWRInfinite, which stores its cache under a different internal key format ($inf$ prefix + serialized page key), not the plain listKey string.
This means mutate(listKey, ...) in useUpdateSession never actually updates the SWRInfinite list cache. The UI shows stale session data (e.g., old name after rename) until SWR's automatic revalidation kicks in a few seconds later.
Root cause in code:
// useUpdateSession.ts — uses global mutate with plain string key
mutate<ListAgentSessionsResponse['data']>(
listKey, // ❌ This key doesn't match useSWRInfinite's internal cache key
(prev) => prev?.map((session) => (session.id === result.id ? result : session)) ?? []
)
// useSessions.ts — uses useSWRInfinite, cache key is [base, pageIndex, pageSize]
const getKey = (pageIndex, previousPageData) => {
return [client.getSessionPaths(agentId).base, pageIndex, pageSize]
}
const { mutate } = useSWRInfinite(getKey, fetcher)
Additionally, useUpdateSession waits for the API response before updating the cache (no optimistic update), causing unnecessary UI delay.
Steps To Reproduce
- Open an Agent with multiple sessions
- Double-click a session name to rename it
- Type a new name and press Enter
- Observe: the session name in the sidebar does NOT update immediately
- Wait ~2-3 seconds, the name eventually updates via SWR revalidation
Expected Behavior
The session name should update immediately in the sidebar after editing, without waiting for API response or SWR revalidation.
Relevant Log Output
Additional Context
The fix requires using unstable_serialize from swr/infinite to generate the correct SWRInfinite cache key, and implementing optimistic updates (update UI before API call, rollback on failure).
Issue Checklist
Platform
All platforms
Version
latest (main branch)
Bug Description
useUpdateSessionuses the globalmutate(listKey, ...)fromswrto update the session list cache after editing a session. However,useSessionsusesuseSWRInfinite, which stores its cache under a different internal key format ($inf$prefix + serialized page key), not the plainlistKeystring.This means
mutate(listKey, ...)inuseUpdateSessionnever actually updates the SWRInfinite list cache. The UI shows stale session data (e.g., old name after rename) until SWR's automatic revalidation kicks in a few seconds later.Root cause in code:
Additionally,
useUpdateSessionwaits for the API response before updating the cache (no optimistic update), causing unnecessary UI delay.Steps To Reproduce
Expected Behavior
The session name should update immediately in the sidebar after editing, without waiting for API response or SWR revalidation.
Relevant Log Output
Additional Context
The fix requires using
unstable_serializefromswr/infiniteto generate the correct SWRInfinite cache key, and implementing optimistic updates (update UI before API call, rollback on failure).