{"record":{"id":"3732893f98e075d5","repo":"plandex-ai/plandex","slug":"error-storing-model-stream-v","errorCode":null,"errorMessage":"error storing model stream: %v","messagePattern":"error storing model stream: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"app/server/model/plan/activate.go","lineNumber":74,"sourceCode":"\t\tautoContext,\n\t\tsessionId,\n\t)\n\n\tmodelStream = &db.ModelStream{\n\t\tOrgId:      auth.OrgId,\n\t\tPlanId:     plan.Id,\n\t\tInternalIp: host.Ip,\n\t\tBranch:     branch,\n\t}\n\terr = db.StoreModelStream(modelStream, active.Ctx, active.CancelFn)\n\tif err != nil {\n\t\tlog.Printf(\"Tell: Error storing model stream for plan ID %s on branch %s: %v\\n\", plan.Id, branch, err) // Log error storing model stream\n\t\tlog.Printf(\"Error storing model stream: %v\\n\", err)\n\t\tlog.Printf(\"Tell: Error storing model stream: %v\\n\", err) // Log error storing model stream\n\n\t\tactive.StreamDoneCh <- &shared.ApiError{Msg: fmt.Sprintf(\"Error storing model stream: %v\", err)}\n\n\t\treturn nil, fmt.Errorf(\"error storing model stream: %v\", err)\n\t}\n\n\tactive.ModelStreamId = modelStream.Id\n\n\tlog.Printf(\"Tell: Model stream stored with ID %s for plan ID %s on branch %s\\n\", modelStream.Id, plan.Id, branch) // Log successful storage of model stream\n\tlog.Println(\"Model stream id:\", modelStream.Id)\n\n\treturn active, nil\n}\n","sourceCodeStart":56,"sourceCodeEnd":84,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/model/plan/activate.go#L56-L84","documentation":"During activation, after creating the ActivePlan, the code stores the model stream via the db layer. If storage fails, it sends an ApiError on active.StreamDoneCh (to abort the just-created active plan) and returns \"error storing model stream: %v\". Activation cannot proceed without a persisted stream record.","triggerScenarios":"db stream-store call fails while activating: DB outage, connection loss between CreateActivePlan and the store call, unique-constraint violation on an existing stream id, or serialization error of the stream payload.","commonSituations":"Database restarts mid-deploy, disk-full on the DB host, credentials rotated between the two DB calls, or constraint conflicts from a half-cleaned previous activation.","solutions":["Inspect the wrapped cause and restore DB connectivity/credentials.","Clean up any partially created active-plan/stream rows from the failed attempt, then retry.","Make activation idempotent: upsert the stream instead of blind insert to tolerate retries.","Ensure the StreamDoneCh abort path also releases the ActivePlan so retries are not blocked by error 645."],"exampleFix":"// before: insert fails on leftover row\nerr := db.CreateModelStream(modelStream)\n// after: idempotent upsert\nerr := db.UpsertModelStream(modelStream)","handlingStrategy":"retry","validationCode":"if err := db.Ping(); err != nil {\n    return fmt.Errorf(\"skipping activation, database unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"_, err := Tell(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"error storing model stream\") {\n    time.Sleep(2 * time.Second) // let ActivePlan abort propagate\n    _, err = Tell(ctx, req)\n}","preventionTips":["Check DB disk space and credential rotation schedules","Make stream storage idempotent (upsert) so retries succeed","Verify the StreamDoneCh abort path releases the ActivePlan before retrying","Add DB write latency/error dashboards"],"tags":["database","persistence","plan-stream"],"backgroundTag":"database-write-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"}