Skip to content

fix(cursor): pre-register cursorSessionId on resume before ACP session/load completes #834

@swear01

Description

@swear01

Summary

When resuming an inactive Cursor session, the hub spawns a new CLI process and calls ACP session/load. For several seconds the new hapi session has no cursorSessionId in metadata, breaking dedup, picker gating, and resume-unavailable checks on the web.

Repro

  1. Spawn Cursor session, wait for cursorSessionId.
  2. Send message, archive.
  3. POST /api/sessions/:id/resume.
  4. Poll GET /api/sessions/:newIdmetadata.cursorSessionId is null for ~0–6s, then populated with the same ACP thread id.

CLI log shows: cursor --resume <cursorSessionId> --hapi-starting-mode remote --started-by runner.

Root cause

cursorAcpRemoteLauncher calls backend.loadSession() then onSessionFoundWithProtocol(). Metadata is written only after load completes. Zed fixed an analogous race in PR #54431 by registering the session before awaiting session/load.

Proposed fix

  1. On resume bootstrap, immediately write pending cursorSessionId (+ cursorSessionProtocol: 'acp') from hub resume token into metadata (via bootstrapExistingSession + pickExistingSessionMetadata, or hub-side merge on spawn).
  2. Optionally coalesce in-flight resume for same cursorSessionId (Zed pending_sessions pattern, PR #53999).

Related

Test plan

  • CLI test: resume path sets metadata before load resolves (mock backend).
  • Live: resume → assert cursorSessionId present within first GET /api/sessions/:id.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions