()
| 134 | let removeTerminationCleanup: (() => void) | undefined; |
| 135 | let cleanupPromise: Promise<void> | undefined; |
| 136 | const cleanupPromptRun = async (): Promise<void> => { |
| 137 | const pending = (cleanupPromise ??= (async () => { |
| 138 | removeTerminationCleanup?.(); |
| 139 | setCrashPhase('shutdown'); |
| 140 | try { |
| 141 | await restorePromptSessionPermission(); |
| 142 | } finally { |
| 143 | await shutdownTelemetry({ timeoutMs: CLI_SHUTDOWN_TIMEOUT_MS }); |
| 144 | await harness.close(); |
| 145 | } |
| 146 | })()); |
| 147 | // Bound cleanup so a wedged shutdown step (e.g. a SessionEnd hook, MCP |
| 148 | // shutdown, or a connection blackholed by a restrictive firewall) cannot |
| 149 | // keep a completed headless run alive forever. The cleanup keeps running in |
| 150 | // the background if it overruns; the caller (`kimi -p`) force-exits shortly |
| 151 | // after, so any straggling work is torn down with the process. |
| 152 | await raceWithTimeout(pending, PROMPT_CLEANUP_TIMEOUT_MS); |
| 153 | }; |
| 154 | removeTerminationCleanup = installPromptTerminationCleanup(promptProcess, cleanupPromptRun); |
| 155 | |
| 156 | try { |
no test coverage detected