{"record":{"id":"e8a0a915db8994bf","repo":"charmbracelet/crush","slug":"session-q-not-found","errorCode":null,"errorMessage":"session %q not found","messagePattern":"session %q not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/run.go","lineNumber":724,"sourceCode":"\t\treturn sess, nil\n\t}\n\n\tsessions, err := c.ListSessions(ctx, wsID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar matches []proto.Session\n\tfor _, s := range sessions {\n\t\thash := session.HashID(s.ID)\n\t\tif hash == id || strings.HasPrefix(hash, id) {\n\t\t\tmatches = append(matches, s)\n\t\t}\n\t}\n\n\tswitch len(matches) {\n\tcase 0:\n\t\treturn nil, fmt.Errorf(\"session %q not found\", id)\n\tcase 1:\n\t\treturn &matches[0], nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"session ID %q is ambiguous (%d matches)\", id, len(matches))\n\t}\n}\n","sourceCodeStart":706,"sourceCodeEnd":731,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/run.go#L706-L731","documentation":"resolveSessionByID first tries a direct GetSession by full ID; on failure it lists sessions and matches short hash prefixes. If no session's full ID or hash prefix equals the given id, it returns \"session %q not found\". Note it cannot distinguish a bad ID from a listing failure propagated earlier.","triggerScenarios":"Passing a session ID/short hash to the command that resolves it (e.g. resuming a session by short hash) where the hash does not match any existing session in the workspace: mistyped prefix, session deleted, or wrong workspace/data-dir.","commonSituations":"Using a short hash copied from `crush session list` of a different project; too-short prefix after sessions were pruned; pointing at a fresh data directory in CI.","solutions":["Re-run `crush session list` in the same workspace and copy the ID/hash exactly.","Use the full UUID instead of a short hash to avoid prefix issues.","Confirm --data-dir matches the environment where the session was created.","If gone, start a new session instead of resuming."],"exampleFix":"// before\ncrush run --session ab12 \"prompt\"      # hash no longer exists\n// after\ncrush session list                     # pick a current hash\ncrush run --session ab12cd34 \"prompt\"","handlingStrategy":"validation","validationCode":"sessions, _ := c.ListSessions(ctx, wsID)\nfound := false\nfor _, s := range sessions {\n    h := session.HashID(s.ID)\n    if s.ID == id || h == id || strings.HasPrefix(h, id) {\n        found = true\n        break\n    }\n}\nif !found {\n    return fmt.Errorf(\"%s matches no current session; run 'crush session list'\", id)\n}","typeGuard":"func matchesSession(sessions []proto.Session, id string) bool {\n    for _, s := range sessions {\n        if s.ID == id || strings.HasPrefix(session.HashID(s.ID), id) {\n            return true\n        }\n    }\n    return false\n}","tryCatchPattern":"sess, err := resolveSessionByID(ctx, c, wsID, id)\nif err != nil && strings.HasSuffix(err.Error(), \"not found\") {\n    log.Warnf(\"session %s gone; starting a new one\", id)\n    sess, err = c.CreateSession(ctx, wsID, \"non-interactive\")\n}","preventionTips":["Copy the exact short hash from `crush session list` output.","Re-resolve IDs at run time rather than hardcoding them in scripts.","Use the full UUID when IDs must be stable across environments."],"tags":["cli","session","not-found"],"backgroundTag":"session-not-found","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}