@@ -42,9 +42,7 @@ import { finalizeDaemonSessionApplicationLifecycle } from '../application-lifecy
4242import { runtimeHintValues } from '../../sessions/session-runtime.ts' ;
4343import {
4444 closeDaemonServers ,
45- createRuntimeContext ,
4645 teardownDaemonSessionForShutdown ,
47- type RuntimeContext ,
4846 type WritableOutput ,
4947 createPluginClose ,
5048 createStartupRollback ,
@@ -71,7 +69,10 @@ import { createPerfCaptureAdmissionLedger } from '@agent-device/capture-kit/perf
7169import { createScreenRecordingAdmissionLedger } from '@agent-device/capture-kit/screen-recording-admission-ledger' ;
7270import { withCommandHost } from '@agent-device/host-kit/command' ;
7371import { cancelAllRequests } from '@agent-device/host-kit/request' ;
74- import type { RuntimeStateHandle } from '@agent-device/host-kit/runtime-slots' ;
72+ import {
73+ createRuntimeStateHandle ,
74+ type RuntimeStateHandle ,
75+ } from '@agent-device/host-kit/runtime-slots' ;
7576import { emitDiagnostic , type ResourceDiagnostic } from '@agent-device/host-kit/diagnostics' ;
7677import type { HostEnvironment } from '@agent-device/kernel/source-value' ;
7778import {
@@ -134,8 +135,6 @@ const DAEMON_RECORDING_REAP_TERM_TIMEOUT_MS = 5_000;
134135 * same factory, so the production assembly is the one every runtime test boots.
135136 */
136137export type DaemonRuntimeDeps = Readonly < {
137- /** State the composition's platform modules keep per daemon runtime (the Apple runner's). */
138- runtimeStates : readonly RuntimeStateHandle [ ] ;
139138 ownedProcessRecords : OwnedProcessRecordStore ;
140139 hostDiagnostics : HostDiagnostics ;
141140 ownerLifecycle : PlatformOwnerLifecycle ;
@@ -254,17 +253,23 @@ export function daemonStartupExitCode(error: unknown): number {
254253 return typeof exitCode === 'number' ? exitCode : 1 ;
255254}
256255
256+ /**
257+ * Starts one daemon runtime: the single entered runtime-state store, the command host, then the
258+ * composition and servers built inside both. Every read of per-runtime state (requests, close,
259+ * timers the startup spawns) runs within this handle, so two runtimes in one process never share
260+ * it and no module exposes a store of its own (#3794).
261+ */
257262export async function startDaemonRuntime (
258263 options : DaemonRuntimeOptions ,
259264) : Promise < DaemonRuntimeController > {
260- const runtimeContext = createRuntimeContext ( ) ;
261- return await runtimeContext . run (
265+ const runtimeState = createRuntimeStateHandle ( ) ;
266+ return await runtimeState . run (
262267 async ( ) =>
263268 await withCommandHost ( { host : options . host , requestEnv : undefined } , async ( ) => {
264269 const rollback = createStartupRollback ( ) ;
265- rollback . onRollback ( ( ) => runtimeContext . dispose ( ) ) ;
270+ rollback . onRollback ( ( ) => runtimeState . dispose ( ) ) ;
266271 try {
267- return await startDaemonRuntimeOnHost ( options , rollback , runtimeContext ) ;
272+ return await startDaemonRuntimeOnHost ( options , rollback , runtimeState ) ;
268273 } catch ( error ) {
269274 await rollback . run ( ) ;
270275 throw error ;
@@ -276,7 +281,7 @@ export async function startDaemonRuntime(
276281async function startDaemonRuntimeOnHost (
277282 options : DaemonRuntimeOptions ,
278283 rollback : StartupRollback ,
279- runtimeContext : RuntimeContext ,
284+ runtimeState : RuntimeStateHandle ,
280285) : Promise < DaemonRuntimeController > {
281286 const { host } = options ;
282287 const { env } = host ;
@@ -316,7 +321,6 @@ async function startDaemonRuntimeOnHost(
316321 } ) ,
317322 openWebSessionNames : ( ) => openWebSessionNames ( sessionStore ) ,
318323 } ) ;
319- runtimeContext . extend ( deps . runtimeStates ) ;
320324 const appLogAdmissionLedger = createAppLogAdmissionLedger ( ) ;
321325 const audioProbeAdmissionLedger = createAudioProbeAdmissionLedger ( ) ;
322326 const perfCaptureAdmissionLedger = createPerfCaptureAdmissionLedger ( ) ;
@@ -561,7 +565,7 @@ async function startDaemonRuntimeOnHost(
561565 const handleRequest : DaemonInvokeFn = lifecycleAdmission . admit ( async ( req ) => {
562566 if ( shuttingDown ) return daemonShuttingDownResponse ( ) ;
563567 idleReap . cancel ( ) ;
564- const dispatch = runtimeContext . run ( ( ) => dispatchRequest ( req ) ) ;
568+ const dispatch = runtimeState . run ( ( ) => dispatchRequest ( req ) ) ;
565569 inFlightRequests . add ( dispatch ) ;
566570 try {
567571 return await dispatch ;
@@ -911,7 +915,7 @@ async function startDaemonRuntimeOnHost(
911915 try {
912916 await deps . ownerLifecycle . clearDaemonLockConfiguration ( ) ;
913917 } catch { }
914- runtimeContext . dispose ( ) ;
918+ runtimeState . dispose ( ) ;
915919 }
916920 }
917921 } ;
@@ -928,7 +932,7 @@ async function startDaemonRuntimeOnHost(
928932 closed . catch ( ( ) => { } ) ;
929933 const close = ( closeOptions : { cause ?: unknown } = { } ) : Promise < ShutdownReport > => {
930934 if ( ! closing ) {
931- closing = runtimeContext . run ( ( ) =>
935+ closing = runtimeState . run ( ( ) =>
932936 withCommandHost (
933937 { host, requestEnv : undefined } ,
934938 async ( ) => await closeOnHost ( closeOptions ) ,
@@ -945,7 +949,7 @@ async function startDaemonRuntimeOnHost(
945949 httpPort,
946950 close,
947951 closed,
948- run : runtimeContext . run ,
952+ run : runtimeState . run ,
949953 socketPort,
950954 token,
951955 } ;
0 commit comments