fix(ai): harden chip mismatch fallback for unstable USB #12

Merged
electron-rare merged 1 commits from fix/guard-env-fallback-on-usb-instability into main 2026-02-21 18:24:09 +00:00
electron-rare commented 2026-02-21 18:22:40 +00:00 (Migrated from github.com)

Why

Le fallback automatique sur détection de mismatch de chip (ESP32/ESP32-S3) dans zeroclaw_hw_firmware_loop.sh peut masquer des dégradations répétées de connexion USB.

Quand le port USB est instable, on peut voir une erreur de mismatch ponctuelle puis passer en env alternatif, ce qui cache le vrai problème.

What changed

  • Ajoute une vérification de stabilité du port USB avant tout fallback:
    • signature de port (hwid|description|serial_number) échantillonnée plusieurs fois.
    • fallback refusé si la signature flappe.
  • Introduit des paramètres d'ajustement:
    • ZEROCLAW_CHIP_MISMATCH_FALLBACK (défaut: 1)
    • ZEROCLAW_USB_STABILITY_SAMPLES (défaut: 2)
    • ZEROCLAW_USB_STABILITY_DELAY (défaut: 1)
  • Message explicite si fallback bloqué pour faciliter le diagnostic de lien USB.

Acceptance

  • bash -n tools/ai/zeroclaw_hw_firmware_loop.sh
  • Le fallback continue de fonctionner avec un mismatch réel sur port stable.
  • Un port instable doit produire un arrêt net sans fallback caché, avec message d'alerte.

Scope

Scriptes d'orchestration only (tools/ai/zeroclaw_hw_firmware_loop.sh).

## Why Le fallback automatique sur détection de mismatch de chip (ESP32/ESP32-S3) dans `zeroclaw_hw_firmware_loop.sh` peut masquer des dégradations répétées de connexion USB. Quand le port USB est instable, on peut voir une erreur de mismatch ponctuelle puis passer en env alternatif, ce qui cache le vrai problème. ## What changed - Ajoute une vérification de stabilité du port USB avant tout fallback: - signature de port (`hwid|description|serial_number`) échantillonnée plusieurs fois. - fallback refusé si la signature flappe. - Introduit des paramètres d'ajustement: - `ZEROCLAW_CHIP_MISMATCH_FALLBACK` (défaut: `1`) - `ZEROCLAW_USB_STABILITY_SAMPLES` (défaut: `2`) - `ZEROCLAW_USB_STABILITY_DELAY` (défaut: `1`) - Message explicite si fallback bloqué pour faciliter le diagnostic de lien USB. ## Acceptance - `bash -n tools/ai/zeroclaw_hw_firmware_loop.sh` - Le fallback continue de fonctionner avec un mismatch réel sur port stable. - Un port instable doit produire un arrêt net sans fallback caché, avec message d'alerte. ## Scope Scriptes d'orchestration only (`tools/ai/zeroclaw_hw_firmware_loop.sh`).
electron-rare commented 2026-02-21 18:23:58 +00:00 (Migrated from github.com)

Codex review (manual): PASS. Scope is strictement , avec garde anti-flapping USB avant fallback env. Shellcheck fix intégré, checks GREEN. Changement utile pour éviter d'occulter des instabilités USB/port par fallback automatique. Je recommande merge squash.

Codex review (manual): PASS. Scope is strictement , avec garde anti-flapping USB avant fallback env. Shellcheck fix intégré, checks GREEN. Changement utile pour éviter d'occulter des instabilités USB/port par fallback automatique. Je recommande merge squash.
electron-rare commented 2026-02-21 18:24:02 +00:00 (Migrated from github.com)

Codex review manuel: PASS. Scope strictement le script zeroclaw_hw_firmware_loop.sh. Ajout d'un contrôle de stabilité port USB avant fallback, ce qui évite de masquer les instabilités série/chute de câble. Checks CI green. Recommandé pour merge (squash).

Codex review manuel: PASS. Scope strictement le script zeroclaw_hw_firmware_loop.sh. Ajout d'un contrôle de stabilité port USB avant fallback, ce qui évite de masquer les instabilités série/chute de câble. Checks CI green. Recommandé pour merge (squash).
chatgpt-codex-connector[bot] (Migrated from github.com) reviewed 2026-02-21 18:24:06 +00:00
chatgpt-codex-connector[bot] (Migrated from github.com) left a comment

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ab3a6b5b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `3ab3a6b5b2` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](http://chatgpt.com/codex/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
@@ -106,0 +155,4 @@
return 1
fi
((i++))
if (( i < samples )); then
chatgpt-codex-connector[bot] (Migrated from github.com) commented 2026-02-21 18:24:06 +00:00

P1 Badge Treat failed signature reads as unstable

The stability guard never detects a failed probe because sig="$(serial_port_signature "$port" 2>/dev/null || true)" always exits successfully, so the if ! ...; then return 1 branch is effectively dead. When pio device list cannot return the target port (the exact unstable-USB case this patch targets), sig becomes empty for each sample and the function incorrectly reports the port as stable, allowing auto-fallback to proceed and masking link flapping.

Useful? React with 👍 / 👎.

**<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Treat failed signature reads as unstable** The stability guard never detects a failed probe because `sig="$(serial_port_signature "$port" 2>/dev/null || true)"` always exits successfully, so the `if ! ...; then return 1` branch is effectively dead. When `pio device list` cannot return the target port (the exact unstable-USB case this patch targets), `sig` becomes empty for each sample and the function incorrectly reports the port as stable, allowing auto-fallback to proceed and masking link flapping. Useful? React with 👍 / 👎.
Sign in to join this conversation.