Skip to content

Fix UI restart hanging before response flush#1619

Open
ruizanthony wants to merge 2 commits into
agent0ai:mainfrom
ruizanthony:fix/ui-restart-hangs
Open

Fix UI restart hanging before response flush#1619
ruizanthony wants to merge 2 commits into
agent0ai:mainfrom
ruizanthony:fix/ui-restart-hangs

Conversation

@ruizanthony
Copy link
Copy Markdown

@ruizanthony ruizanthony commented May 9, 2026

Summary

  • Make /api/restart return immediately and schedule the actual reload in a delayed daemon thread.
  • Prevent duplicate reload requests while one is already in progress.
  • Use in-process restart via os.execv() for normal UI restarts, so the response can flush cleanly.
  • Detect pending native self-updates via /exe/a0-self-update.yaml and hand control back to the native supervisor instead of re-execing run_ui.py.
  • When running under systemd, request systemctl restart --no-block agent-zero.service so the service wrapper can consume the self-update trigger.
  • Allow HEAD /api/health for readiness probes.

Why

The Web UI restart flow could hang because /api/restart called process.reload() before the HTTP response was reliably flushed. In Docker/LXC this could terminate or interrupt the request, leaving the UI polling/waiting indefinitely.

A follow-up issue was found with self-update: if /exe/a0-self-update.yaml was pending, the new UI restart path could directly re-exec run_ui.py and bypass the native wrapper/self-update manager that applies the update. In systemd deployments, the active UI process can also be a child process rather than the service MainPID, so simply exiting the UI process may not restart the whole service. The restart helper now detects this pending self-update case and asks systemd to restart the service before exiting, with a supervisor-exit fallback when systemd is unavailable.

Validation

  • Rebased on current origin/main / v1.14.
  • python -m py_compile api/restart.py api/health.py helpers/process.py tests/test_restart_api.py tests/test_process_reload.py
  • python -m pytest -q tests/test_restart_api.py tests/test_process_reload.py → 12 passed

@ruizanthony ruizanthony force-pushed the fix/ui-restart-hangs branch from e6dbbaf to 23de55d Compare May 13, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant