Skip to content

fix: resolve broken imports, hardcoded credentials, GPU-only crashes, and silent errors across API and backend services - #2

Merged
CoreyLeath-code merged 2 commits into
mainfrom
copilot/update-code-files-for-improvement
Apr 3, 2026
Merged

fix: resolve broken imports, hardcoded credentials, GPU-only crashes, and silent errors across API and backend services#2
CoreyLeath-code merged 2 commits into
mainfrom
copilot/update-code-files-for-improvement

Conversation

Copilot AI commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Multiple services in SentinelAI failed at startup or import time due to missing modules, hardcoded credentials, and unconditional CUDA assumptions. All existing tests were also broken due to a wrong import path in conftest.py.

Broken imports / missing modules

  • api/main.py and api/inference.py both imported from a non-existent core.* namespace — created api/core/ package with SentinelModel (2-layer MLP) and fixed all import paths to use api.core.*
  • Added pytest.ini with pythonpath = . so api.* resolves during pytest runs from repo root
  • Fixed tests/conftest.py: from app.main import appfrom api.main import app (all 4 tests were failing on collection)

Auth hardening

  • api/auth.py had literal admin/admin check — replaced with API_USERNAME / API_PASSWORD env vars; endpoint returns 500 when API_PASSWORD is unset rather than silently accepting any login

GPU / runtime crashes

  • backend/app/main.py: .cuda() called unconditionally → replaced with torch.device("cuda" if ... else "cpu") pattern
  • backend/app/main.py: mlflow.start_run() executed at module level → wrapped in try/except so import succeeds when MLflow is unreachable
  • api/routes/inference.py: LLM loaded synchronously at import time → lazy-loaded on first request, model name now read from LLM_MODEL_NAME env var, returns 503 on load failure, CPU fallback added

Silent failure → observable errors

  • llm-guard/app.py: except Exception: pass on DB write replaced with logger.exception() + conn.rollback()

API completeness

  • api/main.py: wired up /infer POST endpoint (with Bearer-token auth dependency + SlowAPI rate limiting) and GET / root route — both were missing, leaving tests hitting 404

Dependencies / lint

  • requirements.txt: added httpx (required by FastAPI TestClient) and pydantic
  • Fixed 4 pre-existing ruff errors in llm-guard/app.py and streamlit-dashboard/app.py (unused imports, spurious f-string prefix, unused exc binding) that were failing the CI lint job
Original prompt

Create a pull request in Trojan3877/SentinelAI that updates the code files as needed to improve the project.

Requirements:

  • Inspect the repository structure and identify outdated, broken, or low-quality code.
  • Make targeted updates to code files to improve reliability, maintainability, and correctness.
  • Ensure the project runs (or has clear run instructions) after changes.
  • Add/adjust any necessary dependency or configuration updates (e.g., requirements.txt / package.json) if needed.
  • Keep changes focused and avoid unrelated refactors.
  • Add or update a brief section in the README describing what changed and how to run/verify.

Deliverables:

  • A PR with clear title and description summarizing changes.
  • Updated code files committed to a new branch.
  • Any basic tests or smoke checks added or documented if appropriate.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: https://github.com/Trojan3877/Facial-Emotion-Recognition-System open a PR and update code files

Assistant: I’m ready to proceed with opening the pull request and updating the code in Trojan3877/Facial-Emotion-Recognition-System—please respond to the pending prompt (accept or reject) so I can continue.

Assistant: I've initiated the process to open a pull request and update the code files in the repository Trojan3877/Facial-Emotion-Recognition-System. The Copilot coding agent is now working on your request.

You'll be notified once the task is complete.

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Update code files to improve project reliability and maintainability fix: resolve broken imports, hardcoded credentials, GPU-only crashes, and silent errors across API and backend services Apr 3, 2026
Copilot AI requested a review from CoreyLeath-code April 3, 2026 02:19
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.

2 participants