{"record":{"id":"2714fa4b143415a0","repo":"chenhg5/cc-connect","slug":"pi-session-q-not-found","errorCode":null,"errorMessage":"pi: session %q not found","messagePattern":"pi: session %q not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/pi/pi.go","lineNumber":216,"sourceCode":"\t\t})\n\t}\n\n\tsort.Slice(sessions, func(i, j int) bool {\n\t\treturn sessions[i].ModifiedAt.After(sessions[j].ModifiedAt)\n\t})\n\n\treturn sessions, nil\n}\n\nfunc (a *Agent) DeleteSession(_ context.Context, sessionID string) error {\n\tsessDir := piSessionDir(a.workDir)\n\tif sessDir == \"\" {\n\t\treturn fmt.Errorf(\"pi: cannot determine session directory\")\n\t}\n\n\tpath := findSessionFile(sessDir, sessionID)\n\tif path == \"\" {\n\t\treturn fmt.Errorf(\"pi: session %q not found\", sessionID)\n\t}\n\treturn os.Remove(path)\n}\n\nfunc (a *Agent) Stop() error { return nil }\n\n// ── ModeSwitcher ─────────────────────────────────────────────\n\nfunc (a *Agent) SetMode(mode string) {\n\ta.mu.Lock()\n\tdefer a.mu.Unlock()\n\ta.mode = normalizeMode(mode)\n\tslog.Info(\"pi: mode changed\", \"mode\", a.mode)\n}\n\nfunc (a *Agent) GetMode() string {\n\ta.mu.Lock()\n\tdefer a.mu.Unlock()","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/pi/pi.go#L198-L234","documentation":"DeleteSession in the pi agent adapter removes the on-disk session file for a given sessionID. After locating pi's session directory, it calls findSessionFile(sessDir, sessionID); when no matching session file exists, it returns this error instead of attempting os.Remove. It is the pi adapter's 'record not found' signal for session deletion.","triggerScenarios":"Calling Agent.DeleteSession(sessionID) when: (1) the sessionID was never created by pi, (2) the session file was already deleted (manually or by a prior DeleteSession), (3) the sessionID string does not match the session file naming convention findSessionFile uses to match files in the session directory, or (4) the session directory resolved from HOME/PI_USER_DIR does not contain the session.","commonSituations":"Users run /forget or delete-session commands for a stale session ID after the pi data directory was cleaned or the machine changed; double-deletion races where two delete requests fire for the same session; typos or truncated session IDs passed from chat commands.","solutions":["Verify the session ID exists (e.g. via ListSessions or by listing files in ~/.pi/agent session dir) before calling DeleteSession.","Treat this error as an idempotent success in callers if the goal is 'session gone' — the file is already absent.","Check that the pi session directory is correct (HOME or PI_USER_DIR env) and contains the session file you expect.","Ensure the sessionID string exactly matches the ID used at creation; re-obtain it from session listing rather than copying from chat text."],"exampleFix":"// before\nif err := agent.DeleteSession(sessionID); err != nil {\n    return err\n}\n// after\nif err := agent.DeleteSession(sessionID); err != nil {\n    if strings.Contains(err.Error(), \"not found\") {\n        log.Printf(\"session %s already gone, treating as deleted\", sessionID)\n        return nil\n    }\n    return fmt.Errorf(\"delete session: %w\", err)\n}","handlingStrategy":"validation","validationCode":"sessions, err := agent.ListSessions()\nif err != nil {\n    return fmt.Errorf(\"list sessions: %w\", err)\n}\nexists := false\nfor _, s := range sessions {\n    if s.ID == sessionID {\n        exists = true\n        break\n    }\n}\nif !exists {\n    return nil // nothing to delete; skip the call\n}\nerr = agent.DeleteSession(sessionID)","typeGuard":null,"tryCatchPattern":"if err := agent.DeleteSession(sessionID); err != nil {\n    if strings.Contains(err.Error(), \"not found\") {\n        return nil // idempotent delete\n    }\n    return fmt.Errorf(\"delete session: %w\", err)\n}","preventionTips":["Always source session IDs from ListSessions, never from user-typed chat text without lookup.","Treat delete-of-missing as success in UI flows to make /forget idempotent.","Refresh the session list after each delete so stale IDs aren't re-offered to users."],"tags":["go","session-management","not-found"],"backgroundTag":"record-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"}