{"record":{"id":"e86ed09f615cfd74","repo":"plandex-ai/plandex","slug":"error-updating-context-v-e86ed0","errorCode":null,"errorMessage":"error updating context: %v","messagePattern":"error updating context: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/result_helpers.go","lineNumber":697,"sourceCode":"\t\t\t\tcontext := contextsByPath[path]\n\t\t\t\tupdateReq[context.Id] = &shared.UpdateContextParams{\n\t\t\t\t\tBody: currentPlanState.CurrentPlanFiles.Files[path],\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif len(updateReq) > 0 {\n\t\t\t\tres, err := UpdateContexts(\n\t\t\t\t\tUpdateContextsParams{\n\t\t\t\t\t\tOrgId:                    orgId,\n\t\t\t\t\t\tPlan:                     plan,\n\t\t\t\t\t\tBranchName:               branchName,\n\t\t\t\t\t\tReq:                      &updateReq,\n\t\t\t\t\t\tSkipConflictInvalidation: true, // no need to invalidate conflicts when applying plan--and fixes race condition since invalidation check loads description\n\t\t\t\t\t},\n\t\t\t\t)\n\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCh <- fmt.Errorf(\"error updating context: %v\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tupdateContextRes = res\n\t\t\t}\n\t\t\terrCh <- nil\n\n\t\t}()\n\n\t}\n\n\tfor i := 0; i < numRoutines; i++ {\n\t\terr := <-errCh\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error applying plan: %v\", err)\n\t\t}\n\t}\n","sourceCodeStart":679,"sourceCodeEnd":715,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/result_helpers.go#L679-L715","documentation":"This error wraps a failure from UpdateContexts() while ApplyPlan applies new bodies to modified files on the plan's branch. The goroutine builds an UpdateContextRequest keyed by existing context IDs from contextsByPath, calls UpdateContexts with SkipConflictInvalidation=true, and on error sends \"error updating context: %v\" on errCh. ApplyPlan aborts before writing the PlanApply record, so partial updates may already be persisted but the apply is not recorded.","triggerScenarios":"Calling ApplyPlan with pendingUpdatedFilesSet non-empty and UpdateContexts failing: context ID no longer exists (deleted/renamed), DB/storage write error, conflict check inside UpdateContexts fails, or the supplied Body is invalid for the context type.","commonSituations":"File contexts deleted or re-created between loading and applying, so stored context IDs are stale; storage backend unavailable (disk full, permissions); concurrent branch operations invalidating contexts; plan state regenerated between load and apply producing mismatched context IDs.","solutions":["Read the wrapped inner error to find the specific UpdateContexts failure (stale ID, storage error, conflict).","Re-load the plan's contexts (LoadContexts) to get fresh context IDs and re-run ApplyPlan with current state.","Verify the target context still exists for every path in pendingUpdatedFilesSet; re-add missing ones as new files instead of updates.","Check storage directory permissions/disk space for the org/plan data directories.","Avoid running branch switches or plan deletions concurrently with ApplyPlan."],"exampleFix":"// before: stale context IDs cause UpdateContexts to fail\nupdateReq[context.Id] = &shared.UpdateContextParams{Body: body}\nres, err := UpdateContexts(params) // error updating context: context not found\n\n// after: refresh contexts and fall back to load when the ID is gone\ncontext, ok := contextsByPath[path]\nif !ok || context.Id == \"\" {\n    return fmt.Errorf(\"context for %s missing; re-load contexts and retry apply\", path)\n}\nres, err := UpdateContexts(params)","handlingStrategy":"retry","validationCode":"for path := range planState.CurrentPlanFiles.Files {\n    ctxRec, ok := contextsByPath[path]\n    if !ok || ctxRec.Id == \"\" {\n        return fmt.Errorf(\"context for %s missing/stale; re-load before applying\", path)\n    }\n}","typeGuard":null,"tryCatchPattern":"err := db.ApplyPlan(ctx, params)\nif err != nil && strings.Contains(err.Error(), \"error updating context:\") {\n    // re-load contexts to refresh IDs, then retry once\n    fresh, _, lerr := db.LoadContexts(ctx, loadParams)\n    if lerr == nil {\n        err = db.ApplyPlan(ctx, refreshedParams)\n    }\n}","preventionTips":["Re-load contexts immediately before ApplyPlan so context IDs are fresh.","Treat deleted/renamed files as new-file loads rather than context updates.","Avoid branch switches or plan deletions concurrent with an apply.","Monitor storage health (disk space, permissions) on the org data directory."],"tags":["go","context-update","plan-apply","stale-state"],"backgroundTag":"context-update-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}