Funk-lab/ansible/roles/litellm/tasks/main.yml
ALI YESILKAYA 577d61ebaa
feat: anti-502 LLM — heartbeat (litellm) + watchdog auto-réparation (llama_server) (#23)
* feat(litellm): heartbeat anti-502 + request_timeout 20s

Cause racine du 502 « 1ʳᵉ demande après une pause » : la connexion keep-alive
LiteLLM↔llama-server devient inactive → llama-server la ferme → LiteLLM garde le
socket mort → la requête suivante part dans le vide → timeout → 502.

- llm-heartbeat : service systemd qui appelle hermes-default toutes les 15s
  (max_tokens:1, /no_think → ~10ms GPU) → la connexion n'est jamais inactive,
  jamais périmée. Logge les échecs → sert aussi de sonde (vraie génération).
- request_timeout 60→20s : un socket périmé échoue vite, dans la fenêtre où
  num_retries:2 peut rejouer sur une connexion neuve (sinon le client abandonnait
  avant le retry → 502 sec).
- Doc : admin/incidents-llm-gpu.md (fix racine) + README rôle.

⚠️ heartbeat appelle hermes-default en continu → si bascule sur Claude (facturé),
mettre llm_heartbeat_enabled: false. request_timeout global → remonter si Claude.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* feat(llama_server): watchdog auto-réparation du wedge ROCm

Service systemd local sur gpu-01 qui sonde une vraie génération sur :1234
(pas juste /health, qui ment quand le slot d'inférence est figé). Sur N
échecs consécutifs → systemctl restart llama-server en local (root, sans
SSH/sudo distant). Gère le 503 "Loading model" post-restart sans le compter
comme échec.

Complète le llm-heartbeat (rôle litellm) : le heartbeat empêche la péremption
par inactivité de la connexion ; le watchdog répare le figeage du serveur lui-même.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 20:52:29 +02:00

86 lines
2.1 KiB
YAML

---
- name: Install Python pip and devel
ansible.builtin.dnf:
name:
- python3-pip
- python3-devel
state: present
- name: Create litellm system user
ansible.builtin.user:
name: "{{ litellm_user }}"
system: true
shell: /sbin/nologin
home: /opt/litellm
create_home: true
state: present
- name: Install litellm[proxy] in venv
ansible.builtin.pip:
name: "litellm[proxy]"
virtualenv: "{{ litellm_venv }}"
virtualenv_command: python3 -m venv
state: present
- name: Create config directory
ansible.builtin.file:
path: "{{ litellm_config_dir }}"
state: directory
owner: "{{ litellm_user }}"
group: "{{ litellm_user }}"
mode: '0750'
- name: Deploy LiteLLM config
ansible.builtin.template:
src: config.yaml.j2
dest: "{{ litellm_config_dir }}/config.yaml"
owner: "{{ litellm_user }}"
group: "{{ litellm_user }}"
mode: '0640'
notify: Restart litellm
- name: Deploy systemd service
ansible.builtin.template:
src: litellm.service.j2
dest: /etc/systemd/system/litellm.service
mode: '0644'
notify:
- Reload systemd
- Restart litellm
- name: Deploy hermes-switch script
ansible.builtin.copy:
src: hermes-switch
dest: /usr/local/bin/hermes-switch
mode: '0755'
- name: Enable and start litellm
ansible.builtin.systemd:
name: litellm
enabled: true
daemon_reload: true
state: started
# ── Heartbeat : garde chaud le tuyau LiteLLM↔llama-server (anti-502 connexion périmée) ──
- name: Deploy llm-heartbeat script
ansible.builtin.template:
src: llm-heartbeat.sh.j2
dest: /usr/local/bin/llm-heartbeat
mode: '0755'
notify: Restart llm-heartbeat
- name: Deploy llm-heartbeat service
ansible.builtin.template:
src: llm-heartbeat.service.j2
dest: /etc/systemd/system/llm-heartbeat.service
mode: '0644'
notify:
- Reload systemd
- Restart llm-heartbeat
- name: Enable and start llm-heartbeat
ansible.builtin.systemd:
name: llm-heartbeat
enabled: "{{ llm_heartbeat_enabled }}"
state: "{{ 'started' if llm_heartbeat_enabled else 'stopped' }}"
daemon_reload: true