{"record":{"id":"36619e40dd8f91fd","repo":"vitest-dev/vitest","slug":"session-sessionid-not-found","errorCode":null,"errorMessage":"Session \"${sessionId}\" not found.","messagePattern":"Session \"(.+?)\" not found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/node/projectParent.ts","lineNumber":199,"sourceCode":"    options: StackTraceParserOptions = {},\n  ): ParsedStack[] {\n    return parseStacktrace(trace, {\n      ...this.stackTraceOptions,\n      ...options,\n    })\n  }\n\n  public readonly cdps: Map<string, BrowserServerCDPHandler> = new Map()\n  private cdpSessionsPromises = new Map<string, Promise<CDPSession>>()\n\n  async ensureCDPHandler(sessionId: string, rpcId: string): Promise<BrowserServerCDPHandler> {\n    const cachedHandler = this.cdps.get(rpcId)\n    if (cachedHandler) {\n      return cachedHandler\n    }\n    const browserSession = this.vitest._browserSessions.getSession(sessionId)\n    if (!browserSession) {\n      throw new Error(`Session \"${sessionId}\" not found.`)\n    }\n\n    const browser = browserSession.project.browser!\n    const provider = browser.provider\n    if (!provider) {\n      throw new Error(`Browser provider is not defined for the project \"${browserSession.project.name}\".`)\n    }\n    if (!provider.getCDPSession) {\n      throw new Error(`CDP is not supported by the provider \"${provider.name}\".`)\n    }\n\n    const session = await this.cdpSessionsPromises.get(rpcId) ?? await (async () => {\n      const promise = provider.getCDPSession!(sessionId).finally(() => {\n        this.cdpSessionsPromises.delete(rpcId)\n      })\n      this.cdpSessionsPromises.set(rpcId, promise)\n      return promise\n    })()","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser/src/node/projectParent.ts#L181-L217","documentation":"ensureCDPHandler looks up a browser session by sessionId in vitest._browserSessions. Sessions are created when a browser test run starts and removed when it ends; a missing session means the ID is unknown, already cleaned up, or never created.","triggerScenarios":"A CDP debugging client (or browser UI) sends a request referencing a sessionId that has no matching BrowserSession: stale ID after a run finished, typo/malformed ID, a session from a different Vitest process, or a race where the session was torn down before the CDP request arrived.","commonSituations":"Leaving the browser devtools UI open across a test re-run; reconnecting a CDP client with an old session ID after the server restarted; a flaky teardown that removes the session before in-flight CDP traffic lands.","solutions":["Refresh or re-establish the CDP connection so it uses the current run's sessionId.","Ensure the CDP client does not cache session IDs across test runs.","If you are driving CDP programmatically, fetch the live sessionId from the runner state before each call.","Check for premature session teardown (e.g. browser closing before CDP work finishes) and serialize teardown after CDP cleanup."],"exampleFix":"// before\nconst handler = await parent.ensureCDPHandler(staleSessionId, rpcId)\n// after - re-read the live session id\nconst live = vitest._browserSessions.getSession(currentSessionId)!\nconst handler = await parent.ensureCDPHandler(live.id, rpcId)","handlingStrategy":"validation","validationCode":"function sessionExists(getSession: (id: string) => unknown, id: string): boolean {\n  return !!getSession(id)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always read the live sessionId from runner state before issuing CDP requests.","Do not cache sessionIds across test runs.","Serialize teardown so it does not race with in-flight CDP traffic."],"tags":["cdp","session","browser","debugging","lifecycle"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}