{"record":{"id":"8436cc269a21a1ea","repo":"chenhg5/cc-connect","slug":"session-q-not-found","errorCode":null,"errorMessage":"session %q not found","messagePattern":"session %q not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/session.go","lineNumber":434,"sourceCode":"\tsm.activeSession[userKey] = id\n\tsm.userSessions[userKey] = append(sm.userSessions[userKey], id)\n\treturn s\n}\n\nfunc (sm *SessionManager) SwitchSession(userKey, target string) (*Session, error) {\n\tsm.mu.Lock()\n\tdefer sm.mu.Unlock()\n\n\tfor _, sid := range sm.userSessions[userKey] {\n\t\ts := sm.sessions[sid]\n\t\tif s != nil && (s.ID == target || s.Name == target) {\n\t\t\tsm.activeSession[userKey] = s.ID\n\t\t\ts.MarkExplicitlyActivated()\n\t\t\tsm.saveLocked()\n\t\t\treturn s, nil\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"session %q not found\", target)\n}\n\n// SwitchToAgentSession finds or creates an internal session that maps to the\n// given agent session ID. If an existing session already references agentSID,\n// it becomes the active session. Otherwise a new session is created so the\n// previous session's AgentSessionID is preserved in KnownAgentSessionIDs.\nfunc (sm *SessionManager) SwitchToAgentSession(userKey, agentSID, agentName, summary string) *Session {\n\tsm.mu.Lock()\n\tdefer sm.mu.Unlock()\n\n\tfor _, sid := range sm.userSessions[userKey] {\n\t\ts := sm.sessions[sid]\n\t\tif s == nil {\n\t\t\tcontinue\n\t\t}\n\t\ts.mu.Lock()\n\t\taid := s.AgentSessionID\n\t\ts.mu.Unlock()","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/session.go#L416-L452","documentation":"SwitchSession in the SessionManager throws this when the requested target session cannot be located for the given user key. The manager iterates its known sessions for that user and, if no session ID or name matches `target`, returns this error instead of switching. It is a lookup failure, not a state corruption: the current active session is left untouched.","triggerScenarios":"Calling SwitchSession with a session ID that was never created, a stale ID from a deleted/expired session, or a human-typed name that matches no known session (e.g. from a /switch command handled by handleProjectSessionSwitch).","commonSituations":"Users typing /switch with a typo or a session from a previous process run; IDs cached in UI after the session list was reset; switching before any session has been created for that user.","solutions":["List available sessions first (ListSessions) and switch using an exact ID from that list","Check the active session before switching if the intent was just to ensure a session exists — create one via the session manager instead of switching to a guessed ID","If switching by user-facing name, verify the name normalization (case/whitespace) matches how the manager stores it"],"exampleFix":"// before\ns, err := sm.SwitchSession(userKey, \"my-session\")\n// after\nsessions, _ := sm.ListSessions(userKey)\nfound := false\nfor _, s := range sessions { if strings.EqualFold(s.Name, \"my-session\") { found = true } }\nif !found { sm.CreateSession(userKey, \"my-session\") }\ns, err := sm.SwitchSession(userKey, \"my-session\")","handlingStrategy":"validation","validationCode":"sessions, _ := sm.ListSessions(userKey)\nids := map[string]bool{}\nfor _, s := range sessions { ids[s.ID] = true; if s.Name != \"\" { ids[s.Name] = true } }\nif !ids[target] { return fmt.Errorf(\"no such session %q; available: %v\", target, sessions) }","typeGuard":"func sessionExists(sm *core.SessionManager, userKey, target string) bool {\n    sessions, err := sm.ListSessions(userKey)\n    if err != nil { return false }\n    for _, s := range sessions {\n        if s.ID == target || s.Name == target { return true }\n    }\n    return false\n}","tryCatchPattern":"s, err := sm.SwitchSession(userKey, target)\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    s, err = sm.CreateSession(userKey, target)\n}\nif err != nil { slog.Error(\"switch session failed\", \"err\", err) }","preventionTips":["Always enumerate sessions with ListSessions before switching instead of reusing remembered IDs","Treat session IDs as opaque and ephemeral across process restarts","Normalize user-supplied session names (trim, case-fold) before lookup"],"tags":["session","lookup","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}