{"record":{"id":"74c305513ca5a2f8","repo":"chenhg5/cc-connect","slug":"opencode-delete-session-s-w-s","errorCode":null,"errorMessage":"opencode: delete session %s: %w: %s","messagePattern":"opencode: delete session (.+?): %w: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agent/opencode/opencode.go","lineNumber":505,"sourceCode":"\tcmd := a.cmd\n\tworkDir := a.workDir\n\ta.mu.RUnlock()\n\treturn listOpencodeSessions(cmd, workDir)\n}\n\nfunc (a *Agent) Stop() error { return nil }\n\n// DeleteSession implements core.SessionDeleter via `opencode session delete <id>`.\nfunc (a *Agent) DeleteSession(_ context.Context, sessionID string) error {\n\ta.mu.RLock()\n\tcmd := a.cmd\n\tworkDir := a.workDir\n\ta.mu.RUnlock()\n\n\tc := exec.Command(cmd, \"session\", \"delete\", sessionID)\n\tc.Dir = workDir\n\tif out, err := c.CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"opencode: delete session %s: %w: %s\", sessionID, err, strings.TrimSpace(string(out)))\n\t}\n\treturn nil\n}\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(\"opencode: mode changed\", \"mode\", a.mode)\n}\n\nfunc (a *Agent) GetMode() string {\n\ta.mu.Lock()\n\tdefer a.mu.Unlock()\n\treturn a.mode\n}","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/opencode/opencode.go#L487-L523","documentation":"DeleteSession runs `opencode session delete <id>` in the agent's workDir; on failure it wraps the exec error plus the command's combined stdout/stderr as `opencode: delete session <id>: <err>: <output>`. The appended output is opencode's own diagnostic explaining why the delete failed (e.g. session not found).","triggerScenarios":"Deleting a session id that no longer exists (already deleted or a stale ListSessions result); opencode exits non-zero due to a corrupt session store, permission problems on its data directory, or a CLI version whose `session delete` subcommand changed.","commonSituations":"Cleaning up sessions already removed by opencode or manual storage cleanup; cc-connect running as a different user than the one who created the sessions (data-dir ownership); CLI upgrade changing subcommand behavior.","solutions":["Read the embedded output string for the concrete cause; if the session is already gone, treat the delete as idempotent and ignore the error.","Confirm the id exists first: run `opencode session list` before deleting.","Fix ownership/permissions of opencode's session data directory for the daemon user.","Reproduce manually: `cd <workDir> && opencode session delete <id>` and inspect the combined output."],"exampleFix":"// before\nif err := agent.DeleteSession(ctx, id); err != nil {\n    return err // fails hard on already-deleted sessions\n}\n\n// after\nif err := agent.DeleteSession(ctx, id); err != nil {\n    if strings.Contains(err.Error(), \"not found\") {\n        return nil // idempotent delete\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// confirm the session still exists before deleting\nsessions, err := agent.ListSessions(ctx)\nif err == nil && !containsSession(sessions, sessionID) {\n    return nil // nothing to delete\n}","typeGuard":null,"tryCatchPattern":"if err := agent.DeleteSession(ctx, id); err != nil {\n    if strings.Contains(err.Error(), \"not found\") {\n        return nil // idempotent: already deleted\n    }\n    return fmt.Errorf(\"delete session failed, see embedded CLI output: %w\", err)\n}","preventionTips":["Treat deletes as idempotent — the session may already be gone","Run `opencode session delete <id>` manually once to learn the CLI's exact failure strings","Keep the opencode data directory owned by the same user as the cc-connect daemon","Refresh your session cache from ListSessions before delete operations"],"tags":["go","cli","session-management"],"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"}