{"record":{"id":"c54eef0a93d95f65","repo":"plandex-ai/plandex","slug":"error-getting-context-v","errorCode":null,"errorMessage":"error getting context: %v","messagePattern":"error getting context: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/context_helpers_update.go","lineNumber":157,"sourceCode":"\n\tfor id, params := range *req {\n\t\tgo func(id string, params *shared.UpdateContextParams) {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tlog.Printf(\"panic in UpdateContexts: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\terrCh <- fmt.Errorf(\"panic in UpdateContexts: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t\t}\n\t\t\t}()\n\t\t\tvar context *Context\n\t\t\tif _, ok := contextsById[id]; ok {\n\t\t\t\tcontext = contextsById[id]\n\t\t\t} else {\n\t\t\t\tvar err error\n\t\t\t\tcontext, err = GetContext(orgId, planId, id, true, true)\n\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCh <- fmt.Errorf(\"error getting context: %v\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\t// log.Println(\"Got context\", context.Id, \"numTokens\", context.NumTokens)\n\t\t\t}\n\n\t\t\tmu.Lock()\n\t\t\tdefer mu.Unlock()\n\n\t\t\tcontextsById[id] = context\n\t\t\tupdatedContexts = append(updatedContexts, context.ToApi())\n\n\t\t\tif context.ContextType != shared.ContextMapType {\n\t\t\t\tvar updateNumTokens int\n\t\t\t\tvar err error\n\n\t\t\t\tif context.ContextType == shared.ContextImageType {\n\t\t\t\t\tupdateNumTokens, err = shared.GetImageTokens(params.Body, context.ImageDetail)\n\t\t\t\t\tif err != nil {","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/context_helpers_update.go#L139-L175","documentation":"Inside the per-context goroutine, if the context ID is not already in contextsById, UpdateContexts fetches it from the database with GetContext(orgId, planId, id, true, true); this error wraps any failure of that lookup and is sent to errCh, failing the overall update.","triggerScenarios":"Calling UpdateContexts with an ID referencing a context that GetContext cannot load — context doesn't exist under (orgId, planId), the ID is malformed, or the DB read fails (connection error, permissions, missing row).","commonSituations":"Stale client cache holding IDs of contexts already deleted; IDs copied across plans or orgs; transient database connectivity failure during the update; ID string typos or truncation in caller code.","solutions":["Verify the context ID exists under the same orgId/planId (e.g. list contexts first) and drop stale IDs.","Re-fetch the plan's context list to refresh IDs before retrying the update.","Check DB connectivity/logs if GetContext fails on a known-good ID.","Handle missing-context IDs gracefully by skipping them instead of including them in the update request."],"exampleFix":"// before\nreq := map[string]*shared.UpdateContextParams{staleId: {Body: body}}\nUpdateContexts(orgId, planId, branch, &req)\n// after\nexisting := ListContextIds(orgId, planId)\nfor id := range req {\n    if !slices.Contains(existing, id) {\n        delete(req, id) // skip stale ids\n    }\n}","handlingStrategy":"try-catch","validationCode":"ids := ListContextIds(orgId, planId)\nfor id := range req {\n    if !slices.Contains(ids, id) { return fmt.Errorf(\"context %s does not exist for plan %s\", id, planId) }\n}\n","typeGuard":"func contextExists(orgId, planId, id string) bool {\n    c, err := GetContext(orgId, planId, id, false, false)\n    return err == nil && c != nil\n}","tryCatchPattern":"err := <-errCh\nif err != nil && strings.Contains(err.Error(), \"error getting context\") {\n    // refresh context IDs and retry, or skip the missing ID\n}","preventionTips":["Refresh the context ID list before each update; never reuse IDs across plans/orgs","Pre-load contexts into contextsById where possible so GetContext isn't needed","Skip missing IDs client-side instead of including them in the request","Watch DB connectivity; transient read failures also surface here"],"tags":["go","context-lookup","db","not-found"],"backgroundTag":"resource-not-found","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"}