Skip to content

New-worktree session shows "This session cannot be found" while its worktree is still being created #2276

Done

Description

@jqmviegas

Summary

Starting a session in a new worktree shows the "This session cannot be found" panel a second or two after Send, while the worktree is still being created. It's easy to hit when the worktree strategy runs a setup step (here a plugin runs make install-dev, so POST /api/worktree takes about 60 s). With a near-instant worktree the window is too short to notice.

If the user acts on the panel (for example, closes the tab), the session is never created, even though the worktree is.

Versions

  • OpenCode (Rune) 0.0.0-dev-527, macOS arm64
  • Sidecar opencode-cli 0.0.0-dev-1390
  • Code references below are from dev at 3f997ef

Steps to reproduce

  1. Use a worktree strategy whose create takes about 30–60 s, for example a plugin that runs a dependency install after git worktree add.
  2. On the new-session page, choose New worktree and send a prompt.
  3. Keep the pending session open and hover its tab, or let the stream reconnect, before the worktree is ready.

Expected: the pending session keeps showing "Starting session" until the worktree is ready, then lands.

Actual: the tab switches to "This session cannot be found / This tab points to a session that no longer exists on this server".

Evidence (server log)

Two worktree starts, two minutes apart, both with a worktree create of about 57 s:

Send Page read GET /api/session/<id>/message Worktree ready Session created
Start A 08:28:22.4 08:28:23.8 → 404 08:29:19.7 08:29:19 (shown again later)
Start B 08:30:23.2 08:30:26.7 → 404 08:31:21.1 never (the user had closed the tab)

At the moment of Send, every new session (worktree or not) also gets 404s on /api/session/<id>/inbox, /permission and /form. For a normal session the create lands within about a second, so the later page read succeeds and nothing shows.

Cause

  1. Page reads aren't skipped for a pending start. open_now skips reads for a starting session (apps/desktop/src/session/meta/open.rs:132). Other paths that read the newest page don't: prefetch_session on tab or sidebar hover (session/pages/mod.rs:444) and reload_session on reconnect (open.rs:203). When the read 404s and the session is on screen, the pages handler calls session_state::missing (apps/desktop/src/session/pages/mod.rs:640) without checking self.queue.starts.has(&key.id), so the tab resolves to Resolution::NotFound.
  2. NotFound is sticky. In Resolution::step (apps/desktop/src/session/meta/state.rs:64), only Resolving and Unreachable move to Ready on Known. So even after promote_start, the tab keeps the not-found panel until it is closed and reopened.
  3. The panel's "Close Tab" can drop the start. While the panel shows, the start is still in Start::Worktree. Closing or leaving it means the later WorktreeMade finds no start, so the session is never created, but the worktree stays.
  4. Minor: begin_start opens the session before registering the start. It calls show_start (and so open_now) before queue.starts.step(id, Event::Begin{..}) (apps/desktop/src/workspace/lifecycle/new_session/mod.rs:363-365). The same is true for the Existing path at lines 349–352. As a result the open.rs:132 guard never applies on the first open, which causes the immediate /inbox, /permission and /form 404s.

Suggested fix

  • In begin_start (both paths), insert into queue.starts before show_start, so open_now's guard applies.
  • In the pages error handler (pages/mod.rs:623 and :640), treat a 404 for a session in queue.starts as "not yet" rather than missing. Alternatively, make prefetch_session and reload_session skip sessions in queue.starts.
  • Optionally, let Known (or promote_start) move a NotFound tab back to Ready, so a session that turns up after all recovers without reopening its tab.

Found by reading the code and the server log, not with a debugger: the exact read that 404'd (hover prefetch or reconnect reload) wasn't captured on the client.

Activity

  1. added a commit that references this issue on Dec 3, 2026
    87be6a7
  2. Hona commented on Dec 3, 2026

    @Hona
    Member

    Fixed in PR #2293 (merged into dev at 3745cfc2f).

    Pending new-worktree starts are now registered in queue.starts before open_now runs, page and reconnect reads skip sessions still in queue.starts, 404 responses for pending starts no longer transition the tab to "This session cannot be found" (while genuine 404 and deleted sessions still do), pending starts are preserved across memory sweeps, and server-confirmed promotion or landed pages recover Resolution::NotFound to Ready.

    Verification: Checked locally on Windows with pwsh scripts/guardrails.ps1 (11/11), cargo check -j 1 -p opencode-desktop, and cargo clippy -j 1 -p opencode-desktop --no-deps, and validated across macOS, Linux, and Windows CI builds on PR #2293. Not verified interactively against a live slow-worktree server on hardware—please reopen if anything still flashes or gets stuck.

  3. added a commit that references this issue on Dec 3, 2026
    3745cfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions