@ponythewhite/base-context 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/base-context-runtime/pyproject.toml +1 -1
  3. package/dist/base-context-runtime/src/rlm/__init__.py +3 -0
  4. package/dist/base-context-runtime/src/rlm/harness.py +86 -48
  5. package/dist/base-context-runtime/test/test_harness.py +215 -140
  6. package/dist/base-context-runtime/uv.lock +1 -1
  7. package/dist/build-info.json +1 -1
  8. package/dist/bundle/amazon-bedrock.js +3 -3
  9. package/dist/bundle/{anthropic-UV5GZDGU.js → anthropic-5PSCZEER.js} +2 -7
  10. package/dist/bundle/{azure-openai-responses-WSNPXLYC.js → azure-openai-responses-AYTLJR33.js} +2 -2
  11. package/dist/bundle/{bundled-modules-PS66L3IT.js → bundled-modules-5JRM6P4T.js} +5 -5
  12. package/dist/bundle/{chunk-UPVDERMD.js → chunk-2IPDSTDR.js} +11 -9
  13. package/dist/bundle/chunk-D3KOF57W.js +22040 -0
  14. package/dist/bundle/{chunk-VSIYFWYI.js → chunk-KT2BNEPE.js} +21 -8
  15. package/dist/bundle/{chunk-VCW3YDFF.js → chunk-NEHLB7JV.js} +1548 -574
  16. package/dist/bundle/{chunk-KTNETTHI.js → chunk-Q3MBSBEB.js} +3 -101
  17. package/dist/bundle/{chunk-LFPWHI42.js → chunk-QKIFBA7N.js} +2 -2
  18. package/dist/bundle/{chunk-PFROC4EV.js → chunk-VVI3UKGR.js} +12 -9
  19. package/dist/bundle/{cli-main-MMHTK7EB.js → cli-main-YUDBEYE2.js} +4 -4
  20. package/dist/bundle/cli.js +1 -1
  21. package/dist/bundle/{google-T32FMD4G.js → google-HTMCUJ7X.js} +2 -2
  22. package/dist/bundle/{google-vertex-56KP6I3B.js → google-vertex-ZQO65AXF.js} +2 -2
  23. package/dist/bundle/{main-XAIVH4Y7.js → main-ZLGGAAGU.js} +5 -5
  24. package/dist/bundle/{mistral-WGBMYIVU.js → mistral-SB7LU56G.js} +1 -1
  25. package/dist/bundle/{openai-codex-responses-PIV2RQ3G.js → openai-codex-responses-5CEW4VN3.js} +53 -27
  26. package/dist/bundle/{openai-completions-64C3JPR4.js → openai-completions-BAZJQSS2.js} +1 -1
  27. package/dist/bundle/{openai-responses-UI7RSTDV.js → openai-responses-VHOE427P.js} +48 -5
  28. package/dist/core/agent-session.d.ts +9 -1
  29. package/dist/core/agent-session.d.ts.map +1 -1
  30. package/dist/core/agent-session.js +225 -29
  31. package/dist/core/agent-session.js.map +1 -1
  32. package/dist/core/canonical-context.d.ts +8 -0
  33. package/dist/core/canonical-context.d.ts.map +1 -1
  34. package/dist/core/canonical-context.js +37 -5
  35. package/dist/core/canonical-context.js.map +1 -1
  36. package/dist/core/compaction/compaction.d.ts +2 -2
  37. package/dist/core/compaction/compaction.d.ts.map +1 -1
  38. package/dist/core/compaction/compaction.js +31 -13
  39. package/dist/core/compaction/compaction.js.map +1 -1
  40. package/dist/core/context-epoch.d.ts +1 -1
  41. package/dist/core/context-epoch.d.ts.map +1 -1
  42. package/dist/core/context-epoch.js +2 -1
  43. package/dist/core/context-epoch.js.map +1 -1
  44. package/dist/core/extensions/types.d.ts +2 -2
  45. package/dist/core/extensions/types.d.ts.map +1 -1
  46. package/dist/core/extensions/types.js.map +1 -1
  47. package/dist/core/history-index-worker.d.ts.map +1 -1
  48. package/dist/core/history-index-worker.js +29 -8
  49. package/dist/core/history-index-worker.js.map +1 -1
  50. package/dist/core/history-index.d.ts +11 -1
  51. package/dist/core/history-index.d.ts.map +1 -1
  52. package/dist/core/history-index.js +2 -1
  53. package/dist/core/history-index.js.map +1 -1
  54. package/dist/core/inference-coordinator.d.ts +1 -1
  55. package/dist/core/inference-coordinator.d.ts.map +1 -1
  56. package/dist/core/inference-coordinator.js +110 -15
  57. package/dist/core/inference-coordinator.js.map +1 -1
  58. package/dist/core/kernel/bootstrap.d.ts.map +1 -1
  59. package/dist/core/kernel/bootstrap.js +97 -107
  60. package/dist/core/kernel/bootstrap.js.map +1 -1
  61. package/dist/core/kernel/repl-manager.d.ts.map +1 -1
  62. package/dist/core/kernel/repl-manager.js +11 -0
  63. package/dist/core/kernel/repl-manager.js.map +1 -1
  64. package/dist/core/kernel/shared.d.ts +2 -0
  65. package/dist/core/kernel/shared.d.ts.map +1 -1
  66. package/dist/core/kernel/shared.js.map +1 -1
  67. package/dist/core/messages.d.ts.map +1 -1
  68. package/dist/core/messages.js +4 -1
  69. package/dist/core/messages.js.map +1 -1
  70. package/dist/core/prompts/rlm.d.ts.map +1 -1
  71. package/dist/core/prompts/rlm.js +4 -2
  72. package/dist/core/prompts/rlm.js.map +1 -1
  73. package/dist/core/public-context.d.ts.map +1 -1
  74. package/dist/core/public-context.js +16 -0
  75. package/dist/core/public-context.js.map +1 -1
  76. package/dist/core/refinement/refinement.d.ts +19 -5
  77. package/dist/core/refinement/refinement.d.ts.map +1 -1
  78. package/dist/core/refinement/refinement.js +90 -35
  79. package/dist/core/refinement/refinement.js.map +1 -1
  80. package/dist/core/request-view-selection.d.ts +13 -3
  81. package/dist/core/request-view-selection.d.ts.map +1 -1
  82. package/dist/core/request-view-selection.js +239 -101
  83. package/dist/core/request-view-selection.js.map +1 -1
  84. package/dist/core/retained-tool-output.d.ts +28 -0
  85. package/dist/core/retained-tool-output.d.ts.map +1 -0
  86. package/dist/core/retained-tool-output.js +102 -0
  87. package/dist/core/retained-tool-output.js.map +1 -0
  88. package/dist/core/selective-recovery.d.ts +47 -3
  89. package/dist/core/selective-recovery.d.ts.map +1 -1
  90. package/dist/core/selective-recovery.js +428 -109
  91. package/dist/core/selective-recovery.js.map +1 -1
  92. package/dist/core/session-history-index.d.ts +3 -1
  93. package/dist/core/session-history-index.d.ts.map +1 -1
  94. package/dist/core/session-history-index.js +1 -1
  95. package/dist/core/session-history-index.js.map +1 -1
  96. package/dist/core/session-manager.d.ts +2 -0
  97. package/dist/core/session-manager.d.ts.map +1 -1
  98. package/dist/core/session-manager.js +38 -13
  99. package/dist/core/session-manager.js.map +1 -1
  100. package/dist/core/settings-manager.d.ts +5 -0
  101. package/dist/core/settings-manager.d.ts.map +1 -1
  102. package/dist/core/settings-manager.js +3 -0
  103. package/dist/core/settings-manager.js.map +1 -1
  104. package/dist/core/system-prompt.d.ts +3 -1
  105. package/dist/core/system-prompt.d.ts.map +1 -1
  106. package/dist/core/system-prompt.js +3 -3
  107. package/dist/core/system-prompt.js.map +1 -1
  108. package/dist/core/task-frame.d.ts +1 -1
  109. package/dist/core/task-frame.d.ts.map +1 -1
  110. package/dist/core/task-frame.js +21 -1
  111. package/dist/core/task-frame.js.map +1 -1
  112. package/dist/core/task-state-reader.d.ts +10 -2
  113. package/dist/core/task-state-reader.d.ts.map +1 -1
  114. package/dist/core/task-state-reader.js +75 -9
  115. package/dist/core/task-state-reader.js.map +1 -1
  116. package/dist/core/tools/ipython.d.ts +5 -0
  117. package/dist/core/tools/ipython.d.ts.map +1 -1
  118. package/dist/core/tools/ipython.js +59 -17
  119. package/dist/core/tools/ipython.js.map +1 -1
  120. package/dist/core/tools/prime-context.d.ts.map +1 -1
  121. package/dist/core/tools/prime-context.js +1 -1
  122. package/dist/core/tools/prime-context.js.map +1 -1
  123. package/dist/core/view-units.d.ts +4 -0
  124. package/dist/core/view-units.d.ts.map +1 -1
  125. package/dist/core/view-units.js +28 -19
  126. package/dist/core/view-units.js.map +1 -1
  127. package/dist/installer.mjs +98 -77
  128. package/dist/modes/interactive/components/refinement-outcome-message.d.ts.map +1 -1
  129. package/dist/modes/interactive/components/refinement-outcome-message.js.map +1 -1
  130. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  131. package/dist/modes/interactive/interactive-mode.js +5 -5
  132. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  133. package/dist/skills/skill-creator/SKILL.md +18 -1
  134. package/docs/settings.md +45 -0
  135. package/docs/skills.md +77 -2
  136. package/package.json +4 -4
  137. package/skills/skill-creator/SKILL.md +18 -1
  138. package/dist/bundle/chunk-W46VZFI6.js +0 -21681
@@ -1 +1 @@
1
- {"version":3,"file":"repl-manager.js","sourceRoot":"","sources":["../../../src/core/kernel/repl-manager.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iFAA+E;AAC/E,yFAAyF;AAEzF,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EACN,SAAS,EACT,UAAU,EACV,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EACN,gCAAgC,EAChC,0BAA0B,EAE1B,yBAAyB,GACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,2BAA2B,EAC3B,8BAA8B,EAC9B,2BAA2B,EAE3B,+BAA+B,GAC/B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EACN,0BAA0B,EAC1B,uBAAuB,EAEvB,cAAc,EACd,6BAA6B,EAC7B,wBAAwB,EACxB,4BAA4B,EAC5B,iBAAiB,EAGjB,YAAY,EACZ,gCAAgC,EAChC,yBAAyB,EACzB,QAAQ,EACR,qBAAqB,EACrB,iCAAiC,EACjC,yBAAyB,EACzB,0BAA0B,EAE1B,6BAA6B,EAM7B,WAAW,EACX,yBAAyB,EACzB,oCAAoC,EACpC,sBAAsB,EACtB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,6BAA6B,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,0BAA0B,EAC1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CAAC,IAAI,CAAC;gBACvC,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;gBAClC,IAAI,OAAO,CAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;oBAC/B,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,6BAA6B,CAAC,CAAC;oBACrF,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;gBAAA,CAClB,CAAC;aACF,CAAC,CAAC;YACH,IAAI,OAAO;gBAAE,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,CAAC,YAAY;gBAAE,OAAO;YAC1B,MAAM,IAAI,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,CAAC,CAAC;QACnF,CAAC;gBAAS,CAAC;YACV,oEAAoE;YACpE,IAAI,CAAC,0BAA0B,GAAG,KAAK,CAAC;QACzC,CAAC;IAAA,CACD;IAED,+EAA+E;IAC/E,WAAW,GAAS;QACnB,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC;QACxB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAAA,CACxB;IAED,IAAI,SAAS,GAAY;QACxB,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC;IAAA,CAChC;CACD","sourcesContent":["// Kernel client for the REPL runtime: the kernel is a JSON-lines subprocess\n// (`python -m rlm.repl`) — requests on stdin, events on stdout, stderr kept as\n// a diagnostics tail. The protocol is documented in prime-agent-runtime/src/rlm/repl.md.\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport {\n\tcloseSync,\n\texistsSync,\n\tmkdirSync,\n\topenSync,\n\treadFileSync,\n\trenameSync,\n\trmSync,\n\tstatSync,\n\twriteSync,\n} from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport { v4 as uuid } from \"uuid\";\nimport { PRODUCT } from \"../../product-identity.js\";\nimport {\n\tcaptureOrphanProcessJournalOwner,\n\tORPHAN_PROCESS_JOURNAL_ENV,\n\ttype OrphanProcessJournalOwner,\n\treapKernelOrphanProcesses,\n} from \"../orphan-process-journal.js\";\nimport {\n\tcreateNativeRecoveryRefusal,\n\tDEFAULT_NATIVE_RECOVERY_LIMITS,\n\tNativeRecoveryBudgetRefusal,\n\ttype NativeRecoveryResponse,\n\tstringifyNativeRecoveryResponse,\n} from \"../selective-recovery.js\";\nimport { ensureKernelPython } from \"./bootstrap.js\";\nimport {\n\tAGENT_MESSAGE_DISPLAY_MIME,\n\tATTACHMENT_DISPLAY_MIME,\n\ttype CapturedKernelLifecycle,\n\tcreateDeferred,\n\tcreateKernelStartupAbortError,\n\tDEFAULT_MAX_OUTPUT_CHARS,\n\tDEFAULT_SNAPSHOT_DEBOUNCE_MS,\n\tDIFF_DISPLAY_MIME,\n\ttype ExecuteOptions,\n\ttype ExecuteResult,\n\terrorMessage,\n\tHOST_REQUEST_SHUTDOWN_TIMEOUT_MS,\n\tinstallSignalHandlersOnce,\n\tisRecord,\n\tKERNEL_ABORT_GRACE_MS,\n\tKERNEL_BUSY_INTERRUPT_INTERVAL_MS,\n\tKERNEL_BUSY_REUSE_WAIT_MS,\n\tKERNEL_SHUTDOWN_TIMEOUT_MS,\n\ttype KernelAttachment,\n\tKernelBusyAfterInterruptError,\n\ttype KernelDiffDisplay,\n\ttype KernelManagerOptions,\n\ttype KernelSentAgentMessage,\n\ttype KernelShutdownOptions,\n\ttype KernelStartOptions,\n\tliveKernels,\n\tMAX_ATTACHMENT_DATA_CHARS,\n\tMAX_LATE_SENT_AGENT_MESSAGE_HANDLERS,\n\tparseAttachmentDisplay,\n\tparseDiffDisplay,\n\tparseSentAgentMessage,\n\traceStartupWithAbort,\n\tSNAPSHOT_EXECUTION_TIMEOUT_MS,\n} from \"./shared.js\";\nimport {\n\tDEFAULT_SNAPSHOT_MAX_BYTES,\n\tDEFAULT_SNAPSHOT_MAX_VARIABLE_BYTES,\n\ttype RestoreResult,\n\ttype SnapshotResult,\n} from \"./state-snapshot.js\";\n\nconst REPL_PROTOCOL_VERSION = 4;\nconst READY_TIMEOUT_MS = 30_000;\nconst REPAIR_STEP_TIMEOUT_MS = 30_000;\n// Runtime-minted host-request ids never repeat; the bound only guards a\n// misbehaving runtime from growing the dedup set forever.\nconst MAX_HANDLED_HOST_REQUEST_IDS = 1024;\n// Cap for unattributed background output buffered between and during cells.\nconst MAX_BACKGROUND_OUTPUT_CHARS = 64 * 1024;\n\nconst MAX_KERNEL_STDERR_CHARS = 8 * 1024;\nconst MAX_KERNEL_STDERR_LOG_BYTES = 5 * 1024 * 1024;\nconst KERNEL_STDERR_LOG_BUDGET_MARKER = \"[stderr log budget exhausted]\\n\";\n\n/** fs.writeSync may write fewer bytes than asked (partial ENOSPC, signals); loop until done. */\nfunction writeFullySync(fd: number, data: Buffer): void {\n\tlet offset = 0;\n\twhile (offset < data.length) {\n\t\toffset += writeSync(fd, data, offset);\n\t}\n}\n\n/** ExecuteResult plus the raw fields of the request's `done` event (state ops). */\ninterface InternalExecuteResult extends ExecuteResult {\n\tdoneFields?: Record<string, unknown>;\n}\n\ninterface ActiveExecution {\n\trequestId: string;\n\t/** Source of the cell currently executing; surfaced to rlm.run spawns. */\n\tcode: string;\n\tstarted: number;\n\tmaxChars: number;\n\topts: ExecuteOptions;\n\tstdout: string;\n\tstderr: string;\n\tstdoutTruncated: boolean;\n\tstderrTruncated: boolean;\n\tresult?: string;\n\tdiffs: KernelDiffDisplay[];\n\tattachments: KernelAttachment[];\n\tsentAgentMessages: KernelSentAgentMessage[];\n\t// Ephemeral, per-cell output attachment; only the finalized tool result persists it.\n\tnativeRecoveries: NativeRecoveryResponse[];\n\tnativeRecoveryBytes: number;\n\tnativeRecoveryRequests: number;\n\tnativeRecoveryAbort: AbortController;\n\t/** Stream text without this execution's id: user threads, other cells' leftovers, raw fd writes. */\n\tbackgroundOutput: string;\n\tbackgroundOutputTruncated: boolean;\n\terror?: ExecuteResult[\"error\"];\n\tstatus: ExecuteResult[\"status\"];\n\tdoneFields?: Record<string, unknown>;\n\tsettled: boolean;\n\tresolve: (result: InternalExecuteResult) => void;\n\treject: (error: Error) => void;\n}\n\n// Complete event vocabulary of protocol version 2 (see prime-agent-runtime/src/rlm/repl.md).\n// The version handshake is exact, so an unknown kind is corruption, not a newer runtime.\nconst PROTOCOL_EVENT_KINDS = new Set([\n\t\"ready\",\n\t\"stdout\",\n\t\"stderr\",\n\t\"result\",\n\t\"display\",\n\t\"host_request\",\n\t\"error\",\n\t\"done\",\n]);\n\n/**\n * Reason a JSON object still isn't a valid protocol frame, or undefined.\n * `done` and `host_request` route strictly by non-empty string id (the runtime\n * mints uuid hex ids and echoes the host's uuids); silently dropping an id-less\n * one would leave the awaiting request unsettled forever.\n */\nfunction invalidProtocolFrameReason(event: Record<string, unknown>): string | undefined {\n\tif (typeof event.event !== \"string\" || !PROTOCOL_EVENT_KINDS.has(event.event)) {\n\t\treturn \"unknown protocol event\";\n\t}\n\tif (\n\t\t(event.event === \"done\" || event.event === \"host_request\") &&\n\t\t(typeof event.id !== \"string\" || event.id === \"\")\n\t) {\n\t\treturn `${event.event} frame without id`;\n\t}\n\treturn undefined;\n}\n\nfunction asStringArray(value: unknown): string[] {\n\treturn Array.isArray(value) ? value.filter((v): v is string => typeof v === \"string\") : [];\n}\n\nfunction asReasonArray(value: unknown): { name: string; reason: string }[] {\n\tif (!Array.isArray(value)) return [];\n\treturn value.flatMap((entry) => {\n\t\tif (isRecord(entry) && typeof entry.name === \"string\") {\n\t\t\treturn [{ name: entry.name, reason: typeof entry.reason === \"string\" ? entry.reason : \"\" }];\n\t\t}\n\t\treturn [];\n\t});\n}\n\nexport class ReplKernelManager {\n\tprivate readonly options: Pick<\n\t\tKernelManagerOptions,\n\t\t| \"python\"\n\t\t| \"cwd\"\n\t\t| \"env\"\n\t\t| \"sessionId\"\n\t\t| \"hostHandlers\"\n\t\t| \"pythonSkills\"\n\t\t| \"snapshot\"\n\t\t| \"bootstrapCode\"\n\t\t| \"stderrLogPath\"\n\t>;\n\tprivate readonly handledHostRequestIds = new Set<string>();\n\tprivate child?: ChildProcess;\n\tprivate childOrphanOwner?: OrphanProcessJournalOwner;\n\tprivate readyDeferred?: ReturnType<typeof createDeferred<number>>;\n\tprivate pythonVersion?: string;\n\tprivate kernelStderr = \"\";\n\t/** Serializes execute() calls — the runtime runs one request at a time. */\n\tprivate executionQueue: Promise<unknown> = Promise.resolve();\n\tprivate activeExecution?: ActiveExecution;\n\tprivate readonly activeExecutionIdleWaiters = new Set<() => void>();\n\tprivate readonly lateSentAgentMessageHandlers = new Map<string, (message: KernelSentAgentMessage) => void>();\n\t/** Resolvers for done events outside the active execution (the shutdown reply). */\n\tprivate readonly pendingDoneWaiters = new Map<string, () => void>();\n\t// Source of the most recently started cell, retained after it finishes so\n\t// rlm.run spawns from detached asyncio tasks (cell already idle) can still\n\t// attribute their spawning program.\n\tprivate lastCellCode?: string;\n\t/** Unattributed stream text that arrived between cells; surfaced on the next execution. */\n\tprivate pendingBackgroundOutput = \"\";\n\tprivate pendingBackgroundOutputTruncated = false;\n\tprivate readonly inFlightHostRequests = new Set<Promise<void>>();\n\t/** A newly constructed manager is a different owner even when its counter restarts at zero. */\n\tprivate readonly lifecycleOwner = uuid();\n\tprivate state: \"idle\" | \"starting\" | \"running\" | \"shutdown\" = \"idle\";\n\t/** Bumped by every teardown so a stale in-flight doStart can never touch a newer kernel. */\n\tprivate startGeneration = 0;\n\t/** Generation whose graceful shutdown() owns the teardown, so the exit handler must not run it. */\n\tprivate gracefulShutdownGeneration?: number;\n\tprivate gracefulShutdownPromise?: Promise<boolean>;\n\t/** Memoized so concurrent callers all await the same in-flight startup. */\n\tprivate startPromise?: Promise<void>;\n\t/** Pending debounced auto-snapshot, if one has been scheduled. */\n\tprivate snapshotTimer?: ReturnType<typeof globalThis.setTimeout>;\n\t/** While the final dispose snapshot is flushing, new external executions are rejected. */\n\tprivate flushingSnapshotForDispose = false;\n\t/** In-flight final snapshot flush; concurrent teardowns join it instead of re-flushing. */\n\tprivate snapshotFlushForDispose?: Promise<void>;\n\t/** Repairs a child whose dedicated protocol stream emitted an invalid frame. */\n\tprivate protocolRepairPromise?: Promise<void>;\n\tprivate protocolRepairOwner?: { superseded: boolean };\n\t/** Corruption seen while still \"starting\" (e.g. ready and garbage in one chunk) fails that start. */\n\tprivate startupProtocolError?: Error;\n\t/** A repair discarded its kernel: the next fresh start must re-run the runtime bootstrap. */\n\tprivate pendingRebootstrap = false;\n\t/** Restore the saved namespace on that fresh start too (false when the snapshot itself is the declared culprit). */\n\tprivate pendingRestore = false;\n\tprivate rebootstrapPromise?: Promise<boolean>;\n\tprivate teardownInFlight = 0;\n\n\tconstructor(options: KernelManagerOptions) {\n\t\tthis.options = {\n\t\t\tpython: options.python,\n\t\t\tcwd: options.cwd,\n\t\t\tenv: options.env,\n\t\t\tsessionId: options.sessionId,\n\t\t\thostHandlers: options.hostHandlers,\n\t\t\tpythonSkills: options.pythonSkills,\n\t\t\tsnapshot: options.snapshot,\n\t\t\tbootstrapCode: options.bootstrapCode,\n\t\t\tstderrLogPath: options.stderrLogPath,\n\t\t};\n\t}\n\n\tget ownerSessionId(): string | undefined {\n\t\treturn this.options.sessionId;\n\t}\n\n\tcaptureLifecycleState(): CapturedKernelLifecycle {\n\t\tconst generation = this.startGeneration;\n\t\tconst state = this.state;\n\t\treturn Object.freeze({\n\t\t\tsnapshot: Object.freeze({ source: \"repl-manager\" as const, owner: this.lifecycleOwner, generation, state }),\n\t\t\tisCurrent: () => this.startGeneration === generation && this.state === state,\n\t\t});\n\t}\n\n\tprivate appendKernelDiagnostic(message: string): void {\n\t\tthis.appendKernelStderrText(`[kernel] ${message.endsWith(\"\\n\") ? message : `${message}\\n`}`);\n\t}\n\n\tprivate appendKernelStderrText(text: string): void {\n\t\tthis.kernelStderr = (this.kernelStderr + text).slice(-MAX_KERNEL_STDERR_CHARS);\n\t}\n\n\t/**\n\t * The write budget is the file's remaining capacity, not a fresh allowance,\n\t * so current file and `.old` each stay near MAX_KERNEL_STDERR_LOG_BYTES and\n\t * per-session disk near 2x — even when rotation fails and the file is kept.\n\t */\n\tprivate openStderrLog(): { fd: number; budget: number } | undefined {\n\t\tconst path = this.options.stderrLogPath;\n\t\tif (!path) return undefined;\n\t\ttry {\n\t\t\tmkdirSync(dirname(path), { recursive: true });\n\t\t\tlet size = existsSync(path) ? statSync(path).size : 0;\n\t\t\tif (size > MAX_KERNEL_STDERR_LOG_BYTES) {\n\t\t\t\ttry {\n\t\t\t\t\t// Drop any prior .old first: rename fails on Windows if it exists.\n\t\t\t\t\trmSync(`${path}.old`, { force: true });\n\t\t\t\t\trenameSync(path, `${path}.old`);\n\t\t\t\t\tsize = 0;\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// A failed rotation must not cost the log: keep appending instead.\n\t\t\t\t\tthis.appendKernelDiagnostic(`cannot rotate kernel stderr log: ${errorMessage(error)}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { fd: openSync(path, \"a\"), budget: Math.max(0, MAX_KERNEL_STDERR_LOG_BYTES - size) };\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`cannot open kernel stderr log: ${errorMessage(error)}`);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tasync start(options: KernelStartOptions = {}): Promise<void> {\n\t\tif (options.signal?.aborted) {\n\t\t\tthrow createKernelStartupAbortError();\n\t\t}\n\t\tif (!this.startPromise) {\n\t\t\tconst startPromise = this.doStart({ onBootstrapProgress: options.onBootstrapProgress }).catch((error) => {\n\t\t\t\t// Only clear our own memoization: a stale start must not evict a newer one.\n\t\t\t\tif (this.startPromise === startPromise) this.startPromise = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tthis.startPromise = startPromise;\n\t\t}\n\t\treturn raceStartupWithAbort(this.startPromise, options.signal);\n\t}\n\n\tprivate async doStart(startOptions: KernelStartOptions): Promise<void> {\n\t\tif (this.state !== \"idle\") return;\n\t\tconst orphanOwner = captureOrphanProcessJournalOwner();\n\t\tconst generation = ++this.startGeneration;\n\t\tthis.state = \"starting\";\n\t\tinstallSignalHandlersOnce();\n\t\t// Tracked from the moment startup begins so session cleanup and signal\n\t\t// handlers can dispose a kernel that is still booting.\n\t\tliveKernels.add(this);\n\n\t\tlet python: string;\n\t\ttry {\n\t\t\tpython =\n\t\t\t\tthis.options.python ??\n\t\t\t\t(await ensureKernelPython({\n\t\t\t\t\tpythonSkills: this.options.pythonSkills,\n\t\t\t\t\tonProgress: startOptions.onBootstrapProgress,\n\t\t\t\t}));\n\t\t\tif (this.startStale(generation)) throw new Error(\"Kernel start superseded\");\n\t\t\tthis.options.python = python;\n\t\t} catch (error) {\n\t\t\tif (this.startStale(generation)) throw error; // never touch a newer start's state\n\t\t\tliveKernels.delete(this);\n\t\t\tif ((this.state as string) !== \"shutdown\") this.state = \"idle\";\n\t\t\tthrow error;\n\t\t}\n\n\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\tthrow new Error(\"Kernel was disposed during startup\");\n\t\t}\n\n\t\tconst child = spawn(python, [\"-m\", \"rlm.repl\"], {\n\t\t\tcwd: this.options.cwd,\n\t\t\t// bash.py journals its process groups under this pid so the host can\n\t\t\t// reap them if the runtime dies without running its shutdown hook.\n\t\t\tenv: {\n\t\t\t\t...process.env,\n\t\t\t\t...this.options.env,\n\t\t\t\t[ORPHAN_PROCESS_JOURNAL_ENV]: orphanOwner.path,\n\t\t\t\tBASE_CONTEXT_KERNEL_OWNER_PID: String(orphanOwner.ownerPid),\n\t\t\t},\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tthis.child = child;\n\t\tthis.childOrphanOwner = orphanOwner;\n\t\tthis.readyDeferred = createDeferred<number>();\n\t\tthis.pythonVersion = undefined;\n\t\tthis.startupProtocolError = undefined;\n\t\tthis.wireChild(child);\n\n\t\ttry {\n\t\t\tconst registrationError = child.pid !== undefined ? orphanOwner.record(child.pid, true) : undefined;\n\t\t\tif (registrationError) throw registrationError;\n\t\t\tconst protocol = await this.waitForReady(child);\n\t\t\tif (this.startStale(generation)) throw new Error(\"Kernel start superseded\");\n\t\t\t// Ready and a corrupt frame can share one stdout chunk: ready resolved the\n\t\t\t// deferred synchronously before the corruption was parsed, so the rejection\n\t\t\t// in failProtocolFrame was a no-op. Never mark such a child running.\n\t\t\tif (this.startupProtocolError) throw this.startupProtocolError;\n\t\t\tif (protocol !== REPL_PROTOCOL_VERSION) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Kernel runtime speaks protocol ${protocol}, expected ${REPL_PROTOCOL_VERSION}. ` +\n\t\t\t\t\t\t`Update ${PRODUCT.runtimeDistribution} in the kernel Python (BASE_CONTEXT_KERNEL_PYTHON) to match this ${PRODUCT.name}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.assertSnapshotPythonCompatible();\n\t\t} catch (e) {\n\t\t\tif (this.startStale(generation)) throw e; // never tear down a newer start's kernel\n\t\t\tconst canRetryStartup = (this.state as string) !== \"shutdown\";\n\t\t\t// Only the call that performed the cleanup may resurrect to idle; a\n\t\t\t// concurrent kill()/teardown owns the state otherwise.\n\t\t\ttry {\n\t\t\t\tif ((await this.shutdown()) && canRetryStartup) this.state = \"idle\";\n\t\t\t} catch (cleanupError) {\n\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t[e, cleanupError],\n\t\t\t\t\t`Kernel startup failed: ${errorMessage(e)}; cleanup failed: ${errorMessage(cleanupError)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\n\t\tthis.state = \"running\";\n\t}\n\n\tprivate assertSnapshotPythonCompatible(): void {\n\t\tconst snapshot = this.options.snapshot;\n\t\tif (!snapshot || !existsSync(snapshot.path)) return;\n\n\t\tlet savedVersion: unknown;\n\t\ttry {\n\t\t\tconst manifest: unknown = JSON.parse(readFileSync(snapshot.manifestPath, \"utf8\"));\n\t\t\tsavedVersion = isRecord(manifest) ? manifest.pythonVersion : undefined;\n\t\t} catch {\n\t\t\t// The payload alone cannot identify the Python bytecode it contains.\n\t\t}\n\t\tconst minorVersion = (value: unknown): string | undefined =>\n\t\t\ttypeof value === \"string\" ? /^(\\d+\\.\\d+)\\.\\d+(?:a\\d+|b\\d+|rc\\d+)?$/.exec(value)?.[1] : undefined;\n\t\tconst savedMinor = minorVersion(savedVersion);\n\t\tconst currentMinor = minorVersion(this.pythonVersion);\n\t\tconst preserved = \"The saved state was not restored or changed. \";\n\t\tif (!savedMinor || !currentMinor) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot resume saved Python state: ${!savedMinor ? `its Python version is missing or unreadable (${snapshot.manifestPath})` : \"the kernel did not report a valid Python version\"}. ` +\n\t\t\t\t\tpreserved +\n\t\t\t\t\t\"Resume with the original Python runtime or start a new session.\",\n\t\t\t);\n\t\t}\n\t\tif (savedMinor !== currentMinor) {\n\t\t\tthrow new Error(\n\t\t\t\t`Saved Python state uses Python ${savedVersion}; this kernel uses ${this.pythonVersion}. ` +\n\t\t\t\t\tpreserved +\n\t\t\t\t\t`Resume with a matching Python ${savedMinor} runtime or start a new session.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** True when a teardown (or newer start) superseded the start that captured `generation`. */\n\tprivate startStale(generation: number): boolean {\n\t\treturn generation !== this.startGeneration;\n\t}\n\n\tprivate wireChild(child: ChildProcess): void {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tlet buffered = \"\";\n\t\tchild.stdout?.on(\"data\", (buf: Buffer) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tbuffered += decoder.write(buf);\n\t\t\tlet newline = buffered.indexOf(\"\\n\");\n\t\t\twhile (newline !== -1) {\n\t\t\t\tconst line = buffered.slice(0, newline);\n\t\t\t\tbuffered = buffered.slice(newline + 1);\n\t\t\t\tnewline = buffered.indexOf(\"\\n\");\n\t\t\t\tif (!line.trim()) continue;\n\t\t\t\tlet event: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tevent = JSON.parse(line);\n\t\t\t\t} catch {\n\t\t\t\t\tthis.failProtocolFrame(child, `unparseable protocol line: ${line.slice(0, 200)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!isRecord(event)) {\n\t\t\t\t\tthis.failProtocolFrame(child, `non-object protocol line: ${line.slice(0, 200)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst invalidReason = invalidProtocolFrameReason(event);\n\t\t\t\tif (invalidReason) {\n\t\t\t\t\tthis.failProtocolFrame(child, `${invalidReason}: ${line.slice(0, 200)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.handleEvent(event);\n\t\t\t}\n\t\t});\n\n\t\t// The runtime dup2's fd 2 into its protocol pump before ready (repl.py\n\t\t// _setup_fds), so this pipe only ever carries pre-ready bytes; the write\n\t\t// budget caps what lands on disk, and once it is spent the handler keeps\n\t\t// draining but discards (a blocked pipe would wedge a pre-ready kernel).\n\t\tconst stderrLog = this.openStderrLog();\n\t\tconst stderrDecoder = new StringDecoder(\"utf8\");\n\t\tlet stderrLogBudget = stderrLog?.budget ?? 0;\n\t\tlet stderrLogWritable = stderrLog !== undefined;\n\t\tchild.stderr?.on(\"data\", (buf: Buffer) => {\n\t\t\tthis.appendKernelStderrText(stderrDecoder.write(buf));\n\t\t\tif (!stderrLogWritable || stderrLog === undefined) return;\n\t\t\ttry {\n\t\t\t\tif (buf.length <= stderrLogBudget) {\n\t\t\t\t\twriteFullySync(stderrLog.fd, buf);\n\t\t\t\t\tstderrLogBudget -= buf.length;\n\t\t\t\t} else {\n\t\t\t\t\twriteFullySync(stderrLog.fd, Buffer.from(KERNEL_STDERR_LOG_BUDGET_MARKER));\n\t\t\t\t\tstderrLogWritable = false;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tstderrLogWritable = false;\n\t\t\t\tthis.appendKernelDiagnostic(`kernel stderr log write failed: ${errorMessage(error)}`);\n\t\t\t}\n\t\t});\n\t\t// A kernel that dies mid-character leaves bytes buffered in the decoder;\n\t\t// flush them so the tail keeps the truncated final character. Both events,\n\t\t// because each can be the only one to precede the tail build: 'end' beats\n\t\t// 'exit' on natural EOF (whose 'close' emission can land after it), while\n\t\t// a drain-destroyed stream skips 'end'. The second end() returns \"\".\n\t\tchild.stderr?.once(\"end\", () => this.appendKernelStderrText(stderrDecoder.end()));\n\t\tchild.stderr?.once(\"close\", () => {\n\t\t\tthis.appendKernelStderrText(stderrDecoder.end());\n\t\t\tif (stderrLog === undefined) return;\n\t\t\ttry {\n\t\t\t\tcloseSync(stderrLog.fd);\n\t\t\t} catch (error) {\n\t\t\t\tthis.appendKernelDiagnostic(`kernel stderr log close failed: ${errorMessage(error)}`);\n\t\t\t}\n\t\t});\n\t\t// Pipe errors must not crash the worker. The pending writeLine rejection\n\t\t// and child exit handler own cleanup; only record the current child's diagnosis.\n\t\tchild.stdin?.on(\"error\", (error) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tthis.appendKernelDiagnostic(`kernel stdin error: ${errorMessage(error)}`);\n\t\t});\n\t\tchild.stdout?.on(\"error\", (error) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tthis.appendKernelDiagnostic(`kernel stdout error: ${errorMessage(error)}`);\n\t\t});\n\t\tchild.once(\"exit\", () => {\n\t\t\t// One turn for the poll phase to deliver the bytes the kernel wrote\n\t\t\t// before dying (the pipe buffer bounds them), then destroy: EOF may\n\t\t\t// never come, and anything later is a surviving grandchild's\n\t\t\t// post-mortem noise, not the kernel's last words.\n\t\t\tglobalThis.setImmediate(() => child.stderr?.destroy());\n\t\t});\n\n\t\tchild.on(\"error\", (err) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tthis.appendKernelDiagnostic(`spawn error: ${err.message}`);\n\t\t\tthis.state = \"shutdown\";\n\t\t\tliveKernels.delete(this);\n\t\t\t// Fail a pending start() promptly instead of letting it ride out the\n\t\t\t// ready timeout. cleanupResources clears readyDeferred, so reject first;\n\t\t\t// a late error after ready resolved is a no-op on the settled promise.\n\t\t\tthis.readyDeferred?.reject(err);\n\t\t\tthis.cleanupResources();\n\t\t});\n\n\t\tchild.on(\"exit\", (code, signal) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tif (this.state !== \"shutdown\") {\n\t\t\t\tthis.appendKernelDiagnostic(`unexpected exit code=${code} signal=${signal}`);\n\t\t\t}\n\t\t\tthis.state = \"shutdown\";\n\t\t\tliveKernels.delete(this);\n\t\t\t// This exit is part of an in-flight graceful shutdown(): that call owns the\n\t\t\t// teardown and runs cleanupResources itself. Cleaning up here would bump the\n\t\t\t// generation and misread the owning shutdown as superseded.\n\t\t\tif (this.gracefulShutdownGeneration === this.startGeneration) return;\n\t\t\tthis.cleanupResources();\n\t\t});\n\t}\n\n\tprivate failProtocolFrame(child: ChildProcess, diagnostic: string): void {\n\t\tif (this.child !== child) return;\n\t\tthis.appendKernelDiagnostic(diagnostic);\n\t\tconst error = new Error(`Kernel protocol error: ${diagnostic}`);\n\t\tif (this.state === \"starting\") this.startupProtocolError = error;\n\t\tthis.readyDeferred?.reject(error);\n\t\tthis.rejectActiveExecution(error);\n\t\tif (this.teardownInFlight > 0 || this.state !== \"running\") return;\n\n\t\tif (this.protocolRepairOwner) {\n\t\t\t// A repair's own replacement child corrupted: discard it instead of respawn-looping.\n\t\t\tthis.appendKernelDiagnostic(\"replacement kernel corrupted during protocol repair; giving up\");\n\t\t\tthis.protocolRepairOwner.superseded = true;\n\t\t\t// performRestore clears pendingRestore, so it still being set means the\n\t\t\t// corruption struck at or before the restore phase: the snapshot stays\n\t\t\t// the prime suspect (ambiguous attribution, loop-safe — retrying it\n\t\t\t// would re-trigger the corruption). Corruption strictly after a\n\t\t\t// successful restore never implicates the snapshot; keeping the flag\n\t\t\t// costs at most one bounded restore per later attempt.\n\t\t\tconst snapshotSuspect = this.pendingRestore;\n\t\t\tthis.killChildToIdle();\n\t\t\tif (snapshotSuspect) this.pendingRestore = false;\n\t\t\treturn;\n\t\t}\n\t\tconst owner = { superseded: false };\n\t\tthis.protocolRepairOwner = owner;\n\t\tconst repair = this.repairProtocolChild(child, owner);\n\t\tthis.protocolRepairPromise = repair;\n\t\tvoid repair.then(\n\t\t\t() => {\n\t\t\t\tif (this.protocolRepairPromise === repair) this.protocolRepairPromise = undefined;\n\t\t\t\tif (this.protocolRepairOwner === owner) this.protocolRepairOwner = undefined;\n\t\t\t},\n\t\t\t(repairError) => {\n\t\t\t\tthis.appendKernelDiagnostic(`protocol repair failed: ${errorMessage(repairError)}`);\n\t\t\t\tif (this.protocolRepairPromise === repair) this.protocolRepairPromise = undefined;\n\t\t\t\tif (this.protocolRepairOwner === owner) this.protocolRepairOwner = undefined;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async repairProtocolChild(child: ChildProcess, owner: { superseded: boolean }): Promise<void> {\n\t\tif (this.child !== child || this.state === \"shutdown\") return;\n\t\tthis.killChildToIdle();\n\n\t\tconst start = this.start();\n\t\tconst generation = this.startGeneration;\n\t\ttry {\n\t\t\tawait start;\n\t\t} catch (error) {\n\t\t\tthis.finishFailedProtocolRepair(owner, error);\n\t\t\treturn;\n\t\t}\n\t\tif (this.startStale(generation) || (this.state as string) !== \"running\") {\n\t\t\tthis.finishFailedProtocolRepair(owner);\n\t\t\treturn;\n\t\t}\n\n\t\tconst restored = await this.performRestore(true);\n\t\tif (this.startStale(generation) || (this.state as string) !== \"running\") {\n\t\t\tthis.finishFailedProtocolRepair(owner);\n\t\t\treturn;\n\t\t}\n\t\tif (this.options.snapshot && restored === null) {\n\t\t\tif (owner.superseded || this.protocolRepairOwner !== owner) return;\n\t\t\tthis.appendKernelDiagnostic(\"protocol repair restore failed; discarding replacement kernel\");\n\t\t\tthis.killChildToIdle();\n\t\t\t// The snapshot is the declared culprit; the lazy path must not retry it.\n\t\t\tthis.pendingRestore = false;\n\t\t\treturn;\n\t\t}\n\n\t\t// Restore revives only the user namespace; live handles (rlm, bash, skills)\n\t\t// come from the runtime bootstrap, so a repaired kernel must re-run it.\n\t\tif (!this.options.bootstrapCode) return;\n\t\tconst bootstrapped = await this.bootstrapRepairedKernel(this.options.bootstrapCode);\n\t\tif (this.startStale(generation) || (this.state as string) !== \"running\") {\n\t\t\tthis.finishFailedProtocolRepair(owner);\n\t\t\treturn;\n\t\t}\n\t\tif (!bootstrapped) {\n\t\t\tif (owner.superseded || this.protocolRepairOwner !== owner) return;\n\t\t\tthis.appendKernelDiagnostic(\"protocol repair bootstrap failed; discarding replacement kernel\");\n\t\t\tthis.killChildToIdle();\n\t\t}\n\t}\n\n\t/** Bounded bootstrap of a repaired kernel; false when it failed. Never throws. */\n\tprivate async bootstrapRepairedKernel(code: string): Promise<boolean> {\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{ type: \"execute\", code },\n\t\t\t\tcode,\n\t\t\t\t{ internal: true, protocolRepair: true },\n\t\t\t\tREPAIR_STEP_TIMEOUT_MS,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\") {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`protocol repair bootstrap ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.pendingRebootstrap = false;\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`protocol repair bootstrap error: ${errorMessage(error)}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * A fresh kernel started after a discarded repair has none of the runtime\n\t * bootstrap's live handles (rlm, bash, skills) and an empty namespace:\n\t * reprovision (restore, then bootstrap) before any user request. A failed\n\t * re-bootstrap discards the kernel again instead of serving user code on an\n\t * unprovisioned namespace.\n\t */\n\tprivate async ensureKernelRebootstrapped(signal?: AbortSignal): Promise<void> {\n\t\tconst code = this.options.bootstrapCode;\n\t\tconst needsRestore = Boolean(this.options.snapshot) && this.pendingRestore;\n\t\tconst needsBootstrap = Boolean(code) && this.pendingRebootstrap;\n\t\t// An in-flight repair owns its kernel's restore/bootstrap sequence, and\n\t\t// a teardown's final snapshot must never trigger reprovisioning.\n\t\tif (\n\t\t\t(!needsRestore && !needsBootstrap) ||\n\t\t\tthis.protocolRepairPromise ||\n\t\t\tthis.teardownInFlight > 0 ||\n\t\t\tthis.state !== \"running\"\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tlet task = this.rebootstrapPromise;\n\t\tif (!task) {\n\t\t\tconst started = this.reprovisionFreshKernel(code);\n\t\t\ttask = started;\n\t\t\tthis.rebootstrapPromise = started;\n\t\t\tvoid started.finally(() => {\n\t\t\t\tif (this.rebootstrapPromise === started) this.rebootstrapPromise = undefined;\n\t\t\t});\n\t\t}\n\t\t// An aborted request never executes, so it may skip the wait; race the\n\t\t// signal like waitForProtocolRepair does instead of riding out the\n\t\t// bootstrap bound after a mid-wait abort.\n\t\tif (signal) {\n\t\t\tif (signal.aborted) return;\n\t\t\tlet onAbort: () => void = () => {};\n\t\t\tconst aborted = new Promise<void>((resolve) => {\n\t\t\t\tonAbort = resolve;\n\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tawait Promise.race([task, aborted]);\n\t\t\t} finally {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t\tif (signal.aborted) return;\n\t\t}\n\t\tconst ok = await task; // bounded by REPAIR_STEP_TIMEOUT_MS\n\t\tif (!ok) throw new Error(\"Kernel bootstrap failed after protocol repair\");\n\t}\n\n\t/** Restore (one-shot, best-effort) then bootstrap the lazily started fresh kernel. */\n\tprivate async reprovisionFreshKernel(code: string | undefined): Promise<boolean> {\n\t\tif (this.options.snapshot && this.pendingRestore) {\n\t\t\tawait this.performRestore(true); // clears pendingRestore on success\n\t\t\t// Corrupted during the restore: the spawned repair owns the kernel now.\n\t\t\tif (this.protocolRepairPromise || this.state !== \"running\") return false;\n\t\t\t// One attempt per discard: a clean restore failure falls back to an\n\t\t\t// empty namespace (ordinary startup semantics), never a retry loop.\n\t\t\tthis.pendingRestore = false;\n\t\t}\n\t\tif (!code || !this.pendingRebootstrap) return true;\n\t\tconst ok = await this.bootstrapRepairedKernel(code);\n\t\tif (!ok && this.state === \"running\") this.killChildToIdle();\n\t\treturn ok;\n\t}\n\n\t/** Kill the current child and settle at clean idle, so the next start spawns fresh. */\n\tprivate killChildToIdle(): void {\n\t\t// The discarded kernel carried the runtime bootstrap and (possibly) the\n\t\t// restored namespace; a lazily started replacement must reprovision both.\n\t\tthis.pendingRebootstrap = true;\n\t\tthis.pendingRestore = true;\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources(\"SIGKILL\");\n\t\tthis.state = \"idle\";\n\t}\n\n\tprivate finishFailedProtocolRepair(owner: { superseded: boolean }, error?: unknown): void {\n\t\tif (error) this.appendKernelDiagnostic(`protocol repair start failed: ${errorMessage(error)}`);\n\t\tif (owner.superseded || this.protocolRepairOwner !== owner) return;\n\t\tif (this.state === \"shutdown\") this.state = \"idle\";\n\t}\n\n\tprivate supersedeProtocolRepair(): void {\n\t\tif (this.protocolRepairOwner) this.protocolRepairOwner.superseded = true;\n\t}\n\n\t/** Wait until no protocol repair is pending; resolves early when the signal aborts. */\n\tprivate async waitForProtocolRepair(signal?: AbortSignal): Promise<void> {\n\t\twhile (this.protocolRepairPromise && !signal?.aborted) {\n\t\t\tconst repair = this.protocolRepairPromise;\n\t\t\tif (!signal) {\n\t\t\t\tawait repair;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet onAbort: () => void = () => {};\n\t\t\tconst aborted = new Promise<void>((resolve) => {\n\t\t\t\tonAbort = resolve;\n\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tawait Promise.race([repair, aborted]);\n\t\t\t} finally {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async waitForReady(child: ChildProcess): Promise<number> {\n\t\tconst ready = this.readyDeferred;\n\t\tif (!ready) throw new Error(\"Kernel ready state is missing\");\n\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tlet onExit: (() => void) | undefined;\n\t\ttry {\n\t\t\treturn await new Promise<number>((resolve, reject) => {\n\t\t\t\tready.promise.then(resolve, reject);\n\t\t\t\tonExit = () => {\n\t\t\t\t\tconst finish = () => {\n\t\t\t\t\t\tconst tail = this.kernelStderr.slice(-1024);\n\t\t\t\t\t\treject(new Error(`Kernel exited before ready. stderr:\\n${tail || \"(empty)\"}`));\n\t\t\t\t\t};\n\t\t\t\t\t// The final stderr chunks can still be in flight at 'exit'; wait for\n\t\t\t\t\t// the drained pipe so the tail includes the kernel's last words (the\n\t\t\t\t\t// ready timeout stays armed, bounding the wait).\n\t\t\t\t\tconst stderr = child.stderr;\n\t\t\t\t\tif (!stderr || stderr.closed) finish();\n\t\t\t\t\telse stderr.once(\"close\", finish);\n\t\t\t\t};\n\t\t\t\tif (child.exitCode !== null || child.signalCode !== null) {\n\t\t\t\t\tonExit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tchild.once(\"exit\", onExit);\n\t\t\t\ttimeout = globalThis.setTimeout(() => {\n\t\t\t\t\tconst tail = this.kernelStderr.slice(-1024);\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Kernel did not become ready within ${READY_TIMEOUT_MS}ms. stderr tail:\\n${tail || \"(empty)\"}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}, READY_TIMEOUT_MS);\n\t\t\t\ttimeout.unref?.();\n\t\t\t});\n\t\t} finally {\n\t\t\tif (timeout) globalThis.clearTimeout(timeout);\n\t\t\tif (onExit) child.removeListener(\"exit\", onExit);\n\t\t}\n\t}\n\n\t/** Write one JSON-lines request frame; resolves when the OS accepted the bytes. */\n\tprivate writeLine(request: Record<string, unknown>): Promise<void> {\n\t\tconst stdin = this.child?.stdin;\n\t\tif (!stdin || stdin.destroyed) {\n\t\t\treturn Promise.reject(new Error(\"Kernel stdin is not connected\"));\n\t\t}\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tstdin.write(`${JSON.stringify(request)}\\n`, (error) => {\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolve();\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate handleEvent(event: Record<string, unknown>): void {\n\t\tconst type = event.event;\n\t\tif (type === \"ready\") {\n\t\t\tthis.pythonVersion = typeof event.python === \"string\" ? event.python : undefined;\n\t\t\tthis.readyDeferred?.resolve(typeof event.protocol === \"number\" ? event.protocol : -1);\n\t\t\treturn;\n\t\t}\n\t\tif (type === \"host_request\") {\n\t\t\tif (typeof event.id === \"string\") this.startHostRequest(event.id, event.data, event.cellId);\n\t\t\treturn;\n\t\t}\n\n\t\tconst id = typeof event.id === \"string\" ? event.id : undefined;\n\t\tconst execution = this.activeExecution;\n\t\tif (!execution || id !== execution.requestId) {\n\t\t\tif (type === \"display\" && isRecord(event.data)) {\n\t\t\t\tthis.dispatchLateSentAgentMessage(id, event.data[AGENT_MESSAGE_DISPLAY_MIME]);\n\t\t\t} else if (type === \"stdout\" || type === \"stderr\") {\n\t\t\t\t// Unowned output (null id, or another cell's id): never merge it into\n\t\t\t\t// the active cell's streams; buffer it as background output instead.\n\t\t\t\tthis.appendBackgroundOutput(typeof event.text === \"string\" ? event.text : \"\");\n\t\t\t} else if (type === \"done\" && id) {\n\t\t\t\tconst waiter = this.pendingDoneWaiters.get(id);\n\t\t\t\tthis.pendingDoneWaiters.delete(id);\n\t\t\t\twaiter?.();\n\t\t\t} else if (type === \"error\" && id === undefined) {\n\t\t\t\tthis.appendKernelDiagnostic(`protocol error: ${String(event.evalue ?? \"\")}`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (execution.settled && type === \"display\" && isRecord(event.data)) {\n\t\t\tif (this.dispatchLateSentAgentMessage(id, event.data[AGENT_MESSAGE_DISPLAY_MIME])) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (type === \"stdout\" || type === \"stderr\") {\n\t\t\tconst text = typeof event.text === \"string\" ? event.text : \"\";\n\t\t\tif (type === \"stdout\") {\n\t\t\t\tif (execution.stdout.length < execution.maxChars) {\n\t\t\t\t\texecution.stdout += text;\n\t\t\t\t\tif (execution.stdout.length > execution.maxChars) {\n\t\t\t\t\t\texecution.stdout = execution.stdout.slice(0, execution.maxChars);\n\t\t\t\t\t\texecution.stdoutTruncated = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (execution.stderr.length < execution.maxChars) {\n\t\t\t\t\texecution.stderr += text;\n\t\t\t\t\tif (execution.stderr.length > execution.maxChars) {\n\t\t\t\t\t\texecution.stderr = execution.stderr.slice(0, execution.maxChars);\n\t\t\t\t\t\texecution.stderrTruncated = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\texecution.opts.onStream?.(text, type);\n\t\t} else if (type === \"result\") {\n\t\t\tif (typeof event.text === \"string\") execution.result = event.text;\n\t\t} else if (type === \"display\") {\n\t\t\tconst data = isRecord(event.data) ? event.data : {};\n\t\t\tconst diff = parseDiffDisplay(data[DIFF_DISPLAY_MIME]);\n\t\t\tif (diff) execution.diffs.push(diff);\n\t\t\tconst attachment = parseAttachmentDisplay(data[ATTACHMENT_DISPLAY_MIME]);\n\t\t\tif (attachment === \"oversized\") {\n\t\t\t\texecution.stderr += `${execution.stderr ? \"\\n\" : \"\"}attachment dropped: exceeds ${MAX_ATTACHMENT_DATA_CHARS} base64 chars`;\n\t\t\t\texecution.status = \"error\";\n\t\t\t} else if (attachment) {\n\t\t\t\texecution.attachments.push(attachment);\n\t\t\t}\n\t\t\tconst sentAgentMessage = parseSentAgentMessage(data[AGENT_MESSAGE_DISPLAY_MIME]);\n\t\t\tif (sentAgentMessage) execution.sentAgentMessages.push(sentAgentMessage);\n\t\t} else if (type === \"error\") {\n\t\t\texecution.error = {\n\t\t\t\tename: typeof event.ename === \"string\" ? event.ename : \"Error\",\n\t\t\t\tevalue: typeof event.evalue === \"string\" ? event.evalue : \"\",\n\t\t\t\ttraceback: asStringArray(event.traceback),\n\t\t\t};\n\t\t\texecution.status = \"error\";\n\t\t} else if (type === \"done\") {\n\t\t\texecution.doneFields = event;\n\t\t\tif (event.status !== \"ok\" && execution.status === \"ok\") {\n\t\t\t\texecution.status = \"error\";\n\t\t\t\t// State requests report failures as a done reason without an error event.\n\t\t\t\tif (!execution.error && typeof event.reason === \"string\") {\n\t\t\t\t\texecution.error = { ename: \"KernelError\", evalue: event.reason, traceback: [] };\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.finishActiveExecution(execution);\n\t\t}\n\t}\n\n\tasync execute(code: string, opts: ExecuteOptions = {}): Promise<ExecuteResult> {\n\t\tawait this.waitForProtocolRepair(opts.signal);\n\t\tconst result = await this.enqueueExecute(code, opts);\n\t\t// Refresh the on-disk snapshot after real work so a later resume (or a\n\t\t// crash before graceful shutdown) revives the most recent namespace.\n\t\tif (result.status === \"ok\") {\n\t\t\tthis.scheduleSnapshot();\n\t\t}\n\t\treturn result;\n\t}\n\n\t/** Queue and run a cell, serializing against all other executions. */\n\tprivate async enqueueExecute(\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\texecutionTimeoutMs?: number,\n\t): Promise<InternalExecuteResult> {\n\t\treturn this.enqueueRequest({ type: \"execute\", code }, code, opts, executionTimeoutMs);\n\t}\n\n\t/** Queue one protocol request (execute or state op) behind every other request. */\n\tprivate async enqueueRequest(\n\t\trequestFields: Record<string, unknown> & { type: string },\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\texecutionTimeoutMs?: number,\n\t): Promise<InternalExecuteResult> {\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: 0 };\n\t\t}\n\t\tawait this.start({ signal: opts.signal });\n\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t}\n\t\tif (this.flushingSnapshotForDispose && !opts.internal) {\n\t\t\tthrow new Error(\"Kernel is shutting down\");\n\t\t}\n\t\tif (!opts.protocolRepair) await this.ensureKernelRebootstrapped(opts.signal);\n\t\t// Aborted while waiting on the re-bootstrap: settle now instead of parking\n\t\t// on the queue slot behind the still-running bootstrap.\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: 0 };\n\t\t}\n\t\t// Re-check: a final flush may have started while this request awaited the\n\t\t// lazy re-bootstrap; admitting it now would splice it between the flush's\n\t\t// captured queue and the final snapshot, unbounding the teardown.\n\t\tif (this.flushingSnapshotForDispose && !opts.internal) {\n\t\t\tthrow new Error(\"Kernel is shutting down\");\n\t\t}\n\n\t\tconst prev = this.executionQueue;\n\t\tlet resolveNext: () => void = () => {};\n\t\tthis.executionQueue = new Promise<void>((r) => {\n\t\t\tresolveNext = r;\n\t\t});\n\t\tawait prev;\n\n\t\tconst started = Date.now();\n\t\tlet executionTimeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\ttry {\n\t\t\tawait this.waitForActiveExecutionToClearForReuse(opts.signal);\n\t\t\tif (opts.signal?.aborted) {\n\t\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: Date.now() - started };\n\t\t\t}\n\t\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t\t}\n\t\t\t// A repair started while this request was queued or busy-waiting: release\n\t\t\t// the slot so the repair's own restore can run, then requeue behind it.\n\t\t\tif (this.protocolRepairPromise && !opts.protocolRepair) {\n\t\t\t\tresolveNext();\n\t\t\t\tawait this.waitForProtocolRepair(opts.signal);\n\t\t\t\treturn this.enqueueRequest(requestFields, code, opts, executionTimeoutMs);\n\t\t\t}\n\t\t\tif (executionTimeoutMs === undefined) {\n\t\t\t\treturn await this.executeInner(requestFields, code, opts, started);\n\t\t\t}\n\n\t\t\tconst controller = new AbortController();\n\t\t\texecutionTimeout = globalThis.setTimeout(() => controller.abort(), executionTimeoutMs);\n\t\t\texecutionTimeout.unref?.();\n\t\t\tconst signal = opts.signal ? AbortSignal.any([opts.signal, controller.signal]) : controller.signal;\n\t\t\treturn await this.executeInner(requestFields, code, { ...opts, signal }, started);\n\t\t} finally {\n\t\t\tif (executionTimeout) globalThis.clearTimeout(executionTimeout);\n\t\t\tresolveNext();\n\t\t}\n\t}\n\n\tprivate async executeInner(\n\t\trequestFields: Record<string, unknown> & { type: string },\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\tstarted: number,\n\t): Promise<InternalExecuteResult> {\n\t\tconst maxChars = opts.maxOutputChars ?? DEFAULT_MAX_OUTPUT_CHARS;\n\t\tconst requestId = uuid();\n\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: Date.now() - started };\n\t\t}\n\t\tif (this.activeExecution) {\n\t\t\tthrow new Error(\"Kernel already has an active execution\");\n\t\t}\n\n\t\tconst result = createDeferred<InternalExecuteResult>();\n\t\tconst execution: ActiveExecution = {\n\t\t\trequestId,\n\t\t\tcode,\n\t\t\tstarted,\n\t\t\tmaxChars,\n\t\t\topts,\n\t\t\tstdout: \"\",\n\t\t\tstderr: \"\",\n\t\t\tstdoutTruncated: false,\n\t\t\tstderrTruncated: false,\n\t\t\tdiffs: [],\n\t\t\tattachments: [],\n\t\t\tsentAgentMessages: [],\n\t\t\tnativeRecoveries: [],\n\t\t\tnativeRecoveryBytes: 2, // JSON array brackets; reserve one delimiter per admitted response.\n\t\t\tnativeRecoveryRequests: 0,\n\t\t\tnativeRecoveryAbort: new AbortController(),\n\t\t\tbackgroundOutput: this.pendingBackgroundOutput,\n\t\t\tbackgroundOutputTruncated: this.pendingBackgroundOutputTruncated,\n\t\t\tstatus: \"ok\",\n\t\t\tsettled: false,\n\t\t\tresolve: result.resolve,\n\t\t\treject: result.reject,\n\t\t};\n\t\tthis.pendingBackgroundOutput = \"\";\n\t\tthis.pendingBackgroundOutputTruncated = false;\n\t\tlet abortTimer: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tconst clearAbortTimer = () => {\n\t\t\tif (abortTimer) {\n\t\t\t\tglobalThis.clearTimeout(abortTimer);\n\t\t\t\tabortTimer = undefined;\n\t\t\t}\n\t\t};\n\t\tconst forceAbort = () => {\n\t\t\tif (this.activeExecution !== execution) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\texecution.status = \"aborted\";\n\t\t\t// The execution stays active until its done event arrives; clearing it\n\t\t\t// early would let a new cell race the interrupted one (see busy-after-interrupt).\n\t\t\tthis.resolveExecution(execution, { clearActive: false });\n\t\t};\n\t\tconst onAbort = () => {\n\t\t\texecution.nativeRecoveryAbort.abort();\n\t\t\tvoid this.interrupt().catch(() => undefined);\n\t\t\tclearAbortTimer();\n\t\t\tabortTimer = globalThis.setTimeout(forceAbort, KERNEL_ABORT_GRACE_MS);\n\t\t\tif (abortTimer && typeof abortTimer === \"object\" && \"unref\" in abortTimer) {\n\t\t\t\tabortTimer.unref();\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tthis.activeExecution = execution;\n\t\t\topts.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tif (opts.signal?.aborted) {\n\t\t\t\tonAbort();\n\t\t\t}\n\t\t\tif (!opts.internal) {\n\t\t\t\tthis.lastCellCode = code;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst sendPromise = this.writeLine({ ...requestFields, id: requestId });\n\t\t\t\tsendPromise.catch(() => undefined);\n\t\t\t\tawait Promise.race([sendPromise, result.promise.then(() => undefined)]);\n\t\t\t\tif (this.activeExecution === execution && execution.status !== \"aborted\") {\n\t\t\t\t\tawait sendPromise;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (this.activeExecution === execution) {\n\t\t\t\t\tthis.activeExecution = undefined;\n\t\t\t\t}\n\t\t\t\tthrow error instanceof Error ? error : new Error(String(error));\n\t\t\t}\n\t\t\treturn await result.promise;\n\t\t} finally {\n\t\t\tclearAbortTimer();\n\t\t\topts.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\texecution.nativeRecoveryAbort.abort();\n\t\t}\n\t}\n\n\tprivate appendBackgroundOutput(text: string): void {\n\t\tif (!text) return;\n\t\tconst execution = this.activeExecution;\n\t\tif (execution) {\n\t\t\tif (execution.backgroundOutput.length >= MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\t\texecution.backgroundOutputTruncated = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\texecution.backgroundOutput += text;\n\t\t\tif (execution.backgroundOutput.length > MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\t\texecution.backgroundOutput = execution.backgroundOutput.slice(0, MAX_BACKGROUND_OUTPUT_CHARS);\n\t\t\t\texecution.backgroundOutputTruncated = true;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (this.pendingBackgroundOutput.length >= MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\tthis.pendingBackgroundOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.pendingBackgroundOutput += text;\n\t\tif (this.pendingBackgroundOutput.length > MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\tthis.pendingBackgroundOutput = this.pendingBackgroundOutput.slice(0, MAX_BACKGROUND_OUTPUT_CHARS);\n\t\t\tthis.pendingBackgroundOutputTruncated = true;\n\t\t}\n\t}\n\n\tprivate finishActiveExecution(execution: ActiveExecution): void {\n\t\tif (this.activeExecution !== execution) {\n\t\t\treturn;\n\t\t}\n\t\tthis.resolveExecution(execution, { clearActive: true });\n\t}\n\n\tprivate resolveExecution(execution: ActiveExecution, options: { clearActive: boolean }): void {\n\t\tconst didClearActive = options.clearActive && this.activeExecution === execution;\n\t\tif (options.clearActive && this.activeExecution === execution) {\n\t\t\tthis.activeExecution = undefined;\n\t\t}\n\t\tif (!execution.settled) {\n\t\t\texecution.settled = true;\n\t\t\texecution.nativeRecoveryAbort.abort();\n\t\t\tif (execution.opts.onLateSentAgentMessage) {\n\t\t\t\tthis.registerLateSentAgentMessageHandler(execution.requestId, execution.opts.onLateSentAgentMessage);\n\t\t\t}\n\n\t\t\tlet stdout = execution.stdout;\n\t\t\tlet stderr = execution.stderr;\n\t\t\tlet result = execution.result;\n\t\t\tlet status = execution.status;\n\t\t\tif (execution.stdoutTruncated) stdout += `\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\tif (execution.stderrTruncated) stderr += `\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\tif (result !== undefined && result.length > execution.maxChars) {\n\t\t\t\tresult = `${result.slice(0, execution.maxChars)}\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\t}\n\n\t\t\tif (execution.opts.signal?.aborted) status = \"aborted\";\n\n\t\t\tlet backgroundOutput = execution.backgroundOutput;\n\t\t\tif (execution.backgroundOutputTruncated) {\n\t\t\t\tbackgroundOutput += `\\n[... background output truncated at ${MAX_BACKGROUND_OUTPUT_CHARS} chars ...]`;\n\t\t\t}\n\n\t\t\texecution.resolve({\n\t\t\t\tstdout,\n\t\t\t\tstderr,\n\t\t\t\tresult,\n\t\t\t\tdiffs: execution.diffs.length > 0 ? execution.diffs : undefined,\n\t\t\t\tattachments: execution.attachments.length > 0 ? execution.attachments : undefined,\n\t\t\t\tsentAgentMessages: execution.sentAgentMessages.length > 0 ? execution.sentAgentMessages : undefined,\n\t\t\t\tnativeRecoveries: execution.nativeRecoveries.length > 0 ? execution.nativeRecoveries : undefined,\n\t\t\t\tbackgroundOutput: backgroundOutput.length > 0 ? backgroundOutput : undefined,\n\t\t\t\terror: execution.error,\n\t\t\t\tstatus,\n\t\t\t\tdurationMs: Date.now() - execution.started,\n\t\t\t\tdoneFields: execution.doneFields,\n\t\t\t});\n\t\t\texecution.nativeRecoveries = [];\n\t\t}\n\t\tif (didClearActive) {\n\t\t\tthis.notifyActiveExecutionIdle();\n\t\t}\n\t}\n\n\tprivate dispatchLateSentAgentMessage(requestId: string | undefined, value: unknown): boolean {\n\t\tconst sentAgentMessage = parseSentAgentMessage(value);\n\t\tif (!sentAgentMessage || !requestId) {\n\t\t\treturn false;\n\t\t}\n\t\tconst handler = this.lateSentAgentMessageHandlers.get(requestId);\n\t\tif (!handler) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.lateSentAgentMessageHandlers.delete(requestId);\n\t\tthis.lateSentAgentMessageHandlers.set(requestId, handler);\n\t\thandler(sentAgentMessage);\n\t\treturn true;\n\t}\n\n\tprivate registerLateSentAgentMessageHandler(\n\t\trequestId: string,\n\t\thandler: (message: KernelSentAgentMessage) => void,\n\t): void {\n\t\tthis.lateSentAgentMessageHandlers.set(requestId, handler);\n\t\twhile (this.lateSentAgentMessageHandlers.size > MAX_LATE_SENT_AGENT_MESSAGE_HANDLERS) {\n\t\t\tconst oldestRequestId = this.lateSentAgentMessageHandlers.keys().next().value;\n\t\t\tif (oldestRequestId === undefined) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.lateSentAgentMessageHandlers.delete(oldestRequestId);\n\t\t}\n\t}\n\n\tprivate rejectActiveExecution(error: Error): void {\n\t\tconst execution = this.activeExecution;\n\t\tif (!execution) {\n\t\t\treturn;\n\t\t}\n\t\tthis.activeExecution = undefined;\n\t\texecution.nativeRecoveryAbort.abort();\n\t\texecution.nativeRecoveries = [];\n\t\texecution.reject(error);\n\t\tthis.notifyActiveExecutionIdle();\n\t}\n\n\tprivate notifyActiveExecutionIdle(): void {\n\t\tfor (const resolve of this.activeExecutionIdleWaiters) {\n\t\t\tresolve();\n\t\t}\n\t\tthis.activeExecutionIdleWaiters.clear();\n\t}\n\n\tprivate waitForActiveExecutionToClear(signal: AbortSignal | undefined, timeoutMs: number): Promise<boolean> {\n\t\tif (!this.activeExecution) {\n\t\t\treturn Promise.resolve(true);\n\t\t}\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\t\tconst finish = (cleared: boolean) => {\n\t\t\t\tif (settled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsettled = true;\n\t\t\t\tif (timeout) {\n\t\t\t\t\tglobalThis.clearTimeout(timeout);\n\t\t\t\t}\n\t\t\t\tthis.activeExecutionIdleWaiters.delete(onIdle);\n\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(cleared);\n\t\t\t};\n\t\t\tconst onIdle = () => finish(true);\n\t\t\tconst onAbort = () => finish(false);\n\t\t\tthis.activeExecutionIdleWaiters.add(onIdle);\n\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\ttimeout = globalThis.setTimeout(() => finish(false), timeoutMs);\n\t\t\tif (timeout && typeof timeout === \"object\" && \"unref\" in timeout) {\n\t\t\t\ttimeout.unref();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async waitForActiveExecutionToClearForReuse(signal?: AbortSignal): Promise<void> {\n\t\tconst started = Date.now();\n\t\twhile (this.activeExecution && Date.now() - started < KERNEL_BUSY_REUSE_WAIT_MS) {\n\t\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t\t}\n\t\t\tvoid this.interrupt().catch(() => undefined);\n\t\t\tconst remaining = KERNEL_BUSY_REUSE_WAIT_MS - (Date.now() - started);\n\t\t\tconst cleared = await this.waitForActiveExecutionToClear(\n\t\t\t\tsignal,\n\t\t\t\tMath.max(1, Math.min(KERNEL_BUSY_INTERRUPT_INTERVAL_MS, remaining)),\n\t\t\t);\n\t\t\tif (cleared || signal?.aborted) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (this.activeExecution) {\n\t\t\tthrow new KernelBusyAfterInterruptError();\n\t\t}\n\t}\n\n\tprivate startHostRequest(requestId: string, data: unknown, cellId: unknown): void {\n\t\tif (this.handledHostRequestIds.has(requestId)) {\n\t\t\treturn;\n\t\t}\n\t\tthis.handledHostRequestIds.add(requestId);\n\t\twhile (this.handledHostRequestIds.size > MAX_HANDLED_HOST_REQUEST_IDS) {\n\t\t\tconst oldest = this.handledHostRequestIds.values().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\tthis.handledHostRequestIds.delete(oldest);\n\t\t}\n\n\t\tconst task = (async () => {\n\t\t\ttry {\n\t\t\t\tconst result = await this.handleHostRequest(data, cellId);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.writeLine({ type: \"host_reply\", id: requestId, data: { status: \"ok\", result } });\n\t\t\t\t} catch (replyError) {\n\t\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t\t`failed to send host request ok reply for ${requestId}: ${errorMessage(replyError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.appendKernelDiagnostic(`host request failed for ${requestId}: ${errorMessage(error)}`);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.writeLine({\n\t\t\t\t\t\ttype: \"host_reply\",\n\t\t\t\t\t\tid: requestId,\n\t\t\t\t\t\tdata: { status: \"error\", error: errorMessage(error) },\n\t\t\t\t\t});\n\t\t\t\t} catch (replyError) {\n\t\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t\t`failed to send host request error reply for ${requestId}: ${errorMessage(replyError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t})();\n\t\tthis.inFlightHostRequests.add(task);\n\t\tvoid task.finally(() => {\n\t\t\tthis.inFlightHostRequests.delete(task);\n\t\t});\n\t}\n\n\tprivate async handleHostRequest(data: unknown, cellId: unknown): Promise<Record<string, unknown>> {\n\t\tif (!isRecord(data)) {\n\t\t\tthrow new Error(\"host request payload must be an object\");\n\t\t}\n\t\tif (typeof data.type !== \"string\" || data.type.length === 0) {\n\t\t\tthrow new Error(\"host request payload must have a string type\");\n\t\t}\n\n\t\tconst handler = this.options.hostHandlers?.[data.type];\n\t\tif (!handler) {\n\t\t\tthrow new Error(`host request type \"${data.type}\" is not available in this session`);\n\t\t}\n\t\tif (data.type === \"prime_context\") {\n\t\t\tconst execution = this.activeExecution;\n\t\t\t// Only the transport's current cell may own an attachment. No last-cell fallback.\n\t\t\tif (\n\t\t\t\t!execution ||\n\t\t\t\texecution.settled ||\n\t\t\t\texecution.opts.internal ||\n\t\t\t\t!execution.opts.nativeRecovery ||\n\t\t\t\tcellId !== execution.requestId ||\n\t\t\t\texecution.nativeRecoveryAbort.signal.aborted\n\t\t\t) {\n\t\t\t\treturn { ...createNativeRecoveryRefusal(\"not_authorized\", \"active_cell_required\") };\n\t\t\t}\n\t\t\tconst maxBytes = DEFAULT_NATIVE_RECOVERY_LIMITS.maxBytes - execution.nativeRecoveryBytes - 1;\n\t\t\tif (execution.nativeRecoveryRequests >= DEFAULT_NATIVE_RECOVERY_LIMITS.maxRequests || maxBytes <= 0) {\n\t\t\t\tthrow new NativeRecoveryBudgetRefusal();\n\t\t\t}\n\t\t\t// Reserve before invoking the handler: concurrent requests cannot grow past the cell cap.\n\t\t\texecution.nativeRecoveryRequests++;\n\t\t\texecution.nativeRecoveryBytes += maxBytes + 1;\n\t\t\tlet reserved = maxBytes + 1;\n\t\t\ttry {\n\t\t\t\tconst read = async () =>\n\t\t\t\t\thandler(data, {\n\t\t\t\t\t\tsignal: execution.nativeRecoveryAbort.signal,\n\t\t\t\t\t\tnativeRecovery: { maxBytes },\n\t\t\t\t\t});\n\t\t\t\tconst response = (await (execution.opts.runNativeRecovery\n\t\t\t\t\t? execution.opts.runNativeRecovery(read)\n\t\t\t\t\t: read())) as unknown as NativeRecoveryResponse;\n\t\t\t\texecution.nativeRecoveryAbort.signal.throwIfAborted();\n\t\t\t\tif (this.activeExecution !== execution || execution.settled) {\n\t\t\t\t\tthrow new Error(\"Native recovery cell has finalized\");\n\t\t\t\t}\n\t\t\t\tconst encoded = stringifyNativeRecoveryResponse(response, maxBytes);\n\t\t\t\tconst admittedBytes = Buffer.byteLength(encoded) + 1;\n\t\t\t\texecution.nativeRecoveryBytes -= reserved - admittedBytes;\n\t\t\t\treserved = 0;\n\t\t\t\tconst admitted = JSON.parse(encoded) as NativeRecoveryResponse;\n\t\t\t\texecution.nativeRecoveries.push(admitted);\n\t\t\t\treturn { ...admitted };\n\t\t\t} finally {\n\t\t\t\texecution.nativeRecoveryBytes -= reserved;\n\t\t\t}\n\t\t}\n\t\t// Tag the request with the cell that triggered it. A blocking call is still\n\t\t// the in-flight execution; detached spawns (asyncio.create_task) fire after\n\t\t// the scheduling cell goes idle, so fall back to that last cell's source.\n\t\tconst cellSourceCode = this.activeExecution?.code ?? this.lastCellCode;\n\t\treturn handler({ ...data, cellSourceCode });\n\t}\n\n\tprivate async interrupt(): Promise<void> {\n\t\tconst requestId = this.activeExecution?.requestId;\n\t\tif (!requestId) return;\n\t\tawait this.writeLine({ type: \"interrupt\", id: requestId });\n\t}\n\n\tprivate cleanupResources(killSignal: NodeJS.Signals = \"SIGTERM\"): Error | undefined {\n\t\tconst failures: unknown[] = [];\n\t\tthis.startGeneration++; // any teardown invalidates in-flight starts\n\t\tthis.clearSnapshotTimer();\n\t\tthis.lateSentAgentMessageHandlers.clear();\n\t\tthis.pendingDoneWaiters.clear();\n\t\t// Stale pre-teardown background output must not surface after a restart.\n\t\tthis.pendingBackgroundOutput = \"\";\n\t\tthis.pendingBackgroundOutputTruncated = false;\n\t\tthis.rejectActiveExecution(new Error(\"Kernel has been shut down\"));\n\t\tconst child = this.child;\n\t\tconst orphanOwner = this.childOrphanOwner;\n\t\tthis.child = undefined;\n\t\tthis.childOrphanOwner = undefined;\n\t\tthis.readyDeferred = undefined;\n\t\tif (child) {\n\t\t\tchild.stdin?.destroy();\n\t\t\tchild.stdout?.destroy();\n\t\t\t// An exited child keeps its stderr: the post-exit drain owns it, and\n\t\t\t// destroying here would drop its buffered last words. A still-alive\n\t\t\t// child may ignore the kill signal and never emit 'exit', so that\n\t\t\t// drain would never run — destroy now to bound the pipe's lifetime.\n\t\t\tif (child.exitCode === null && child.signalCode === null) {\n\t\t\t\tchild.stderr?.destroy();\n\t\t\t}\n\t\t\tconst pid = child.pid;\n\t\t\tlet signaled = false;\n\t\t\ttry {\n\t\t\t\tsignaled = child.kill(killSignal);\n\t\t\t} catch (error) {\n\t\t\t\tfailures.push(error);\n\t\t\t}\n\t\t\t// Inactive only when the signal proved the pid still named our un-reaped child.\n\t\t\tif (pid !== undefined && signaled) {\n\t\t\t\tconst failure = orphanOwner?.record(pid, false);\n\t\t\t\tif (failure) failures.push(failure);\n\t\t\t}\n\t\t\t// A killed/crashed kernel cannot run its own shutdown hook, so the host\n\t\t\t// reaps the bash() process groups it journaled under this kernel pid.\n\t\t\tif (pid !== undefined && orphanOwner) {\n\t\t\t\tconst failure = reapKernelOrphanProcesses(pid, orphanOwner);\n\t\t\t\tif (failure) failures.push(failure);\n\t\t\t}\n\t\t}\n\t\tthis.startPromise = undefined;\n\t\tif (failures.length) {\n\t\t\tconst failure = new AggregateError(\n\t\t\t\tfailures,\n\t\t\t\t`Kernel cleanup tracking is unknown: ${failures.map(errorMessage).join(\"; \")}`,\n\t\t\t);\n\t\t\tthis.appendKernelDiagnostic(failure.message);\n\t\t\treturn failure;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate async waitForKernelExit(): Promise<void> {\n\t\tconst child = this.child;\n\t\tif (!child) return;\n\t\tif (child.exitCode !== null || child.signalCode !== null) return;\n\t\tawait new Promise<void>((resolve) => child.once(\"exit\", () => resolve()));\n\t}\n\n\tprivate async waitForHostRequestsToSettle(tasks: Promise<void>[], timeoutMs: number): Promise<void> {\n\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tconst timeoutPromise = new Promise<\"timeout\">((resolve) => {\n\t\t\ttimeout = globalThis.setTimeout(() => resolve(\"timeout\"), timeoutMs);\n\t\t\tif (timeout && typeof timeout === \"object\" && \"unref\" in timeout) {\n\t\t\t\ttimeout.unref();\n\t\t\t}\n\t\t});\n\n\t\tconst result = await Promise.race([Promise.allSettled(tasks).then(() => \"settled\" as const), timeoutPromise]);\n\t\tif (timeout) {\n\t\t\tglobalThis.clearTimeout(timeout);\n\t\t}\n\t\tif (result === \"timeout\") {\n\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t`timed out waiting ${timeoutMs}ms for ${tasks.length} host request task(s) during shutdown`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Resolves true when this call performed the cleanup (false: a concurrent teardown won; a joiner's options are ignored - the first caller's policy wins). */\n\tasync shutdown(opts: KernelShutdownOptions = {}): Promise<boolean> {\n\t\tconst inFlightShutdown = this.gracefulShutdownPromise;\n\t\tif (inFlightShutdown) {\n\t\t\tawait inFlightShutdown;\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.teardownInFlight++;\n\t\tthis.supersedeProtocolRepair();\n\t\tconst operation = this.performShutdown(opts);\n\t\tthis.gracefulShutdownPromise = operation;\n\t\ttry {\n\t\t\treturn await operation;\n\t\t} finally {\n\t\t\tthis.teardownInFlight--;\n\t\t\tif (this.gracefulShutdownPromise === operation) this.gracefulShutdownPromise = undefined;\n\t\t}\n\t}\n\n\tprivate async performShutdown(opts: KernelShutdownOptions): Promise<boolean> {\n\t\tif (this.state === \"shutdown\") {\n\t\t\tliveKernels.delete(this);\n\t\t\tif (this.gracefulShutdownGeneration === this.startGeneration) return false;\n\t\t\tconst failure = this.cleanupResources();\n\t\t\tif (failure) throw failure;\n\t\t\treturn true;\n\t\t}\n\t\t// Captured before any await: teardowns and newer starts bump the counter.\n\t\tconst generation = this.startGeneration;\n\t\tif (opts.snapshot) {\n\t\t\tawait this.flushSnapshotForDispose();\n\t\t\tif (this.startStale(generation)) return false;\n\t\t}\n\t\t// Protocol shutdown first: the runtime closes MCP servers and kills live bash() process groups a bare hard-kill would leak.\n\t\tconst protocolShutdownAvailable = this.state === \"running\";\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.gracefulShutdownGeneration = generation;\n\n\t\tlet shutdownTimer: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tlet doneWaiterId: string | undefined;\n\t\tlet performedCleanup = false;\n\t\tlet gracefulFailure: unknown;\n\t\tlet cleanupFailure: Error | undefined;\n\t\ttry {\n\t\t\tif (opts.drainHostRequests) {\n\t\t\t\tconst inFlightHostRequests = [...this.inFlightHostRequests];\n\t\t\t\tif (inFlightHostRequests.length > 0) {\n\t\t\t\t\tawait this.waitForHostRequestsToSettle(inFlightHostRequests, HOST_REQUEST_SHUTDOWN_TIMEOUT_MS);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\n\t\t\t\tprotocolShutdownAvailable &&\n\t\t\t\t!this.startStale(generation) &&\n\t\t\t\tthis.child?.stdin &&\n\t\t\t\t!this.child.stdin.destroyed\n\t\t\t) {\n\t\t\t\tconst requestId = uuid();\n\t\t\t\tdoneWaiterId = requestId;\n\t\t\t\tconst doneReply = new Promise<void>((resolve) => {\n\t\t\t\t\tthis.pendingDoneWaiters.set(requestId, resolve);\n\t\t\t\t});\n\t\t\t\tconst shutdownDeadline = new Promise<never>((_resolve, reject) => {\n\t\t\t\t\tshutdownTimer = globalThis.setTimeout(\n\t\t\t\t\t\t() => reject(new Error(`Kernel did not shut down within ${KERNEL_SHUTDOWN_TIMEOUT_MS}ms`)),\n\t\t\t\t\t\tKERNEL_SHUTDOWN_TIMEOUT_MS,\n\t\t\t\t\t);\n\t\t\t\t\tshutdownTimer.unref?.();\n\t\t\t\t});\n\t\t\t\tconst send = this.writeLine({ type: \"shutdown\", id: requestId });\n\t\t\t\tsend.catch(() => undefined);\n\t\t\t\tconst kernelExit = this.waitForKernelExit();\n\t\t\t\tconst gracefulReply = Promise.all([send, doneReply]);\n\t\t\t\tgracefulReply.catch(() => undefined);\n\t\t\t\tawait Promise.race([gracefulReply, kernelExit, shutdownDeadline]);\n\t\t\t\tawait Promise.race([kernelExit, shutdownDeadline]);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tgracefulFailure = error;\n\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t`graceful shutdown failed (killing instead): ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t} finally {\n\t\t\tif (shutdownTimer) globalThis.clearTimeout(shutdownTimer);\n\t\t\tif (doneWaiterId) this.pendingDoneWaiters.delete(doneWaiterId);\n\t\t\tif (this.gracefulShutdownGeneration === generation) this.gracefulShutdownGeneration = undefined;\n\t\t\tif (!this.startStale(generation)) {\n\t\t\t\tcleanupFailure = this.cleanupResources();\n\t\t\t\tperformedCleanup = true;\n\t\t\t}\n\t\t}\n\n\t\tif (cleanupFailure)\n\t\t\tthrow gracefulFailure\n\t\t\t\t? new AggregateError([gracefulFailure, cleanupFailure], \"Kernel graceful shutdown and cleanup failed\")\n\t\t\t\t: cleanupFailure;\n\t\treturn performedCleanup;\n\t}\n\n\tasync restart(): Promise<void> {\n\t\t// A final dispose flush owns the queue tail. Taking a slot now and joining\n\t\t// the in-flight shutdown would deadlock: the flush's snapshot waits on our\n\t\t// slot while we wait on the flush's shutdown.\n\t\tif (this.flushingSnapshotForDispose) {\n\t\t\tthrow new Error(\"Kernel is shutting down\");\n\t\t}\n\t\tconst prev = this.executionQueue;\n\t\tlet resolveNext: () => void = () => {};\n\t\tthis.executionQueue = new Promise<void>((r) => {\n\t\t\tresolveNext = r;\n\t\t});\n\t\tawait prev;\n\n\t\ttry {\n\t\t\tconst performedCleanup = await this.shutdown();\n\t\t\tif (!performedCleanup) return;\n\t\t\tthis.state = \"idle\";\n\t\t\tthis.kernelStderr = \"\";\n\t\t\tawait this.start();\n\t\t} finally {\n\t\t\tresolveNext();\n\t\t}\n\t}\n\n\tasync kill(): Promise<void> {\n\t\tthis.supersedeProtocolRepair();\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources(\"SIGKILL\");\n\t}\n\n\t/**\n\t * Serialize the user namespace to disk (best-effort, per-variable). No-op when\n\t * the kernel isn't running or no snapshot target was configured. Never throws.\n\t */\n\tasync snapshotState(): Promise<SnapshotResult | null> {\n\t\treturn this.captureSnapshot();\n\t}\n\n\t/** Persist the namespace, then remove variables above the per-variable cap. */\n\tasync pruneOversizedVariables(): Promise<SnapshotResult | null> {\n\t\treturn this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS, pruneOversized: true });\n\t}\n\n\tprivate async captureSnapshot(\n\t\toptions: { executionTimeoutMs?: number; pruneOversized?: boolean } = {},\n\t): Promise<SnapshotResult | null> {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg || !this.isRunning) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{\n\t\t\t\t\ttype: \"snapshot\",\n\t\t\t\t\tpath: cfg.path,\n\t\t\t\t\tmanifest_path: cfg.manifestPath,\n\t\t\t\t\tmax_bytes: cfg.maxBytes ?? DEFAULT_SNAPSHOT_MAX_BYTES,\n\t\t\t\t\tmax_variable_bytes: cfg.maxVariableBytes ?? DEFAULT_SNAPSHOT_MAX_VARIABLE_BYTES,\n\t\t\t\t\tprune_oversized: options.pruneOversized ?? false,\n\t\t\t\t},\n\t\t\t\t\"\",\n\t\t\t\t{ internal: true },\n\t\t\t\toptions.executionTimeoutMs,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`state snapshot ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst pruned = asStringArray(r.doneFields.pruned);\n\t\t\treturn {\n\t\t\t\tsaved: asStringArray(r.doneFields.saved),\n\t\t\t\tskipped: asReasonArray(r.doneFields.skipped),\n\t\t\t\tpruned: pruned.length > 0 ? pruned : undefined,\n\t\t\t\tbytes: typeof r.doneFields.bytes === \"number\" ? r.doneFields.bytes : 0,\n\t\t\t\tpath: cfg.path,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`state snapshot error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Revive a previously snapshotted namespace into the kernel. Call right after\n\t * start() and before the runtime bootstrap, which then refreshes live handles\n\t * (rlm, skills) over anything restored. Never throws.\n\t */\n\tasync restoreState(): Promise<RestoreResult | null> {\n\t\treturn this.performRestore(false);\n\t}\n\n\t/** Repair restores bypass the repair gate and are bounded so a stalled kernel cannot wedge it. */\n\tprivate async performRestore(protocolRepair: boolean): Promise<RestoreResult | null> {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{ type: \"restore\", path: cfg.path },\n\t\t\t\t\"\",\n\t\t\t\t{ internal: true, protocolRepair },\n\t\t\t\tprotocolRepair ? REPAIR_STEP_TIMEOUT_MS : undefined,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`state restore ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthis.pendingRestore = false;\n\t\t\treturn {\n\t\t\t\trestored: asStringArray(r.doneFields.restored),\n\t\t\t\tfailed: asReasonArray(r.doneFields.failed),\n\t\t\t\tpath: cfg.path,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`state restore error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/** Live user-defined top-level names, or null if the kernel isn't running. Never throws. */\n\tasync listNamespaceNames(signal?: AbortSignal): Promise<string[] | null> {\n\t\tif (!this.isRunning) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest({ type: \"list_names\" }, \"\", { internal: true, signal });\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(`namespace listing failed: ${r.error?.evalue ?? r.stderr}`);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn asStringArray(r.doneFields.names);\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`namespace listing error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprivate scheduleSnapshot(): void {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg) return;\n\t\tif (this.snapshotTimer) clearTimeout(this.snapshotTimer);\n\t\tthis.snapshotTimer = globalThis.setTimeout(() => {\n\t\t\tthis.snapshotTimer = undefined;\n\t\t\tvoid this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS });\n\t\t}, cfg.debounceMs ?? DEFAULT_SNAPSHOT_DEBOUNCE_MS);\n\t\tif (this.snapshotTimer && typeof this.snapshotTimer === \"object\" && \"unref\" in this.snapshotTimer) {\n\t\t\tthis.snapshotTimer.unref();\n\t\t}\n\t}\n\n\tprivate clearSnapshotTimer(): void {\n\t\tif (this.snapshotTimer) {\n\t\t\tclearTimeout(this.snapshotTimer);\n\t\t\tthis.snapshotTimer = undefined;\n\t\t}\n\t}\n\n\tprivate flushSnapshotForDispose(): Promise<void> {\n\t\t// Concurrent teardowns (dispose vs a signal-handler shutdown) join one flush:\n\t\t// a second flusher would clear the execution guard while the first is still\n\t\t// snapshotting and enqueue a duplicate final snapshot behind it.\n\t\tthis.snapshotFlushForDispose ??= this.runSnapshotFlushForDispose().finally(() => {\n\t\t\tthis.snapshotFlushForDispose = undefined;\n\t\t});\n\t\treturn this.snapshotFlushForDispose;\n\t}\n\n\tprivate async runSnapshotFlushForDispose(): Promise<void> {\n\t\tif (!this.options.snapshot || !this.isRunning) return;\n\t\t// A kernel that never restored the saved namespace must not overwrite it:\n\t\t// the on-disk snapshot is strictly fresher than this namespace.\n\t\tif (this.pendingRestore) return;\n\t\t// Block new external executions so none can splice ahead of the final snapshot and stall dispose.\n\t\tthis.flushingSnapshotForDispose = true;\n\t\ttry {\n\t\t\tconst pendingExecutions = this.executionQueue;\n\t\t\tif (this.activeExecution) void this.interrupt().catch(() => undefined);\n\t\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\t\tconst queueSettled = await Promise.race([\n\t\t\t\tpendingExecutions.then(() => true),\n\t\t\t\tnew Promise<false>((resolve) => {\n\t\t\t\t\ttimeout = globalThis.setTimeout(() => resolve(false), SNAPSHOT_EXECUTION_TIMEOUT_MS);\n\t\t\t\t\ttimeout.unref?.();\n\t\t\t\t}),\n\t\t\t]);\n\t\t\tif (timeout) globalThis.clearTimeout(timeout);\n\t\t\tif (!queueSettled) return;\n\t\t\tawait this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS });\n\t\t} finally {\n\t\t\t// Reset: a superseding start() can revive this kernel for new work.\n\t\t\tthis.flushingSnapshotForDispose = false;\n\t\t}\n\t}\n\n\t/** Synchronous best-effort cleanup. Safe to call from `process.on('exit')`. */\n\tdisposeSync(): void {\n\t\tthis.supersedeProtocolRepair();\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources();\n\t}\n\n\tget isRunning(): boolean {\n\t\treturn this.state === \"running\";\n\t}\n}\n"]}
1
+ {"version":3,"file":"repl-manager.js","sourceRoot":"","sources":["../../../src/core/kernel/repl-manager.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iFAA+E;AAC/E,yFAAyF;AAEzF,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EACN,SAAS,EACT,UAAU,EACV,SAAS,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,eAAe;gBAAE,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YACvE,IAAI,OAA6D,CAAC;YAClE,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;gBACvC,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;gBAClC,IAAI,OAAO,CAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;oBAC/B,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,6BAA6B,CAAC,CAAC;oBACrF,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;gBAAA,CAClB,CAAC;aACF,CAAC,CAAC;YACH,IAAI,OAAO;gBAAE,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,CAAC,YAAY;gBAAE,OAAO;YAC1B,MAAM,IAAI,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,CAAC,CAAC;QACnF,CAAC;gBAAS,CAAC;YACV,oEAAoE;YACpE,IAAI,CAAC,0BAA0B,GAAG,KAAK,CAAC;QACzC,CAAC;IAAA,CACD;IAED,+EAA+E;IAC/E,WAAW,GAAS;QACnB,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC;QACxB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAAA,CACxB;IAED,IAAI,SAAS,GAAY;QACxB,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC;IAAA,CAChC;CACD","sourcesContent":["// Kernel client for the REPL runtime: the kernel is a JSON-lines subprocess\n// (`python -m rlm.repl`) — requests on stdin, events on stdout, stderr kept as\n// a diagnostics tail. The protocol is documented in prime-agent-runtime/src/rlm/repl.md.\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport {\n\tcloseSync,\n\texistsSync,\n\tmkdirSync,\n\topenSync,\n\treadFileSync,\n\trenameSync,\n\trmSync,\n\tstatSync,\n\twriteSync,\n} from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport { v4 as uuid } from \"uuid\";\nimport { PRODUCT } from \"../../product-identity.js\";\nimport {\n\tcaptureOrphanProcessJournalOwner,\n\tORPHAN_PROCESS_JOURNAL_ENV,\n\ttype OrphanProcessJournalOwner,\n\treapKernelOrphanProcesses,\n} from \"../orphan-process-journal.js\";\nimport {\n\tcreateNativeRecoveryRefusal,\n\tDEFAULT_NATIVE_RECOVERY_LIMITS,\n\tNativeRecoveryBudgetRefusal,\n\ttype NativeRecoveryResponse,\n\tstringifyNativeRecoveryResponse,\n} from \"../selective-recovery.js\";\nimport { ensureKernelPython } from \"./bootstrap.js\";\nimport {\n\tAGENT_MESSAGE_DISPLAY_MIME,\n\tATTACHMENT_DISPLAY_MIME,\n\ttype CapturedKernelLifecycle,\n\tcreateDeferred,\n\tcreateKernelStartupAbortError,\n\tDEFAULT_MAX_OUTPUT_CHARS,\n\tDEFAULT_SNAPSHOT_DEBOUNCE_MS,\n\tDIFF_DISPLAY_MIME,\n\ttype ExecuteOptions,\n\ttype ExecuteResult,\n\terrorMessage,\n\tHOST_REQUEST_SHUTDOWN_TIMEOUT_MS,\n\tinstallSignalHandlersOnce,\n\tisRecord,\n\tKERNEL_ABORT_GRACE_MS,\n\tKERNEL_BUSY_INTERRUPT_INTERVAL_MS,\n\tKERNEL_BUSY_REUSE_WAIT_MS,\n\tKERNEL_SHUTDOWN_TIMEOUT_MS,\n\ttype KernelAttachment,\n\tKernelBusyAfterInterruptError,\n\ttype KernelDiffDisplay,\n\ttype KernelManagerOptions,\n\ttype KernelSentAgentMessage,\n\ttype KernelShutdownOptions,\n\ttype KernelStartOptions,\n\tliveKernels,\n\tMAX_ATTACHMENT_DATA_CHARS,\n\tMAX_LATE_SENT_AGENT_MESSAGE_HANDLERS,\n\tparseAttachmentDisplay,\n\tparseDiffDisplay,\n\tparseSentAgentMessage,\n\traceStartupWithAbort,\n\tSNAPSHOT_EXECUTION_TIMEOUT_MS,\n} from \"./shared.js\";\nimport {\n\tDEFAULT_SNAPSHOT_MAX_BYTES,\n\tDEFAULT_SNAPSHOT_MAX_VARIABLE_BYTES,\n\ttype RestoreResult,\n\ttype SnapshotResult,\n} from \"./state-snapshot.js\";\n\nconst REPL_PROTOCOL_VERSION = 4;\nconst READY_TIMEOUT_MS = 30_000;\nconst REPAIR_STEP_TIMEOUT_MS = 30_000;\n// Runtime-minted host-request ids never repeat; the bound only guards a\n// misbehaving runtime from growing the dedup set forever.\nconst MAX_HANDLED_HOST_REQUEST_IDS = 1024;\n// Cap for unattributed background output buffered between and during cells.\nconst MAX_BACKGROUND_OUTPUT_CHARS = 64 * 1024;\n\nconst MAX_KERNEL_STDERR_CHARS = 8 * 1024;\nconst MAX_KERNEL_STDERR_LOG_BYTES = 5 * 1024 * 1024;\nconst KERNEL_STDERR_LOG_BUDGET_MARKER = \"[stderr log budget exhausted]\\n\";\n\n/** fs.writeSync may write fewer bytes than asked (partial ENOSPC, signals); loop until done. */\nfunction writeFullySync(fd: number, data: Buffer): void {\n\tlet offset = 0;\n\twhile (offset < data.length) {\n\t\toffset += writeSync(fd, data, offset);\n\t}\n}\n\n/** ExecuteResult plus the raw fields of the request's `done` event (state ops). */\ninterface InternalExecuteResult extends ExecuteResult {\n\tdoneFields?: Record<string, unknown>;\n}\n\ninterface ActiveExecution {\n\trequestId: string;\n\t/** Source of the cell currently executing; surfaced to rlm.run spawns. */\n\tcode: string;\n\tstarted: number;\n\tmaxChars: number;\n\topts: ExecuteOptions;\n\tstdout: string;\n\tstderr: string;\n\tstdoutTruncated: boolean;\n\tstderrTruncated: boolean;\n\tresult?: string;\n\tdiffs: KernelDiffDisplay[];\n\tattachments: KernelAttachment[];\n\tsentAgentMessages: KernelSentAgentMessage[];\n\t// Ephemeral, per-cell output attachment; only the finalized tool result persists it.\n\tnativeRecoveries: NativeRecoveryResponse[];\n\tnativeRecoveryBytes: number;\n\tnativeRecoveryRequests: number;\n\tnativeRecoveryAbort: AbortController;\n\t/** Stream text without this execution's id: user threads, other cells' leftovers, raw fd writes. */\n\tbackgroundOutput: string;\n\tbackgroundOutputTruncated: boolean;\n\terror?: ExecuteResult[\"error\"];\n\tstatus: ExecuteResult[\"status\"];\n\tdoneFields?: Record<string, unknown>;\n\tsettled: boolean;\n\tresolve: (result: InternalExecuteResult) => void;\n\treject: (error: Error) => void;\n}\n\n// Complete event vocabulary of protocol version 2 (see prime-agent-runtime/src/rlm/repl.md).\n// The version handshake is exact, so an unknown kind is corruption, not a newer runtime.\nconst PROTOCOL_EVENT_KINDS = new Set([\n\t\"ready\",\n\t\"stdout\",\n\t\"stderr\",\n\t\"result\",\n\t\"display\",\n\t\"host_request\",\n\t\"error\",\n\t\"done\",\n]);\n\n/**\n * Reason a JSON object still isn't a valid protocol frame, or undefined.\n * `done` and `host_request` route strictly by non-empty string id (the runtime\n * mints uuid hex ids and echoes the host's uuids); silently dropping an id-less\n * one would leave the awaiting request unsettled forever.\n */\nfunction invalidProtocolFrameReason(event: Record<string, unknown>): string | undefined {\n\tif (typeof event.event !== \"string\" || !PROTOCOL_EVENT_KINDS.has(event.event)) {\n\t\treturn \"unknown protocol event\";\n\t}\n\tif (\n\t\t(event.event === \"done\" || event.event === \"host_request\") &&\n\t\t(typeof event.id !== \"string\" || event.id === \"\")\n\t) {\n\t\treturn `${event.event} frame without id`;\n\t}\n\treturn undefined;\n}\n\nfunction asStringArray(value: unknown): string[] {\n\treturn Array.isArray(value) ? value.filter((v): v is string => typeof v === \"string\") : [];\n}\n\nfunction asReasonArray(value: unknown): { name: string; reason: string }[] {\n\tif (!Array.isArray(value)) return [];\n\treturn value.flatMap((entry) => {\n\t\tif (isRecord(entry) && typeof entry.name === \"string\") {\n\t\t\treturn [{ name: entry.name, reason: typeof entry.reason === \"string\" ? entry.reason : \"\" }];\n\t\t}\n\t\treturn [];\n\t});\n}\n\nexport class ReplKernelManager {\n\tprivate readonly options: Pick<\n\t\tKernelManagerOptions,\n\t\t| \"python\"\n\t\t| \"cwd\"\n\t\t| \"env\"\n\t\t| \"sessionId\"\n\t\t| \"hostHandlers\"\n\t\t| \"pythonSkills\"\n\t\t| \"snapshot\"\n\t\t| \"bootstrapCode\"\n\t\t| \"stderrLogPath\"\n\t>;\n\tprivate readonly handledHostRequestIds = new Set<string>();\n\tprivate child?: ChildProcess;\n\tprivate childOrphanOwner?: OrphanProcessJournalOwner;\n\tprivate readyDeferred?: ReturnType<typeof createDeferred<number>>;\n\tprivate pythonVersion?: string;\n\tprivate kernelStderr = \"\";\n\t/** Serializes execute() calls — the runtime runs one request at a time. */\n\tprivate executionQueue: Promise<unknown> = Promise.resolve();\n\tprivate activeExecution?: ActiveExecution;\n\tprivate readonly activeExecutionIdleWaiters = new Set<() => void>();\n\tprivate readonly lateSentAgentMessageHandlers = new Map<string, (message: KernelSentAgentMessage) => void>();\n\t/** Resolvers for done events outside the active execution (the shutdown reply). */\n\tprivate readonly pendingDoneWaiters = new Map<string, () => void>();\n\t// Source of the most recently started cell, retained after it finishes so\n\t// rlm.run spawns from detached asyncio tasks (cell already idle) can still\n\t// attribute their spawning program.\n\tprivate lastCellCode?: string;\n\t/** Unattributed stream text that arrived between cells; surfaced on the next execution. */\n\tprivate pendingBackgroundOutput = \"\";\n\tprivate pendingBackgroundOutputTruncated = false;\n\tprivate readonly inFlightHostRequests = new Set<Promise<void>>();\n\t/** A newly constructed manager is a different owner even when its counter restarts at zero. */\n\tprivate readonly lifecycleOwner = uuid();\n\tprivate state: \"idle\" | \"starting\" | \"running\" | \"shutdown\" = \"idle\";\n\t/** Bumped by every teardown so a stale in-flight doStart can never touch a newer kernel. */\n\tprivate startGeneration = 0;\n\t/** Generation whose graceful shutdown() owns the teardown, so the exit handler must not run it. */\n\tprivate gracefulShutdownGeneration?: number;\n\tprivate gracefulShutdownPromise?: Promise<boolean>;\n\t/** Memoized so concurrent callers all await the same in-flight startup. */\n\tprivate startPromise?: Promise<void>;\n\t/** Pending debounced auto-snapshot, if one has been scheduled. */\n\tprivate snapshotTimer?: ReturnType<typeof globalThis.setTimeout>;\n\t/** While the final dispose snapshot is flushing, new external executions are rejected. */\n\tprivate flushingSnapshotForDispose = false;\n\t/** In-flight final snapshot flush; concurrent teardowns join it instead of re-flushing. */\n\tprivate snapshotFlushForDispose?: Promise<void>;\n\t/** Repairs a child whose dedicated protocol stream emitted an invalid frame. */\n\tprivate protocolRepairPromise?: Promise<void>;\n\tprivate protocolRepairOwner?: { superseded: boolean };\n\t/** Corruption seen while still \"starting\" (e.g. ready and garbage in one chunk) fails that start. */\n\tprivate startupProtocolError?: Error;\n\t/** A repair discarded its kernel: the next fresh start must re-run the runtime bootstrap. */\n\tprivate pendingRebootstrap = false;\n\t/** Restore the saved namespace on that fresh start too (false when the snapshot itself is the declared culprit). */\n\tprivate pendingRestore = false;\n\tprivate rebootstrapPromise?: Promise<boolean>;\n\tprivate teardownInFlight = 0;\n\n\tconstructor(options: KernelManagerOptions) {\n\t\tthis.options = {\n\t\t\tpython: options.python,\n\t\t\tcwd: options.cwd,\n\t\t\tenv: options.env,\n\t\t\tsessionId: options.sessionId,\n\t\t\thostHandlers: options.hostHandlers,\n\t\t\tpythonSkills: options.pythonSkills,\n\t\t\tsnapshot: options.snapshot,\n\t\t\tbootstrapCode: options.bootstrapCode,\n\t\t\tstderrLogPath: options.stderrLogPath,\n\t\t};\n\t}\n\n\tget ownerSessionId(): string | undefined {\n\t\treturn this.options.sessionId;\n\t}\n\n\tcaptureLifecycleState(): CapturedKernelLifecycle {\n\t\tconst generation = this.startGeneration;\n\t\tconst state = this.state;\n\t\treturn Object.freeze({\n\t\t\tsnapshot: Object.freeze({ source: \"repl-manager\" as const, owner: this.lifecycleOwner, generation, state }),\n\t\t\tisCurrent: () => this.startGeneration === generation && this.state === state,\n\t\t});\n\t}\n\n\tprivate appendKernelDiagnostic(message: string): void {\n\t\tthis.appendKernelStderrText(`[kernel] ${message.endsWith(\"\\n\") ? message : `${message}\\n`}`);\n\t}\n\n\tprivate appendKernelStderrText(text: string): void {\n\t\tthis.kernelStderr = (this.kernelStderr + text).slice(-MAX_KERNEL_STDERR_CHARS);\n\t}\n\n\t/**\n\t * The write budget is the file's remaining capacity, not a fresh allowance,\n\t * so current file and `.old` each stay near MAX_KERNEL_STDERR_LOG_BYTES and\n\t * per-session disk near 2x — even when rotation fails and the file is kept.\n\t */\n\tprivate openStderrLog(): { fd: number; budget: number } | undefined {\n\t\tconst path = this.options.stderrLogPath;\n\t\tif (!path) return undefined;\n\t\ttry {\n\t\t\tmkdirSync(dirname(path), { recursive: true });\n\t\t\tlet size = existsSync(path) ? statSync(path).size : 0;\n\t\t\tif (size > MAX_KERNEL_STDERR_LOG_BYTES) {\n\t\t\t\ttry {\n\t\t\t\t\t// Drop any prior .old first: rename fails on Windows if it exists.\n\t\t\t\t\trmSync(`${path}.old`, { force: true });\n\t\t\t\t\trenameSync(path, `${path}.old`);\n\t\t\t\t\tsize = 0;\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// A failed rotation must not cost the log: keep appending instead.\n\t\t\t\t\tthis.appendKernelDiagnostic(`cannot rotate kernel stderr log: ${errorMessage(error)}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { fd: openSync(path, \"a\"), budget: Math.max(0, MAX_KERNEL_STDERR_LOG_BYTES - size) };\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`cannot open kernel stderr log: ${errorMessage(error)}`);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tasync start(options: KernelStartOptions = {}): Promise<void> {\n\t\tif (options.signal?.aborted) {\n\t\t\tthrow createKernelStartupAbortError();\n\t\t}\n\t\tif (!this.startPromise) {\n\t\t\tconst startPromise = this.doStart({ onBootstrapProgress: options.onBootstrapProgress }).catch((error) => {\n\t\t\t\t// Only clear our own memoization: a stale start must not evict a newer one.\n\t\t\t\tif (this.startPromise === startPromise) this.startPromise = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tthis.startPromise = startPromise;\n\t\t}\n\t\treturn raceStartupWithAbort(this.startPromise, options.signal);\n\t}\n\n\tprivate async doStart(startOptions: KernelStartOptions): Promise<void> {\n\t\tif (this.state !== \"idle\") return;\n\t\tconst orphanOwner = captureOrphanProcessJournalOwner();\n\t\tconst generation = ++this.startGeneration;\n\t\tthis.state = \"starting\";\n\t\tinstallSignalHandlersOnce();\n\t\t// Tracked from the moment startup begins so session cleanup and signal\n\t\t// handlers can dispose a kernel that is still booting.\n\t\tliveKernels.add(this);\n\n\t\tlet python: string;\n\t\ttry {\n\t\t\tpython =\n\t\t\t\tthis.options.python ??\n\t\t\t\t(await ensureKernelPython({\n\t\t\t\t\tpythonSkills: this.options.pythonSkills,\n\t\t\t\t\tonProgress: startOptions.onBootstrapProgress,\n\t\t\t\t}));\n\t\t\tif (this.startStale(generation)) throw new Error(\"Kernel start superseded\");\n\t\t\tthis.options.python = python;\n\t\t} catch (error) {\n\t\t\tif (this.startStale(generation)) throw error; // never touch a newer start's state\n\t\t\tliveKernels.delete(this);\n\t\t\tif ((this.state as string) !== \"shutdown\") this.state = \"idle\";\n\t\t\tthrow error;\n\t\t}\n\n\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\tthrow new Error(\"Kernel was disposed during startup\");\n\t\t}\n\n\t\tconst child = spawn(python, [\"-m\", \"rlm.repl\"], {\n\t\t\tcwd: this.options.cwd,\n\t\t\t// bash.py journals its process groups under this pid so the host can\n\t\t\t// reap them if the runtime dies without running its shutdown hook.\n\t\t\tenv: {\n\t\t\t\t...process.env,\n\t\t\t\t...this.options.env,\n\t\t\t\t[ORPHAN_PROCESS_JOURNAL_ENV]: orphanOwner.path,\n\t\t\t\tBASE_CONTEXT_KERNEL_OWNER_PID: String(orphanOwner.ownerPid),\n\t\t\t},\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tthis.child = child;\n\t\tthis.childOrphanOwner = orphanOwner;\n\t\tthis.readyDeferred = createDeferred<number>();\n\t\tthis.pythonVersion = undefined;\n\t\tthis.startupProtocolError = undefined;\n\t\tthis.wireChild(child);\n\n\t\ttry {\n\t\t\tconst registrationError = child.pid !== undefined ? orphanOwner.record(child.pid, true) : undefined;\n\t\t\tif (registrationError) throw registrationError;\n\t\t\tconst protocol = await this.waitForReady(child);\n\t\t\tif (this.startStale(generation)) throw new Error(\"Kernel start superseded\");\n\t\t\t// Ready and a corrupt frame can share one stdout chunk: ready resolved the\n\t\t\t// deferred synchronously before the corruption was parsed, so the rejection\n\t\t\t// in failProtocolFrame was a no-op. Never mark such a child running.\n\t\t\tif (this.startupProtocolError) throw this.startupProtocolError;\n\t\t\tif (protocol !== REPL_PROTOCOL_VERSION) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Kernel runtime speaks protocol ${protocol}, expected ${REPL_PROTOCOL_VERSION}. ` +\n\t\t\t\t\t\t`Update ${PRODUCT.runtimeDistribution} in the kernel Python (BASE_CONTEXT_KERNEL_PYTHON) to match this ${PRODUCT.name}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.assertSnapshotPythonCompatible();\n\t\t} catch (e) {\n\t\t\tif (this.startStale(generation)) throw e; // never tear down a newer start's kernel\n\t\t\tconst canRetryStartup = (this.state as string) !== \"shutdown\";\n\t\t\t// Only the call that performed the cleanup may resurrect to idle; a\n\t\t\t// concurrent kill()/teardown owns the state otherwise.\n\t\t\ttry {\n\t\t\t\tif ((await this.shutdown()) && canRetryStartup) this.state = \"idle\";\n\t\t\t} catch (cleanupError) {\n\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t[e, cleanupError],\n\t\t\t\t\t`Kernel startup failed: ${errorMessage(e)}; cleanup failed: ${errorMessage(cleanupError)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\n\t\tthis.state = \"running\";\n\t}\n\n\tprivate assertSnapshotPythonCompatible(): void {\n\t\tconst snapshot = this.options.snapshot;\n\t\tif (!snapshot || !existsSync(snapshot.path)) return;\n\n\t\tlet savedVersion: unknown;\n\t\ttry {\n\t\t\tconst manifest: unknown = JSON.parse(readFileSync(snapshot.manifestPath, \"utf8\"));\n\t\t\tsavedVersion = isRecord(manifest) ? manifest.pythonVersion : undefined;\n\t\t} catch {\n\t\t\t// The payload alone cannot identify the Python bytecode it contains.\n\t\t}\n\t\tconst minorVersion = (value: unknown): string | undefined =>\n\t\t\ttypeof value === \"string\" ? /^(\\d+\\.\\d+)\\.\\d+(?:a\\d+|b\\d+|rc\\d+)?$/.exec(value)?.[1] : undefined;\n\t\tconst savedMinor = minorVersion(savedVersion);\n\t\tconst currentMinor = minorVersion(this.pythonVersion);\n\t\tconst preserved = \"The saved state was not restored or changed. \";\n\t\tif (!savedMinor || !currentMinor) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot resume saved Python state: ${!savedMinor ? `its Python version is missing or unreadable (${snapshot.manifestPath})` : \"the kernel did not report a valid Python version\"}. ` +\n\t\t\t\t\tpreserved +\n\t\t\t\t\t\"Resume with the original Python runtime or start a new session.\",\n\t\t\t);\n\t\t}\n\t\tif (savedMinor !== currentMinor) {\n\t\t\tthrow new Error(\n\t\t\t\t`Saved Python state uses Python ${savedVersion}; this kernel uses ${this.pythonVersion}. ` +\n\t\t\t\t\tpreserved +\n\t\t\t\t\t`Resume with a matching Python ${savedMinor} runtime or start a new session.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** True when a teardown (or newer start) superseded the start that captured `generation`. */\n\tprivate startStale(generation: number): boolean {\n\t\treturn generation !== this.startGeneration;\n\t}\n\n\tprivate wireChild(child: ChildProcess): void {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tlet buffered = \"\";\n\t\tchild.stdout?.on(\"data\", (buf: Buffer) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tbuffered += decoder.write(buf);\n\t\t\tlet newline = buffered.indexOf(\"\\n\");\n\t\t\twhile (newline !== -1) {\n\t\t\t\tconst line = buffered.slice(0, newline);\n\t\t\t\tbuffered = buffered.slice(newline + 1);\n\t\t\t\tnewline = buffered.indexOf(\"\\n\");\n\t\t\t\tif (!line.trim()) continue;\n\t\t\t\tlet event: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tevent = JSON.parse(line);\n\t\t\t\t} catch {\n\t\t\t\t\tthis.failProtocolFrame(child, `unparseable protocol line: ${line.slice(0, 200)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!isRecord(event)) {\n\t\t\t\t\tthis.failProtocolFrame(child, `non-object protocol line: ${line.slice(0, 200)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst invalidReason = invalidProtocolFrameReason(event);\n\t\t\t\tif (invalidReason) {\n\t\t\t\t\tthis.failProtocolFrame(child, `${invalidReason}: ${line.slice(0, 200)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.handleEvent(event);\n\t\t\t}\n\t\t});\n\n\t\t// The runtime dup2's fd 2 into its protocol pump before ready (repl.py\n\t\t// _setup_fds), so this pipe only ever carries pre-ready bytes; the write\n\t\t// budget caps what lands on disk, and once it is spent the handler keeps\n\t\t// draining but discards (a blocked pipe would wedge a pre-ready kernel).\n\t\tconst stderrLog = this.openStderrLog();\n\t\tconst stderrDecoder = new StringDecoder(\"utf8\");\n\t\tlet stderrLogBudget = stderrLog?.budget ?? 0;\n\t\tlet stderrLogWritable = stderrLog !== undefined;\n\t\tchild.stderr?.on(\"data\", (buf: Buffer) => {\n\t\t\tthis.appendKernelStderrText(stderrDecoder.write(buf));\n\t\t\tif (!stderrLogWritable || stderrLog === undefined) return;\n\t\t\ttry {\n\t\t\t\tif (buf.length <= stderrLogBudget) {\n\t\t\t\t\twriteFullySync(stderrLog.fd, buf);\n\t\t\t\t\tstderrLogBudget -= buf.length;\n\t\t\t\t} else {\n\t\t\t\t\twriteFullySync(stderrLog.fd, Buffer.from(KERNEL_STDERR_LOG_BUDGET_MARKER));\n\t\t\t\t\tstderrLogWritable = false;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tstderrLogWritable = false;\n\t\t\t\tthis.appendKernelDiagnostic(`kernel stderr log write failed: ${errorMessage(error)}`);\n\t\t\t}\n\t\t});\n\t\t// A kernel that dies mid-character leaves bytes buffered in the decoder;\n\t\t// flush them so the tail keeps the truncated final character. Both events,\n\t\t// because each can be the only one to precede the tail build: 'end' beats\n\t\t// 'exit' on natural EOF (whose 'close' emission can land after it), while\n\t\t// a drain-destroyed stream skips 'end'. The second end() returns \"\".\n\t\tchild.stderr?.once(\"end\", () => this.appendKernelStderrText(stderrDecoder.end()));\n\t\tchild.stderr?.once(\"close\", () => {\n\t\t\tthis.appendKernelStderrText(stderrDecoder.end());\n\t\t\tif (stderrLog === undefined) return;\n\t\t\ttry {\n\t\t\t\tcloseSync(stderrLog.fd);\n\t\t\t} catch (error) {\n\t\t\t\tthis.appendKernelDiagnostic(`kernel stderr log close failed: ${errorMessage(error)}`);\n\t\t\t}\n\t\t});\n\t\t// Pipe errors must not crash the worker. The pending writeLine rejection\n\t\t// and child exit handler own cleanup; only record the current child's diagnosis.\n\t\tchild.stdin?.on(\"error\", (error) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tthis.appendKernelDiagnostic(`kernel stdin error: ${errorMessage(error)}`);\n\t\t});\n\t\tchild.stdout?.on(\"error\", (error) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tthis.appendKernelDiagnostic(`kernel stdout error: ${errorMessage(error)}`);\n\t\t});\n\t\tchild.once(\"exit\", () => {\n\t\t\t// One turn for the poll phase to deliver the bytes the kernel wrote\n\t\t\t// before dying (the pipe buffer bounds them), then destroy: EOF may\n\t\t\t// never come, and anything later is a surviving grandchild's\n\t\t\t// post-mortem noise, not the kernel's last words.\n\t\t\tglobalThis.setImmediate(() => child.stderr?.destroy());\n\t\t});\n\n\t\tchild.on(\"error\", (err) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tthis.appendKernelDiagnostic(`spawn error: ${err.message}`);\n\t\t\tthis.state = \"shutdown\";\n\t\t\tliveKernels.delete(this);\n\t\t\t// Fail a pending start() promptly instead of letting it ride out the\n\t\t\t// ready timeout. cleanupResources clears readyDeferred, so reject first;\n\t\t\t// a late error after ready resolved is a no-op on the settled promise.\n\t\t\tthis.readyDeferred?.reject(err);\n\t\t\tthis.cleanupResources();\n\t\t});\n\n\t\tchild.on(\"exit\", (code, signal) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tif (this.state !== \"shutdown\") {\n\t\t\t\tthis.appendKernelDiagnostic(`unexpected exit code=${code} signal=${signal}`);\n\t\t\t}\n\t\t\tthis.state = \"shutdown\";\n\t\t\tliveKernels.delete(this);\n\t\t\t// This exit is part of an in-flight graceful shutdown(): that call owns the\n\t\t\t// teardown and runs cleanupResources itself. Cleaning up here would bump the\n\t\t\t// generation and misread the owning shutdown as superseded.\n\t\t\tif (this.gracefulShutdownGeneration === this.startGeneration) return;\n\t\t\tthis.cleanupResources();\n\t\t});\n\t}\n\n\tprivate failProtocolFrame(child: ChildProcess, diagnostic: string): void {\n\t\tif (this.child !== child) return;\n\t\tthis.appendKernelDiagnostic(diagnostic);\n\t\tconst error = new Error(`Kernel protocol error: ${diagnostic}`);\n\t\tif (this.state === \"starting\") this.startupProtocolError = error;\n\t\tthis.readyDeferred?.reject(error);\n\t\tthis.rejectActiveExecution(error);\n\t\tif (this.teardownInFlight > 0 || this.state !== \"running\") return;\n\n\t\tif (this.protocolRepairOwner) {\n\t\t\t// A repair's own replacement child corrupted: discard it instead of respawn-looping.\n\t\t\tthis.appendKernelDiagnostic(\"replacement kernel corrupted during protocol repair; giving up\");\n\t\t\tthis.protocolRepairOwner.superseded = true;\n\t\t\t// performRestore clears pendingRestore, so it still being set means the\n\t\t\t// corruption struck at or before the restore phase: the snapshot stays\n\t\t\t// the prime suspect (ambiguous attribution, loop-safe — retrying it\n\t\t\t// would re-trigger the corruption). Corruption strictly after a\n\t\t\t// successful restore never implicates the snapshot; keeping the flag\n\t\t\t// costs at most one bounded restore per later attempt.\n\t\t\tconst snapshotSuspect = this.pendingRestore;\n\t\t\tthis.killChildToIdle();\n\t\t\tif (snapshotSuspect) this.pendingRestore = false;\n\t\t\treturn;\n\t\t}\n\t\tconst owner = { superseded: false };\n\t\tthis.protocolRepairOwner = owner;\n\t\tconst repair = this.repairProtocolChild(child, owner);\n\t\tthis.protocolRepairPromise = repair;\n\t\tvoid repair.then(\n\t\t\t() => {\n\t\t\t\tif (this.protocolRepairPromise === repair) this.protocolRepairPromise = undefined;\n\t\t\t\tif (this.protocolRepairOwner === owner) this.protocolRepairOwner = undefined;\n\t\t\t},\n\t\t\t(repairError) => {\n\t\t\t\tthis.appendKernelDiagnostic(`protocol repair failed: ${errorMessage(repairError)}`);\n\t\t\t\tif (this.protocolRepairPromise === repair) this.protocolRepairPromise = undefined;\n\t\t\t\tif (this.protocolRepairOwner === owner) this.protocolRepairOwner = undefined;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async repairProtocolChild(child: ChildProcess, owner: { superseded: boolean }): Promise<void> {\n\t\tif (this.child !== child || this.state === \"shutdown\") return;\n\t\tthis.killChildToIdle();\n\n\t\tconst start = this.start();\n\t\tconst generation = this.startGeneration;\n\t\ttry {\n\t\t\tawait start;\n\t\t} catch (error) {\n\t\t\tthis.finishFailedProtocolRepair(owner, error);\n\t\t\treturn;\n\t\t}\n\t\tif (this.startStale(generation) || (this.state as string) !== \"running\") {\n\t\t\tthis.finishFailedProtocolRepair(owner);\n\t\t\treturn;\n\t\t}\n\n\t\tconst restored = await this.performRestore(true);\n\t\tif (this.startStale(generation) || (this.state as string) !== \"running\") {\n\t\t\tthis.finishFailedProtocolRepair(owner);\n\t\t\treturn;\n\t\t}\n\t\tif (this.options.snapshot && restored === null) {\n\t\t\tif (owner.superseded || this.protocolRepairOwner !== owner) return;\n\t\t\tthis.appendKernelDiagnostic(\"protocol repair restore failed; discarding replacement kernel\");\n\t\t\tthis.killChildToIdle();\n\t\t\t// The snapshot is the declared culprit; the lazy path must not retry it.\n\t\t\tthis.pendingRestore = false;\n\t\t\treturn;\n\t\t}\n\n\t\t// Restore revives only the user namespace; live handles (rlm, bash, skills)\n\t\t// come from the runtime bootstrap, so a repaired kernel must re-run it.\n\t\tif (!this.options.bootstrapCode) return;\n\t\tconst bootstrapped = await this.bootstrapRepairedKernel(this.options.bootstrapCode);\n\t\tif (this.startStale(generation) || (this.state as string) !== \"running\") {\n\t\t\tthis.finishFailedProtocolRepair(owner);\n\t\t\treturn;\n\t\t}\n\t\tif (!bootstrapped) {\n\t\t\tif (owner.superseded || this.protocolRepairOwner !== owner) return;\n\t\t\tthis.appendKernelDiagnostic(\"protocol repair bootstrap failed; discarding replacement kernel\");\n\t\t\tthis.killChildToIdle();\n\t\t}\n\t}\n\n\t/** Bounded bootstrap of a repaired kernel; false when it failed. Never throws. */\n\tprivate async bootstrapRepairedKernel(code: string): Promise<boolean> {\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{ type: \"execute\", code },\n\t\t\t\tcode,\n\t\t\t\t{ internal: true, protocolRepair: true },\n\t\t\t\tREPAIR_STEP_TIMEOUT_MS,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\") {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`protocol repair bootstrap ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.pendingRebootstrap = false;\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`protocol repair bootstrap error: ${errorMessage(error)}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * A fresh kernel started after a discarded repair has none of the runtime\n\t * bootstrap's live handles (rlm, bash, skills) and an empty namespace:\n\t * reprovision (restore, then bootstrap) before any user request. A failed\n\t * re-bootstrap discards the kernel again instead of serving user code on an\n\t * unprovisioned namespace.\n\t */\n\tprivate async ensureKernelRebootstrapped(signal?: AbortSignal): Promise<void> {\n\t\tconst code = this.options.bootstrapCode;\n\t\tconst needsRestore = Boolean(this.options.snapshot) && this.pendingRestore;\n\t\tconst needsBootstrap = Boolean(code) && this.pendingRebootstrap;\n\t\t// An in-flight repair owns its kernel's restore/bootstrap sequence, and\n\t\t// a teardown's final snapshot must never trigger reprovisioning.\n\t\tif (\n\t\t\t(!needsRestore && !needsBootstrap) ||\n\t\t\tthis.protocolRepairPromise ||\n\t\t\tthis.teardownInFlight > 0 ||\n\t\t\tthis.state !== \"running\"\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tlet task = this.rebootstrapPromise;\n\t\tif (!task) {\n\t\t\tconst started = this.reprovisionFreshKernel(code);\n\t\t\ttask = started;\n\t\t\tthis.rebootstrapPromise = started;\n\t\t\tvoid started.finally(() => {\n\t\t\t\tif (this.rebootstrapPromise === started) this.rebootstrapPromise = undefined;\n\t\t\t});\n\t\t}\n\t\t// An aborted request never executes, so it may skip the wait; race the\n\t\t// signal like waitForProtocolRepair does instead of riding out the\n\t\t// bootstrap bound after a mid-wait abort.\n\t\tif (signal) {\n\t\t\tif (signal.aborted) return;\n\t\t\tlet onAbort: () => void = () => {};\n\t\t\tconst aborted = new Promise<void>((resolve) => {\n\t\t\t\tonAbort = resolve;\n\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tawait Promise.race([task, aborted]);\n\t\t\t} finally {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t\tif (signal.aborted) return;\n\t\t}\n\t\tconst ok = await task; // bounded by REPAIR_STEP_TIMEOUT_MS\n\t\tif (!ok) throw new Error(\"Kernel bootstrap failed after protocol repair\");\n\t}\n\n\t/** Restore (one-shot, best-effort) then bootstrap the lazily started fresh kernel. */\n\tprivate async reprovisionFreshKernel(code: string | undefined): Promise<boolean> {\n\t\tif (this.options.snapshot && this.pendingRestore) {\n\t\t\tawait this.performRestore(true); // clears pendingRestore on success\n\t\t\t// Corrupted during the restore: the spawned repair owns the kernel now.\n\t\t\tif (this.protocolRepairPromise || this.state !== \"running\") return false;\n\t\t\t// One attempt per discard: a clean restore failure falls back to an\n\t\t\t// empty namespace (ordinary startup semantics), never a retry loop.\n\t\t\tthis.pendingRestore = false;\n\t\t}\n\t\tif (!code || !this.pendingRebootstrap) return true;\n\t\tconst ok = await this.bootstrapRepairedKernel(code);\n\t\tif (!ok && this.state === \"running\") this.killChildToIdle();\n\t\treturn ok;\n\t}\n\n\t/** Kill the current child and settle at clean idle, so the next start spawns fresh. */\n\tprivate killChildToIdle(): void {\n\t\t// The discarded kernel carried the runtime bootstrap and (possibly) the\n\t\t// restored namespace; a lazily started replacement must reprovision both.\n\t\tthis.pendingRebootstrap = true;\n\t\tthis.pendingRestore = true;\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources(\"SIGKILL\");\n\t\tthis.state = \"idle\";\n\t}\n\n\tprivate finishFailedProtocolRepair(owner: { superseded: boolean }, error?: unknown): void {\n\t\tif (error) this.appendKernelDiagnostic(`protocol repair start failed: ${errorMessage(error)}`);\n\t\tif (owner.superseded || this.protocolRepairOwner !== owner) return;\n\t\tif (this.state === \"shutdown\") this.state = \"idle\";\n\t}\n\n\tprivate supersedeProtocolRepair(): void {\n\t\tif (this.protocolRepairOwner) this.protocolRepairOwner.superseded = true;\n\t}\n\n\t/** Wait until no protocol repair is pending; resolves early when the signal aborts. */\n\tprivate async waitForProtocolRepair(signal?: AbortSignal): Promise<void> {\n\t\twhile (this.protocolRepairPromise && !signal?.aborted) {\n\t\t\tconst repair = this.protocolRepairPromise;\n\t\t\tif (!signal) {\n\t\t\t\tawait repair;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet onAbort: () => void = () => {};\n\t\t\tconst aborted = new Promise<void>((resolve) => {\n\t\t\t\tonAbort = resolve;\n\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tawait Promise.race([repair, aborted]);\n\t\t\t} finally {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async waitForReady(child: ChildProcess): Promise<number> {\n\t\tconst ready = this.readyDeferred;\n\t\tif (!ready) throw new Error(\"Kernel ready state is missing\");\n\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tlet onExit: (() => void) | undefined;\n\t\ttry {\n\t\t\treturn await new Promise<number>((resolve, reject) => {\n\t\t\t\tready.promise.then(resolve, reject);\n\t\t\t\tonExit = () => {\n\t\t\t\t\tconst finish = () => {\n\t\t\t\t\t\tconst tail = this.kernelStderr.slice(-1024);\n\t\t\t\t\t\treject(new Error(`Kernel exited before ready. stderr:\\n${tail || \"(empty)\"}`));\n\t\t\t\t\t};\n\t\t\t\t\t// The final stderr chunks can still be in flight at 'exit'; wait for\n\t\t\t\t\t// the drained pipe so the tail includes the kernel's last words (the\n\t\t\t\t\t// ready timeout stays armed, bounding the wait).\n\t\t\t\t\tconst stderr = child.stderr;\n\t\t\t\t\tif (!stderr || stderr.closed) finish();\n\t\t\t\t\telse stderr.once(\"close\", finish);\n\t\t\t\t};\n\t\t\t\tif (child.exitCode !== null || child.signalCode !== null) {\n\t\t\t\t\tonExit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tchild.once(\"exit\", onExit);\n\t\t\t\ttimeout = globalThis.setTimeout(() => {\n\t\t\t\t\tconst tail = this.kernelStderr.slice(-1024);\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Kernel did not become ready within ${READY_TIMEOUT_MS}ms. stderr tail:\\n${tail || \"(empty)\"}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}, READY_TIMEOUT_MS);\n\t\t\t\ttimeout.unref?.();\n\t\t\t});\n\t\t} finally {\n\t\t\tif (timeout) globalThis.clearTimeout(timeout);\n\t\t\tif (onExit) child.removeListener(\"exit\", onExit);\n\t\t}\n\t}\n\n\t/** Write one JSON-lines request frame; resolves when the OS accepted the bytes. */\n\tprivate writeLine(request: Record<string, unknown>): Promise<void> {\n\t\tconst stdin = this.child?.stdin;\n\t\tif (!stdin || stdin.destroyed) {\n\t\t\treturn Promise.reject(new Error(\"Kernel stdin is not connected\"));\n\t\t}\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tstdin.write(`${JSON.stringify(request)}\\n`, (error) => {\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolve();\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate handleEvent(event: Record<string, unknown>): void {\n\t\tconst type = event.event;\n\t\tif (type === \"ready\") {\n\t\t\tthis.pythonVersion = typeof event.python === \"string\" ? event.python : undefined;\n\t\t\tthis.readyDeferred?.resolve(typeof event.protocol === \"number\" ? event.protocol : -1);\n\t\t\treturn;\n\t\t}\n\t\tif (type === \"host_request\") {\n\t\t\tif (typeof event.id === \"string\") this.startHostRequest(event.id, event.data, event.cellId);\n\t\t\treturn;\n\t\t}\n\n\t\tconst id = typeof event.id === \"string\" ? event.id : undefined;\n\t\tconst execution = this.activeExecution;\n\t\tif (!execution || id !== execution.requestId) {\n\t\t\tif (type === \"display\" && isRecord(event.data)) {\n\t\t\t\tthis.dispatchLateSentAgentMessage(id, event.data[AGENT_MESSAGE_DISPLAY_MIME]);\n\t\t\t} else if (type === \"stdout\" || type === \"stderr\") {\n\t\t\t\t// Unowned output (null id, or another cell's id): never merge it into\n\t\t\t\t// the active cell's streams; buffer it as background output instead.\n\t\t\t\tthis.appendBackgroundOutput(typeof event.text === \"string\" ? event.text : \"\");\n\t\t\t} else if (type === \"done\" && id) {\n\t\t\t\tconst waiter = this.pendingDoneWaiters.get(id);\n\t\t\t\tthis.pendingDoneWaiters.delete(id);\n\t\t\t\twaiter?.();\n\t\t\t} else if (type === \"error\" && id === undefined) {\n\t\t\t\tthis.appendKernelDiagnostic(`protocol error: ${String(event.evalue ?? \"\")}`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (execution.settled && type === \"display\" && isRecord(event.data)) {\n\t\t\tif (this.dispatchLateSentAgentMessage(id, event.data[AGENT_MESSAGE_DISPLAY_MIME])) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (type === \"stdout\" || type === \"stderr\") {\n\t\t\tconst text = typeof event.text === \"string\" ? event.text : \"\";\n\t\t\tif (type === \"stdout\") {\n\t\t\t\tif (execution.stdout.length < execution.maxChars) {\n\t\t\t\t\texecution.stdout += text;\n\t\t\t\t\tif (execution.stdout.length > execution.maxChars) {\n\t\t\t\t\t\texecution.stdout = execution.stdout.slice(0, execution.maxChars);\n\t\t\t\t\t\texecution.stdoutTruncated = true;\n\t\t\t\t\t}\n\t\t\t\t} else if (text.length > 0) {\n\t\t\t\t\texecution.stdoutTruncated = true;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (execution.stderr.length < execution.maxChars) {\n\t\t\t\t\texecution.stderr += text;\n\t\t\t\t\tif (execution.stderr.length > execution.maxChars) {\n\t\t\t\t\t\texecution.stderr = execution.stderr.slice(0, execution.maxChars);\n\t\t\t\t\t\texecution.stderrTruncated = true;\n\t\t\t\t\t}\n\t\t\t\t} else if (text.length > 0) {\n\t\t\t\t\texecution.stderrTruncated = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\texecution.opts.onStream?.(text, type);\n\t\t} else if (type === \"result\") {\n\t\t\tif (typeof event.text === \"string\") execution.result = event.text;\n\t\t} else if (type === \"display\") {\n\t\t\tconst data = isRecord(event.data) ? event.data : {};\n\t\t\tconst diff = parseDiffDisplay(data[DIFF_DISPLAY_MIME]);\n\t\t\tif (diff) execution.diffs.push(diff);\n\t\t\tconst attachment = parseAttachmentDisplay(data[ATTACHMENT_DISPLAY_MIME]);\n\t\t\tif (attachment === \"oversized\") {\n\t\t\t\texecution.stderr += `${execution.stderr ? \"\\n\" : \"\"}attachment dropped: exceeds ${MAX_ATTACHMENT_DATA_CHARS} base64 chars`;\n\t\t\t\texecution.status = \"error\";\n\t\t\t} else if (attachment) {\n\t\t\t\texecution.attachments.push(attachment);\n\t\t\t}\n\t\t\tconst sentAgentMessage = parseSentAgentMessage(data[AGENT_MESSAGE_DISPLAY_MIME]);\n\t\t\tif (sentAgentMessage) execution.sentAgentMessages.push(sentAgentMessage);\n\t\t} else if (type === \"error\") {\n\t\t\texecution.error = {\n\t\t\t\tename: typeof event.ename === \"string\" ? event.ename : \"Error\",\n\t\t\t\tevalue: typeof event.evalue === \"string\" ? event.evalue : \"\",\n\t\t\t\ttraceback: asStringArray(event.traceback),\n\t\t\t};\n\t\t\texecution.status = \"error\";\n\t\t} else if (type === \"done\") {\n\t\t\texecution.doneFields = event;\n\t\t\tif (event.status !== \"ok\" && execution.status === \"ok\") {\n\t\t\t\texecution.status = \"error\";\n\t\t\t\t// State requests report failures as a done reason without an error event.\n\t\t\t\tif (!execution.error && typeof event.reason === \"string\") {\n\t\t\t\t\texecution.error = { ename: \"KernelError\", evalue: event.reason, traceback: [] };\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.finishActiveExecution(execution);\n\t\t}\n\t}\n\n\tasync execute(code: string, opts: ExecuteOptions = {}): Promise<ExecuteResult> {\n\t\tawait this.waitForProtocolRepair(opts.signal);\n\t\tconst result = await this.enqueueExecute(code, opts);\n\t\t// Refresh the on-disk snapshot after real work so a later resume (or a\n\t\t// crash before graceful shutdown) revives the most recent namespace.\n\t\tif (result.status === \"ok\") {\n\t\t\tthis.scheduleSnapshot();\n\t\t}\n\t\treturn result;\n\t}\n\n\t/** Queue and run a cell, serializing against all other executions. */\n\tprivate async enqueueExecute(\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\texecutionTimeoutMs?: number,\n\t): Promise<InternalExecuteResult> {\n\t\treturn this.enqueueRequest({ type: \"execute\", code }, code, opts, executionTimeoutMs);\n\t}\n\n\t/** Queue one protocol request (execute or state op) behind every other request. */\n\tprivate async enqueueRequest(\n\t\trequestFields: Record<string, unknown> & { type: string },\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\texecutionTimeoutMs?: number,\n\t): Promise<InternalExecuteResult> {\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: 0 };\n\t\t}\n\t\tawait this.start({ signal: opts.signal });\n\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t}\n\t\tif (this.flushingSnapshotForDispose && !opts.internal) {\n\t\t\tthrow new Error(\"Kernel is shutting down\");\n\t\t}\n\t\tif (!opts.protocolRepair) await this.ensureKernelRebootstrapped(opts.signal);\n\t\t// Aborted while waiting on the re-bootstrap: settle now instead of parking\n\t\t// on the queue slot behind the still-running bootstrap.\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: 0 };\n\t\t}\n\t\t// Re-check: a final flush may have started while this request awaited the\n\t\t// lazy re-bootstrap; admitting it now would splice it between the flush's\n\t\t// captured queue and the final snapshot, unbounding the teardown.\n\t\tif (this.flushingSnapshotForDispose && !opts.internal) {\n\t\t\tthrow new Error(\"Kernel is shutting down\");\n\t\t}\n\n\t\tconst prev = this.executionQueue;\n\t\tlet resolveNext: () => void = () => {};\n\t\tthis.executionQueue = new Promise<void>((r) => {\n\t\t\tresolveNext = r;\n\t\t});\n\t\tawait prev;\n\n\t\tconst started = Date.now();\n\t\tlet executionTimeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\ttry {\n\t\t\tawait this.waitForActiveExecutionToClearForReuse(opts.signal);\n\t\t\tif (opts.signal?.aborted) {\n\t\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: Date.now() - started };\n\t\t\t}\n\t\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t\t}\n\t\t\t// A repair started while this request was queued or busy-waiting: release\n\t\t\t// the slot so the repair's own restore can run, then requeue behind it.\n\t\t\tif (this.protocolRepairPromise && !opts.protocolRepair) {\n\t\t\t\tresolveNext();\n\t\t\t\tawait this.waitForProtocolRepair(opts.signal);\n\t\t\t\treturn this.enqueueRequest(requestFields, code, opts, executionTimeoutMs);\n\t\t\t}\n\t\t\tif (executionTimeoutMs === undefined) {\n\t\t\t\treturn await this.executeInner(requestFields, code, opts, started);\n\t\t\t}\n\n\t\t\tconst controller = new AbortController();\n\t\t\texecutionTimeout = globalThis.setTimeout(() => controller.abort(), executionTimeoutMs);\n\t\t\texecutionTimeout.unref?.();\n\t\t\tconst signal = opts.signal ? AbortSignal.any([opts.signal, controller.signal]) : controller.signal;\n\t\t\treturn await this.executeInner(requestFields, code, { ...opts, signal }, started);\n\t\t} finally {\n\t\t\tif (executionTimeout) globalThis.clearTimeout(executionTimeout);\n\t\t\tresolveNext();\n\t\t}\n\t}\n\n\tprivate async executeInner(\n\t\trequestFields: Record<string, unknown> & { type: string },\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\tstarted: number,\n\t): Promise<InternalExecuteResult> {\n\t\tconst maxChars = opts.maxOutputChars ?? DEFAULT_MAX_OUTPUT_CHARS;\n\t\tconst requestId = uuid();\n\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: Date.now() - started };\n\t\t}\n\t\tif (this.activeExecution) {\n\t\t\tthrow new Error(\"Kernel already has an active execution\");\n\t\t}\n\n\t\tconst result = createDeferred<InternalExecuteResult>();\n\t\tconst execution: ActiveExecution = {\n\t\t\trequestId,\n\t\t\tcode,\n\t\t\tstarted,\n\t\t\tmaxChars,\n\t\t\topts,\n\t\t\tstdout: \"\",\n\t\t\tstderr: \"\",\n\t\t\tstdoutTruncated: false,\n\t\t\tstderrTruncated: false,\n\t\t\tdiffs: [],\n\t\t\tattachments: [],\n\t\t\tsentAgentMessages: [],\n\t\t\tnativeRecoveries: [],\n\t\t\tnativeRecoveryBytes: 2, // JSON array brackets; reserve one delimiter per admitted response.\n\t\t\tnativeRecoveryRequests: 0,\n\t\t\tnativeRecoveryAbort: new AbortController(),\n\t\t\tbackgroundOutput: this.pendingBackgroundOutput,\n\t\t\tbackgroundOutputTruncated: this.pendingBackgroundOutputTruncated,\n\t\t\tstatus: \"ok\",\n\t\t\tsettled: false,\n\t\t\tresolve: result.resolve,\n\t\t\treject: result.reject,\n\t\t};\n\t\tthis.pendingBackgroundOutput = \"\";\n\t\tthis.pendingBackgroundOutputTruncated = false;\n\t\tlet abortTimer: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tconst clearAbortTimer = () => {\n\t\t\tif (abortTimer) {\n\t\t\t\tglobalThis.clearTimeout(abortTimer);\n\t\t\t\tabortTimer = undefined;\n\t\t\t}\n\t\t};\n\t\tconst forceAbort = () => {\n\t\t\tif (this.activeExecution !== execution) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\texecution.status = \"aborted\";\n\t\t\t// The execution stays active until its done event arrives; clearing it\n\t\t\t// early would let a new cell race the interrupted one (see busy-after-interrupt).\n\t\t\tthis.resolveExecution(execution, { clearActive: false });\n\t\t};\n\t\tconst onAbort = () => {\n\t\t\texecution.nativeRecoveryAbort.abort();\n\t\t\tvoid this.interrupt().catch(() => undefined);\n\t\t\tclearAbortTimer();\n\t\t\tabortTimer = globalThis.setTimeout(forceAbort, KERNEL_ABORT_GRACE_MS);\n\t\t\tif (abortTimer && typeof abortTimer === \"object\" && \"unref\" in abortTimer) {\n\t\t\t\tabortTimer.unref();\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tthis.activeExecution = execution;\n\t\t\topts.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tif (opts.signal?.aborted) {\n\t\t\t\tonAbort();\n\t\t\t}\n\t\t\tif (!opts.internal) {\n\t\t\t\tthis.lastCellCode = code;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst sendPromise = this.writeLine({ ...requestFields, id: requestId });\n\t\t\t\tsendPromise.catch(() => undefined);\n\t\t\t\tawait Promise.race([sendPromise, result.promise.then(() => undefined)]);\n\t\t\t\tif (this.activeExecution === execution && execution.status !== \"aborted\") {\n\t\t\t\t\tawait sendPromise;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (this.activeExecution === execution) {\n\t\t\t\t\tthis.activeExecution = undefined;\n\t\t\t\t}\n\t\t\t\tthrow error instanceof Error ? error : new Error(String(error));\n\t\t\t}\n\t\t\treturn await result.promise;\n\t\t} finally {\n\t\t\tclearAbortTimer();\n\t\t\topts.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\texecution.nativeRecoveryAbort.abort();\n\t\t}\n\t}\n\n\tprivate appendBackgroundOutput(text: string): void {\n\t\tif (!text) return;\n\t\tconst execution = this.activeExecution;\n\t\tif (execution) {\n\t\t\tif (execution.backgroundOutput.length >= MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\t\texecution.backgroundOutputTruncated = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\texecution.backgroundOutput += text;\n\t\t\tif (execution.backgroundOutput.length > MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\t\texecution.backgroundOutput = execution.backgroundOutput.slice(0, MAX_BACKGROUND_OUTPUT_CHARS);\n\t\t\t\texecution.backgroundOutputTruncated = true;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (this.pendingBackgroundOutput.length >= MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\tthis.pendingBackgroundOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.pendingBackgroundOutput += text;\n\t\tif (this.pendingBackgroundOutput.length > MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\tthis.pendingBackgroundOutput = this.pendingBackgroundOutput.slice(0, MAX_BACKGROUND_OUTPUT_CHARS);\n\t\t\tthis.pendingBackgroundOutputTruncated = true;\n\t\t}\n\t}\n\n\tprivate finishActiveExecution(execution: ActiveExecution): void {\n\t\tif (this.activeExecution !== execution) {\n\t\t\treturn;\n\t\t}\n\t\tthis.resolveExecution(execution, { clearActive: true });\n\t}\n\n\tprivate resolveExecution(execution: ActiveExecution, options: { clearActive: boolean }): void {\n\t\tconst didClearActive = options.clearActive && this.activeExecution === execution;\n\t\tif (options.clearActive && this.activeExecution === execution) {\n\t\t\tthis.activeExecution = undefined;\n\t\t}\n\t\tif (!execution.settled) {\n\t\t\texecution.settled = true;\n\t\t\texecution.nativeRecoveryAbort.abort();\n\t\t\tif (execution.opts.onLateSentAgentMessage) {\n\t\t\t\tthis.registerLateSentAgentMessageHandler(execution.requestId, execution.opts.onLateSentAgentMessage);\n\t\t\t}\n\n\t\t\tlet stdout = execution.stdout;\n\t\t\tlet stderr = execution.stderr;\n\t\t\tlet result = execution.result;\n\t\t\tlet status = execution.status;\n\t\t\tif (execution.stdoutTruncated) stdout += `\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\tif (execution.stderrTruncated) stderr += `\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\tif (result !== undefined && result.length > execution.maxChars) {\n\t\t\t\tresult = `${result.slice(0, execution.maxChars)}\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\t}\n\n\t\t\tif (execution.opts.signal?.aborted) status = \"aborted\";\n\n\t\t\tlet backgroundOutput = execution.backgroundOutput;\n\t\t\tif (execution.backgroundOutputTruncated) {\n\t\t\t\tbackgroundOutput += `\\n[... background output truncated at ${MAX_BACKGROUND_OUTPUT_CHARS} chars ...]`;\n\t\t\t}\n\n\t\t\texecution.resolve({\n\t\t\t\toutputComplete:\n\t\t\t\t\tstatus !== \"aborted\" &&\n\t\t\t\t\t!execution.stdoutTruncated &&\n\t\t\t\t\t!execution.stderrTruncated &&\n\t\t\t\t\t!execution.backgroundOutputTruncated &&\n\t\t\t\t\t(execution.result?.length ?? 0) <= execution.maxChars,\n\t\t\t\tstdout,\n\t\t\t\tstderr,\n\t\t\t\tresult,\n\t\t\t\tdiffs: execution.diffs.length > 0 ? execution.diffs : undefined,\n\t\t\t\tattachments: execution.attachments.length > 0 ? execution.attachments : undefined,\n\t\t\t\tsentAgentMessages: execution.sentAgentMessages.length > 0 ? execution.sentAgentMessages : undefined,\n\t\t\t\tnativeRecoveries: execution.nativeRecoveries.length > 0 ? execution.nativeRecoveries : undefined,\n\t\t\t\tbackgroundOutput: backgroundOutput.length > 0 ? backgroundOutput : undefined,\n\t\t\t\terror: execution.error,\n\t\t\t\tstatus,\n\t\t\t\tdurationMs: Date.now() - execution.started,\n\t\t\t\tdoneFields: execution.doneFields,\n\t\t\t});\n\t\t\texecution.nativeRecoveries = [];\n\t\t}\n\t\tif (didClearActive) {\n\t\t\tthis.notifyActiveExecutionIdle();\n\t\t}\n\t}\n\n\tprivate dispatchLateSentAgentMessage(requestId: string | undefined, value: unknown): boolean {\n\t\tconst sentAgentMessage = parseSentAgentMessage(value);\n\t\tif (!sentAgentMessage || !requestId) {\n\t\t\treturn false;\n\t\t}\n\t\tconst handler = this.lateSentAgentMessageHandlers.get(requestId);\n\t\tif (!handler) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.lateSentAgentMessageHandlers.delete(requestId);\n\t\tthis.lateSentAgentMessageHandlers.set(requestId, handler);\n\t\thandler(sentAgentMessage);\n\t\treturn true;\n\t}\n\n\tprivate registerLateSentAgentMessageHandler(\n\t\trequestId: string,\n\t\thandler: (message: KernelSentAgentMessage) => void,\n\t): void {\n\t\tthis.lateSentAgentMessageHandlers.set(requestId, handler);\n\t\twhile (this.lateSentAgentMessageHandlers.size > MAX_LATE_SENT_AGENT_MESSAGE_HANDLERS) {\n\t\t\tconst oldestRequestId = this.lateSentAgentMessageHandlers.keys().next().value;\n\t\t\tif (oldestRequestId === undefined) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.lateSentAgentMessageHandlers.delete(oldestRequestId);\n\t\t}\n\t}\n\n\tprivate rejectActiveExecution(error: Error): void {\n\t\tconst execution = this.activeExecution;\n\t\tif (!execution) {\n\t\t\treturn;\n\t\t}\n\t\tthis.activeExecution = undefined;\n\t\texecution.nativeRecoveryAbort.abort();\n\t\texecution.nativeRecoveries = [];\n\t\texecution.reject(error);\n\t\tthis.notifyActiveExecutionIdle();\n\t}\n\n\tprivate notifyActiveExecutionIdle(): void {\n\t\tfor (const resolve of this.activeExecutionIdleWaiters) {\n\t\t\tresolve();\n\t\t}\n\t\tthis.activeExecutionIdleWaiters.clear();\n\t}\n\n\tprivate waitForActiveExecutionToClear(signal: AbortSignal | undefined, timeoutMs: number): Promise<boolean> {\n\t\tif (!this.activeExecution) {\n\t\t\treturn Promise.resolve(true);\n\t\t}\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\t\tconst finish = (cleared: boolean) => {\n\t\t\t\tif (settled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsettled = true;\n\t\t\t\tif (timeout) {\n\t\t\t\t\tglobalThis.clearTimeout(timeout);\n\t\t\t\t}\n\t\t\t\tthis.activeExecutionIdleWaiters.delete(onIdle);\n\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(cleared);\n\t\t\t};\n\t\t\tconst onIdle = () => finish(true);\n\t\t\tconst onAbort = () => finish(false);\n\t\t\tthis.activeExecutionIdleWaiters.add(onIdle);\n\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\ttimeout = globalThis.setTimeout(() => finish(false), timeoutMs);\n\t\t\tif (timeout && typeof timeout === \"object\" && \"unref\" in timeout) {\n\t\t\t\ttimeout.unref();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async waitForActiveExecutionToClearForReuse(signal?: AbortSignal): Promise<void> {\n\t\tconst started = Date.now();\n\t\twhile (this.activeExecution && Date.now() - started < KERNEL_BUSY_REUSE_WAIT_MS) {\n\t\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t\t}\n\t\t\tvoid this.interrupt().catch(() => undefined);\n\t\t\tconst remaining = KERNEL_BUSY_REUSE_WAIT_MS - (Date.now() - started);\n\t\t\tconst cleared = await this.waitForActiveExecutionToClear(\n\t\t\t\tsignal,\n\t\t\t\tMath.max(1, Math.min(KERNEL_BUSY_INTERRUPT_INTERVAL_MS, remaining)),\n\t\t\t);\n\t\t\tif (cleared || signal?.aborted) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (this.activeExecution) {\n\t\t\tthrow new KernelBusyAfterInterruptError();\n\t\t}\n\t}\n\n\tprivate startHostRequest(requestId: string, data: unknown, cellId: unknown): void {\n\t\tif (this.handledHostRequestIds.has(requestId)) {\n\t\t\treturn;\n\t\t}\n\t\tthis.handledHostRequestIds.add(requestId);\n\t\twhile (this.handledHostRequestIds.size > MAX_HANDLED_HOST_REQUEST_IDS) {\n\t\t\tconst oldest = this.handledHostRequestIds.values().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\tthis.handledHostRequestIds.delete(oldest);\n\t\t}\n\n\t\tconst task = (async () => {\n\t\t\ttry {\n\t\t\t\tconst result = await this.handleHostRequest(data, cellId);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.writeLine({ type: \"host_reply\", id: requestId, data: { status: \"ok\", result } });\n\t\t\t\t} catch (replyError) {\n\t\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t\t`failed to send host request ok reply for ${requestId}: ${errorMessage(replyError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.appendKernelDiagnostic(`host request failed for ${requestId}: ${errorMessage(error)}`);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.writeLine({\n\t\t\t\t\t\ttype: \"host_reply\",\n\t\t\t\t\t\tid: requestId,\n\t\t\t\t\t\tdata: { status: \"error\", error: errorMessage(error) },\n\t\t\t\t\t});\n\t\t\t\t} catch (replyError) {\n\t\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t\t`failed to send host request error reply for ${requestId}: ${errorMessage(replyError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t})();\n\t\tthis.inFlightHostRequests.add(task);\n\t\tvoid task.finally(() => {\n\t\t\tthis.inFlightHostRequests.delete(task);\n\t\t});\n\t}\n\n\tprivate async handleHostRequest(data: unknown, cellId: unknown): Promise<Record<string, unknown>> {\n\t\tif (!isRecord(data)) {\n\t\t\tthrow new Error(\"host request payload must be an object\");\n\t\t}\n\t\tif (typeof data.type !== \"string\" || data.type.length === 0) {\n\t\t\tthrow new Error(\"host request payload must have a string type\");\n\t\t}\n\n\t\tconst handler = this.options.hostHandlers?.[data.type];\n\t\tif (!handler) {\n\t\t\tthrow new Error(`host request type \"${data.type}\" is not available in this session`);\n\t\t}\n\t\tif (data.type === \"prime_context\") {\n\t\t\tconst execution = this.activeExecution;\n\t\t\t// Only the transport's current cell may own an attachment. No last-cell fallback.\n\t\t\tif (\n\t\t\t\t!execution ||\n\t\t\t\texecution.settled ||\n\t\t\t\texecution.opts.internal ||\n\t\t\t\t!execution.opts.nativeRecovery ||\n\t\t\t\tcellId !== execution.requestId ||\n\t\t\t\texecution.nativeRecoveryAbort.signal.aborted\n\t\t\t) {\n\t\t\t\treturn { ...createNativeRecoveryRefusal(\"not_authorized\", \"active_cell_required\") };\n\t\t\t}\n\t\t\tconst maxBytes = DEFAULT_NATIVE_RECOVERY_LIMITS.maxBytes - execution.nativeRecoveryBytes - 1;\n\t\t\tif (execution.nativeRecoveryRequests >= DEFAULT_NATIVE_RECOVERY_LIMITS.maxRequests || maxBytes <= 0) {\n\t\t\t\tthrow new NativeRecoveryBudgetRefusal();\n\t\t\t}\n\t\t\t// Reserve before invoking the handler: concurrent requests cannot grow past the cell cap.\n\t\t\texecution.nativeRecoveryRequests++;\n\t\t\texecution.nativeRecoveryBytes += maxBytes + 1;\n\t\t\tlet reserved = maxBytes + 1;\n\t\t\ttry {\n\t\t\t\tconst read = async () =>\n\t\t\t\t\thandler(data, {\n\t\t\t\t\t\tsignal: execution.nativeRecoveryAbort.signal,\n\t\t\t\t\t\tnativeRecovery: { maxBytes },\n\t\t\t\t\t});\n\t\t\t\tconst response = (await (execution.opts.runNativeRecovery\n\t\t\t\t\t? execution.opts.runNativeRecovery(read)\n\t\t\t\t\t: read())) as unknown as NativeRecoveryResponse;\n\t\t\t\texecution.nativeRecoveryAbort.signal.throwIfAborted();\n\t\t\t\tif (this.activeExecution !== execution || execution.settled) {\n\t\t\t\t\tthrow new Error(\"Native recovery cell has finalized\");\n\t\t\t\t}\n\t\t\t\tconst encoded = stringifyNativeRecoveryResponse(response, maxBytes);\n\t\t\t\tconst admittedBytes = Buffer.byteLength(encoded) + 1;\n\t\t\t\texecution.nativeRecoveryBytes -= reserved - admittedBytes;\n\t\t\t\treserved = 0;\n\t\t\t\tconst admitted = JSON.parse(encoded) as NativeRecoveryResponse;\n\t\t\t\texecution.nativeRecoveries.push(admitted);\n\t\t\t\treturn { ...admitted };\n\t\t\t} finally {\n\t\t\t\texecution.nativeRecoveryBytes -= reserved;\n\t\t\t}\n\t\t}\n\t\t// Tag the request with the cell that triggered it. A blocking call is still\n\t\t// the in-flight execution; detached spawns (asyncio.create_task) fire after\n\t\t// the scheduling cell goes idle, so fall back to that last cell's source.\n\t\tconst cellSourceCode = this.activeExecution?.code ?? this.lastCellCode;\n\t\treturn handler({ ...data, cellSourceCode });\n\t}\n\n\tprivate async interrupt(): Promise<void> {\n\t\tconst requestId = this.activeExecution?.requestId;\n\t\tif (!requestId) return;\n\t\tawait this.writeLine({ type: \"interrupt\", id: requestId });\n\t}\n\n\tprivate cleanupResources(killSignal: NodeJS.Signals = \"SIGTERM\"): Error | undefined {\n\t\tconst failures: unknown[] = [];\n\t\tthis.startGeneration++; // any teardown invalidates in-flight starts\n\t\tthis.clearSnapshotTimer();\n\t\tthis.lateSentAgentMessageHandlers.clear();\n\t\tthis.pendingDoneWaiters.clear();\n\t\t// Stale pre-teardown background output must not surface after a restart.\n\t\tthis.pendingBackgroundOutput = \"\";\n\t\tthis.pendingBackgroundOutputTruncated = false;\n\t\tthis.rejectActiveExecution(new Error(\"Kernel has been shut down\"));\n\t\tconst child = this.child;\n\t\tconst orphanOwner = this.childOrphanOwner;\n\t\tthis.child = undefined;\n\t\tthis.childOrphanOwner = undefined;\n\t\tthis.readyDeferred = undefined;\n\t\tif (child) {\n\t\t\tchild.stdin?.destroy();\n\t\t\tchild.stdout?.destroy();\n\t\t\t// An exited child keeps its stderr: the post-exit drain owns it, and\n\t\t\t// destroying here would drop its buffered last words. A still-alive\n\t\t\t// child may ignore the kill signal and never emit 'exit', so that\n\t\t\t// drain would never run — destroy now to bound the pipe's lifetime.\n\t\t\tif (child.exitCode === null && child.signalCode === null) {\n\t\t\t\tchild.stderr?.destroy();\n\t\t\t}\n\t\t\tconst pid = child.pid;\n\t\t\tlet signaled = false;\n\t\t\ttry {\n\t\t\t\tsignaled = child.kill(killSignal);\n\t\t\t} catch (error) {\n\t\t\t\tfailures.push(error);\n\t\t\t}\n\t\t\t// Inactive only when the signal proved the pid still named our un-reaped child.\n\t\t\tif (pid !== undefined && signaled) {\n\t\t\t\tconst failure = orphanOwner?.record(pid, false);\n\t\t\t\tif (failure) failures.push(failure);\n\t\t\t}\n\t\t\t// A killed/crashed kernel cannot run its own shutdown hook, so the host\n\t\t\t// reaps the bash() process groups it journaled under this kernel pid.\n\t\t\tif (pid !== undefined && orphanOwner) {\n\t\t\t\tconst failure = reapKernelOrphanProcesses(pid, orphanOwner);\n\t\t\t\tif (failure) failures.push(failure);\n\t\t\t}\n\t\t}\n\t\tthis.startPromise = undefined;\n\t\tif (failures.length) {\n\t\t\tconst failure = new AggregateError(\n\t\t\t\tfailures,\n\t\t\t\t`Kernel cleanup tracking is unknown: ${failures.map(errorMessage).join(\"; \")}`,\n\t\t\t);\n\t\t\tthis.appendKernelDiagnostic(failure.message);\n\t\t\treturn failure;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate async waitForKernelExit(): Promise<void> {\n\t\tconst child = this.child;\n\t\tif (!child) return;\n\t\tif (child.exitCode !== null || child.signalCode !== null) return;\n\t\tawait new Promise<void>((resolve) => child.once(\"exit\", () => resolve()));\n\t}\n\n\tprivate async waitForHostRequestsToSettle(tasks: Promise<void>[], timeoutMs: number): Promise<void> {\n\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tconst timeoutPromise = new Promise<\"timeout\">((resolve) => {\n\t\t\ttimeout = globalThis.setTimeout(() => resolve(\"timeout\"), timeoutMs);\n\t\t\tif (timeout && typeof timeout === \"object\" && \"unref\" in timeout) {\n\t\t\t\ttimeout.unref();\n\t\t\t}\n\t\t});\n\n\t\tconst result = await Promise.race([Promise.allSettled(tasks).then(() => \"settled\" as const), timeoutPromise]);\n\t\tif (timeout) {\n\t\t\tglobalThis.clearTimeout(timeout);\n\t\t}\n\t\tif (result === \"timeout\") {\n\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t`timed out waiting ${timeoutMs}ms for ${tasks.length} host request task(s) during shutdown`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Resolves true when this call performed the cleanup (false: a concurrent teardown won; a joiner's options are ignored - the first caller's policy wins). */\n\tasync shutdown(opts: KernelShutdownOptions = {}): Promise<boolean> {\n\t\tconst inFlightShutdown = this.gracefulShutdownPromise;\n\t\tif (inFlightShutdown) {\n\t\t\tawait inFlightShutdown;\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.teardownInFlight++;\n\t\tthis.supersedeProtocolRepair();\n\t\tconst operation = this.performShutdown(opts);\n\t\tthis.gracefulShutdownPromise = operation;\n\t\ttry {\n\t\t\treturn await operation;\n\t\t} finally {\n\t\t\tthis.teardownInFlight--;\n\t\t\tif (this.gracefulShutdownPromise === operation) this.gracefulShutdownPromise = undefined;\n\t\t}\n\t}\n\n\tprivate async performShutdown(opts: KernelShutdownOptions): Promise<boolean> {\n\t\tif (this.state === \"shutdown\") {\n\t\t\tliveKernels.delete(this);\n\t\t\tif (this.gracefulShutdownGeneration === this.startGeneration) return false;\n\t\t\tconst failure = this.cleanupResources();\n\t\t\tif (failure) throw failure;\n\t\t\treturn true;\n\t\t}\n\t\t// Captured before any await: teardowns and newer starts bump the counter.\n\t\tconst generation = this.startGeneration;\n\t\tif (opts.snapshot) {\n\t\t\tawait this.flushSnapshotForDispose();\n\t\t\tif (this.startStale(generation)) return false;\n\t\t}\n\t\t// Protocol shutdown first: the runtime closes MCP servers and kills live bash() process groups a bare hard-kill would leak.\n\t\tconst protocolShutdownAvailable = this.state === \"running\";\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.gracefulShutdownGeneration = generation;\n\n\t\tlet shutdownTimer: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tlet doneWaiterId: string | undefined;\n\t\tlet performedCleanup = false;\n\t\tlet gracefulFailure: unknown;\n\t\tlet cleanupFailure: Error | undefined;\n\t\ttry {\n\t\t\tif (opts.drainHostRequests) {\n\t\t\t\tconst inFlightHostRequests = [...this.inFlightHostRequests];\n\t\t\t\tif (inFlightHostRequests.length > 0) {\n\t\t\t\t\tawait this.waitForHostRequestsToSettle(inFlightHostRequests, HOST_REQUEST_SHUTDOWN_TIMEOUT_MS);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\n\t\t\t\tprotocolShutdownAvailable &&\n\t\t\t\t!this.startStale(generation) &&\n\t\t\t\tthis.child?.stdin &&\n\t\t\t\t!this.child.stdin.destroyed\n\t\t\t) {\n\t\t\t\tconst requestId = uuid();\n\t\t\t\tdoneWaiterId = requestId;\n\t\t\t\tconst doneReply = new Promise<void>((resolve) => {\n\t\t\t\t\tthis.pendingDoneWaiters.set(requestId, resolve);\n\t\t\t\t});\n\t\t\t\tconst shutdownDeadline = new Promise<never>((_resolve, reject) => {\n\t\t\t\t\tshutdownTimer = globalThis.setTimeout(\n\t\t\t\t\t\t() => reject(new Error(`Kernel did not shut down within ${KERNEL_SHUTDOWN_TIMEOUT_MS}ms`)),\n\t\t\t\t\t\tKERNEL_SHUTDOWN_TIMEOUT_MS,\n\t\t\t\t\t);\n\t\t\t\t\tshutdownTimer.unref?.();\n\t\t\t\t});\n\t\t\t\tconst send = this.writeLine({ type: \"shutdown\", id: requestId });\n\t\t\t\tsend.catch(() => undefined);\n\t\t\t\tconst kernelExit = this.waitForKernelExit();\n\t\t\t\tconst gracefulReply = Promise.all([send, doneReply]);\n\t\t\t\tgracefulReply.catch(() => undefined);\n\t\t\t\tawait Promise.race([gracefulReply, kernelExit, shutdownDeadline]);\n\t\t\t\tawait Promise.race([kernelExit, shutdownDeadline]);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tgracefulFailure = error;\n\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t`graceful shutdown failed (killing instead): ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t} finally {\n\t\t\tif (shutdownTimer) globalThis.clearTimeout(shutdownTimer);\n\t\t\tif (doneWaiterId) this.pendingDoneWaiters.delete(doneWaiterId);\n\t\t\tif (this.gracefulShutdownGeneration === generation) this.gracefulShutdownGeneration = undefined;\n\t\t\tif (!this.startStale(generation)) {\n\t\t\t\tcleanupFailure = this.cleanupResources();\n\t\t\t\tperformedCleanup = true;\n\t\t\t}\n\t\t}\n\n\t\tif (cleanupFailure)\n\t\t\tthrow gracefulFailure\n\t\t\t\t? new AggregateError([gracefulFailure, cleanupFailure], \"Kernel graceful shutdown and cleanup failed\")\n\t\t\t\t: cleanupFailure;\n\t\treturn performedCleanup;\n\t}\n\n\tasync restart(): Promise<void> {\n\t\t// A final dispose flush owns the queue tail. Taking a slot now and joining\n\t\t// the in-flight shutdown would deadlock: the flush's snapshot waits on our\n\t\t// slot while we wait on the flush's shutdown.\n\t\tif (this.flushingSnapshotForDispose) {\n\t\t\tthrow new Error(\"Kernel is shutting down\");\n\t\t}\n\t\tconst prev = this.executionQueue;\n\t\tlet resolveNext: () => void = () => {};\n\t\tthis.executionQueue = new Promise<void>((r) => {\n\t\t\tresolveNext = r;\n\t\t});\n\t\tawait prev;\n\n\t\ttry {\n\t\t\tconst performedCleanup = await this.shutdown();\n\t\t\tif (!performedCleanup) return;\n\t\t\tthis.state = \"idle\";\n\t\t\tthis.kernelStderr = \"\";\n\t\t\tawait this.start();\n\t\t} finally {\n\t\t\tresolveNext();\n\t\t}\n\t}\n\n\tasync kill(): Promise<void> {\n\t\tthis.supersedeProtocolRepair();\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources(\"SIGKILL\");\n\t}\n\n\t/**\n\t * Serialize the user namespace to disk (best-effort, per-variable). No-op when\n\t * the kernel isn't running or no snapshot target was configured. Never throws.\n\t */\n\tasync snapshotState(): Promise<SnapshotResult | null> {\n\t\treturn this.captureSnapshot();\n\t}\n\n\t/** Persist the namespace, then remove variables above the per-variable cap. */\n\tasync pruneOversizedVariables(): Promise<SnapshotResult | null> {\n\t\treturn this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS, pruneOversized: true });\n\t}\n\n\tprivate async captureSnapshot(\n\t\toptions: { executionTimeoutMs?: number; pruneOversized?: boolean } = {},\n\t): Promise<SnapshotResult | null> {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg || !this.isRunning) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{\n\t\t\t\t\ttype: \"snapshot\",\n\t\t\t\t\tpath: cfg.path,\n\t\t\t\t\tmanifest_path: cfg.manifestPath,\n\t\t\t\t\tmax_bytes: cfg.maxBytes ?? DEFAULT_SNAPSHOT_MAX_BYTES,\n\t\t\t\t\tmax_variable_bytes: cfg.maxVariableBytes ?? DEFAULT_SNAPSHOT_MAX_VARIABLE_BYTES,\n\t\t\t\t\tprune_oversized: options.pruneOversized ?? false,\n\t\t\t\t},\n\t\t\t\t\"\",\n\t\t\t\t{ internal: true },\n\t\t\t\toptions.executionTimeoutMs,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`state snapshot ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst pruned = asStringArray(r.doneFields.pruned);\n\t\t\treturn {\n\t\t\t\tsaved: asStringArray(r.doneFields.saved),\n\t\t\t\tskipped: asReasonArray(r.doneFields.skipped),\n\t\t\t\tpruned: pruned.length > 0 ? pruned : undefined,\n\t\t\t\tbytes: typeof r.doneFields.bytes === \"number\" ? r.doneFields.bytes : 0,\n\t\t\t\tpath: cfg.path,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`state snapshot error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Revive a previously snapshotted namespace into the kernel. Call right after\n\t * start() and before the runtime bootstrap, which then refreshes live handles\n\t * (rlm, skills) over anything restored. Never throws.\n\t */\n\tasync restoreState(): Promise<RestoreResult | null> {\n\t\treturn this.performRestore(false);\n\t}\n\n\t/** Repair restores bypass the repair gate and are bounded so a stalled kernel cannot wedge it. */\n\tprivate async performRestore(protocolRepair: boolean): Promise<RestoreResult | null> {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{ type: \"restore\", path: cfg.path },\n\t\t\t\t\"\",\n\t\t\t\t{ internal: true, protocolRepair },\n\t\t\t\tprotocolRepair ? REPAIR_STEP_TIMEOUT_MS : undefined,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`state restore ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthis.pendingRestore = false;\n\t\t\treturn {\n\t\t\t\trestored: asStringArray(r.doneFields.restored),\n\t\t\t\tfailed: asReasonArray(r.doneFields.failed),\n\t\t\t\tpath: cfg.path,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`state restore error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/** Live user-defined top-level names, or null if the kernel isn't running. Never throws. */\n\tasync listNamespaceNames(signal?: AbortSignal): Promise<string[] | null> {\n\t\tif (!this.isRunning) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest({ type: \"list_names\" }, \"\", { internal: true, signal });\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(`namespace listing failed: ${r.error?.evalue ?? r.stderr}`);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn asStringArray(r.doneFields.names);\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`namespace listing error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprivate scheduleSnapshot(): void {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg) return;\n\t\tif (this.snapshotTimer) clearTimeout(this.snapshotTimer);\n\t\tthis.snapshotTimer = globalThis.setTimeout(() => {\n\t\t\tthis.snapshotTimer = undefined;\n\t\t\tvoid this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS });\n\t\t}, cfg.debounceMs ?? DEFAULT_SNAPSHOT_DEBOUNCE_MS);\n\t\tif (this.snapshotTimer && typeof this.snapshotTimer === \"object\" && \"unref\" in this.snapshotTimer) {\n\t\t\tthis.snapshotTimer.unref();\n\t\t}\n\t}\n\n\tprivate clearSnapshotTimer(): void {\n\t\tif (this.snapshotTimer) {\n\t\t\tclearTimeout(this.snapshotTimer);\n\t\t\tthis.snapshotTimer = undefined;\n\t\t}\n\t}\n\n\tprivate flushSnapshotForDispose(): Promise<void> {\n\t\t// Concurrent teardowns (dispose vs a signal-handler shutdown) join one flush:\n\t\t// a second flusher would clear the execution guard while the first is still\n\t\t// snapshotting and enqueue a duplicate final snapshot behind it.\n\t\tthis.snapshotFlushForDispose ??= this.runSnapshotFlushForDispose().finally(() => {\n\t\t\tthis.snapshotFlushForDispose = undefined;\n\t\t});\n\t\treturn this.snapshotFlushForDispose;\n\t}\n\n\tprivate async runSnapshotFlushForDispose(): Promise<void> {\n\t\tif (!this.options.snapshot || !this.isRunning) return;\n\t\t// A kernel that never restored the saved namespace must not overwrite it:\n\t\t// the on-disk snapshot is strictly fresher than this namespace.\n\t\tif (this.pendingRestore) return;\n\t\t// Block new external executions so none can splice ahead of the final snapshot and stall dispose.\n\t\tthis.flushingSnapshotForDispose = true;\n\t\ttry {\n\t\t\tconst pendingExecutions = this.executionQueue;\n\t\t\tif (this.activeExecution) void this.interrupt().catch(() => undefined);\n\t\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\t\tconst queueSettled = await Promise.race([\n\t\t\t\tpendingExecutions.then(() => true),\n\t\t\t\tnew Promise<false>((resolve) => {\n\t\t\t\t\ttimeout = globalThis.setTimeout(() => resolve(false), SNAPSHOT_EXECUTION_TIMEOUT_MS);\n\t\t\t\t\ttimeout.unref?.();\n\t\t\t\t}),\n\t\t\t]);\n\t\t\tif (timeout) globalThis.clearTimeout(timeout);\n\t\t\tif (!queueSettled) return;\n\t\t\tawait this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS });\n\t\t} finally {\n\t\t\t// Reset: a superseding start() can revive this kernel for new work.\n\t\t\tthis.flushingSnapshotForDispose = false;\n\t\t}\n\t}\n\n\t/** Synchronous best-effort cleanup. Safe to call from `process.on('exit')`. */\n\tdisposeSync(): void {\n\t\tthis.supersedeProtocolRepair();\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources();\n\t}\n\n\tget isRunning(): boolean {\n\t\treturn this.state === \"running\";\n\t}\n}\n"]}