personal memory agent
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Restart cortex on code.shipped callosum event

Extract _restart_service helper from _handle_supervisor_request and add
_handle_code_shipped handler that listens for code.shipped events and
triggers a graceful cortex restart. Skips if cortex is already mid-restart.

+39 -20
+1
docs/CALLOSUM.md
··· 143 143 **Source:** `make sail` (Makefile) 144 144 **Events:** `shipped` 145 145 **Key fields:** `hash` (short git commit hash) 146 + **Consumer:** Supervisor restarts cortex on `shipped` events (`think/supervisor.py:_handle_code_shipped`) 146 147 **Purpose:** Track code deployment and release events 147 148 148 149 ---
+38 -20
think/supervisor.py
··· 664 664 _task_queue.submit(cmd, ref, day=day) 665 665 666 666 667 - def _handle_supervisor_request(message: dict) -> None: 668 - """Handle incoming supervisor control messages.""" 669 - if message.get("tract") != "supervisor" or message.get("event") != "restart": 670 - return 667 + def _restart_service(service: str) -> bool: 668 + """Send SIGINT to a managed service to trigger graceful restart. 671 669 672 - service = message.get("service") 673 - if not service: 674 - logging.error("Invalid restart request: missing service") 675 - return 676 - if service == "supervisor": 677 - logging.debug("Ignoring restart request for supervisor itself") 678 - return 679 - 680 - # Find the process 670 + Returns True if the service was found and running, False if not found 671 + or already exited. 672 + """ 681 673 for proc in _managed_procs: 682 674 if proc.name == service: 683 - # Check if process is still running 684 675 if proc.process.poll() is not None: 685 - # Already exited - ignore, supervision loop will auto-restart 686 676 logging.debug( 687 677 f"Ignoring restart for {service}: already exited, awaiting auto-restart" 688 678 ) 689 - return 679 + return False 690 680 691 681 logging.info(f"Restart requested for {service}, sending SIGINT...") 692 682 693 - # Emit restarting event 694 683 if _supervisor_callosum: 695 684 _supervisor_callosum.emit( 696 685 "supervisor", ··· 700 689 ref=proc.ref, 701 690 ) 702 691 703 - # Send SIGINT to trigger graceful shutdown 704 692 try: 705 693 proc.process.send_signal(signal.SIGINT) 706 - # Track restart request for SIGKILL enforcement 707 694 _restart_requests[service] = (time.time(), proc.process) 708 695 except Exception as e: 709 696 logging.error(f"Failed to send SIGINT to {service}: {e}") 710 - return 697 + return True 711 698 712 699 logging.warning(f"Cannot restart {service}: not found in managed processes") 700 + return False 701 + 702 + 703 + def _handle_supervisor_request(message: dict) -> None: 704 + """Handle incoming supervisor control messages.""" 705 + if message.get("tract") != "supervisor" or message.get("event") != "restart": 706 + return 707 + 708 + service = message.get("service") 709 + if not service: 710 + logging.error("Invalid restart request: missing service") 711 + return 712 + if service == "supervisor": 713 + logging.debug("Ignoring restart request for supervisor itself") 714 + return 715 + 716 + _restart_service(service) 717 + 718 + 719 + def _handle_code_shipped(message: dict) -> None: 720 + """Restart cortex when new code is deployed via sail.""" 721 + if message.get("tract") != "code" or message.get("event") != "shipped": 722 + return 723 + 724 + if "cortex" in _restart_requests: 725 + logging.debug("Skipping code.shipped restart: cortex already restarting") 726 + return 727 + 728 + logging.info("Code shipped (hash=%s), restarting cortex", message.get("hash")) 729 + _restart_service("cortex") 713 730 714 731 715 732 def get_task_status(ref: str) -> dict: ··· 1269 1286 """Dispatch incoming Callosum messages to appropriate handlers.""" 1270 1287 _handle_task_request(message) 1271 1288 _handle_supervisor_request(message) 1289 + _handle_code_shipped(message) 1272 1290 _handle_segment_observed(message) 1273 1291 _handle_observe_status(message) 1274 1292 _handle_activity_recorded(message)