fix(frontend): inject orchestrator session into cache before navigating#371
Open
i-trytoohard wants to merge 2 commits into
Open
fix(frontend): inject orchestrator session into cache before navigating#371i-trytoohard wants to merge 2 commits into
i-trytoohard wants to merge 2 commits into
Conversation
Fixes #370 — new project creation navigated to the session route before useWorkspaceQuery's cache contained the spawned orchestrator session, leaving SessionView stuck on "Session not found" until the 15s refetchInterval caught up. Root cause: createProject's optimistic setQueryData (adding the workspace with sessions: []) reset dataUpdatedAt, and React Query v5's invalidateQueries swallows refetch errors (refetchQueries does promise.catch(noop)), so a failed refetch left stale sessions: [] in the cache. The global staleTime: 10_000 then suppressed a mount-triggered refetch in SessionView. Fix: after spawnOrchestrator returns the sessionId, optimistically inject the orchestrator session into the workspace's sessions array via updateWorkspaces, then use refetchQueries (forces fresh data ASAP). SessionView can now find the session immediately regardless of refetch timing.
This was referenced Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #370
Summary
New project creation navigated to
/projects/$projectId/sessions/$sessionIdbeforeuseWorkspaceQuery's cache contained the spawned orchestrator session.SessionViewfound no session and showed "Session not found" until the 15srefetchIntervaleventually caught up — confusing UX on every new project.Root cause (3 compounding factors):
createProject's optimisticsetQueryData(adding workspace withsessions: []) resetdataUpdatedAttonow.invalidateQueries→refetchQueriesswallows fetch errors (promise.catch(noop)inqueryClient.js:174), soawait invalidateQueries(...)always resolves — even when the refetch fails (daemon busy during spawn workload: git worktree + provisioning + Zellij runtime). Cache retains stalesessions: [].staleTime: 10_000suppresses the mount-triggered refetch inSessionView's observer, becausedataUpdatedAtwas just reset by the optimistic update.Fix: After
spawnOrchestratorreturns the sessionId, optimistically inject the orchestratorWorkspaceSessioninto the workspace'ssessionsarray viaupdateWorkspaces, then userefetchQueries(forces fresh data ASAP).SessionViewcan now find the session immediately regardless of refetch timing.The backend is not the issue —
Manager.Spawnpersists the session synchronously (manager.go:191); the race is purely in the React Query cache layer.Test