{"record":{"id":"be7424e258aaae5c","repo":"charmbracelet/crush","slug":"failed-to-resolve-session-w","errorCode":null,"errorMessage":"failed to resolve session: %w","messagePattern":"failed to resolve session: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/run.go","lineNumber":237,"sourceCode":"\t\t}\n\t}\n\n\t// Wait for the agent to become ready (MCP init, etc).\n\tif err := waitForAgent(ctx, c, ws.ID); err != nil {\n\t\tstopSpinner()\n\t\treturn fmt.Errorf(\"agent not ready: %w\", err)\n\t}\n\n\t// Force-update agent models so MCP tools are loaded.\n\tif err := c.UpdateAgent(ctx, ws.ID); err != nil {\n\t\tslog.Warn(\"Failed to update agent\", \"error\", err)\n\t}\n\n\tdefer stopSpinner()\n\n\tsess, err := resolveSession(ctx, c, ws.ID, continueSessionID, useLast)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to resolve session: %w\", err)\n\t}\n\tif continueSessionID != \"\" || useLast {\n\t\tslog.Info(\"Continuing session for non-interactive run\", \"session_id\", sess.ID)\n\t\t// If no explicit model override was requested, restore the\n\t\t// model/provider from the last assistant message in the\n\t\t// session, provided it is still available.\n\t\tif largeModel == \"\" && smallModel == \"\" {\n\t\t\tif err := restoreModelFromSession(ctx, c, ws, sess.ID); err != nil {\n\t\t\t\tslog.Warn(\"Failed to restore model from session\", \"error\", err)\n\t\t\t}\n\t\t}\n\t} else {\n\t\tslog.Info(\"Created session for non-interactive run\", \"session_id\", sess.ID)\n\t}\n\n\tevents, err := c.SubscribeEvents(ctx, ws.ID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to subscribe to events: %w\", err)","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/run.go#L219-L255","documentation":"Wraps errors from resolveSession(), which finds the session for a non-interactive run based on --continue (session id) or --last flags. Thrown when no matching session exists or session lookup fails.","triggerScenarios":"`crush run --continue <id>` / `--last` where resolveSession(ctx, c, ws.ID, continueSessionID, useLast) cannot find the session in the SQLite store or the query errors.","commonSituations":"Session id typo or session belongs to a different workspace/project; database moved or deleted (fresh clone); --last used when no prior sessions exist; wrong working directory so a different workspace ID is derived.","solutions":["List existing sessions (`crush sessions`) and copy the exact id","Omit --continue/--last to create a new session instead","Run from the same project directory used when the session was created","Check the local SQLite database exists and is readable"],"exampleFix":"// before\ncrush run --continue abc123 \"continue\"\n// after: use the exact session id\ncrush run --continue 0195f2a1-7c3b-7e22-9d4e-1a2b3c4d5e6f \"continue\"","handlingStrategy":"fallback","validationCode":"// verify the session exists before asking for --continue\nif continueSessionID != \"\" {\n\tif _, err := q.GetSession(ctx, continueSessionID); err != nil {\n\t\treturn fmt.Errorf(\"session %q not found; omit --continue to start fresh\", continueSessionID)\n\t}\n}","typeGuard":null,"tryCatchPattern":"sess, err := resolveSession(ctx, c, ws.ID, continueSessionID, useLast)\nif err != nil {\n\tif useLast || continueSessionID != \"\" {\n\t\tslog.Warn(\"Session not found, starting a new one\")\n\t\tsess, err = createNewSession(ctx, c, ws.ID)\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to resolve session: %w\", err)\n\t}\n}","preventionTips":["Copy session ids from `crush sessions` output, not from memory","Run from the same project directory the session was created in","Fall back to a new session in scripted/CI usage"],"tags":["go","session","cli","persistence"],"backgroundTag":"session-not-found","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}