{"record":{"id":"3df09a6d07e63626","repo":"plandex-ai/plandex","slug":"error-getting-recent-model-streams-v","errorCode":null,"errorMessage":"error getting recent model streams: %v","messagePattern":"error getting recent model streams: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_crud.go","lineNumber":460,"sourceCode":"\tvar branches []*db.Branch\n\n\tgo func() {\n\t\tdefer func() {\n\t\t\tif r := recover(); r != nil {\n\t\t\t\tlog.Printf(\"panic in ListPlansRunningHandler: %v\\n%s\", r, debug.Stack())\n\t\t\t\terrCh <- fmt.Errorf(\"panic in ListPlansRunningHandler: %v\\n%s\", r, debug.Stack())\n\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t}\n\t\t}()\n\n\t\tvar err error\n\t\tif includeRecent {\n\t\t\tstreams, err = db.GetActiveOrRecentModelStreams(planIds)\n\t\t} else {\n\t\t\tstreams, err = db.GetActiveModelStreams(planIds)\n\t\t}\n\t\tif err != nil {\n\t\t\terrCh <- fmt.Errorf(\"error getting recent model streams: %v\", err)\n\t\t\treturn\n\t\t}\n\t\terrCh <- nil\n\t}()\n\n\tgo func() {\n\t\tdefer func() {\n\t\t\tif r := recover(); r != nil {\n\t\t\t\tlog.Printf(\"panic in ListPlansRunningHandler: %v\\n%s\", r, debug.Stack())\n\t\t\t\terrCh <- fmt.Errorf(\"panic in ListPlansRunningHandler: %v\\n%s\", r, debug.Stack())\n\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t}\n\t\t}()\n\t\tvar err error\n\t\tbranches, err = db.ListBranchesForPlans(auth.OrgId, planIds)\n\t\tif err != nil {\n\t\t\terrCh <- fmt.Errorf(\"error getting branches: %v\", err)\n\t\t\treturn","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_crud.go#L442-L478","documentation":"In ListPlansRunningHandler, a goroutine fetches active or recent model streams for the requested plan IDs via db.GetActiveOrRecentModelStreams / db.GetActiveModelStreams. When the database query fails, the underlying error is wrapped with this message and sent to errCh; the handler collects it and returns HTTP 500.","triggerScenarios":"The Postgres query for model streams fails: DB unreachable, connection pool exhausted, SQL error, table/schema drift (e.g. model_streams table missing or migration not applied), or empty/invalid planIds causing a malformed IN clause.","commonSituations":"Database outage or restart during deployment; connection-pool saturation under load; running the server against a schema that predates the model streams migration; read-replica failover.","solutions":["Check the wrapped %v cause and verify the database is reachable (connection string, network, pool limits).","Run schema migrations and confirm the model streams tables exist.","Verify planIds is populated and correctly formed before querying.","Check Postgres logs at the time of failure for the exact SQL error."],"exampleFix":"// before\nstreams, err = db.GetActiveOrRecentModelStreams(planIds)\n// after\nif len(planIds) == 0 { planIds = []string{\"\"} }\nstreams, err = db.GetActiveOrRecentModelStreams(planIds)\nif err != nil {\n    log.Printf(\"stream query failed: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Go\nif len(planIds) == 0 {\n    return nil // nothing to query; skip DB round-trip\n}\nif err := db.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"db unavailable: %w\", err)\n}","typeGuard":"func planIdsValid(ids []string) bool { return len(ids) > 0 }","tryCatchPattern":"streams, err := db.GetActiveOrRecentModelStreams(planIds)\nif err != nil {\n    log.Printf(\"model streams query failed: %v\", err)\n    http.Error(w, \"failed to load model streams\", http.StatusBadGateway)\n    return\n}","preventionTips":["Apply migrations before deploying server updates.","Monitor DB pool saturation and connection errors.","Keep planIds non-empty before querying.","Alert on Postgres error logs for the model_streams tables."],"tags":["database","go","postgres"],"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-14T00:17:10.932Z"}