{"record":{"id":"44a253074877c3e2","repo":"chenhg5/cc-connect","slug":"agent-session-id-not-yet-available-session-may-st","errorCode":null,"errorMessage":"agent session ID not yet available (session may still be starting)","messagePattern":"agent session ID not yet available \\(session may still be starting\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"cmd/cc-connect/session_id.go","lineNumber":221,"sourceCode":"\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()\n}\n\nfunc printAgentSIDUsage() {\n\tfmt.Println(`Usage: cc-connect agent-sid [options]\n\nPrint the agent session ID (e.g. Claude Code, Codex, Gemini CLI) for the\ncurrent session. This is the ID used for --resume.","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/session_id.go#L203-L239","documentation":"readAgentSessionID found the session entry but its AgentSessionID field is empty, meaning the session file exists but the agent has not yet written the real session ID (the session may still be starting). It returns this non-definite error with the session timestamp so findAgentSessionID can prefer other candidates; it surfaces only when no better match exists.","triggerScenarios":"Running `cc-connect agent-sid` immediately after spawning an agent session, before the agent process has flushed its session ID to the session file.","commonSituations":"Scripting that starts a Claude Code/Codex session and queries agent-sid in the same second; agent crashed during startup before writing the ID.","solutions":["Retry after a short delay (e.g. sleep 1-2s or poll with retries) until the session ID appears","Check the agent process actually started and is running (ps / logs)","If the session is dead, remove the stale entry and start a new session"],"exampleFix":"// before\ncc-connect agent start ... && cc-connect agent-sid --project $P --key $K\n// after\ncc-connect agent start ...\nfor i in $(seq 1 10); do cc-connect agent-sid --project $P --key $K && break; sleep 1; done","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for i in 1 2 3 4 5; do\n  sid=$(cc-connect agent-sid --project \"$P\" --key \"$K\") && break\n  sleep 1\ndone","preventionTips":["Insert a startup delay between launching an agent session and querying its ID","Poll instead of querying once in scripts","Check agent logs if the ID never appears"],"tags":["cli","sessions","timing","race"],"backgroundTag":"empty-required-field","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"}