{"record":{"id":"0ebd1f23d6b60f5e","repo":"vxcontrol/pentagi","slug":"failed-to-get-all-flows-w","errorCode":null,"errorMessage":"failed to get all flows: %w","messagePattern":"failed to get all flows: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/docker/client.go","lineNumber":791,"sourceCode":"\t\tStatus: database.ContainerStatusDeleted,\n\t\tID:     dbID,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to update container status to deleted: %w\", err)\n\t}\n\n\tlogger.Info(\"container removed\")\n\n\treturn nil\n}\n\nfunc (dc *dockerClient) Cleanup(ctx context.Context) error {\n\tlogger := dc.logger.WithContext(ctx).WithField(\"docker\", \"cleanup\")\n\tlogger.Info(\"cleaning up containers and making all flows finished...\")\n\n\tflows, err := dc.db.GetFlows(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get all flows: %w\", err)\n\t}\n\n\tcontainers, err := dc.db.GetContainers(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get all containers: %w\", err)\n\t}\n\n\tflowsStatusMap := make(map[int64]database.FlowStatus)\n\tfor _, flow := range flows {\n\t\tflowsStatusMap[flow.ID] = flow.Status\n\t}\n\tflowContainersMap := make(map[int64][]database.Container)\n\tfor _, container := range containers {\n\t\tflowContainersMap[container.FlowID] = append(flowContainersMap[container.FlowID], container)\n\t}\n\n\tvar wg sync.WaitGroup\n\tremoveContainer := func(containerID string, dbID int64) {","sourceCodeStart":773,"sourceCodeEnd":809,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/docker/client.go#L773-L809","documentation":"Cleanup starts by fetching every flow row to mark flows finished and stop containers; this error wraps a failure of that initial GetFlows query. No cleanup work has been performed when it is returned.","triggerScenarios":"dc.db.GetFlows fails at Cleanup start: database unreachable, query timeout, corrupted/locked table, or a schema mismatch (migration not applied).","commonSituations":"Postgres down or restarting at backend shutdown/startup when Cleanup runs; network partition to the DB; pending goose migration leaving the flows table in an unexpected schema; connection pool exhausted.","solutions":["Verify database connectivity and that all goose migrations are applied","Check for table-level locks on flows (`pg_locks`) and terminate blocking sessions","Retry Cleanup after the database is healthy — it is safe to re-run since it is idempotent in intent","Review backend logs for the underlying pq/pgx error code to distinguish connectivity vs schema issues"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := db.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"database unavailable, deferring cleanup: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := dc.Cleanup(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to get all flows\") {\n        // DB was unavailable; re-run cleanup after recovery\n        scheduleRetry(ctx, dc.Cleanup)\n    }\n}","preventionTips":["Verify all goose migrations are applied before backend startup","Delay startup cleanup until the DB health check passes","Monitor Postgres availability with readiness probes","Keep the flows table free of long-held locks"],"tags":["database","postgresql","startup-cleanup"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}