11#!/usr/bin/env node
22/**
3- * CP1 bounded single-turn serve — the worker side of the ADO e2e .
3+ * Bounded single-turn session worker.
44 *
55 * Boots a REAL PilotSwarm worker (a duroxide Runtime) against the deployed
66 * durable store, serves the ONE already-seeded turn for the target session
77 * (SESSION_ID), confirms the response landed in the store, then stops and
8- * exits. Bounded so the ADO pipeline job completes on its own.
8+ * exits. Bounded so a per-run invoker (e.g. an ADO pipeline job) completes on
9+ * its own.
10+ *
11+ * Substrate-agnostic: it talks only to the durable store and calls no
12+ * ADO/CI APIs. ADO is merely the current invoker — the one ADO-flavored input
13+ * is the optional BUILD_SOURCESDIRECTORY checkout dir (with the generic
14+ * PILOTSWARM_SESSION_WORKING_DIR override) used to root the session so the
15+ * Copilot CLI can discover the enlistment's `.github` skills/agents.
916 *
1017 * The turn is seeded OUT OF BAND by the customer client (the local portal's
1118 * REST API). This process only provides the worker (the compute that claims
1219 * and runs the turn) and then asserts completion by reading the session's
1320 * latest response straight from the CMS — no orchestration id required.
1421 *
15- * CP1 scoping note: this worker is UNSCOPED (no tag filter yet — see TODO
16- * ado-hybrid-tag-pin). It is safe ONLY because CP1 has no other workers
17- * polling the store (the AKS worker pool is empty / scaled to zero), making
18- * this the sole consumer. Do NOT run this against a store with other active
19- * workers until the tag-based pin lands.
22+ * Scoping note: this worker is UNSCOPED (no tag filter yet — see TODO
23+ * ado-hybrid-tag-pin). It is safe ONLY when no other workers poll the store
24+ * (the AKS worker pool is empty / scaled to zero), making this the sole
25+ * consumer. Do NOT run this against a store with other active workers until
26+ * the tag-based pin lands.
2027 *
2128 * Env:
2229 * DATABASE_URL full store URL (overrides the PG* builder if set)
@@ -62,7 +69,7 @@ function redact(url) {
6269
6370const truthy = ( v ) => [ "1" , "true" , "yes" , "on" ] . includes ( String ( v || "" ) . trim ( ) . toLowerCase ( ) ) ;
6471
65- const OK = "SERVE_OK: ADO worker served the seeded turn against the deployed store" ;
72+ const OK = "SERVE_OK: worker served the seeded turn against the deployed store" ;
6673const FAIL = "SERVE_FAIL" ;
6774const timeoutMs = Number . parseInt ( process . env . SERVE_TIMEOUT_MS || "300000" , 10 ) ;
6875const pollMs = Number . parseInt ( process . env . SERVE_POLL_MS || "3000" , 10 ) ;
@@ -77,17 +84,17 @@ let worker = null;
7784let mgmt = null ;
7885
7986try {
80- console . log ( `[cp1-serve ] node ${ process . version } on ${ os . platform ( ) } -${ os . arch ( ) } (${ os . hostname ( ) } )` ) ;
87+ console . log ( `[session-worker ] node ${ process . version } on ${ os . platform ( ) } -${ os . arch ( ) } (${ os . hostname ( ) } )` ) ;
8188
8289 const sessionId = process . env . SESSION_ID || process . env . SESSION_TREE_ID ;
8390 if ( ! sessionId ) throw new Error ( "SESSION_ID is required" ) ;
8491
8592 const store = buildStoreUrl ( ) ;
8693 const useManagedIdentity = truthy ( process . env . PILOTSWARM_USE_MANAGED_IDENTITY ) ;
8794 const aadDbUser = process . env . PILOTSWARM_DB_AAD_USER || undefined ;
88- console . log ( `[cp1-serve ] store: ${ redact ( store ) } (managedIdentity=${ useManagedIdentity } )` ) ;
89- console . log ( `[cp1-serve ] target session=${ sessionId } ` ) ;
90- console . log ( `[cp1-serve ] model provider: type=${ process . env . LLM_PROVIDER_TYPE || "(unset)" } model=${ process . env . COPILOT_MODEL || "(unset)" } endpoint=${ process . env . LLM_ENDPOINT || "(unset)" } ` ) ;
95+ console . log ( `[session-worker ] store: ${ redact ( store ) } (managedIdentity=${ useManagedIdentity } )` ) ;
96+ console . log ( `[session-worker ] target session=${ sessionId } ` ) ;
97+ console . log ( `[session-worker ] model provider: type=${ process . env . LLM_PROVIDER_TYPE || "(unset)" } model=${ process . env . COPILOT_MODEL || "(unset)" } endpoint=${ process . env . LLM_ENDPOINT || "(unset)" } ` ) ;
9198
9299 const workerNodeId = process . env . WORKER_NODE_ID
93100 || process . env . AGENT_NAME || process . env . POD_NAME || `${ os . hostname ( ) } #${ process . pid } ` ;
@@ -116,9 +123,9 @@ try {
116123 ? true
117124 : truthy ( process . env . PILOTSWARM_ENABLE_CONFIG_DISCOVERY ) ;
118125 if ( sessionWorkingDirectory ) {
119- console . log ( `[cp1-serve ] platform session workingDirectory=${ sessionWorkingDirectory } (enableConfigDiscovery=${ enableConfigDiscovery } ) — repo .github skills/agents will be discovered` ) ;
126+ console . log ( `[session-worker ] platform session workingDirectory=${ sessionWorkingDirectory } (enableConfigDiscovery=${ enableConfigDiscovery } ) — repo .github skills/agents will be discovered` ) ;
120127 } else {
121- console . log ( `[cp1-serve ] no enlistment checkout detected (PILOTSWARM_SESSION_WORKING_DIR / BUILD_SOURCESDIRECTORY lacked .github); sessions use the worker cwd — repo .github skills NOT discovered (enableConfigDiscovery=${ enableConfigDiscovery } )` ) ;
128+ console . log ( `[session-worker ] no enlistment checkout detected (PILOTSWARM_SESSION_WORKING_DIR / BUILD_SOURCESDIRECTORY lacked .github); sessions use the worker cwd — repo .github skills NOT discovered (enableConfigDiscovery=${ enableConfigDiscovery } )` ) ;
122129 }
123130
124131 const { PilotSwarmWorker, PilotSwarmManagementClient } = await import ( "pilotswarm-sdk" ) ;
@@ -136,21 +143,21 @@ try {
136143 blobConnectionString : process . env . AZURE_STORAGE_CONNECTION_STRING || undefined ,
137144 blobContainer : process . env . AZURE_STORAGE_CONTAINER || undefined ,
138145 } ) ;
139- console . log ( `[cp1-serve ] worker constructed (workerNodeId=${ workerNodeId } ); starting runtime...` ) ;
146+ console . log ( `[session-worker ] worker constructed (workerNodeId=${ workerNodeId } ); starting runtime...` ) ;
140147 await worker . start ( ) ;
141- console . log ( "[cp1-serve ] worker.start() complete — runtime is polling the durable store" ) ;
148+ console . log ( "[session-worker ] worker.start() complete — runtime is polling the durable store" ) ;
142149
143150 mgmt = new PilotSwarmManagementClient ( { store, useManagedIdentity, aadDbUser } ) ;
144151 await mgmt . start ( ) ;
145- console . log ( `[cp1-serve ] observing session completion (timeout=${ timeoutMs } ms, poll=${ pollMs } ms)...` ) ;
152+ console . log ( `[session-worker ] observing session completion (timeout=${ timeoutMs } ms, poll=${ pollMs } ms)...` ) ;
146153
147154 const t0 = Date . now ( ) ;
148155 let latest = null ;
149156 while ( Date . now ( ) - t0 < timeoutMs ) {
150157 latest = await mgmt . getLatestResponse ( sessionId ) . catch ( ( ) => null ) ;
151158 const type = latest ?. type ;
152159 if ( type === "completed" || type === "error" || type === "input_required" ) {
153- console . log ( `[cp1-serve ] session reached terminal response type=${ type } in ${ Date . now ( ) - t0 } ms` ) ;
160+ console . log ( `[session-worker ] session reached terminal response type=${ type } in ${ Date . now ( ) - t0 } ms` ) ;
154161 break ;
155162 }
156163 await new Promise ( ( r ) => setTimeout ( r , pollMs ) ) ;
0 commit comments