chenhg5/cc-connect · error

session not found: %s

Error message

session not found: %s

What it means

Agent.DeleteSession returns this when findKimiSessionDir cannot locate a directory corresponding to the given sessionID under kimi's session storage. It guards os.RemoveAll against deleting a nonexistent or unresolvable session path.

Source

Thrown at agent/kimi/kimi.go:202

	flagSupport := a.flagSupport
	if a.activeIdx >= 0 && a.activeIdx < len(a.providers) {
		if m := a.providers[a.activeIdx].Model; m != "" {
			model = m
		}
	}
	a.mu.Unlock()

	return newKimiSession(ctx, cmd, extraArgs, workDir, model, mode, sessionID, extraEnv, timeout, flagSupport)
}

func (a *Agent) ListSessions(_ context.Context) ([]core.AgentSessionInfo, error) {
	return listKimiSessions(a.workDir)
}

func (a *Agent) DeleteSession(_ context.Context, sessionID string) error {
	path := findKimiSessionDir(sessionID)
	if path == "" {
		return fmt.Errorf("session not found: %s", sessionID)
	}
	return os.RemoveAll(path)
}

func (a *Agent) Stop() error { return nil }

// ── ModeSwitcher ────────────────────────────────────────────────

func (a *Agent) SetMode(mode string) {
	a.mu.Lock()
	defer a.mu.Unlock()
	a.mode = normalizeMode(mode)
	slog.Info("kimi: mode changed", "mode", a.mode)
}

func (a *Agent) GetMode() string {
	a.mu.Lock()
	defer a.mu.Unlock()

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Call ListSessions first and use an exact ID from its output
  2. Verify the session directory exists under kimiSessionsBaseDirs() for the daemon user
  3. Treat this as idempotent: ignore the error if the goal is 'ensure deleted'
  4. Check that the daemon's HOME matches the user who created the sessions

Example fix

// before
_ = agent.DeleteSession(ctx, "abc123") // guessed ID
// after
sessions, _ := agent.ListSessions(ctx)
for _, s := range sessions {
    if s.ID == wantID {
        if err := agent.DeleteSession(ctx, wantID); err != nil {
            if !strings.Contains(err.Error(), "session not found") { return err }
        }
    }
}
Defensive patterns

Strategy: validation

Validate before calling

sessions, err := agent.ListSessions(ctx)
if err != nil { return err }
found := false
for _, s := range sessions { if s.ID == sessionID { found = true } }
if !found { return nil } // nothing to delete

Try / catch

if err := agent.DeleteSession(ctx, id); err != nil {
    if strings.Contains(err.Error(), "session not found") {
        return nil // idempotent delete
    }
    return err
}

Prevention

When it happens

Trigger: Calling DeleteSession(ctx, sessionID) with an ID that does not match any on-disk kimi session directory — already deleted, wrong ID format, or the session belongs to a different workDir/user.

Common situations: User issues /delete with a stale or mistyped session ID from chat; session was removed by kimi CLI cleanup; sessions stored under another user's HOME because the daemon runs as a different user.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/14bc0f86c9ebbc71. Report an issue: GitHub.