{"results":{"result":{"added-files":{"code-health":10.0,"old-code-health":0.0,"files":[{"file":"apps/experiments/tests/test_participant_consent.py","loc":44,"code-health":10.0},{"file":"apps/api/chat_consent.py","loc":41,"code-health":10.0},{"file":"apps/api/tests/test_chat_consent_api.py","loc":243,"code-health":10.0}]},"external-review-url":"https://github.com/dimagi/open-chat-studio/pull/4306","old-code-health":8.061109512204032,"modified-files":{"code-health":7.8835750656785,"old-code-health":8.061109512204032,"files":[{"file":"apps/experiments/models.py","loc":1512,"old-loc":1496,"code-health":6.861990946250543,"old-code-health":6.861990946250543},{"file":"apps/channels/tests/test_widget_versions.py","loc":230,"old-loc":214,"code-health":10.0,"old-code-health":10.0},{"file":"apps/channels/widget_versions.py","loc":177,"old-loc":172,"code-health":10.0,"old-code-health":10.0},{"file":"apps/api/serializers.py","loc":382,"old-loc":358,"code-health":10.0,"old-code-health":10.0},{"file":"apps/api/tests/test_chat_api_anon.py","loc":229,"old-loc":208,"code-health":10.0,"old-code-health":10.0},{"file":"apps/api/views/chat.py","loc":895,"old-loc":804,"code-health":7.559811009488815,"old-code-health":8.601454004310554},{"file":"apps/experiments/tests/test_models.py","loc":968,"old-loc":957,"code-health":7.552876135642913,"old-code-health":7.552876135642913}]},"removed-files":{"code-health":0.0,"old-code-health":0.0,"files":[]},"external-review-id":"4306","analysis-time":"2026-08-31T11:12:42Z","negative-impact-count":3,"suppressions":{"number-of-types":0,"number-of-files-touched":0,"findings":[]},"affected-hotspots":2,"commits":["4060392c3e65fac6907b451fa9d7c351860afb4a","2fb95c7312f9385e5132b3e72f1924adf48d5e2c","ecade0fce6703c59718113b6bf8c112fd8a76bb5","cd3192877b1cce96ecc3ee531e31921a13e49312","9c166cc2fe85e6a6c7245b0ea022698857c80347","6dd19488759999edbc5f4f8823ef26220d519129","c1fdb4fbd30f32a71c8576b80174706b6e531d1d","cacce4f219bb5f2ede85ffdb22fb69d1b1e66b15","a97f4cd012ddb1a45a544b4f2e7e803009af1c56","8443ea1f75bf92ce694d70a7fe1d9af2e7a0cc39","615306a9cfce01bb4668d7717021056d8bb797fa","a503dd63f2a7c5881a66945f58a351350b8eb725","b66ff35b75fc2ddbf5dba9292a6ef279da5bafb0","5171cd0fca41f000958b8a7aeae68965ce2fcab7","86bf68af74b569ce939d22bb5046eb4a6807071c","6f41d285daf4b73bcd11e7991d90dd663de5be8e","33b05ad329fddd808b62a83bf4b537802589cdfa"],"is-negative-review":true,"negative-findings":{"number-of-types":2,"number-of-files-touched":1,"findings":[{"why-it-occurs":"Cohesion is a measure of how well the elements in a file belong together. CodeScene measures cohesion using the LCOM4 metric (Lack of Cohesion Measure). With LCOM4, the functions inside a module are related if a) they access the same data members, or b) they call each other. High Cohesion is desirable as it means that all functions are related and likely to represent the same responsibility. Low Cohesion is problematic since it means that the module contains multiple behaviors. Low Cohesion leads to code that's harder to understand, requires more tests, and very often become a coordination magnet for developers.","name":"Low Cohesion","file":"apps/api/views/chat.py","refactoring-examples":[{"diff":"diff --git a/low_cohesion_example.js b/low_cohesion_example.js\nindex 1ae56cf85b..209fc02c73 100644\n--- a/low_cohesion_example.js\n+++ b/low_cohesion_example.js\n@@ -2,8 +2,10 @@\n \n var userLayer = connectUsers(myConnectionProperties);\n \n-var chessEngine = startEngine(gameProperties);\n+// [Refactoring: moved the data related to chess to a new chessGame.js module]\n \n+// The module contains login related functionality that forms one behaviour: all\n+// code is related since it either a) uses the same data, or b) calls the same functions.\n export function login(newUser) {\n   val authenticated = userLayer.authenticate(newUser);\n   traceLoginFor(authenticated);\n@@ -19,11 +21,6 @@ function traceLogin(user) {\n    // ...some code...\n }\n \n-// playChess seems like a very unrelated responsibility.\n-// Should it really be within the same module?\n-\n-export function playChess(loggedInUser) {\n-   var board = chessEngine.newBoard();\n-\n-   return newGameOn(board, loggedInUser);\n-}\n+// [Refactoring: moved playChess to a new chessGame.js module\n+// As a result of this refactoring, the module maintains a\n+// single behavior where all code and data is related: high cohesion.]\n","language":"python","improvement-type":"Low Cohesion"}],"change-level":"warning","is-hotspot?":true,"what-changed":"This module has at least 4 different responsibilities amongst its 26 functions, threshold = 4","how-to-fix":"Look to modularize the code by splitting the file into more cohesive units; functions that belong together should still be located together. A common refactoring is [EXTRACT CLASS](https://refactoring.com/catalog/extractClass.html).","change-type":"introduced"},{"method":"chat_start_session","why-it-occurs":"A Complex Method has a high cyclomatic complexity. The recommended threshold for the Python language is a cyclomatic complexity lower than 11.","name":"Complex Method","file":"apps/api/views/chat.py","refactoring-examples":[{"diff":"diff --git a/complex_method.js b/complex_method.js\nindex 10cce78e6d..0c1a8cabaf 100644\n--- a/complex_method.js\n+++ b/complex_method.js\n@@ -1,15 +1,20 @@\n function postItem(item) {\n   if (!item.id) {\n-    if (item.x != null && item.y != null) {\n-      post(item);\n-    } else {\n-      throw Error(\"Item must have x and y\");\n-    }\n+    // extract a separate function for creating new item\n+    postNew(item);\n   } else {\n-    if (item.x < 10 && item.y > 25) {\n-      put(item);\n-    } else {\n-      throw Error(\"Item must have an x and y value between 10 and 25\");\n-    }\n+    // and one for updating existing items\n+    updateItem(item);\n   }\n }\n+\n+function postNew(item) {\n+  validateNew(item);\n+  post(item);\n+}\n+\n+function updateItem(item) {\n+  validateUpdate(item);\n+  put(item);\n+}\n+\n","language":"python","improvement-type":"Complex Method"}],"change-level":"warning","is-hotspot?":true,"line":573,"what-changed":"chat_start_session increases in cyclomatic complexity from 17 to 18, threshold = 11","how-to-fix":"There are many reasons for Complex Method. Sometimes, another design approach is beneficial such as a) modeling state using an explicit state machine rather than conditionals, or b) using table lookup rather than long chains of logic. In other scenarios, the function can be split using [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html). Just make sure you extract natural and cohesive functions. Complex Methods can also be addressed by identifying complex conditional expressions and then using the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring.","change-type":"degraded"},{"method":"chat_upload_file","why-it-occurs":"A Complex Method has a high cyclomatic complexity. The recommended threshold for the Python language is a cyclomatic complexity lower than 11.","name":"Complex Method","file":"apps/api/views/chat.py","refactoring-examples":[{"diff":"diff --git a/complex_method.js b/complex_method.js\nindex 10cce78e6d..0c1a8cabaf 100644\n--- a/complex_method.js\n+++ b/complex_method.js\n@@ -1,15 +1,20 @@\n function postItem(item) {\n   if (!item.id) {\n-    if (item.x != null && item.y != null) {\n-      post(item);\n-    } else {\n-      throw Error(\"Item must have x and y\");\n-    }\n+    // extract a separate function for creating new item\n+    postNew(item);\n   } else {\n-    if (item.x < 10 && item.y > 25) {\n-      put(item);\n-    } else {\n-      throw Error(\"Item must have an x and y value between 10 and 25\");\n-    }\n+    // and one for updating existing items\n+    updateItem(item);\n   }\n }\n+\n+function postNew(item) {\n+  validateNew(item);\n+  post(item);\n+}\n+\n+function updateItem(item) {\n+  validateUpdate(item);\n+  put(item);\n+}\n+\n","language":"python","improvement-type":"Complex Method"}],"change-level":"warning","is-hotspot?":true,"line":172,"what-changed":"chat_upload_file increases in cyclomatic complexity from 14 to 15, threshold = 11","how-to-fix":"There are many reasons for Complex Method. Sometimes, another design approach is beneficial such as a) modeling state using an explicit state machine rather than conditionals, or b) using table lookup rather than long chains of logic. In other scenarios, the function can be split using [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html). Just make sure you extract natural and cohesive functions. Complex Methods can also be addressed by identifying complex conditional expressions and then using the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring.","change-type":"degraded"}]},"positive-impact-count":0,"repo":"open-chat-studio","code-health":8.030617509749131,"version":"3.0","authors":["barry47products"],"directives":{"added":[],"removed":[]},"positive-findings":{"number-of-types":0,"number-of-files-touched":0,"findings":[]},"notices":{"number-of-types":0,"number-of-files-touched":0,"findings":[]},"external-review-provider":"GitHub"},"analysistime":"2026-08-31T11:12:41.000Z","project-name":"open-chat-studio","repository":"https://github.com/dimagi/open-chat-studio.git"}}