{"record":{"id":"1a06e0112da9c338","repo":"plandex-ai/plandex","slug":"error-getting-active-model-stream-v","errorCode":null,"errorMessage":"error getting active model stream: %v","messagePattern":"error getting active model stream: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"app/server/model/plan/activate.go","lineNumber":41,"sourceCode":"\tsessionId string,\n) (*types.ActivePlan, error) {\n\tlog.Printf(\"Activate plan: plan ID %s on branch %s\\n\", plan.Id, branch)\n\n\t// Just in case this request was made immediately after another stream finished, wait a little to allow for cleanup\n\tlog.Println(\"Waiting 100ms before checking for active plan\")\n\ttime.Sleep(100 * time.Millisecond)\n\tlog.Println(\"Done waiting, checking for active plan\")\n\n\tactive := GetActivePlan(plan.Id, branch)\n\tif active != nil {\n\t\tlog.Printf(\"Tell: Active plan found for plan ID %s on branch %s\\n\", plan.Id, branch) // Log if an active plan is found\n\t\treturn nil, fmt.Errorf(\"plan %s branch %s already has an active stream on this host\", plan.Id, branch)\n\t}\n\n\tmodelStream, err := db.GetActiveModelStream(plan.Id, branch)\n\tif err != nil {\n\t\tlog.Printf(\"Error getting active model stream: %v\\n\", err)\n\t\treturn nil, fmt.Errorf(\"error getting active model stream: %v\", err)\n\t}\n\n\tif modelStream != nil {\n\t\tlog.Printf(\"Tell: Active model stream found for plan ID %s on branch %s on host %s\\n\", plan.Id, branch, modelStream.InternalIp) // Log if an active model stream is found\n\t\treturn nil, fmt.Errorf(\"plan %s branch %s already has an active stream on host %s\", plan.Id, branch, modelStream.InternalIp)\n\t}\n\n\tactive = CreateActivePlan(\n\t\tauth.OrgId,\n\t\tauth.User.Id,\n\t\tplan.Id,\n\t\tbranch,\n\t\tprompt,\n\t\tbuildOnly,\n\t\tautoContext,\n\t\tsessionId,\n\t)\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/model/plan/activate.go#L23-L59","documentation":"After the in-memory active-plan check, activatePlan queries db.GetActiveModelStream(plan.Id, branch). If that database call fails, the error is wrapped and returned as \"error getting active model stream: %v\". This is a storage/persistence failure during activation, not a business conflict.","triggerScenarios":"db.GetActiveModelStream returns a database error: DB connection failure, timeout, schema/migration mismatch, or locked database while another writer holds a transaction.","commonSituations":"Database unreachable after a deploy, expired DB credentials, migration lag where the model_streams table is missing a column, or sqlite/file DB lock contention.","solutions":["Read the wrapped cause (%v payload) and fix the underlying DB error (connectivity, auth, schema).","Verify DB reachability and credentials from the server host.","Run pending migrations so the active-model-stream schema exists.","Retry activation after transient DB failures; add backoff on the caller side."],"exampleFix":"// before: raw call without health guard\nif !dbHealthy() { return errors.New(\"db not ready\") }\n_, err := db.GetActiveModelStream(planId, branch)\n// after: retry transient DB errors\nstream, err := db.GetActiveModelStream(planId, branch)\nif isTransientDBErr(err) { time.Sleep(time.Second); stream, err = db.GetActiveModelStream(planId, branch) }","handlingStrategy":"retry","validationCode":"if err := db.Ping(); err != nil {\n    return fmt.Errorf(\"database unavailable before plan activation: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"_, err := Tell(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"error getting active model stream\") {\n    // retry after DB recovers\n    time.Sleep(2 * time.Second)\n    _, err = Tell(ctx, req)\n}","preventionTips":["Monitor DB health/latency before and during deploys","Apply migrations before rolling out new server versions","Use connection pooling with sane timeouts","Alert on DB error rates to catch outages early"],"tags":["database","persistence","plan-stream"],"backgroundTag":"database-query-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"}