Skip to content

fix(app)/test: a New task after an engine upgrade reload lands on a session route - #4781

Closed
yomgui wants to merge 9 commits into
devfrom
e2e/new-session-route-after-reload
Closed

yomgui wants to merge 9 commits into
devfrom
e2e/new-session-route-after-reload

Conversation

@yomgui

@yomgui yomgui commented Sep 10, 2026

Copy link
Copy Markdown
Member

Root cause

Triage: reports/e2e-red-2026-09-09/triage.md → Cluster 1, workspace-engine-upgrade follow-up from #4757 ("step 2 fails on new session route after the reload — pre-existing since Sep 7, #4577").

Two things, one per commit:

  1. Spec drift (fix(app): open workspace New task without waiting for the engine #4577, Sep 6). The sidebar New session button and the per-workspace plus (onCreateTaskInWorkspace) now open the workspace's empty New task composer immediately (#/workspace/<id>/session) and the session is created by the first send. Three steps of workspace-engine-upgrade still waited for a ses_ route on click; step 2 starts on that very route after reload(), so hash !== previousRoute && includes("/session/ses_") could never resolve. Steps 4 and 5 carried the same stale claim but were never reached. The palette New session option still creates its session up front and was untouched.
  2. Product bug found once step 2 could run (v2 chat routing). With OpenCode v2 routing on, the New task submit created the session and navigated to it, but the prompt never went out: the person landed on an empty new session ("Try one of these"). onCreateTaskWithPrompt keyed the handoff's auto-send mark with endpointForWorkspace(...).opencodeBaseUrl, which is always ${mountedBaseUrl}/opencode (v1), while SessionSurface looks the mark up with sessionOwner built from the URL it actually owns the session under — /opencode2 when v2 routes chats. Keys never matched, so getComposerAutoSendPayload returned null and the submitted prompt was dropped. v1 matched by coincidence, which is why workspace-new-task-hit-target stayed green.

What changed

  • evals/specs/workspace-engine-upgrade.e2e.test.ts: openEmptyNewTask waits for the empty New task route for the target workspace with no [data-session-surface-id] and a prompt-ready composer (composer + Run task); greet now returns the session the send landed in and asserts it is one no earlier turn of the journey used (usedSessionIds, seeded with both fixture sessions) — the same "distinct new session per send" claim shape as bench-openwork-app-v1 in fix(app)/test: list the injected bench provider model in the composer picker #4738. Step 4 performs its opencode2 200 / opencode 404 ownership checks on that session; step 5 additionally asserts the v1 engine owns the session it created. No assertion loosened, no waits added; the 2 s "user row visible" bound is unchanged (the New task composer renders the pending row itself).
  • apps/app/src/react-app/shell/route-workspaces.ts: createRouteSessionWithEndpoint returns the session and the resolved engine endpoint; createRouteSession delegates to it (other callers unchanged).
  • apps/app/src/react-app/shell/session-route.tsx: the New task handoff keys its auto-send with sessionEndpoint.opencodeBaseUrl.

This branch includes origin/e2e/fresh-session-send-gate (#4757) merged in — step 2 is only reachable once step 1's immediate send passes. After #4757 lands the diff reduces to the two commits above (0ad717693, ce0193f66).

Proof (Daytona, single spec, OPENWORK_EVAL_REF pinned; the sandbox printed source verified <sha>)

Placement line: {"command":"evals:e2e","lane":"e2e","daytona":true,"placement":"daytona","engine":"legacy","surface":"legacy",…,"passed":1,"failed":0,"skipped":0,"skips":[],"verdict":"passed"}

run sha pnpm evals:e2e workspace-engine-upgrade --daytona notes
1 0ad717693 (spec only) 0 passed / 1 failed Failed in step 1 (palette chat, not touched here) after reload(): session error card "Session snapshot owner changed before the local read completed." and no transcript — see Noticed.
2 0ad717693 (spec only) 0 passed / 1 failed Step 1 green. Step 2 reached: New session → empty route 74 ms → pending user row 37 ms → ses_ route 575 ms → reply never arrived; screenshot right after the route landed shows the new session empty. This is the product bug above.
3 ce0193f66 1 passed / 0 failed / 0 skipped All 7 steps green. Each of the three empty-New-task sends landed on a fresh session ~530 ms after Run task and survived the reload; both Daytona sandboxes deleted by the runner.

Unit: bun test on route-session-list, task-create-engine-retry, workspace-routes (34 pass); pnpm --filter app typecheck clean.

Warden final review at HEAD ce0193f66 vs origin/dev 7d5097d42 (refs identical before/after): pnpm warden:check exit 0, 4 triggers matched and completed (diff-security-review, confidentiality-review, spec-provenance-review, desktop-den-sync-review), no findings.

Noticed, not touched

…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.
…ssion button

The sidebar button was renamed from "New task" to "New session" in #4491
(Sep 5) and the "new" scenario added in #4631 (Sep 8) still targeted the old
label, so it could never find the button. Same user action, current label.
…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.
@vercel

vercel Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 10, 2026 9:07pm UTC
openwork-den Ready Ready Preview Sep 10, 2026 9:07pm UTC
openwork-diagnostics Ready Ready Preview Sep 10, 2026 9:07pm UTC
openwork-landing Ready Ready Preview, v0 Sep 10, 2026 9:07pm UTC

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Warden review summary — Clear

Native 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 (122201 ms), confidentiality-review (64018 ms), spec-provenance-review (122533 ms), desktop-den-sync-review (176264 ms).

Blockers

  • None.

Advisories

  • None.

Needs recheck

  • None.

Observed review-thread metrics

  • Unique observed run attempts in retained window: 2
  • Distinct heads in retained window: 2
  • Current unresolved Warden threads: 0 of 0 observed
  • Observed resolved/unresolved transitions in retained snapshots: 0 / 0
  • First observed resolved/unresolved (state at first collection, not event time): 0 / 0
  • Precision: unavailable (no adjudications; no TP/FP values are inferred)
  • Observation window: 2/20 run attempts retained; truncated: false
  • Transition snapshot: 0/0 current attributed threads retained (limit 500); truncated: false

Thread states are read-only collection snapshots. These metrics are neither lifetime totals nor exact resolution times, and this summary is not clearance authority.

diff-warden[bot]
diff-warden Bot previously approved these changes Sep 10, 2026

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (ce0193f66bfebde21a0ee3f70b8684d40400a68f). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Passed · 12/12 tests · 18/18 assertions · 8 images

Commit 7522402647a1715c7bc693ed6baa218beb2f84f7 · selected evidence

Open review report

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Deploying openwork with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7522402
Status: ✅  Deploy successful!
Preview URL: https://22e8fcc0.openwork.pages.dev
Branch Preview URL: https://e2e-new-session-route-after.openwork.pages.dev

View logs

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (7522402647a1715c7bc693ed6baa218beb2f84f7). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@yomgui

yomgui commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Resynced — merge commit 7522402647a1715c7bc693ed6baa218beb2f84f7 — re-proof Failed (dev regression at step 2, not a merge artefact)

Merged the updated e2e/fresh-session-send-gate (#4757 at 4a2f43213, which already contains origin/dev 9a60a4b59) into this branch; git merge origin/dev afterwards was Already up to date, so there is a single merge commit. No rebase, no amend, no force-push. Signed (G).

Conflicts resolved

Proof at 752240264

  • pnpm --filter @openwork/app typecheck → clean.
  • bun test --isolate tests/opencode-session-native.test.ts tests/queued-drain-admission-wedge.test.ts tests/workspace-routes.test.ts → 80 pass / 0 fail.
  • pnpm --filter @openwork/app test → 1661 pass / 82 fail; identical 82 on a clean origin/dev 9a60a4b59 control (same host/command) → pre-existing, none introduced.
  • Daytona OPENWORK_EVAL_REF=752240264… pnpm evals:e2e workspace-engine-upgrade --daytona:
    • run 1: 0 passed / 1 failed — step 1 (palette chat) green; step 2 "a new chat in the selected existing workspace keeps the first message visible" fails: Timed out after 90000ms seeing text=Hello. Your upgrade conversation is working.
    • run 2: died in provisioning (source dependency install gate, no counts) — vitest process terminated; sandboxes deleted by hand.
    • run 3: 0 passed / 1 failed, same step, same signature.

What collides

The screenshot taken 125–240 ms after the send lands on ses_… shows the new session route with a red CancelledError SessionErrorCard, hi back in the composer, no user row, Run task disabled. So the auto-send mark matched (this PR's/#4777's fix works — sendDraft ran), but the send threw.

CancelledError is only thrown by TanStack Query's retryer when an in-flight fetch is cancelled. Since #4838 (4462762b4, merged to dev today, not in the proven head ce0193f66) sendDraft awaits openingHistory.ensureFullSnapshot() → queryClient.ensureQueryData(snapshotKey). On this route there is no cached snapshot — #4757's seedCreatedSessionSnapshot only seeds the open-mode create path (handleCreateTaskInWorkspaceWithOpenMode, session-route.tsx ~L2254), not onCreateTaskWithPrompt (~L3508) — so ensureQueryData joins the surface's freshly started snapshot fetch; that fetch is cancelled within ~300 ms (observer unsubscribe / re-key or an invalidation with cancelRefetch) and the send rejects with CancelledError. Step 1 passes because the palette path creates the session up front through the seeded path, so ensureQueryData returns the cached seed and never waits on the network. Deterministic here (2/2 completed runs); same shape would hit dev's own v2-sessionless-first-send scenario whenever the snapshot fetch is cancelled mid-flight.

Not touched (outside a merge resync): the likely minimal fixes are (a) also call seedCreatedSessionSnapshot(workspaceId, session) in the onCreateTaskWithPrompt path before navigating, and/or (b) make ensureFullSnapshot() in sendDraft tolerate a cancelled read (retry the uncapped read once instead of failing the send). Owner call needed; this PR's spec claim for step 2 is unproven at this sha until then. Test-run: evals/results/test-runs/2026-09-10T21-26-57-001Z-existing-workspaces-create-usable-sessions-after-changing-chat-engines (local machine).

@yomgui

yomgui commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Now CONFLICTING again after dev 858414c41 — stopped, semantic collision (superseded)

dev moved after the 752240264 resync. A dry git merge-tree against origin/dev 858414c41 conflicts only in evals/specs/workspace-engine-upgrade.e2e.test.ts: #4869 (51a769f97, "preserve conversation history across engine switches") rewrote the whole spec (118 → 331 lines, new test "completed workspace history survives v1/v2 switches and sidecar restart"). This PR's spec commit 0ad717693 edits the old test body (openEmptyNewTask, greet + usedSessionIds), which no longer exists, so no textual resolution can keep both.

Reading the new spec: its createChat(workspaceId, engine, "button" | "sidebar" | "palette", …) already expresses this PR's claim — sidebar/New session opens the sessionless /workspace/<id>/session route with an empty, editable composer (state.route === sessionlessRoute, userMessageCount === 0), the send is then checked against the native session list — i.e. the "New session opens the empty New task composer; the first send creates the session" re-expression this PR made for steps 2/4/5.

Together with the earlier finding that this PR's product commit ce0193f66 is the same fix as #4777 (already on dev), every commit unique to this PR is superseded on dev; after any resolution its diff versus dev + #4757 would be empty. I have not merged or edited anything further (worktree untouched at 752240264). Owner call: close as superseded by #4777 + #4869, or re-express a residual claim on the new spec. The CancelledError first-send regression documented above still stands as a dev issue (#4838 ensureFullSnapshot on the unseeded New-task path) and should be tracked independently of this PR.

@yomgui

yomgui commented Sep 11, 2026

Copy link
Copy Markdown
Member Author

Closing as superseded by #4777 + #4869 (and #4757, now merged)

Premise check (gh pr diff 4869): #4869 rewrites evals/specs/workspace-engine-upgrade.e2e.test.ts wholesale and touches no route/session-route product files. Coverage of this PR's two commits on origin/dev:

After #4757 merged (ae69a0368), this branch's diff against dev is empty apart from the now-conflicting old spec body. Closing; nothing here is lost.

Proof at origin/dev ea1ef4f5c — not green

OPENWORK_EVAL_REF=ea1ef4f5c3b8bb6fe40e08cb87900796f93df372 pnpm evals:e2e workspace-engine-upgrade --daytona (clean detached worktree, source verified ea1ef4f5c…, sandboxes deleted) → 0 passed / 1 failed at the first step "workspace A completes its first v1 conversation through New session": Timed out waiting for v1 completed native assistant response after 150000ms; last value: []. Trace: New session → sessionless composer → type → Run task → "first send uses a session in the selected workspace" ok (689 ms) → the native message list for that session stays empty. #4869's own body reports the same first-send failure on its real-LLM run ("root cause unresolved").

Root cause (from this PR's earlier runs at 752240264, where the DOM dump was available): the send from the sessionless New task route fails within ~300 ms with a TanStack CancelledError and the prompt is restored to the composer. Since #4838 (4462762b4) sendDraft awaits openingHistory.ensureFullSnapshot() → ensureQueryData(snapshotKey); the New-task-with-prompt path (onCreateTaskWithPrompt, session-route.tsx ~L3508) does not seed the snapshot (#4757's seedCreatedSessionSnapshot seeds only the open-mode path), so the send joins the surface's in-flight snapshot fetch, which is cancelled → the send rejects. The palette path (session allocated up front, seeded) works, which is why step 1 passed on the old spec and only the New-session steps fail.

This needs a new fix PR (not this one): seed the snapshot in onCreateTaskWithPrompt before navigating and/or make ensureFullSnapshot() in sendDraft tolerate a cancelled read. Until then workspace-engine-upgrade is red on dev at its first step. Stacked PRs #4797 and #4811 have been resynced against dev and are MERGEABLE (see their comments).

@yomgui yomgui closed this Sep 11, 2026

This branch was successfully deployed

4 active deployments
Preview – openwork-landing — 75224026 Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-den — 75224026 Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-app — 75224026 Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-diagnostics — 75224026 Deployed Sep 10, 2026 by vercel[bot]
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.

1 participant