{"record":{"id":"f71766e86fbd3b57","repo":"chenhg5/cc-connect","slug":"opencode-session-list-w","errorCode":null,"errorMessage":"opencode: session list: %w","messagePattern":"opencode: session list: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/opencode/opencode.go","lineNumber":632,"sourceCode":"}\n\n// -- Session listing --\n\n// opencodeSessionEntry represents a session from `opencode session list` output.\ntype opencodeSessionEntry struct {\n\tID      string `json:\"id\"`\n\tTitle   string `json:\"title\"`\n\tUpdated int64  `json:\"updated\"` // Unix timestamp in milliseconds\n\tCreated int64  `json:\"created\"`\n}\n\nfunc listOpencodeSessions(cmd, workDir string) ([]core.AgentSessionInfo, error) {\n\tc := exec.Command(cmd, \"session\", \"list\", \"--format\", \"json\")\n\tc.Dir = workDir\n\n\tout, err := c.Output()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"opencode: session list: %w\", err)\n\t}\n\n\tvar entries []opencodeSessionEntry\n\tif err := json.Unmarshal(out, &entries); err != nil {\n\t\treturn nil, fmt.Errorf(\"opencode: parse session list: %w\", err)\n\t}\n\n\tmsgCounts := querySessionMessageCounts()\n\n\tvar sessions []core.AgentSessionInfo\n\tfor _, e := range entries {\n\t\tsessions = append(sessions, core.AgentSessionInfo{\n\t\t\tID:           e.ID,\n\t\t\tSummary:      e.Title,\n\t\t\tMessageCount: msgCounts[e.ID],\n\t\t\tModifiedAt:   time.UnixMilli(e.Updated),\n\t\t})\n\t}","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/opencode/opencode.go#L614-L650","documentation":"listOpencodeSessions runs `opencode session list --format json` and reads its stdout via c.Output(); if the command fails (non-zero exit), the exec error is wrapped as `opencode: session list: %w`. Note only the exec error is wrapped — the CLI's diagnostic output (available via ExitError.Stderr) is not included, so check the wrapped error's type for details.","triggerScenarios":"Calling ListSessions when: the opencode CLI cannot run in workDir (missing binary, bad workDir, permissions); opencode exits non-zero (corrupt session store, changed subcommand flags such as --format being removed in a newer/older CLI version); the command times out or is killed.","commonSituations":"CLI version mismatch (older opencode without `--format json`); running as a user without access to the opencode data directory; workDir deleted after the agent was constructed; PATH issues for the daemon.","solutions":["Check the wrapped exec.ExitError's Stderr for opencode's own message; run `opencode session list --format json` manually in workDir to reproduce.","Verify CLI version supports `--format json` (`opencode session list --help`); upgrade/downgrade opencode to match this adapter.","Fix PATH/workDir/permissions for the daemon user, then retry ListSessions.","Guard callers: on this error fall back to an empty session list or surface a clear message instead of crashing the command handler."],"exampleFix":"// before\nsessions, err := agent.ListSessions(ctx)\nif err != nil {\n    return err\n}\n\n// after\nsessions, err := agent.ListSessions(ctx)\nif err != nil {\n    var exitErr *exec.ExitError\n    if errors.As(err, &exitErr) {\n        slog.Warn(\"opencode session list failed\", \"stderr\", string(exitErr.Stderr))\n    }\n    return nil // degraded: empty list instead of hard failure\n}","handlingStrategy":"retry","validationCode":"// verify the CLI works in this workDir before relying on ListSessions\nprobe := exec.Command(opencodeCmd, \"session\", \"list\", \"--format\", \"json\")\nprobe.Dir = workDir\nif out, err := probe.CombinedOutput(); err != nil {\n    return fmt.Errorf(\"opencode session list unusable here: %v: %s\", err, out)\n}","typeGuard":"func isSessionListFailure(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"opencode: session list:\")\n}","tryCatchPattern":"sessions, err := agent.ListSessions(ctx)\nif err != nil {\n    var exitErr *exec.ExitError\n    if errors.As(err, &exitErr) {\n        slog.Warn(\"opencode session list failed\", \"stderr\", string(exitErr.Stderr))\n    }\n    sessions = nil // degrade gracefully\n}","preventionTips":["Confirm `opencode session list --format json` works under the daemon user after installs/upgrades","Pin an opencode version whose flags match this adapter (older CLIs may lack --format)","Keep the agent workDir valid and accessible for the daemon lifetime","Surface degraded (empty) session lists to the UI rather than failing the command"],"tags":["go","cli","exec","sessions"],"backgroundTag":"cli-process-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}