Description
Currently, the daemon's /api/prompt handler spawns a subprocess for all ask dialog display tiers (tkinter, NiceGUI, Textual). This was implemented in #1151 to fix the daemon orphaning issue caused by tkinter's macOS main-thread requirement.
However, NiceGUI is browser-based and has no main-thread restriction. It can safely run in-process in the daemon, which would:
- Eliminate ~100-200ms subprocess spawn overhead
- Simplify the call chain for NiceGUI dialogs
- Still provide the same user experience
Current Behavior
All ask dialogs use subprocess delegation:
# daemon/rest_api.py:_handle_prompt
result = _show_via_subprocess(violation, fallback, timeout)
This spawns ai-guardian prompt --mode ask which tries: tkinter → NiceGUI → Textual → fallback.
Proposed Improvement
Optimize the daemon's _handle_prompt to:
- Try NiceGUI in-process first (safe, no main-thread requirement)
- Fall back to subprocess for tkinter/Textual (required for those tiers)
# Pseudocode
if _nicegui_available():
result = _NiceGuiAskDialog(violation, timeout).run()
if result is None:
result = _show_via_subprocess(violation, fallback, timeout)
Why Not All In-Process?
- tkinter: MUST use subprocess on macOS (tk.Tk() requires main thread)
- NiceGUI: CAN run in-process (browser-based, no thread restrictions) ← optimization opportunity
- Textual: MUST use subprocess (daemon has no controlling terminal)
Benefits
- Faster response time for NiceGUI users (~100-200ms saved)
- No change in safety/isolation (NiceGUI already proven stable in-process in the tray)
Related
Priority
Low — current subprocess approach works correctly, this is a performance optimization.
Description
Currently, the daemon's
/api/prompthandler spawns a subprocess for all ask dialog display tiers (tkinter, NiceGUI, Textual). This was implemented in #1151 to fix the daemon orphaning issue caused by tkinter's macOS main-thread requirement.However, NiceGUI is browser-based and has no main-thread restriction. It can safely run in-process in the daemon, which would:
Current Behavior
All ask dialogs use subprocess delegation:
This spawns
ai-guardian prompt --mode askwhich tries: tkinter → NiceGUI → Textual → fallback.Proposed Improvement
Optimize the daemon's
_handle_promptto:Why Not All In-Process?
Benefits
Related
.wolf/cerebrum.md: "Only NiceGUI (browser-based) can run in-process"Priority
Low — current subprocess approach works correctly, this is a performance optimization.