Skip to content

Conversation

@utkshukla
Copy link
Contributor

Foundation Model Serve Health Check

@github-actions
Copy link

github-actions bot commented Nov 24, 2025

Test Results for assets-test

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 1c6ce13.

♻️ This comment has been updated with latest results.

except Exception as e:
logger.error(f"Downstream engine health check failed: {str(e)}")
return JSONResponse(
content={"status": "unhealthy", "downstream": "error", "error": str(e)},

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI about 17 hours ago

To fix this problem, we should avoid sending the exception's string representation (str(e)) in responses returned to the user. Instead, log the exception on the server using the configured logger and return a generic error message to the client, e.g., “internal error.” Only minimal, non-sensitive information should be exposed in API responses. This change can be accomplished by editing the except Exception as e: block in the /health endpoint. The logger.error() call can still record the full details of the exception for server-side troubleshooting. No new methods or imports are needed, as appropriate logging is already in use.

Specifically:

  • Remove the "error": str(e) entry from the JSON response returned to the client on line 400.
  • Continue logging the error server-side as is.

Only assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py needs to be edited, within lines 397-401.


Suggested changeset 1
assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py b/assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py
--- a/assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py
+++ b/assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py
@@ -397,7 +397,7 @@
     except Exception as e:
         logger.error(f"Downstream engine health check failed: {str(e)}")
         return JSONResponse(
-            content={"status": "unhealthy", "downstream": "error", "error": str(e)},
+            content={"status": "unhealthy", "downstream": "error"},
             status_code=503
         )
 
EOF
@@ -397,7 +397,7 @@
except Exception as e:
logger.error(f"Downstream engine health check failed: {str(e)}")
return JSONResponse(
content={"status": "unhealthy", "downstream": "error", "error": str(e)},
content={"status": "unhealthy", "downstream": "error"},
status_code=503
)

Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
@github-actions
Copy link

github-actions bot commented Nov 24, 2025

Test Results for training-model-mgmt-unittests

45 tests   45 ✅  11s ⏱️
 1 suites   0 💤
 1 files     0 ❌

Results for commit 1c6ce13.

♻️ This comment has been updated with latest results.

503 Service Unavailable if downstream is not ready.
"""
try:
ready_path = os.getenv(EnvironmentVariables.CONTAINER_READY_CHECK_PATH, "/ready")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be better to abstract this code more reusable because readiness probe and heacth check seems to be similar.

@github-actions
Copy link

github-actions bot commented Nov 25, 2025

Test Results for scripts-test

79 tests   79 ✅  8m 48s ⏱️
 1 suites   0 💤
 1 files     0 ❌

Results for commit 1c6ce13.

♻️ This comment has been updated with latest results.

except Exception as e:
logger.error(f"Downstream engine readiness check failed: {str(e)}")
return JSONResponse(
content={"status": "not_ready", "downstream": "error", "error": str(e)},

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI about 17 hours ago

To resolve this issue, the exception handling in the ready endpoint should avoid returning the raw error message (str(e)) to the client. Instead, log the exception and return a generic error response. This ensures that sensitive internal details are kept only in server logs, not exposed via the API response. Specifically, for lines 449–451, change the code so that logger.error logs the full exception and stack trace for developer use, but the JSON returned to the client only includes a fixed, non-detailed "internal error" message. Required edits include:

  • Use logger.error with exc_info=True to capture stack trace.
  • Remove the "error": str(e) field from the response; replace with a generic "error": "internal_error" or similar.
    No additional imports or methods are needed beyond what is already present.
Suggested changeset 1
assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py b/assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py
--- a/assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py
+++ b/assets/training/model_management/environments/foundation-model-serve/context/foundation/model/serve/api_server.py
@@ -446,9 +446,9 @@
             status_code=503
         )
     except Exception as e:
-        logger.error(f"Downstream engine readiness check failed: {str(e)}")
+        logger.error(f"Downstream engine readiness check failed: {str(e)}", exc_info=True)
         return JSONResponse(
-            content={"status": "not_ready", "downstream": "error", "error": str(e)},
+            content={"status": "not_ready", "downstream": "error", "error": "internal_error"},
             status_code=503
         )
 
EOF
@@ -446,9 +446,9 @@
status_code=503
)
except Exception as e:
logger.error(f"Downstream engine readiness check failed: {str(e)}")
logger.error(f"Downstream engine readiness check failed: {str(e)}", exc_info=True)
return JSONResponse(
content={"status": "not_ready", "downstream": "error", "error": str(e)},
content={"status": "not_ready", "downstream": "error", "error": "internal_error"},
status_code=503
)

Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants