fix(sandbox): reconcile stale VIRTUAL_MCP cache so preview unsticks w…#4041
Open
Rooseveltfj wants to merge 1 commit into
Open
fix(sandbox): reconcile stale VIRTUAL_MCP cache so preview unsticks w…#4041Rooseveltfj wants to merge 1 commit into
Rooseveltfj wants to merge 1 commit into
Conversation
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.
Problem
When the
sandboxMapentry is written by a path that doesn't resolve a client-sideuseSandboxStartmutation — agent-triggered start, another tab, or an SSE reconnect onto an already-running pod — the cached VIRTUAL_MCP entity stays stale.previewUrlresolves to null even though the dev server reportsrunning, so the preview sticks on "Server is starting…" and the Sections Editor stays inaccessible until a hard refresh re-fetches the entity. This matches the issue's "requires refresh on first open."Root cause
previewUrlis derived only from the React-Query-cached entity (COLLECTION_VIRTUAL_MCP_GET,staleTime 60s, no polling). The SSE stream carriesphasebut neverpreviewUrl, and no cache invalidation is tied to the SSE lifecycle. So any write path that doesn't go through the mutation'sonSuccessleaves the cache stale for up to 60s — exactly the window where a hard refresh "fixes" it.(Slightly narrower than the trigger described in the issue: the stuck state is reproducible whenever the cache is stale with
phase === 'running', not only on first CMS-tab open.)Fix
Adds a stale-cache reconcile in
SandboxLifecycleProvider: when the pod reportsrunningbut the cache still has nopreviewUrl, invalidate the VIRTUAL_MCP query once sopreviewUrlre-resolves. Gated on:phase === 'running'— write is guaranteed landed, avoids re-fetching before the row exists (no early-write race)!previewUrl— warm path untouched, zero regressionshouldAutoStart/shouldSelfHealeffects in the same fileReuses
invalidateVirtualMcpQueries. Touches onlyVIRTUAL_MCPkeys, so no redundant refetch ofdecofile/liveMeta.Interaction with #4034
Consistent.
decofile/metaare gated ondevServerReadyand resolve via the mesh proxy, independent ofpreviewUrl, so they're unaffected. This fix restores thepreviewUrlthat gives the iframe its localsrc— enabling (not conflicting with) #4034's browser-reachable fetch path.Verification
shouldReconcileStaleCache(27 pass): running+null → invalidate; previewUrl present → no-op (warm path); non-running → no-op (no early race); userStopped → no-op; deduped → no loop.main(post-fix(preview): derive sandbox from active thread's provider kind #4025 / fix(sections-editor): fetch desktop preview metadata locally #4034).running), unrelated to this change.Fixes #3482
Summary by cubic
Unsticks the sandbox preview by reconciling a stale
VIRTUAL_MCPcache when the dev server is already running, removing the need to refresh. Fixes #3482.SandboxLifecycleProvider, when SSE reportsphase === 'running'but cachedpreviewUrlis null, invalidateVIRTUAL_MCPqueries once (keyed byvmId:branch:kind) to re-fetch and populate the preview URL.previewUrlexists, not running, or user stopped; dedup resets once the preview is available or on restart. OnlyVIRTUAL_MCPqueries are touched (nodecofile/liveMetarefetch).shouldReconcileStaleCache.Written for commit 81cd1a3. Summary will update on new commits.