Local Server Restart Hardening¶
Motivation¶
Restarting local VS Code tasks could leave child server processes behind when the wrapper process was terminated. The next start then hit duplicate listeners or crashed with address-in-use errors, and background exceptions outside request handling were not always easy to correlate in logs.
User-facing change¶
scripts/dev/run-with-log.shnow starts wrapped commands in a signal-forwarded process group and terminates that group onSIGTERM,SIGINT, orSIGHUP, reducing orphaneduvicorn,vite, andterminal/exec_server.pyprocesses after task restarts.scripts/dev/local-run.sh webandterminal-execnow mirror the API guard: if their expected local endpoint is already healthy, they exit cleanly instead of spawning a duplicate process or crashing on a busy port.- The API sidecar now installs process-wide
sys,threading, andasyncioexception log hooks, plus a generic FastAPI unhandled-exception JSON handler, so request-external crashes land in logs with context.
API / IaC diff summary¶
- Local development scripts only for restart behavior.
- API process logging only; no route contract or infrastructure changes.
Validation evidence¶
bash -n scripts/dev/run-with-log.sh scripts/dev/local-run.shuv run ruff check --fix api/app/global_exception_logging.py api/main.py api/app/lifespan.pyuv run ruff format api/app/global_exception_logging.py api/main.py api/app/lifespan.pyuv run pytest -q api/tests/test_smoke.py api/tests/test_request_metrics_detail.py- Duplicate guard smoke checks while services were already listening:
LOCAL_LOG_CONSOLE=false bash scripts/dev/local-run.sh apiLOCAL_LOG_CONSOLE=false bash scripts/dev/local-run.sh webLOCAL_LOG_CONSOLE=false bash scripts/dev/local-run.sh terminal-exec