Skip to content

chore: implement caching for session lists, details, and chat history with react query - #1479

Merged
harshil-2096 merged 15 commits into
mainfrom
harshil/age-2926-migrate-session-listing-and-chat-page-to
Dec 3, 2026
Merged

harshil-2096 merged 15 commits into
mainfrom
harshil/age-2926-migrate-session-listing-and-chat-page-to

Conversation

@harshil-2096

@harshil-2096 harshil-2096 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Moves the Sessions list, session detail, session history, and share-dialog grants onto React Query. Session caches are scoped per server, so a server swap can't leak another account's data.

What changed

  • Session cache layer: packages/trueforge-ui/src/server/sessionQueries.ts wraps the session server port. Detail uses a 30s staleTime, or 0 while the last turn is running. History is cached by updatedAt version.
  • Invalidation: Detail is invalidated on create/send/cancel turn, rename, and delete. It is also invalidated when a list page shows a newer updatedAt than the cached detail.
  • Server scoping: src/server/queryClient.ts hashes keys with the server scope and rescopes on server swap. A isCurrentScope guard stops a swapped-out server's list result from being cached.
  • Sessions list: src/atoms/agent-details/AgentSessions.tsx uses useInfiniteQuery with keyset pagination. It polls every 30s while any session is running or paused (src/atoms/lib/sessionListPoll.ts). ThreadListContainer.tsx polls only the first page and skips the open thread, whose status comes from the live stream.
  • Detail errors: A failed background refetch keeps the timeline on screen. "Unable to load session" shows only when nothing is loaded.
  • Share dialog: src/hooks/useShareSessionDialog.ts reads grants with useQuery. Permission, invite, and remove are mutations with optimistic updates. Invite responses are merged, not replaced, so a concurrent tenant grant isn't overwritten. Grants are revalidated once no other grant mutation is in flight.
  • Runtime dedupe: packages/assistant-ui-runtime/src/dedupeInflightBySession.ts shares in-flight session loads. It is used by loadSessionSnapshot.ts and useTrueForgeAgentMessages.ts.
  • Removed: src/server/sessionListCache.ts and its test.

Closes AGE-2926

Changes

How was this tested?

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, python/trueforge_sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed

Note

Medium Risk
Touches session loading, caching, and account-switch boundaries across chat, sessions browser, and sharing—incorrect scope handling could leak or stale data, but behavior is heavily covered by new tests.

Overview
Replaces ad-hoc session list caching and local React state with TanStack React Query on the server-scoped query client. Session lists (infinite pagination + live-turn polling), detail, event timelines, and share access grants are cached, invalidated on mutations, and scoped so data from a prior server/account cannot be served after a swap.

The runtime withSessionListCache wrapper is removed in favor of withSessionQueries, which wraps list/detail/history reads and ties cache writes to serverQueryScope. AgentSessions and related shells consume queries directly; failed background refetches keep the last good UI.

Assistant-ui-runtime dedupes in-flight getSession / snapshot loads by server + sessionId (WeakMap), and useTrueForgeAgentMessages keeps the transcript when re-opening a thread but clears it on server change.

Draft catalog exposes modelsSettled so send/composer gating depends only on models (not skills/connectors). Share dialog uses query mutations with optimistic updates and targeted rollback.

Reviewed by Cursor Bugbot for commit 958164e. Bugbot is set up for automated code reviews on this repo. Configure here.

harshil-2096 and others added 3 commits November 24, 2026 16:54
…ession-listing-and-chat-page-to

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	packages/trueforge-ui/src/containers/ThreadContainer.tsx
#	packages/trueforge-ui/src/containers/ThreadListContainer.tsx
…ectors load

The gate and warning waited on the aggregate catalog flags, so a slow skills or MCP request left Send enabled for a saved chat whose model was dropped. Gate on the models query alone via modelsSettled.

Co-authored-by: Cursor <cursoragent@cursor.com>
@harshil-2096
harshil-2096 marked this pull request as ready for review November 30, 2026 12:27
@veria-ai

veria-ai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 3 · PR risk: 0/10

Reviews

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7a9e65b. Configure here.

harshil-2096 and others added 3 commits December 2, 2026 04:12
…to' of github.com:truefoundry/trueforge into harshil/age-2926-migrate-session-listing-and-chat-page-to
@harshil-2096
harshil-2096 enabled auto-merge (squash) December 3, 2026 03:55
@harshil-2096
harshil-2096 merged commit d75ebc1 into main Dec 3, 2026
15 checks passed
@harshil-2096
harshil-2096 deleted the harshil/age-2926-migrate-session-listing-and-chat-page-to branch December 3, 2026 04:01
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