{"record":{"id":"cb896f1edaac5e1b","repo":"plandex-ai/plandex","slug":"error-rejecting-result-v","errorCode":null,"errorMessage":"error rejecting result: %v","messagePattern":"error rejecting result: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/result_helpers.go","lineNumber":820,"sourceCode":"\n\terrCh := make(chan error, len(files))\n\tnow := time.Now()\n\n\tfor _, file := range files {\n\t\tresultId := strings.TrimSuffix(file.Name(), \".json\")\n\n\t\tgo func(resultId string) {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tlog.Printf(\"panic in RejectAllResults: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\terrCh <- fmt.Errorf(\"panic in RejectAllResults: %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\terr := RejectPlanFile(orgId, planId, resultId, now)\n\n\t\t\tif err != nil {\n\t\t\t\terrCh <- fmt.Errorf(\"error rejecting result: %v\", err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\terrCh <- nil\n\t\t}(resultId)\n\t}\n\n\tfor i := 0; i < len(files); i++ {\n\t\terr := <-errCh\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error rejecting plan: %v\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc DeletePendingResultsForPaths(orgId, planId string, paths map[string]bool) error {","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/result_helpers.go#L802-L838","documentation":"Each goroutine in RejectAllResults calls RejectPlanFile(orgId, planId, resultId, now) to reject one pending result. If that call returns an error, it is wrapped with this message and sent to errCh. It means a single result file failed to be rejected; the parent surfaces it as 'error rejecting plan'.","triggerScenarios":"RejectPlanFile fails for one resultId — the result file disappeared between ReadDir and read, JSON unmarshal fails on corrupt content, a write/rename inside RejectPlanFile hits permissions or disk-full, or a sub-call rejects invalid state.","commonSituations":"Result file deleted concurrently by another cleanup job; truncated JSON from an earlier crashed write; read-only mount; two instances of the app processing the same plan simultaneously.","solutions":["Read the wrapped cause to see which sub-step of RejectPlanFile failed","Re-run RejectAllResults — transient/concurrent cases often succeed on retry","Validate/repair the specific <resultId>.json content (truncated/corrupt files may need removal)","Ensure only one process mutates the plan's results directory at a time (locking or leader election)"],"exampleFix":"// before\nerr := RejectPlanFile(orgId, planId, resultId, now)\nif err != nil {\n    errCh <- fmt.Errorf(\"error rejecting result: %v\", err)\n    return\n}\n// after: tolerate already-deleted files\nerr := RejectPlanFile(orgId, planId, resultId, now)\nif err != nil {\n    if os.IsNotExist(err) {\n        errCh <- nil\n        return\n    }\n    errCh <- fmt.Errorf(\"error rejecting result %s: %v\", resultId, err)\n    return\n}","handlingStrategy":"retry","validationCode":"resultPath := filepath.Join(resultsDir, resultId+\".json\")\nif _, err := os.Stat(resultPath); os.IsNotExist(err) {\n    return nil // already gone; nothing to reject\n}","typeGuard":null,"tryCatchPattern":"err := RejectPlanFile(orgId, planId, resultId, now)\nif err != nil {\n    if os.IsNotExist(err) {\n        errCh <- nil\n        return\n    }\n    errCh <- fmt.Errorf(\"error rejecting result %s: %v\", resultId, err)\n    return\n}","preventionTips":["Serialize reject/apply jobs per plan to avoid concurrent mutation","Treat ENOENT as success in idempotent cleanup flows","Log resultId with every failure for targeted follow-up","Validate result file contents before processing and quarantine corrupt files"],"tags":["go","concurrency","filesystem","error-handling"],"backgroundTag":"reject-result-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"}