{"record":{"id":"150be9f6e735208d","repo":"github/copilot-sdk","slug":"failed-to-resume-session-w","errorCode":null,"errorMessage":"failed to resume session: %w","messagePattern":"failed to resume session: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":1470,"sourceCode":"\tif c.options.SessionFS != nil {\n\t\tif config.CreateSessionFSProvider == nil {\n\t\t\trestoreReplacedSession()\n\t\t\treturn nil, fmt.Errorf(\"CreateSessionFSProvider is required in session config when SessionFS is enabled in client options\")\n\t\t}\n\t\tprovider := config.CreateSessionFSProvider(session)\n\t\tif c.options.SessionFS.Capabilities != nil && c.options.SessionFS.Capabilities.Sqlite {\n\t\t\tif _, ok := provider.(SessionFSSqliteProvider); !ok {\n\t\t\t\trestoreReplacedSession()\n\t\t\t\treturn nil, fmt.Errorf(\"SessionFS capabilities declare SQLite support but the provider does not implement SessionFSSqliteProvider\")\n\t\t\t}\n\t\t}\n\t\tsession.clientSessionAPIs.SessionFS = newSessionFSAdapter(provider)\n\t}\n\n\tresult, err := c.client.Request(ctx, \"session.resume\", req)\n\tif err != nil {\n\t\trestoreReplacedSession()\n\t\treturn nil, fmt.Errorf(\"failed to resume session: %w\", err)\n\t}\n\n\tvar response resumeSessionResponse\n\tif err := json.Unmarshal(result, &response); err != nil {\n\t\trestoreReplacedSession()\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal response: %w\", err)\n\t}\n\n\tif config.OnMCPAuthRequest != nil {\n\t\tif _, err := c.client.Request(ctx, \"session.eventLog.registerInterest\", map[string]any{\n\t\t\t\"sessionId\": sessionID,\n\t\t\t\"eventType\": \"mcp.oauth_required\",\n\t\t}); err != nil {\n\t\t\trestoreReplacedSession()\n\t\t\treturn nil, err\n\t\t}\n\t}\n","sourceCodeStart":1452,"sourceCodeEnd":1488,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L1452-L1488","documentation":"ResumeSessionWithOptions wraps any error from the underlying \"session.resume\" request in this message and restores the previously replaced session before returning. It is the generic failure envelope for the resume round trip — transport errors, timeouts, and server-side rejections all surface here wrapped via %w.","triggerScenarios":"Calling ResumeSession/ResumeSessionWithOptions when c.client.Request(ctx, \"session.resume\", req) fails: server unreachable, session ID unknown to the server, connection reset, or a resume rejected server-side.","commonSituations":"Resuming a session after the server restarted and lost its state; wrong/stale session ID; network interruption; server rejecting resume due to version or permission issues.","solutions":["Unwrap the error (errors.Unwrap/errors.As) to identify the root cause","Verify the session ID exists server-side; create a new session if the server lost state after restart","Check connectivity to the agent server and that ensureConnected succeeded","Retry with backoff for transient network failures; check server logs for the session.resume rejection reason"],"exampleFix":"// before\nsess, err := client.ResumeSession(ctx, id)\n// after\nsess, err := client.ResumeSession(ctx, id)\nif err != nil {\n    if isSessionGone(err) { sess, err = client.CreateSession(ctx, opts) }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if sessionID == \"\" { return errors.New(\"cannot resume: empty session ID\") }\nconn, err := net.DialTimeout(\"tcp\", serverAddr, 2*time.Second)\nif err != nil { return fmt.Errorf(\"agent server unreachable: %w\", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"sess, err := client.ResumeSession(ctx, id)\nif err != nil {\n    root := errors.Unwrap(err)\n    if isNotFound(root) { sess, err = client.CreateSession(ctx, opts) } // server lost state\n    else if isTransient(root) { /* retry with backoff */ }\n    return err\n}","preventionTips":["Persist session IDs and verify they still exist before resuming","Fall back to CreateSession when the server no longer knows the session","Retry transient network errors with exponential backoff"],"tags":["rpc","session","resume","network"],"backgroundTag":"api-request-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}