velxio/backend/app
David Montero Crespo be0cd514aa fix(esp32): worker subprocess fallback for esp32_flash_image import
CI's e2e test_hcsr04_simulation.mjs caught the regression introduced by
a3f21a2 (the issue #101 fix). The worker crashes on boot with

    Firmware decode error: No module named 'app'

esp32_worker.py runs as a subprocess via subprocess.Popen([sys.executable,
WORKER_PATH, ...]). When Python launches a script directly, sys.path[0]
is the SCRIPT's directory (backend/app/services/), not the backend root.
So `from app.services.esp32_flash_image import pad_to_flash_size` fails
because there is no `app/` under `backend/app/services/`.

esp32_lib_bridge.py wasn't affected because it runs in-process inside
uvicorn, where backend/ is implicitly on sys.path.

Fix: same try/except + importlib fallback the worker already uses for
esp32_i2c_slaves at the top of the file. First try the package import
(works when imported by the bridge's tests or anything else with the
backend root on sys.path), fall back to direct file loading otherwise.

Verified the fallback works in isolation by simulating the subprocess
context (sys.path containing only backend/app/services/) — the package
import fails as expected and the file-load fallback returns a properly
padded 4 MB buffer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 22:22:53 -03:00
..
api Merge pull request #137 from davidmonterocrespo24/esp32-cam 2026-05-02 22:40:06 -03:00
core
database
mcp
models feat(backend): subscription state columns on users table 2026-05-05 10:21:37 -03:00
schemas feat(backend): subscription state columns on users table 2026-05-05 10:21:37 -03:00
services fix(esp32): worker subprocess fallback for esp32_flash_image import 2026-05-08 22:22:53 -03:00
utils feat(metrics): add usage analytics dashboard with country tracking 2026-04-25 19:47:40 -03:00
__init__.py
main.py feat(backend): subscription state columns on users table 2026-05-05 10:21:37 -03:00