Skip to content

Fail to launch the server #6

Closed
Closed

Description

@thesk7828

Fail to Launch frontend and backend server.

command used to initialise:

git clone https://github.com/AISecurityConsortium/AIGoat.git
cd AIGoat
./scripts/start.sh

Output:

Cloning into 'AIGoat'...
remote: Enumerating objects: 699, done.
remote: Counting objects: 100% (134/134), done.
remote: Compressing objects: 100% (99/99), done.
remote: Total 699 (delta 51), reused 82 (delta 33), pack-reused 565 (from 2)
Receiving objects: 100% (699/699), 47.88 MiB | 3.68 MiB/s, done.
Resolving deltas: 100% (209/209), done.

==========================================
AI Goat -- Starting Application

[INFO] Checking Ollama...
[INFO] Starting Ollama in the background...
[OK] Ollama is running
[INFO] Pulling model 'mistral' (this may take a few minutes on first run)...
pulling manifest
pulling f5074b1221da: 100% ▕████████████████████████████████████████████████████████▏ 4.4 GB
pulling 43070e2d4e53: 100% ▕████████████████████████████████████████████████████████▏ 11 KB
pulling 1ff5b64b61b9: 100% ▕████████████████████████████████████████████████████████▏ 799 B
pulling ed11eda7790d: 100% ▕████████████████████████████████████████████████████████▏ 30 B
pulling 1064e17101bd: 100% ▕████████████████████████████████████████████████████████▏ 487 B
verifying sha256 digest
writing manifest
success
[OK] Model 'mistral' pulled successfully
[INFO] Checking Python dependencies...
[OK] Python dependencies ready
[INFO] Initializing database...

Tried running, http://localhost:3000/ and http://localhost:8000/docs in browser.

Output:
Firefox can’t connect to the server at localhost:3000
Firefox can’t connect to the server at localhost:8000

Tried running commands to see if port 3000 and 8000 is occupied somewhere

lsof -i :3000
lsof -i :8000

the output was blank

Tried Stopping / Resetting with command:

./scripts/stop.sh      
./scripts/start.sh --fresh

Output:

==========================================
AI Goat -- Stopping Application

[INFO] No PID file for frontend
[INFO] No PID file for backend
[INFO] Stopping ollama (PID: 10219)...
[OK] ollama stopped

[OK] AI Goat stopped.

[INFO] Fresh start requested -- removing existing database and vector store
[OK] Cleared database and ChromaDB

==========================================
AI Goat -- Starting Application

[INFO] Checking Ollama...
[INFO] Starting Ollama in the background...
[OK] Ollama is running
[OK] Model 'mistral' is available
[INFO] Checking Python dependencies...
[OK] Python dependencies ready
[INFO] Initializing database...

Current Configuration:

  • System: MacOS 26.4.1, M5 Pro
  • Python 3.11.15
  • Node.js v25.9.0
  • Ollama 0.20.7
  • Firefox 149.0.2 (aarch64)

Activity

  1. thesk7828 commented on Apr 15, 2026

    @thesk7828
    Author

    The problem occurred because of a compatibility issue with your Python version. The scripts/start.sh initializes the database as part of its startup sequence. When this initialization step ran, an error silently forced the script to terminate, which meant your backend and frontend never had the chance to start!

    Root Cause:
    The codebase natively uses the Python 3.10 syntax for type hinting (e.g., str | None). However, the script is running with Python 3.9. While Python 3.9 can sometimes skip over | annotations, libraries like SQLAlchemy and Pydantic explicitly evaluate these types at runtime.

    Evaluating str | None using eval() in Python 3.9 natively throws a TypeError, causing the backend initialization code and subsequent data-seeding steps to fail completely. Since start.sh explicitly suppresses Standard Error outputs for these steps using 2>/dev/null, it masked the underlying bug.

  2. thesk7828 commented on Apr 15, 2026

    @thesk7828
    Author

    I have a PR ready to fix this issue, fix is as follows:

    Replaces X | None type hinting with Optional[X] within app/models/ and adds the eval-type-backport dependency to provide proper support for executing the platform locally on Python 3.9 environments.

    Background: While Python 3.9 supports the PEP 563 stringified union type hints natively when skipping evaluation, robust systems like SQLAlchemy 2.0 and Pydantic dynamically invoke eval() on these annotations at runtime. Evaluating str | None using type objects without Python 3.10 produces an immediate TypeError. This was silently preventing developers on Python 3.9 from successfully executing scripts/start.sh during the SQLite database schema setup and artifact seeding.

    Checklist

    • > Validated locally ✅
    • > Tested with pytest ✅
    • > Passed all lint checks (ruff, pyflakes) ✅
    • > Kept PR focused to one code-compatibility change ✅
  3. added a commit that references this issue on Apr 15, 2026
  4. iamfarooqh commented on Apr 23, 2026

    @iamfarooqh
    Member

    Dear @thesk7828 ,
    Thanks for trying to run AI Goat locally in your machine and opening the issue. Appreciate the investigation and the fix! The Python 3.9 type hint fix looks technically sound. Please also note whether you were running Python 3.9 or 3.11 when you hit this issue, as we'd like to confirm this fully resolves the startup failure.

    Also please run the below diagnostic command and share the output:
    source venv/bin/activate python3 -c " import asyncio from app.core.database import init_db asyncio.run(init_db()) "

  5. self-assigned this
    on Apr 23, 2026
  6. added theissue type on Apr 23, 2026
  7. thesk7828 commented on Apr 23, 2026

    @thesk7828
    Author

    Sure @iamfarooqh, Here's the screenshot! Btw, I was using 3.11 by the time!

    Image
  8. iamfarooqh commented on Apr 23, 2026

    @iamfarooqh
    Member

    @thesk7828 - Thanks for the screenshot! Can you also run the same command while on the original main branch (without your fix applied) so we can confirm that main specifically fails due to the type hint issue on Python 3.11? This will help us confirm whether your fix is addressing the root cause. The command to run on main:

    git checkout main
    source venv/bin/activate
    python3 -c "import asyncio; from app.core.database import init_db; asyncio.run(init_db())"
    
  9. thesk7828 commented on Apr 23, 2026

    @thesk7828
    Author

    here's the result @iamfarooqh

    Image
  10. thesk7828 commented on Apr 23, 2026

    @thesk7828
    Author

    @iamfarooqh - Also, attaching my branch too for better visibility!

    Image
  11. iamfarooqh commented on Apr 24, 2026

    @iamfarooqh
    Member

    @thesk7828 Thank you so much for sharing all the required information.
    The screenshots confirm your fix is exactly right. Could you please open a PR against AISecurityConsortium/AIGoat:main from your fix/python-39-type-hints branch? We're ready to review and merge.

    Please follow these steps to open a PR against the main repo:

    1. Go to your fork on GitHub Visit: https://github.com/thesk7828/AIGoat
    2. Switch to your fix branch Make sure you're on the fix/python-39-type-hints branch (use the branch dropdown near the top left of the repo page)
    3. Open a Pull Request Click the "Contribute" button (appears just above the file list) → then click "Open pull request"
    4. Verify the PR targets the correct repo and branch On the PR creation page, confirm it shows:
      base repository: AISecurityConsortium/AIGoat
      base branch: main
      head repository: thesk7828/AIGoat
      compare branch: fix/python-39-type-hints
    5. Fill in the PR description Please include:
      A short summary of what the fix does
      The Python version affected (3.9)
      A reference to the issue: type Closes Fail to launch the server #6 in the description so the issue auto-closes when merged
    6. Submit Click "Create pull request" — that's it!

    We'll review and merge it from there. Thanks for the contribution!

  12. iamfarooqh commented on Apr 24, 2026

    @iamfarooqh
    Member

    Thanks @thesk7828 for the thorough investigation and the fix!

    Note: this fix is required for Python 3.9 users. If you are on Python 3.10 or higher and still hit startup issues, please check logs/backend.log for errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions