fix: resolve broken imports, hardcoded credentials, GPU-only crashes, and silent errors across API and backend services - #2
Merged
Conversation
… tests Agent-Logs-Url: https://github.com/Trojan3877/SentinelAI/sessions/70592dc3-e67d-478d-853c-f6e4dba5389b Co-authored-by: Trojan3877 <182694928+Trojan3877@users.noreply.github.com>
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
CoreyLeath-code
approved these changes
Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pyandapi/inference.pyboth imported from a non-existentcore.*namespace — createdapi/core/package withSentinelModel(2-layer MLP) and fixed all import paths to useapi.core.*pytest.iniwithpythonpath = .soapi.*resolves duringpytestruns from repo roottests/conftest.py:from app.main import app→from api.main import app(all 4 tests were failing on collection)Auth hardening
api/auth.pyhad literaladmin/admincheck — replaced withAPI_USERNAME/API_PASSWORDenv vars; endpoint returns500whenAPI_PASSWORDis unset rather than silently accepting any loginGPU / runtime crashes
backend/app/main.py:.cuda()called unconditionally → replaced withtorch.device("cuda" if ... else "cpu")patternbackend/app/main.py:mlflow.start_run()executed at module level → wrapped intry/exceptso import succeeds when MLflow is unreachableapi/routes/inference.py: LLM loaded synchronously at import time → lazy-loaded on first request, model name now read fromLLM_MODEL_NAMEenv var, returns503on load failure, CPU fallback addedSilent failure → observable errors
llm-guard/app.py:except Exception: passon DB write replaced withlogger.exception()+conn.rollback()API completeness
api/main.py: wired up/inferPOST endpoint (with Bearer-token auth dependency + SlowAPI rate limiting) andGET /root route — both were missing, leaving tests hitting 404Dependencies / lint
requirements.txt: addedhttpx(required by FastAPITestClient) andpydanticrufferrors inllm-guard/app.pyandstreamlit-dashboard/app.py(unused imports, spurious f-string prefix, unusedexcbinding) that were failing the CI lint jobOriginal prompt
This pull request was created from Copilot chat.