chenhg5/cc-connect · warning

copilot: session.delete failed: unknown error

Error message

copilot: session.delete failed: unknown error

What it means

The session/delete RPC result parsed fine and reported success=false, but no Error detail string was provided in the payload, so the library can only report an unknown failure. It signals the copilot CLI deviated from its expected response contract (success=false must carry an error reason).

Source

Thrown at agent/copilot/copilot.go:411

	if delResp.Error != nil {
		// method-not-found or invalid-request means unsupported
		if delResp.Error.Code == -32601 || delResp.Error.Code == -32600 {
			return nil
		}
		return fmt.Errorf("copilot: session.delete: %s", delResp.Error.Message)
	}

	var result copilotDeleteSessionResponse
	if err := json.Unmarshal(delResp.Result, &result); err != nil {
		// Ignore parse errors - treat as success
		return nil
	}
	if !result.Success {
		if result.Error != nil {
			return fmt.Errorf("copilot: session.delete failed: %s", *result.Error)
		}
		return fmt.Errorf("copilot: session.delete failed: unknown error")
	}
	slog.Info("copilot: session deleted", "sessionId", sessionID)
	return nil
}

// GetSessionHistory implements core.HistoryProvider.
// Copilot does not expose a history RPC; return empty gracefully.
func (a *Agent) GetSessionHistory(_ context.Context, _ string, _ int) ([]core.HistoryEntry, error) {
	return nil, nil
}

// CompressCommand implements core.ContextCompressor.
// Copilot has no built-in compact/compress command.
func (a *Agent) CompressCommand() string { return "" }

// ── ProviderSwitcher implementation ──────────────────────────

func (a *Agent) SetProviders(providers []core.ProviderConfig) {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Upgrade the copilot CLI to a version that populates the error field on failed deletes
  2. Check copilot CLI logs for the actual failure cause since the response carries none
  3. Treat defensively: re-list sessions to see if the delete actually took effect despite success=false

Example fix

// before
if !result.Success {
    return fmt.Errorf("copilot: session.delete failed: unknown error")
}
// after
if !result.Success {
    if result.Error != nil { return fmt.Errorf("copilot: session.delete failed: %s", *result.Error) }
    slog.Warn("copilot session.delete reported failure without detail")
    return fmt.Errorf("copilot: session.delete failed: unknown error")
}
Defensive patterns

Strategy: fallback

Validate before calling

// confirm current state instead of trusting the ambiguous response
sessions, _ := a.ListSessions(ctx)
for _, s := range sessions { if s.ID == sessionID { /* still present */ } }

Type guard

func deleteErrKnown(err error) bool { return err != nil && strings.Contains(err.Error(), "session.delete failed") }

Try / catch

if err := a.DeleteSession(ctx, id); deleteErrKnown(err) {
    if still, _ := sessionExists(a, ctx, id); !still {
        slog.Info("session actually deleted despite unknown failure")
    }
}

Prevention

When it happens

Trigger: DeleteSession receiving copilotDeleteSessionResponse{Success:false, Error:nil} — a CLI build that omits the error field on failure.

Common situations: Older or beta copilot CLI versions with incomplete session.delete implementations; third-party/forked CLI binaries not following the documented response shape.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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