Repository navigation
fix(app): keep a v2 session's snapshot query alive across the routing-status flip on reload - #4797
Conversation
…immediately A freshly created session had no cached snapshot, so deriveSessionRenderModel reported "switching" while the first snapshot round trip ran and the composer disabled Run task. On Daytona that window is ~0.9 s and a click or Enter inside it was silently dropped with the draft intact. Seed the snapshot cache from the create response (stale, so the real fetch still runs as a background refresh).
…ad of wedging A prompt_async answered with 5xx/408 is an uncertain admission (#4635), but the hold it created could never end: the acceptance check treated absence as no evidence, Stop refused while the admission was unknown, and the failure body was dropped, so the person saw a paused composer with no explanation. - Keep the settled response body on PromptAdmissionUnknownError and show it as the session error card right away; the hold still prevents any resend. - readPromptAdmission: after the exact-message GET misses, list the idle conversation; when native lists it without the message the POST is settled and did not admit, so the drain receives admission_rejected and halts like any definite failure (explicit retry only, never an automatic resend). - On release the pending row is removed and the submitted composer is kept as an unsent message to restore; on confirmed acceptance the stale failure card is cleared.
Lexical keeps one empty paragraph in an empty editor, which innerText reports
as "\n". readComposerState now drops that trailing line break so draftText
matches what the person sees; user.see("composer", { text }) already trimmed.
…o e2e/new-session-route-after-reload
…ace-engine-upgrade Since #4577 the sidebar New session controls open the workspace's empty New task composer at once and the session is created by the first send, so waiting for a ses_ route on click never resolves. Re-express the three sidebar steps: the click lands on the empty New task route without a session surface and a prompt-ready composer; the send must land in a session no earlier turn used (same claim shape as bench-openwork-app-v1 in #4738). Palette steps still create their session up front.
The empty New task composer creates its session on submit and hands the prompt over through a scoped auto-send mark. The mark was keyed with the workspace's default endpoint URL (always /opencode), while the session surface under OpenCode v2 routing owns the session as /opencode2, so the lookup missed and the prompt silently vanished: the person landed on an empty new session. Key the mark with the endpoint that created the session (createRouteSessionWithEndpoint), which is the URL the surface will own it under.
The surface mounts under the v1 URL before chat routing resolves; the owned read 404s, parks for its retry, and the routing flip changes the owner while it is in flight. The read rejects with 'Session snapshot owner changed' and the (workspace, session) query never refetches, so the transcript stays empty.
The snapshot query is keyed on (workspace, session) with retry off on the desktop loopback path. When chat routing resolves to /opencode2 after boot (or the draft scope resolves once identity verifies) while the owned read is in flight, the read rejects with 'Session snapshot owner changed' and nothing refetched, leaving the error card over an empty transcript. Cancel the doomed read and refetch under the new owner; a bare invalidate would only join the in-flight promise because the first load has no data yet.
…ad' into e2e/v2-reload-owner-change-race
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Warden review summary — ClearNative findings: 0. Blocking policy matches before consolidation: 0. Full finding text remains in Warden's native checks and review threads. This comment retains only native IDs, severity, skill attribution, and safe locations. Analysis run Reported trigger coverage (not proof of complete repository or context coverage): diff-security-review (15744 ms), confidentiality-review (11267 ms), desktop-den-sync-review (21483 ms). Blockers
Advisories
Needs recheck
Observed review-thread metrics
Thread states are read-only collection snapshots. These metrics are neither lifetime totals nor exact resolution times, and this summary is not clearance authority. |
There was a problem hiding this comment.
Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (ef4c88939b559342467ca163e87b4d3dc3ab5a98). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run
|
Passed · 12/12 tests · 18/18 assertions · 8 images Commit |
|
Second witness for this fix from the Cluster 10 session (#4811): |
Deploying openwork with
|
| Latest commit: |
152974e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c2692762.openwork.pages.dev |
| Branch Preview URL: | https://e2e-v2-reload-owner-change-r.openwork.pages.dev |
There was a problem hiding this comment.
Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (152974edb9c4be952274f2357a511e6201111a44). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run
Resync onto
|
|
Status: CONFLICTING again after dev A fresh |
Resynced with
|
There was a problem hiding this comment.
Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (7af859637899d7bb8442e777cbe9d97ae4248836). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run
Root cause
Out-of-cluster race observed by #4781 (run 1 of
workspace-engine-upgrade, 1 in 3): afterreload()on a v2 session,SessionSurfacemounts under the v1 URL (engineV2ChatRoutingstartsfalseinuse-workspace-route-state.ts), starts the owned snapshot read, and the chat-routing status then flipsopencodeBaseUrlto/opencode2.sessionOwnerchanges,readOwnedSnapshotTargetthrows "Session snapshot owner changed before the local read completed.", and because the snapshot query is keyed only on(workspace, session)withretry: falseon the desktop loopback path, nothing ever refetched: the error card stuck over an empty transcript.draftScopeflipping whendenAuth.verifiedIdentityresolves has the same shape. Triage context:reports/e2e-red-2026-09-09/triage.mdCluster 1 → #4781 "Noticed, not touched".A second wrinkle found while fixing: a bare
invalidateQueriesdoes not help here. TanStack'sQuery.fetchonly honourscancelRefetchwhenstate.data !== undefined; on a first load (exactly the reload case) it joins the doomed in-flight promise instead of cancelling it.What changed
apps/app/src/react-app/domains/session/surface/session-surface.tsx: whensessionOwnerchanges under an unchanged snapshot query key, cancel the in-flight owned read and invalidate/refetch under the new owner. Key-changing navigations (different workspace/session) are untouched: they already fetch through the new key. No change toreadOwnedSnapshotTarget: the owner check still protects against attributing a read to the wrong owner; the surface now reacts to it instead of dying.apps/app/tests/session-snapshot-owner-flip.test.tsx(new): mounts the surface under/opencodein desktop-loopback mode using the realcomposeNativeSessionSnapshotWithRetrywith injected operations (v1 404s, v2 answers) and a parked retry; flips props to/opencode2while the read is parked; asserts the transcript renders from the v2 read, the query issuccess, no "owner changed" text, and endpoints read are exactly[/opencode, /opencode2]. Red on the unmodified surface with exactlyerror: Session snapshot owner changed before the local read completed.and only/opencoderead; green with the fix.This branch is stacked on
origin/e2e/new-session-route-after-reload(#4781, which itself carries #4757) via merge commitef4c88939, becauseworkspace-engine-upgradeonly reaches the reload steps once those land. After #4781 merges the diff reduces to the two commitsec1d2d1c4(test) and9038068bf(fix).Proof (Daytona, single spec,
OPENWORK_EVAL_REFpinned; each sandbox printedsource verified ef4c88939b559342467ca163e87b4d3dc3ab5a98)The race is intermittent, so the spec was run three times at
ef4c88939, sequentially, one spec per run:pnpm evals:e2e workspace-engine-upgrade --daytona{"command":"evals:e2e","lane":"e2e","daytona":true,"placement":"daytona","engine":"legacy","surface":"legacy",…,"passed":1,"failed":0,"skipped":0,"skips":[],"verdict":"passed"}"passed":1,"failed":0,"skipped":0,"verdict":"passed""passed":1,"failed":0,"skipped":0,"verdict":"passed"No "owner changed" text appears in any run log. All six Daytona sandboxes created by these runs were deleted by the runner (verified with
daytona sandbox list).Unit:
bun test --isolate tests/opencode-session-native.test.ts tests/session-error-resilience.test.tsx tests/session-transition-controller.test.ts tests/session-snapshot-owner-flip.test.tsx→ 59 pass / 0 fail.pnpm --filter app typecheckclean (before and after the stack merge).Noticed, not touched
apps/app/tests/composer-editable-on-snapshot-error.test.tsxis already red on cleanorigin/dev(586c4100f): "Platform context is missing" fromuseNativeContextMenu→usePlatformwhen the transcript renders, i.e.SessionSurfacegrew aPlatformProviderrequirement (andWorkspaceRunModeMenuaDesktopConfigProviderone, feat: choose workspace run modes from the composer #4293) without that test being updated. My new test wraps inPlatformProviderand mocks the run-mode menu; the old test needs the same.mock.modulegotcha for anyone writing similar tests: mocking an already-imported module rewires its live bindings, so a mock that calls throughnamespace.fnrecurses into itself and hangsactforever; bind the real function to a const beforemock.module.seed.workspaceadoption trap in theworkspaceEngineUpgradeworld) still stand.