MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / cleanupPromptRun

Function cleanupPromptRun

apps/kimi-code/src/cli/run-prompt.ts:136–153  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 {

Callers 1

runPromptFunction · 0.85

Calls 5

setCrashPhaseFunction · 0.85
shutdownTelemetryFunction · 0.85
raceWithTimeoutFunction · 0.85
closeMethod · 0.65

Tested by

no test coverage detected