When a user closes a terminal tab, SIGHUP exits the main thread but the non-daemon agent_thread kept the entire Python process alive — stuck in the API call loop with no interrupt signal. Over many conversations, these orphan processes accumulate and cause massive swap usage (reported: 77GB on a 32GB M1 Pro). Changes: - Make agent_thread daemon=True so the process exits when the main thread finishes its cleanup. Under normal operation this changes nothing — the main thread already waits on agent_thread.is_alive(). - Interrupt the agent in the finally/exit path so the daemon thread stops making API calls promptly rather than being killed mid-flight.
431 KiB
431 KiB