plandex-ai/plandex · error

failed to delete contexts: %v

Error message

failed to delete contexts: %v

What it means

When the outdated result marks removed contexts, UpdateContext calls api.Client.DeleteContext with their ids; any API failure there is wrapped as 'failed to delete contexts'. The update result is aborted so deletions and updates stay transactional from the caller's perspective.

Source

Thrown at app/cli/lib/context_update.go:278

	hasConflicts, err = checkContextConflicts(filesToLoad)
	if err != nil {
		return UpdateContextResult{}, fmt.Errorf("failed to check context conflicts: %v", err)
	}

	if len(req) > 0 {
		res, apiErr := api.Client.UpdateContext(CurrentPlanId, CurrentBranch, req)
		if apiErr != nil {
			return UpdateContextResult{}, fmt.Errorf("failed to update context: %v", apiErr)
		}
		msg = res.Msg
	}

	if len(deleteIds) > 0 {
		res, apiErr := api.Client.DeleteContext(CurrentPlanId, CurrentBranch, shared.DeleteContextRequest{
			Ids: deleteIds,
		})
		if apiErr != nil {
			return UpdateContextResult{}, fmt.Errorf("failed to delete contexts: %v", apiErr)
		}
		msg += " " + res.Msg
	}

	return UpdateContextResult{
		HasConflicts: hasConflicts,
		Msg:          strings.TrimSpace(msg),
	}, nil
}

// CheckOutdatedContext is where we replicate your partial-read logic for map files
// so that large map files or newly added map files do not read more than MaxContextMapSingleInputSize
func CheckOutdatedContext(maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (*types.ContextOutdatedResult, error) {
	return checkOutdatedAndMaybeUpdateContext(false, maybeContexts, projectPaths)
}

type mapState struct {
	removedMapPaths      []string

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the wrapped apiErr — 'not found' errors usually mean the context was already deleted elsewhere; re-list context and retry
  2. Re-authenticate on 401/403 and retry
  3. Avoid concurrent updates to the same plan/branch from multiple sessions
  4. Verify CurrentPlanId/CurrentBranch match the plan you intend (reload current plan state)

Example fix

// before: hard fail when context already deleted server-side
res, apiErr := api.Client.DeleteContext(CurrentPlanId, CurrentBranch, shared.DeleteContextRequest{Ids: deleteIds})
if apiErr != nil { return UpdateContextResult{}, fmt.Errorf("failed to delete contexts: %v", apiErr) }
// after (caller): refresh context list and retry once
res, err := lib.UpdateContext(params)
if err != nil && strings.Contains(err.Error(), "failed to delete contexts") {
    fresh, _ := api.Client.ListContext(CurrentPlanId, CurrentBranch)
    _ = fresh
    res, err = lib.UpdateContext(params)
}
Defensive patterns

Strategy: retry

Validate before calling

// ensure the ids to delete still exist server-side
fresh, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)
if err != nil { return err }
live := map[string]bool{}
for _, c := range fresh { live[c.Id] = true }

Try / catch

res, err := lib.UpdateContext(params)
if err != nil && strings.Contains(err.Error(), "failed to delete contexts") {
    // refresh context list, rebuild params, retry once
    fresh, _ := api.Client.ListContext(CurrentPlanId, CurrentBranch)
    params = rebuildParams(fresh)
    res, err = lib.UpdateContext(params)
}

Prevention

When it happens

Trigger: api.Client.DeleteContext(CurrentPlanId, CurrentBranch, {Ids: deleteIds}) errors: one or more ids already deleted on the server (another session), plan/branch mismatch, expired auth, network failure, or server 5xx.

Common situations: Two terminals on the same plan both updating outdated context concurrently; files deleted locally then server rejects partial deletion; stale plan id after switching plans without refreshing CurrentPlanId.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/43baf2190547bd2f. Report an issue: GitHub.