{"record":{"id":"c5e34f1bfc2f164c","repo":"chenhg5/cc-connect","slug":"session-q-referenced-by-key-q-not-found-in-s","errorCode":null,"errorMessage":"session %q referenced by key %q not found in %s","messagePattern":"session %q referenced by key %q not found in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/cc-connect/session_id.go","lineNumber":214,"sourceCode":"\t\treturn \"\", 0, false, nil // file unreadable, skip\n\t}\n\tvar fd sessionFileData\n\tif err := json.Unmarshal(data, &fd); err != nil {\n\t\treturn \"\", 0, false, nil // malformed, skip\n\t}\n\tactiveID, ok := fd.ActiveSession[sessionKey]\n\tif !ok {\n\t\treturn \"\", 0, false, nil // key not in this file\n\t}\n\t// Key found in this file — errors from here are definitive.\n\t// Use the file's modtime as fallback when the session entry is missing or\n\t// has a zero UpdatedAt, so error-candidate timestamps can still compete\n\t// with valid candidates from other files.\n\tfileMod := fileModTime(path)\n\n\tsess := fd.Sessions[activeID]\n\tif sess == nil {\n\t\treturn \"\", fileMod, false, fmt.Errorf(\"session %q referenced by key %q not found in %s\", activeID, sessionKey, filepath.Base(path))\n\t}\n\tts := sess.UpdatedAt.UnixNano()\n\tif ts == 0 {\n\t\tts = fileMod\n\t}\n\tif sess.AgentSessionID == \"\" {\n\t\treturn \"\", ts, false, fmt.Errorf(\"agent session ID not yet available (session may still be starting)\")\n\t}\n\treturn sess.AgentSessionID, ts, true, nil\n}\n\n// fileModTime returns the file's modification time as UnixNano, or 0 on error.\nfunc fileModTime(path string) int64 {\n\tinfo, err := os.Stat(path)\n\tif err != nil {\n\t\treturn 0\n\t}\n\treturn info.ModTime().UnixNano()","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/session_id.go#L196-L232","documentation":"readAgentSessionID parses a session file's index/key file and looks up the active session ID in fd.Sessions. If the key references an ID absent from that file's Sessions map, it reports this error as a non-definite failure; findAgentSessionID keeps scanning other candidate files and only surfaces it (via definiteErr) if nothing better is found.","triggerScenarios":"A session key/ID stored in the key file (e.g. <project>.sessions.json or hashed naming) no longer has a corresponding entry in the sessions file — stale key after the session file was rewritten, truncated, or created by a different agent version.","commonSituations":"Manually edited or partially synced agent data directories, agent crash mid-write leaving key and sessions file inconsistent, running `cc-connect agent-sid` against an old project directory.","solutions":["Re-run and confirm the key is correct; check what keys exist in the referenced session file","Delete or regenerate the stale key/session file pair so the agent recreates them on next session start","Start a new agent session so a fresh, consistent key->session entry is written"],"exampleFix":"// before\ncc-connect agent-sid --project myproj --key stale-session-id\n// after\n# start a fresh session, then:\ncc-connect agent-sid --project myproj --key <new-session-key>","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if out=$(cc-connect agent-sid --project \"$P\" --key \"$K\" 2>&1); then\n  echo \"$out\"\nelse\n  echo \"lookup failed: $out\" >&2; exit 1\nfi","preventionTips":["Do not hand-edit session files","Let the agent regenerate key/session pairs after crashes","Treat this error as stale state and re-create the session"],"tags":["cli","sessions","state","stale-data"],"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"}