()
| 782 | const handler = (ev: GatewayEvent) => onEventRef.current(ev) |
| 783 | |
| 784 | const exitHandler = () => { |
| 785 | turnController.reset() |
| 786 | |
| 787 | // A still-owned child dying while the TUI is alive is an *unexpected* |
| 788 | // death — a user /quit exits Node before this fires, and a replaced child |
| 789 | // is identity-skipped in GatewayClient. Rather than stranding a long |
| 790 | // session (the user's complaint), respawn the gateway and resume the |
| 791 | // persisted session via the next gateway.ready, so a single crash / OOM / |
| 792 | // signal doesn't lose their work. planGatewayRecovery bounds the attempts |
| 793 | // so a gateway that crash-loops on startup can't spawn-storm, and falls |
| 794 | // back to recoverSidRef when sid was already cleared by a prior exit. |
| 795 | const plan = planGatewayRecovery(getUiState().sid, recoverSidRef.current, recoveryAtRef.current, Date.now()) |
| 796 | |
| 797 | // Clear sid immediately: while the gateway is down, sid-guarded effects |
| 798 | // (session.active_list poll, queue drain) would otherwise fire RPCs at a |
| 799 | // dead/respawning gateway. recoverSidRef carries the session forward, and |
| 800 | // resumeById restores sid once the fresh gateway is ready. |
| 801 | recoveryAtRef.current = plan.attempts |
| 802 | patchUiState({ busy: false, sid: null, status: 'gateway exited' }) |
| 803 | |
| 804 | if (plan.recover && plan.sid) { |
| 805 | recoverSidRef.current = plan.sid |
| 806 | turnController.pushActivity('gateway exited · recovering session…', 'warn') |
| 807 | sys('gateway exited — recovering your session (any in-flight reply was lost)') |
| 808 | gw.start() |
| 809 | |
| 810 | return |
| 811 | } |
| 812 | |
| 813 | recoverSidRef.current = null |
| 814 | turnController.pushActivity('gateway exited · /logs to inspect', 'error') |
| 815 | sys('error: gateway exited') |
| 816 | } |
| 817 | |
| 818 | gw.on('event', handler) |
| 819 | gw.on('exit', exitHandler) |
nothing calls this directly
no test coverage detected