@@ -28,6 +28,34 @@ import { type MainToWorkerMessage, type SerializableMongoClientOptions, type Wor
2828 *
2929 * The public API is unchanged from the in-process evaluator:
3030 * `evaluate(connection, code) → Promise<ExecutionResult>`
31+ *
32+ * ## Lifecycle
33+ *
34+ * The evaluator instance and the worker thread have **independent lifecycles**:
35+ *
36+ * ```
37+ * Evaluator instance Worker thread
38+ * ───────────────── ─────────────
39+ * new PlaygroundEvaluator()
40+ * └─ evaluate() ────────► spawn + connect
41+ * └─ evaluate() ────────► reuse (no re-auth)
42+ * └─ killWorker() ──────► terminate
43+ * └─ evaluate() ────────► re-spawn + re-connect
44+ * └─ shutdown() ────────► graceful close
45+ * ```
46+ *
47+ * After `killWorker()` (called on user cancellation), the evaluator instance
48+ * stays registered in the per-cluster evaluator pool (`evaluators` Map in
49+ * `executePlaygroundCode.ts`). The next `evaluate()` call detects that the
50+ * worker is dead and transparently spawns a new one. Session telemetry
51+ * (`_sessionId`, `_sessionEvalCount`) resets on each worker spawn, so a
52+ * killed-and-respawned worker behaves like a fresh evaluator session.
53+ *
54+ * The evaluator is only removed from the pool by `shutdownEvaluator()` (when
55+ * all playground documents for the cluster close) or by `disposeEvaluators()`
56+ * (on extension deactivation). `shutdownEvaluator()` calls `shutdown()`, while
57+ * `disposeEvaluators()` calls `dispose()`. Both paths gracefully close the
58+ * worker before removing the evaluator.
3159 */
3260export class PlaygroundEvaluator implements vscode . Disposable {
3361 private readonly _workerManager : WorkerSessionManager ;
0 commit comments