{"record":{"id":"43baf2190547bd2f","repo":"plandex-ai/plandex","slug":"failed-to-delete-contexts-v","errorCode":null,"errorMessage":"failed to delete contexts: %v","messagePattern":"failed to delete contexts: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/context_update.go","lineNumber":278,"sourceCode":"\thasConflicts, err = checkContextConflicts(filesToLoad)\n\tif err != nil {\n\t\treturn UpdateContextResult{}, fmt.Errorf(\"failed to check context conflicts: %v\", err)\n\t}\n\n\tif len(req) > 0 {\n\t\tres, apiErr := api.Client.UpdateContext(CurrentPlanId, CurrentBranch, req)\n\t\tif apiErr != nil {\n\t\t\treturn UpdateContextResult{}, fmt.Errorf(\"failed to update context: %v\", apiErr)\n\t\t}\n\t\tmsg = res.Msg\n\t}\n\n\tif len(deleteIds) > 0 {\n\t\tres, apiErr := api.Client.DeleteContext(CurrentPlanId, CurrentBranch, shared.DeleteContextRequest{\n\t\t\tIds: deleteIds,\n\t\t})\n\t\tif apiErr != nil {\n\t\t\treturn UpdateContextResult{}, fmt.Errorf(\"failed to delete contexts: %v\", apiErr)\n\t\t}\n\t\tmsg += \" \" + res.Msg\n\t}\n\n\treturn UpdateContextResult{\n\t\tHasConflicts: hasConflicts,\n\t\tMsg:          strings.TrimSpace(msg),\n\t}, nil\n}\n\n// CheckOutdatedContext is where we replicate your partial-read logic for map files\n// so that large map files or newly added map files do not read more than MaxContextMapSingleInputSize\nfunc CheckOutdatedContext(maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (*types.ContextOutdatedResult, error) {\n\treturn checkOutdatedAndMaybeUpdateContext(false, maybeContexts, projectPaths)\n}\n\ntype mapState struct {\n\tremovedMapPaths      []string","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_update.go#L260-L296","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the wrapped apiErr — 'not found' errors usually mean the context was already deleted elsewhere; re-list context and retry","Re-authenticate on 401/403 and retry","Avoid concurrent updates to the same plan/branch from multiple sessions","Verify CurrentPlanId/CurrentBranch match the plan you intend (reload current plan state)"],"exampleFix":"// before: hard fail when context already deleted server-side\nres, apiErr := api.Client.DeleteContext(CurrentPlanId, CurrentBranch, shared.DeleteContextRequest{Ids: deleteIds})\nif apiErr != nil { return UpdateContextResult{}, fmt.Errorf(\"failed to delete contexts: %v\", apiErr) }\n// after (caller): refresh context list and retry once\nres, err := lib.UpdateContext(params)\nif err != nil && strings.Contains(err.Error(), \"failed to delete contexts\") {\n    fresh, _ := api.Client.ListContext(CurrentPlanId, CurrentBranch)\n    _ = fresh\n    res, err = lib.UpdateContext(params)\n}","handlingStrategy":"retry","validationCode":"// ensure the ids to delete still exist server-side\nfresh, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)\nif err != nil { return err }\nlive := map[string]bool{}\nfor _, c := range fresh { live[c.Id] = true }","typeGuard":null,"tryCatchPattern":"res, err := lib.UpdateContext(params)\nif err != nil && strings.Contains(err.Error(), \"failed to delete contexts\") {\n    // refresh context list, rebuild params, retry once\n    fresh, _ := api.Client.ListContext(CurrentPlanId, CurrentBranch)\n    params = rebuildParams(fresh)\n    res, err = lib.UpdateContext(params)\n}","preventionTips":["Avoid updating the same plan from multiple terminals concurrently","Re-list context before applying deletions","Treat 'not found' delete errors as already-satisfied, not fatal","Keep CurrentPlanId/CurrentBranch synchronized with the loaded plan"],"tags":["go","api","delete","concurrency"],"backgroundTag":"api-request-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}