---
description: How to deploy the AI Hub application to the production server (192.168.68.113)
---

This workflow automates the deployment of the Cortex Hub to the production server located at `192.168.68.113`. 
The production server runs the application out of `/home/coder/project/cortex-hub`.

**MAIN KNOWLEDGE POINT:** Agents and Users should refer to `.agent/workflows/deployment_reference.md` to understand the full proxy and architecture layout prior to running production debugging.

1. **Automated Secret Fetching**: The `scripts/remote_deploy.sh` script will automatically pull the production password from the GitBucket Secret Vault if the `GITBUCKET_TOKEN` is available in `/app/.env.gitbucket`.
2. **Sync**: Sync local codebase to `/tmp/cortex-hub/` on the server.
3. **Proto & Version Management**: 
   - If `ai-hub/app/protos/agent.proto` has changed, regenerate stubs:
     ```bash
     cd /app/ai-hub/app/protos && python3 -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. agent.proto
     cd /app/agent-node && python3 -m grpc_tools.protoc -Iprotos --python_out=. --grpc_python_out=. protos/agent.proto
     ```
   - **Triggering Client Updates**: To force all active agents (like the Mac Mini) to pull new code or skills, bump the version in `/app/agent-node/VERSION`.
   - **Auto-Update**: Once deployed, agents check for version mismatches every 5 minutes and will automatically re-bootstrap themselves if a newer version is detected on the Hub.
4. **Migrate & Rebuild**: Overwrite production files and run `bash scripts/local_rebuild.sh` on the server.
5. **Post-Deployment Health Check**: Perform a backend connectivity check (Python Trick). Only use `/frontend_tester` as a last resort if UI behavior is suspect.

### Automated Command
```bash
# This script handles authentication, syncing, and remote rebuilding.
bash /app/scripts/remote_deploy.sh
```

### Post-Deployment (MANDATORY)
After the script completes, the agent MUST run a basic connectivity check directly inside the production container:
```bash
# SSH into the host and run (you may need to provide the SSH pass or be logged in)
docker exec ai_hub_service python3 -c "
import requests
# Ensure you use a valid user_id
headers = {'X-User-ID': '9a333ccd-9c3f-432f-a030-7b1e1284a436'}
r = requests.get('http://localhost:8000/api/v1/nodes/test-prod-node/fs/ls?path=.', headers=headers)
print(f'Status: {r.status_code}')
print(r.text)
"
```
**Expected Outcome**: A `200 OK` status and a JSON body.

### Visual Verification (Worst Case)
If the backend check passes but UI behaviors are suspect or need deeper frontend validation, use the `/frontend_tester` workflow:
```bash
/frontend_tester
```
