@north-light/cli 0.3.662 → 0.3.663

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 (29) hide show
  1. package/dist/clients/attach/viewer.js +1 -1
  2. package/dist/core/canvas/schema-pg/020-machine-calls-status-all.sql +8 -0
  3. package/dist/core/canvas/schema-version.d.ts +1 -1
  4. package/dist/core/canvas/schema-version.js +1 -1
  5. package/dist/core/runtime/runner/machine/call.js +2 -2
  6. package/dist/core/runtime/runner/machine/executor.d.ts +7 -0
  7. package/dist/core/runtime/runner/machine/executor.js +1 -1
  8. package/dist/core/runtime/runner/machine/machine-executor.test.js +2 -2
  9. package/dist/core/runtime/runner/machine/ops.d.ts +14 -1
  10. package/dist/core/runtime/runner/machine/ops.js +1 -1
  11. package/dist/daemon/broker-signals/bus.d.ts +3 -2
  12. package/dist/daemon/broker-signals/bus.js +1 -1
  13. package/dist/daemon/crtrd.d.ts +4 -0
  14. package/dist/daemon/crtrd.js +12 -12
  15. package/dist/daemon/machine-daemon.js +1 -1
  16. package/dist/daemon/machine-link/client.d.ts +9 -0
  17. package/dist/daemon/machine-link/client.js +1 -1
  18. package/dist/daemon/machine-link/frames.d.ts +8 -0
  19. package/dist/daemon/machine-link/frames.js +1 -1
  20. package/dist/daemon/machine-link/holder.d.ts +11 -0
  21. package/dist/daemon/machine-link/holder.js +4 -4
  22. package/dist/daemon/reconcilers/grant-effects.js +1 -1
  23. package/dist/daemon/reconcilers/node-lifecycle/machine-sweep.d.ts +5 -0
  24. package/dist/daemon/reconcilers/node-lifecycle/machine-sweep.js +4 -0
  25. package/dist/daemon/reconcilers/node-lifecycle/tick.d.ts +3 -0
  26. package/dist/daemon/reconcilers/node-lifecycle/tick.js +1 -1
  27. package/package.json +2 -2
  28. package/packages/crouter-identity/package.json +1 -1
  29. package/runtime.lock.json +13 -13
@@ -1,9 +1,9 @@
1
- var N=Object.defineProperty;var s=(i,e)=>N(i,"name",{value:e,configurable:!0});import{EventEmitter as u}from"node:events";import{hostname as k}from"node:os";import{randomUUID as R}from"node:crypto";import{WebSocket as T,WebSocketServer as I}from"ws";import{openDb as r}from"../../core/canvas/db.js";import{emitEvent as _}from"../../core/events/emit.js";import{brokerSignalBus as L}from"../broker-signals/bus.js";import{verifyMachineCredential as E}from"./credential.js";import{CLOSE_REVOKED as y,CLOSE_SUPERSEDED as p,LINK_MAX_PAYLOAD_BYTES as O,parseFrame as b}from"./frames.js";const U=45e3,C=15e3,x=3e4,M=1e3,w=10,P=new I({noServer:!0,maxPayload:O}),c=new Map,H="unroutable:";let g;const q=s(i=>{g=i},"setApiAddress"),W=s(()=>process.env.CRTR_API_ADDRESS??g??`${H}${k()}:${process.pid}`,"apiAddress"),m=s(()=>new Date(Date.now()+U).toISOString(),"lease");class F extends u{static{s(this,"HeldLink")}environmentId;generation;ws;token;timers=[];unsubscribe;claiming=!1;closed=!1;alive=!0;channels=new Map;constructor(e,t,n,a){super(),this.environmentId=e,this.generation=t,this.ws=n,this.token=a}start(){const{ws:e}=this;e.on("message",t=>{this.onMessage(t).catch(n=>this.fault("daemon.machine_link.frame_failed",n))}),e.on("pong",()=>{this.alive=!0}),e.on("close",()=>{this.teardown().catch(t=>this.fault("daemon.machine_link.teardown_failed",t))}),e.on("error",()=>{}),this.timers.push(setInterval(()=>{this.renew().catch(t=>this.fault("daemon.machine_link.renew_failed",t))},C)),this.timers.push(setInterval(()=>{if(!this.alive){e.terminate();return}this.alive=!1;try{e.ping()}catch{}},x)),this.timers.push(setInterval(()=>{this.claim().catch(t=>this.fault("daemon.machine_link.claim_failed",t))},M)),L.subscribe(t=>{t===this.environmentId&&this.claim().catch(n=>this.fault("daemon.machine_link.claim_failed",n))},{kinds:["machine"],onListenStart:s(()=>{this.claim().catch(t=>this.fault("daemon.machine_link.claim_failed",t))},"onListenStart")}).then(t=>{this.closed?t():this.unsubscribe=t})}fault(e,t){_({level:"error",event:e,fields:{environment:this.environmentId},error:t})}send(e){return this.ws.readyState!==T.OPEN?!1:(this.ws.send(JSON.stringify(e)),!0)}async renew(){if(this.closed)return;const e=await r(),t=m();if((await e.prepare("UPDATE machine_links SET lease_expires_at = ? WHERE environment = ? AND generation = ?").run(t,this.environmentId,this.generation)).changes===0){this.ws.close(p,"superseded");return}await e.prepare("UPDATE machine_calls SET lease_expires_at = ? WHERE environment = ? AND state = 'sent' AND claimed_generation = ?").run(t,this.environmentId,this.generation),await e.prepare("UPDATE environments SET last_seen_at = ? WHERE object = ?").run(new Date().toISOString(),this.environmentId),await this.credentialValid()||this.ws.close(y,"revoked")}async credentialValid(){return await E(this.environmentId,this.token)}async claim(){if(!(this.closed||this.claiming)){this.claiming=!0;try{for(;;){const e=await(await r()).prepare(`UPDATE machine_calls SET state = 'sent', claimed_generation = ?, lease_expires_at = ?
1
+ var N=Object.defineProperty;var s=(i,e)=>N(i,"name",{value:e,configurable:!0});import{importedNodesHeld as k}from"../reconcilers/live-obligation.js";import{EventEmitter as _}from"node:events";import{hostname as R}from"node:os";import{randomUUID as T}from"node:crypto";import{WebSocket as L,WebSocketServer as I}from"ws";import{openDb as r}from"../../core/canvas/db.js";import{emitEvent as m}from"../../core/events/emit.js";import{endExecution as y,recordExecutionExit as O}from"../../core/canvas/executions.js";import{machineEnvironmentOfNode as b}from"../../core/runtime/runner/machine/runner.js";import{brokerSignalBus as x}from"../broker-signals/bus.js";import{verifyMachineCredential as E}from"./credential.js";import{CLOSE_REVOKED as C,CLOSE_SUPERSEDED as p,LINK_MAX_PAYLOAD_BYTES as M,parseFrame as U}from"./frames.js";const H=45e3,P=15e3,W=3e4,F=1e3,w=10,B=new I({noServer:!0,maxPayload:M}),c=new Map,$="unroutable:";let g;const oe=s(i=>{g=i},"setApiAddress"),K=s(()=>process.env.CRTR_API_ADDRESS??g??`${$}${R()}:${process.pid}`,"apiAddress"),u=s(()=>new Date(Date.now()+H).toISOString(),"lease");class X extends _{static{s(this,"HeldLink")}environmentId;generation;ws;token;timers=[];unsubscribe;claiming=!1;closed=!1;alive=!0;channels=new Map;constructor(e,n,t,a){super(),this.environmentId=e,this.generation=n,this.ws=t,this.token=a}start(){const{ws:e}=this;e.on("message",n=>{this.onMessage(n).catch(t=>this.fault("daemon.machine_link.frame_failed",t))}),e.on("pong",()=>{this.alive=!0}),e.on("close",()=>{this.teardown().catch(n=>this.fault("daemon.machine_link.teardown_failed",n))}),e.on("error",()=>{}),this.timers.push(setInterval(()=>{this.renew().catch(n=>this.fault("daemon.machine_link.renew_failed",n))},P)),this.timers.push(setInterval(()=>{if(!this.alive){e.terminate();return}this.alive=!1;try{e.ping()}catch{}},W)),this.timers.push(setInterval(()=>{this.claim().catch(n=>this.fault("daemon.machine_link.claim_failed",n))},F)),x.subscribe(n=>{n===this.environmentId&&this.claim().catch(t=>this.fault("daemon.machine_link.claim_failed",t))},{kinds:["machine"],onListenStart:s(()=>{this.claim().catch(n=>this.fault("daemon.machine_link.claim_failed",n))},"onListenStart")}).then(n=>{this.closed?n():this.unsubscribe=n})}fault(e,n){m({level:"error",event:e,fields:{environment:this.environmentId},error:n})}send(e){return this.ws.readyState!==L.OPEN?!1:(this.ws.send(JSON.stringify(e)),!0)}async renew(){if(this.closed)return;const e=await r(),n=u();if((await e.prepare("UPDATE machine_links SET lease_expires_at = ? WHERE environment = ? AND generation = ?").run(n,this.environmentId,this.generation)).changes===0){this.ws.close(p,"superseded");return}await e.prepare("UPDATE machine_calls SET lease_expires_at = ? WHERE environment = ? AND state = 'sent' AND claimed_generation = ?").run(n,this.environmentId,this.generation),await e.prepare("UPDATE environments SET last_seen_at = ? WHERE object = ?").run(new Date().toISOString(),this.environmentId),await this.credentialValid()||this.ws.close(C,"revoked")}async credentialValid(){return await E(this.environmentId,this.token)}async claim(){if(!(this.closed||this.claiming)){this.claiming=!0;try{for(;;){const e=await(await r()).prepare(`UPDATE machine_calls SET state = 'sent', claimed_generation = ?, lease_expires_at = ?
2
2
  WHERE call_id IN (SELECT call_id FROM machine_calls WHERE environment = ? AND state = 'pending'
3
3
  AND EXISTS (SELECT 1 FROM machine_links WHERE environment = ? AND generation = ?)
4
4
  ORDER BY created_at FOR UPDATE SKIP LOCKED LIMIT ${w})
5
- RETURNING call_id, op, args_json`).all(this.generation,m(),this.environmentId,this.environmentId,this.generation),t=!this.closed&&await this.isCurrentGeneration();for(const n of e)t?this.send({type:"call",call_id:n.call_id,op:n.op,args:JSON.parse(n.args_json)})||await this.failCall(n.call_id,"machine_offline","link closed before the call was sent",!1):await this.release(n.call_id);if(e.length<w)return}}finally{this.claiming=!1}}}async failCall(e,t,n,a){await this.settle(e,"failed",{code:t,message:n,sent:a},!1)}async isCurrentGeneration(){return await(await r()).prepare("SELECT 1 AS live FROM machine_links WHERE environment = ? AND generation = ?").get(this.environmentId,this.generation)!==void 0}async release(e){await(await r()).prepare("UPDATE machine_calls SET state = 'pending', claimed_generation = NULL, lease_expires_at = NULL WHERE call_id = ? AND state = 'sent' AND claimed_generation = ?").run(e,this.generation)}async settle(e,t,n,a){await B(e,t,n,this.environmentId,this.generation,a)}async onMessage(e){const t=b(e);if(t!==null)switch(t.type){case"result":t.ok?await this.settle(t.call_id,"done",t.value??null,!0):await this.settle(t.call_id,"failed",{code:"machine_call_failed",message:t.error},!0);return;case"view.ready":this.channels.get(t.channel)?.emit("connect");return;case"view.data":this.channels.get(t.channel)?.emit("data",Buffer.from(t.bytes,"base64"));return;case"view.close":this.channels.get(t.channel)?.finish(t.error);return;default:return}}async teardown(){if(this.closed)return;this.closed=!0;for(const n of this.timers)clearInterval(n);this.unsubscribe?.(),c.get(this.environmentId)===this&&c.delete(this.environmentId);for(const n of[...this.channels.values()])n.finish("machine link closed");const e=await r(),t=await e.prepare("SELECT call_id FROM machine_calls WHERE environment = ? AND state = 'sent' AND claimed_generation = ?").all(this.environmentId,this.generation);for(const{call_id:n}of t)await this.failCall(n,"machine_offline","link dropped before the result",!0);await e.prepare("DELETE FROM machine_links WHERE environment = ? AND generation = ?").run(this.environmentId,this.generation)}}async function B(i,e,t,n,a,l){const o=await r();(await o.prepare(`UPDATE machine_calls SET state = ?, result_json = ?, finished_at = ?
5
+ RETURNING call_id, op, args_json`).all(this.generation,u(),this.environmentId,this.environmentId,this.generation),n=!this.closed&&await this.isCurrentGeneration();for(const t of e)n?this.send({type:"call",call_id:t.call_id,op:t.op,args:JSON.parse(t.args_json)})||await this.failCall(t.call_id,"machine_offline","link closed before the call was sent",!1):await this.release(t.call_id);if(e.length<w)return}}finally{this.claiming=!1}}}async failCall(e,n,t,a){await this.settle(e,"failed",{code:n,message:t,sent:a},!1)}async isCurrentGeneration(){return await(await r()).prepare("SELECT 1 AS live FROM machine_links WHERE environment = ? AND generation = ?").get(this.environmentId,this.generation)!==void 0}async release(e){await(await r()).prepare("UPDATE machine_calls SET state = 'pending', claimed_generation = NULL, lease_expires_at = NULL WHERE call_id = ? AND state = 'sent' AND claimed_generation = ?").run(e,this.generation)}async settle(e,n,t,a){await j(e,n,t,this.environmentId,this.generation,a)}async onMessage(e){const n=U(e);if(n!==null)switch(n.type){case"result":n.ok?await this.settle(n.call_id,"done",n.value??null,!0):await this.settle(n.call_id,"failed",{code:"machine_call_failed",message:n.error},!0);return;case"exit":await G(this.environmentId,n);return;case"view.ready":this.channels.get(n.channel)?.emit("connect");return;case"view.data":this.channels.get(n.channel)?.emit("data",Buffer.from(n.bytes,"base64"));return;case"view.close":this.channels.get(n.channel)?.finish(n.error);return;default:return}}async teardown(){if(this.closed)return;this.closed=!0;for(const t of this.timers)clearInterval(t);this.unsubscribe?.(),c.get(this.environmentId)===this&&c.delete(this.environmentId);for(const t of[...this.channels.values()])t.finish("machine link closed");const e=await r(),n=await e.prepare("SELECT call_id FROM machine_calls WHERE environment = ? AND state = 'sent' AND claimed_generation = ?").all(this.environmentId,this.generation);for(const{call_id:t}of n)await this.failCall(t,"machine_offline","link dropped before the result",!0);await e.prepare("DELETE FROM machine_links WHERE environment = ? AND generation = ?").run(this.environmentId,this.generation)}}async function j(i,e,n,t,a,o){const l=await r();(await l.prepare(`UPDATE machine_calls SET state = ?, result_json = ?, finished_at = ?
6
6
  WHERE call_id = ? AND environment = ? AND claimed_generation = ? AND state = 'sent'
7
- ${l?"AND EXISTS (SELECT 1 FROM machine_links WHERE environment = ? AND generation = ?)":""}`).run(e,JSON.stringify(t),new Date().toISOString(),i,n,a,...l?[n,a]:[])).changes>0&&await o.prepare("SELECT pg_notify(?, ?)").get("crtr_signal",`machine_call:${i}`)}s(B,"withNotify");class ee extends u{static{s(this,"MachineViewLink")}link;ended=!1;failed=!1;channel=R();constructor(e,t){super(),this.link=e,e.channels.set(this.channel,this),e.send({type:"view.open",channel:this.channel,node:t})||queueMicrotask(()=>this.finish("machine link closed"))}get destroyed(){return this.ended}write(e){return!this.ended&&this.link.send({type:"view.data",channel:this.channel,bytes:Buffer.from(e).toString("base64")})}destroy(){return this.ended||(this.link.send({type:"view.close",channel:this.channel}),this.finish(void 0)),this}finish(e){this.ended||(this.ended=!0,this.link.channels.delete(this.channel),e!==void 0&&!this.failed&&(this.failed=!0,this.emit("error",Object.assign(new Error(e),{code:"ECONNRESET"}))),this.emit("close",this.failed))}}const te=s(i=>c.get(i)??null,"heldLinkOf"),K=/^\/v1\/machines\/([A-Za-z0-9_-]+)\/link$/;function ne(i){const e=K.exec(new URL(i.url??"/","http://runtime.local").pathname);return e===null?null:e[1]}s(ne,"machineLinkEnvironment");async function ie(i,e,t,n){const a=i.headers.authorization,l=/^Bearer (\S+)$/.exec(Array.isArray(a)?a[0]??"":a??"")?.[1];if(l===void 0||!await E(n,l))return{status:401,text:"Unauthorized",code:"unauthorized",message:"machine credential refused"};const o=new Date().toISOString(),h=await r(),v=await h.prepare(`INSERT INTO machine_links (environment, generation, api_address, connected_at, lease_expires_at) VALUES (?, 1, ?, ?, ?)
7
+ ${o?"AND EXISTS (SELECT 1 FROM machine_links WHERE environment = ? AND generation = ?)":""}`).run(e,JSON.stringify(n),new Date().toISOString(),i,t,a,...o?[t,a]:[])).changes>0&&await l.prepare("SELECT pg_notify(?, ?)").get("crtr_signal",`machine_call:${i}`)}s(j,"withNotify");async function G(i,e){const n=await r(),t=await n.prepare("SELECT stop_requested_at, stop_reason FROM executions WHERE execution_id = ? AND node_id = ? AND runner = 'machine' AND state != 'exited'").get(e.execution,e.node);return t===void 0||await b(e.node)!==i||(await k()).has(e.node)||(await O(e.execution,{code:e.code,signal:e.signal}),!await y(e.execution,{reason:"exited"}))?!1:(t.stop_requested_at===null&&t.stop_reason===null&&await n.prepare("SELECT pg_notify(?, ?)").get("crtr_signal",`execution_exit:${e.node}`),m({level:"info",event:"broker.exit.reported",node_id:e.node,fields:{environment:i,code:e.code,signal:e.signal}}),!0)}s(G,"recordMachineBrokerExit");class le extends _{static{s(this,"MachineViewLink")}link;ended=!1;failed=!1;channel=T();constructor(e,n){super(),this.link=e,e.channels.set(this.channel,this),e.send({type:"view.open",channel:this.channel,node:n})||queueMicrotask(()=>this.finish("machine link closed"))}get destroyed(){return this.ended}write(e){return!this.ended&&this.link.send({type:"view.data",channel:this.channel,bytes:Buffer.from(e).toString("base64")})}destroy(){return this.ended||(this.link.send({type:"view.close",channel:this.channel}),this.finish(void 0)),this}finish(e){this.ended||(this.ended=!0,this.link.channels.delete(this.channel),e!==void 0&&!this.failed&&(this.failed=!0,this.emit("error",Object.assign(new Error(e),{code:"ECONNRESET"}))),this.emit("close",this.failed))}}const ce=s(i=>c.get(i)??null,"heldLinkOf"),V=/^\/v1\/machines\/([A-Za-z0-9_-]+)\/link$/;function de(i){const e=V.exec(new URL(i.url??"/","http://runtime.local").pathname);return e===null?null:e[1]}s(de,"machineLinkEnvironment");async function he(i,e,n,t){const a=i.headers.authorization,o=/^Bearer (\S+)$/.exec(Array.isArray(a)?a[0]??"":a??"")?.[1];if(o===void 0||!await E(t,o))return{status:401,text:"Unauthorized",code:"unauthorized",message:"machine credential refused"};const l=new Date().toISOString(),d=await r(),v=await d.prepare(`INSERT INTO machine_links (environment, generation, api_address, connected_at, lease_expires_at) VALUES (?, 1, ?, ?, ?)
8
8
  ON CONFLICT (environment) DO UPDATE SET generation = machine_links.generation + 1, api_address = EXCLUDED.api_address, connected_at = EXCLUDED.connected_at, lease_expires_at = EXCLUDED.lease_expires_at
9
- RETURNING generation`).get(n,W(),o,m());await h.prepare("UPDATE environments SET last_seen_at = ? WHERE object = ?").run(o,n);const f=Number(v.generation);return e.destroyed?(await h.prepare("DELETE FROM machine_links WHERE environment = ? AND generation = ?").run(n,f),null):(P.handleUpgrade(i,e,t,S=>{const d=new F(n,f,S,l),D=c.get(n);c.set(n,d),D?.ws.close(p,"superseded"),d.start(),d.claim().catch(A=>_({level:"error",event:"daemon.machine_link.claim_failed",fields:{environment:n},error:A}))}),null)}s(ie,"handleMachineLinkUpgrade");export{F as HeldLink,U as LINK_LEASE_MS,x as LINK_PING_MS,C as LINK_RENEW_MS,ee as MachineViewLink,H as UNROUTABLE_PREFIX,W as apiAddress,ie as handleMachineLinkUpgrade,te as heldLinkOf,ne as machineLinkEnvironment,q as setApiAddress};
9
+ RETURNING generation`).get(t,K(),l,u());await d.prepare("UPDATE environments SET last_seen_at = ? WHERE object = ?").run(l,t);const f=Number(v.generation);return e.destroyed?(await d.prepare("DELETE FROM machine_links WHERE environment = ? AND generation = ?").run(t,f),null):(B.handleUpgrade(i,e,n,S=>{const h=new X(t,f,S,o),D=c.get(t);c.set(t,h),D?.ws.close(p,"superseded"),h.start(),h.claim().catch(A=>m({level:"error",event:"daemon.machine_link.claim_failed",fields:{environment:t},error:A}))}),null)}s(he,"handleMachineLinkUpgrade");export{X as HeldLink,H as LINK_LEASE_MS,W as LINK_PING_MS,P as LINK_RENEW_MS,le as MachineViewLink,$ as UNROUTABLE_PREFIX,K as apiAddress,he as handleMachineLinkUpgrade,ce as heldLinkOf,de as machineLinkEnvironment,G as recordMachineBrokerExit,oe as setApiAddress};
@@ -1 +1 @@
1
- var L=Object.defineProperty;var o=(t,e)=>L(t,"name",{value:e,configurable:!0});import{canvasPoolSize as T,openDb as v}from"../../core/canvas/db.js";import{isCloudRole as x}from"../../core/canvas/person.js";import{endLiveExecution as O,liveExecutionForNode as D}from"../../core/canvas/executions.js";import{emitEvent as d}from"../../core/events/emit.js";import{afterRevocationStop as M}from"../../core/grants/on-sync.js";import{allGrants as h,grantIdsWhere as y,grantStanding as E,mirrorOnly as R}from"../../core/grants/mirror.js";import{removeApp as A,removePersonData as P}from"../../core/grants/remove.js";import{wakeAllGrantWaiters as G,wakeGrantWaiters as C}from"../../core/grants/watch.js";import{discardOrphanedTokens as g,discardTokensForGrant as F}from"../../core/providers/token-cache.js";import{isUnsandboxedMachine as W}from"../../core/runtime/unsandboxed.js";import{runnerForExecution as U}from"../../core/runtime/runner/index.js";import{closeGrantStreams as B,heldGrantIds as $}from"../../core/runs/events.js";import{stopNodeSandboxes as H}from"../../core/spaces/stop.js";import{brokerSignalBus as J}from"../broker-signals/bus.js";import{withRowClaim as z}from"./row-claim.js";const K=6e4,V=o(()=>Math.max(1,Math.floor(T()/3)),"grantSlotLimit");let _=0;const b=[];async function X(t){for(;_>=V();)await new Promise(e=>{b.push(e)});_+=1;try{return await t()}finally{_-=1,b.shift()?.()}}o(X,"withGrantSlot");const Y=3e4,j=5;function m(t,e,r){d({level:"error",event:`daemon.grants.${t}`,error:e,fields:r})}o(m,"failed");function q(t,e,r){try{const n=e.sub===null||e.grantee===null?g(r):F({sub:e.sub,grantee:e.grantee,active:e.standing==="active"},r);n.tokens>0&&d({level:"info",event:"daemon.grants.outbound_tokens_discarded",fields:{grant:t,tokens:n.tokens}})}catch(n){m("outbound_tokens_discard_failed",n,{grant:t})}}o(q,"discardTokens");async function N(){try{await(await import("../../core/providers/bundles.js")).syncProviderBundles()}catch(t){d({level:"error",event:"daemon.providers.bundle_sync_failed",error:t})}}o(N,"reconcileProviderBundles");async function Q(t,e){if(C(t),e.standing==="inactive"){const r=B(t);r>0&&d({level:"info",event:"daemon.grants.streams_closed",fields:{grant:t,grantee:e.grantee,streams:r}})}await N()}o(Q,"serveEffects");async function Z(t,e){const r=await z("nodes",t,K,async n=>{const a=await D(t);if(a===null)return;await n.assertOwned(),d({level:"info",event:"daemon.grants.node_stop",node_id:t,fields:{grant:e,execution_id:a.executionId}});const c=o(async()=>{await n.assertOwned(),await O(t,{reason:"permission_revoked"}),await M(t)},"finish");if(a.runner==="process"){const w=await H(t,"permission_revoked",{holdRecovery:!0,after:c});if(!w.confirmed)throw w.error??new Error(`stop of ${t} was not confirmed`);return}const u=await U(a.runner).stop(a,{reason:"permission_revoked"});if(!u.confirmed)throw u.error??new Error(`stop of ${t} was not confirmed`);await c()},{waitForLock:!0})}o(Z,"stopRevokedNode");async function I(t,e){if(!(e.grantee!==null&&R({grantee:e.grantee}))){if(e.standing==="inactive"){const r=await(await v()).prepare("SELECT DISTINCT n.node_id FROM nodes n JOIN executions e ON e.node_id = n.node_id AND e.state != 'exited' WHERE n.grant_id = ?").all(t);for(const{node_id:n}of r)try{await Z(n,t)}catch(a){m("node_stop_failed",a,{grant:t,node_id:n})}}if(e.status==="removed"&&e.removal_done_at===null&&e.grantee!==null&&e.sub!==null)try{e.grantee!=="app:terminal"?await A(e.grantee,e.sub):x()?await P(e.grantee,e.sub):d({level:"info",event:"daemon.grants.removal_settled_without_cleanup",fields:{grant:t,grantee:e.grantee,sub:e.sub}}),await(await v()).prepare("UPDATE grants SET removal_done_at = ? WHERE id = ? AND rev = ? AND removal_done_at IS NULL").run(new Date().toISOString(),t,e.rev)}catch(r){m("removal_failed",r,{grant:t,grantee:e.grantee})}}}o(I,"laneEffects");async function ee(t,e,r){let n;await X(async()=>{const a=await E(e);q(e,a,r??await h()),t.serves&&(n=Q(e,a)),t.runsLanes&&a.standing!=="lagging"&&await I(e,a)}),await n}o(ee,"applyGrantEffects");async function te(t){const e=new Set;if(t.serves)for(const n of $())e.add(n);if(t.runsLanes){const n=await(await v()).prepare("SELECT DISTINCT n.grant_id FROM nodes n JOIN executions e ON e.node_id = n.node_id AND e.state != 'exited' WHERE n.grant_id IS NOT NULL").all();for(const{grant_id:a}of n)e.add(a)}const r=[];for(const n of e)(await E(n)).status===null&&r.push(n);return r}o(te,"goneGrantIds");async function Se(t,e={}){const r=new Map,n=o((s,l)=>{const i=(r.get(s)??Promise.resolve()).then(()=>ee(t,s,l)).catch(f=>m("effects_failed",f,{grant:s})).finally(()=>{r.get(s)===i&&r.delete(s)});return r.set(s,i),i},"run"),a=o(async()=>{const s=t.serves?N():void 0;try{t.serves&&G();const l=await h();g(l);const i=new Set(await y(`status <> 'active' OR expires_at <= '${new Date().toISOString()}'`));for(const f of await te(t))i.add(f);await Promise.all([...i].map(f=>n(f,l)))}catch(l){m("catch_up_failed",l,{})}await s},"catchUp"),c=new Map;let u=!1;const w=o(async()=>{if(!u){u=!0;try{const s=new Set(await y(`status = 'removed' AND removal_done_at IS NULL${W()?" AND grantee = 'app:terminal'":""}`));for(const i of c.keys())s.has(i)||c.delete(i);const l=[...s].filter(i=>!r.has(i)&&(c.get(i)?.notBefore??0)<=Date.now());await Promise.all(l.map(async i=>{await n(i);const f=(c.get(i)?.failures??0)+1;c.set(i,{failures:f,notBefore:Date.now()+S*2**Math.min(f,j)})}))}catch(s){m("removal_sweep_failed",s,{})}finally{u=!1}}},"sweepRemovals"),S=e.sweepMs??Y,p=t.runsLanes?setInterval(()=>{w()},S):void 0;p?.unref();const k=await J.subscribe(s=>{n(s)},{kinds:["grant"],onListenStart:o(()=>{a()},"onListenStart")});return()=>{p!==void 0&&clearInterval(p),k()}}o(Se,"startGrantEffects");export{ee as applyGrantEffects,Se as startGrantEffects};
1
+ var L=Object.defineProperty;var a=(t,e)=>L(t,"name",{value:e,configurable:!0});import{canvasPoolSize as T,openDb as v}from"../../core/canvas/db.js";import{isCloudRole as x}from"../../core/canvas/person.js";import{endLiveExecution as O,liveExecutionForNode as R}from"../../core/canvas/executions.js";import{emitEvent as m}from"../../core/events/emit.js";import{afterRevocationStop as D}from"../../core/grants/on-sync.js";import{allGrants as y,grantIdsWhere as S,grantStanding as E,mirrorOnly as M}from"../../core/grants/mirror.js";import{removeApp as A,removePersonData as P}from"../../core/grants/remove.js";import{wakeAllGrantWaiters as G,wakeGrantWaiters as C}from"../../core/grants/watch.js";import{discardOrphanedTokens as g,discardTokensForGrant as F}from"../../core/providers/token-cache.js";import{isUnsandboxedMachine as W}from"../../core/runtime/unsandboxed.js";import{runnerForExecution as U}from"../../core/runtime/runner/index.js";import{closeGrantStreams as B,heldGrantIds as $}from"../../core/runs/events.js";import{stopNodeSandboxes as H}from"../../core/spaces/stop.js";import{holdRecovery as J}from"../../core/runtime/recovery-hold.js";import{brokerSignalBus as z}from"../broker-signals/bus.js";import{withRowClaim as K}from"./row-claim.js";const V=6e4,X=a(()=>Math.max(1,Math.floor(T()/3)),"grantSlotLimit");let _=0;const b=[];async function Y(t){for(;_>=X();)await new Promise(e=>{b.push(e)});_+=1;try{return await t()}finally{_-=1,b.shift()?.()}}a(Y,"withGrantSlot");const j=3e4,q=5;function w(t,e,r){m({level:"error",event:`daemon.grants.${t}`,error:e,fields:r})}a(w,"failed");function Q(t,e,r){try{const n=e.sub===null||e.grantee===null?g(r):F({sub:e.sub,grantee:e.grantee,active:e.standing==="active"},r);n.tokens>0&&m({level:"info",event:"daemon.grants.outbound_tokens_discarded",fields:{grant:t,tokens:n.tokens}})}catch(n){w("outbound_tokens_discard_failed",n,{grant:t})}}a(Q,"discardTokens");async function N(){try{await(await import("../../core/providers/bundles.js")).syncProviderBundles()}catch(t){m({level:"error",event:"daemon.providers.bundle_sync_failed",error:t})}}a(N,"reconcileProviderBundles");async function Z(t,e){if(C(t),e.standing==="inactive"){const r=B(t);r>0&&m({level:"info",event:"daemon.grants.streams_closed",fields:{grant:t,grantee:e.grantee,streams:r}})}await N()}a(Z,"serveEffects");async function I(t,e){const r=await K("nodes",t,V,async n=>{const o=await R(t);if(o===null)return;await n.assertOwned(),m({level:"info",event:"daemon.grants.node_stop",node_id:t,fields:{grant:e,execution_id:o.executionId}});const c=a(async()=>{await n.assertOwned(),await O(t,{reason:"permission_revoked"}),await D(t)},"finish");if(o.runner==="process"){const u=await H(t,"permission_revoked",{holdRecovery:!0,after:c});if(!u.confirmed)throw u.error??new Error(`stop of ${t} was not confirmed`);return}const d=await J(t);if(d!==null)try{const u=await U(o.runner).stop(o,{reason:"permission_revoked"});if(!u.confirmed)throw u.error??new Error(`stop of ${t} was not confirmed`);await c()}finally{await d.release()}},{waitForLock:!0})}a(I,"stopRevokedNode");async function ee(t,e){if(!(e.grantee!==null&&M({grantee:e.grantee}))){if(e.standing==="inactive"){const r=await(await v()).prepare("SELECT DISTINCT n.node_id FROM nodes n JOIN executions e ON e.node_id = n.node_id AND e.state != 'exited' WHERE n.grant_id = ?").all(t);for(const{node_id:n}of r)try{await I(n,t)}catch(o){w("node_stop_failed",o,{grant:t,node_id:n})}}if(e.status==="removed"&&e.removal_done_at===null&&e.grantee!==null&&e.sub!==null)try{e.grantee!=="app:terminal"?await A(e.grantee,e.sub):x()?await P(e.grantee,e.sub):m({level:"info",event:"daemon.grants.removal_settled_without_cleanup",fields:{grant:t,grantee:e.grantee,sub:e.sub}}),await(await v()).prepare("UPDATE grants SET removal_done_at = ? WHERE id = ? AND rev = ? AND removal_done_at IS NULL").run(new Date().toISOString(),t,e.rev)}catch(r){w("removal_failed",r,{grant:t,grantee:e.grantee})}}}a(ee,"laneEffects");async function te(t,e,r){let n;await Y(async()=>{const o=await E(e);Q(e,o,r??await y()),t.serves&&(n=Z(e,o)),t.runsLanes&&o.standing!=="lagging"&&await ee(e,o)}),await n}a(te,"applyGrantEffects");async function re(t){const e=new Set;if(t.serves)for(const n of $())e.add(n);if(t.runsLanes){const n=await(await v()).prepare("SELECT DISTINCT n.grant_id FROM nodes n JOIN executions e ON e.node_id = n.node_id AND e.state != 'exited' WHERE n.grant_id IS NOT NULL").all();for(const{grant_id:o}of n)e.add(o)}const r=[];for(const n of e)(await E(n)).status===null&&r.push(n);return r}a(re,"goneGrantIds");async function Se(t,e={}){const r=new Map,n=a((s,l)=>{const i=(r.get(s)??Promise.resolve()).then(()=>te(t,s,l)).catch(f=>w("effects_failed",f,{grant:s})).finally(()=>{r.get(s)===i&&r.delete(s)});return r.set(s,i),i},"run"),o=a(async()=>{const s=t.serves?N():void 0;try{t.serves&&G();const l=await y();g(l);const i=new Set(await S(`status <> 'active' OR expires_at <= '${new Date().toISOString()}'`));for(const f of await re(t))i.add(f);await Promise.all([...i].map(f=>n(f,l)))}catch(l){w("catch_up_failed",l,{})}await s},"catchUp"),c=new Map;let d=!1;const u=a(async()=>{if(!d){d=!0;try{const s=new Set(await S(`status = 'removed' AND removal_done_at IS NULL${W()?" AND grantee = 'app:terminal'":""}`));for(const i of c.keys())s.has(i)||c.delete(i);const l=[...s].filter(i=>!r.has(i)&&(c.get(i)?.notBefore??0)<=Date.now());await Promise.all(l.map(async i=>{await n(i);const f=(c.get(i)?.failures??0)+1;c.set(i,{failures:f,notBefore:Date.now()+h*2**Math.min(f,q)})}))}catch(s){w("removal_sweep_failed",s,{})}finally{d=!1}}},"sweepRemovals"),h=e.sweepMs??j,p=t.runsLanes?setInterval(()=>{u()},h):void 0;p?.unref();const k=await z.subscribe(s=>{n(s)},{kinds:["grant"],onListenStart:a(()=>{o()},"onListenStart")});return()=>{p!==void 0&&clearInterval(p),k()}}a(Se,"startGrantEffects");export{te as applyGrantEffects,Se as startGrantEffects};
@@ -0,0 +1,5 @@
1
+ /** Ends each `running` machine execution whose machine reports no broker for it. The rows are read before the call, so a broker that
2
+ * started after the scan is never judged by it (its execution was not yet `running`). An environment whose call fails (offline, lost)
3
+ * is left as it is. A machine on a release before `status.all` is asked per execution with `status`, as before. A node held by an
4
+ * import is left to the import. Returns the nodes whose execution this call ended, so the caller can re-read their rows. */
5
+ export declare function endGoneMachineExecutions(): Promise<ReadonlySet<string>>;
@@ -0,0 +1,4 @@
1
+ var s=Object.defineProperty;var c=(n,o)=>s(n,"name",{value:o,configurable:!0});import{openDb as l}from"../../../core/canvas/db.js";import{endExecution as m,liveExecutionForNode as f}from"../../../core/canvas/executions.js";import{emitEvent as d}from"../../../core/events/emit.js";import{callMachine as u}from"../../../core/runtime/runner/machine/call.js";import{MachineCallFailedError as p,MachineOfflineError as x}from"../../../core/runtime/runner/machine/ops.js";import{importedNodesHeld as h}from"../live-obligation.js";import{endRemoteExecutionIfGone as w}from"./remote-wake.js";async function I(){const n=new Set;let o,a;try{a=await h(),o=await(await l()).prepare(`SELECT x.execution_id, x.node_id, e.object AS environment
2
+ FROM executions x JOIN nodes n ON n.node_id = x.node_id JOIN profiles p ON p.id = n.profile_id
3
+ JOIN environments e ON e.object = p.environment_id AND e.kind = 'machine'
4
+ WHERE x.state = 'running' AND x.runner = 'machine'`).all()}catch(e){return d({level:"error",event:"execution.machine_check_failed",error:e}),n}const i=new Map;for(const e of o)a.has(e.node_id)||i.set(e.environment,[...i.get(e.environment)??[],e]);return await Promise.all([...i].map(async([e,t])=>{try{await _(e,t,n)}catch(r){d({level:r instanceof x?"debug":"warn",event:"execution.machine_check_failed",fields:{environment:e},error:r})}})),n}c(I,"endGoneMachineExecutions");async function _(n,o,a){let i;try{i=new Set((await u(n,"status.all",{})).running.map(e=>e.execution))}catch(e){if(!(e instanceof p&&e.message.includes("does not execute status.all")))throw e;for(const{node_id:t}of o){const r=await f(t);r?.state==="running"&&r.runner==="machine"&&await w(r)&&a.add(t)}return}for(const{execution_id:e,node_id:t}of o)i.has(e)||await m(e,{reason:"lost"})&&(a.add(t),d({level:"warn",event:"execution.lost",node_id:t}))}c(_,"endGoneOn");export{I as endGoneMachineExecutions};
@@ -17,6 +17,9 @@ export declare function isLaunchInFlight(row: Pick<NodeRow, 'created' | 'launche
17
17
  export declare class NodeLifecycleReconciler {
18
18
  private readonly freezeLane;
19
19
  run(now: number, ctx: NodeLifecycleContext): Promise<FrozenCounts>;
20
+ /** The pass for one node whose broker exit was just reported (`execution_exit`), so its relaunch does not wait for the next tick. */
21
+ runNode(now: number, row: NodeRow, fleet: FleetRegistry): Promise<void>;
22
+ private pass;
20
23
  private classifyRow;
21
24
  private thawMark;
22
25
  /** An idle row with no wake-worthy inbox entry still needs the lifecycle
@@ -1 +1 @@
1
- var g=Object.defineProperty;var o=(s,i)=>g(s,"name",{value:i,configurable:!0});import{clearFrozen as P,getNode as z}from"../../../core/canvas/index.js";import{isSafeNodeId as L}from"../../../core/canvas/paths.js";import{recordedPidLiveness as x}from"../../../core/canvas/pid.js";import{endExecution as v,hasAbsorbedProfilePauseStop as N,hasObservedExit as M,latestExecutionForNode as w,liveExecutionForNode as c}from"../../../core/canvas/executions.js";import{emitEvent as I}from"../../../core/events/emit.js";import{operationIdContext as D}from"../../../core/events/operation-id.js";import{readInterruptedTurn as F}from"../../../core/canvas/recovery.js";import{isProfilePaused as d}from"../../../core/profiles/manifest.js";import{isRecoveryHeld as E}from"../../../core/runtime/recovery-hold.js";import{hasUnseenWakeMail as p}from"../../../core/canvas/deliveries.js";import{hasIdleReleaseIntent as A,isParkedResident as C}from"../../../core/runtime/lifecycle.js";import{classifyDeadNode as S}from"../../fleet.js";import{applyParkEvent as T,hasPendingWake as U,parkEvent as W}from"../live-obligation.js";import{FreezeLaneReconciler as B}from"./freeze-lane.js";import{isInBackoff as k}from"./respawn-policy.js";import{asNodePerson as G,NodePersonUnresolvedError as R}from"./node-person.js";import{handleTerminatingRow as H}from"./terminating.js";import{wantsExecution as O}from"./wants-execution.js";import{enactRequestedStops as q}from"./requested-stops.js";import{endRemoteExecutionIfGone as j,recoverLaunching as J,wakeResident as K}from"./remote-wake.js";import{isDrained as Q}from"../../drain.js";function V(s){return s.status==="done"||s.status==="canceled"||s.status==="dead"}o(V,"isTerminal");const X=12e4;function Y(s,i,e){const n=Math.max(...[s.created,s.launched_at].map(r=>r==null?0:Date.parse(r)||0));return n>0&&i-n<X&&e?.state!=="exited"}o(Y,"isLaunchInFlight");async function b(s){const i=await c(s);return i!==null&&i.state==="running"&&i.pid!=null&&x(i.pid,i.processIdentity)==="dead"?i:null}o(b,"executionWithDeadPid");class we{static{o(this,"NodeLifecycleReconciler")}freezeLane=new B;async run(i,e){const n=[];await q(i);for(const r of e.rows)await D.fresh(async()=>{try{await G(r,()=>this.classifyRow(i,r,e,n))}catch(t){const l=r.node_id;I({level:t instanceof R?"warn":"error",event:t instanceof R?"node.lifecycle.person_unresolved":"node.lifecycle.classify_failed",...L(l)?{node_id:l}:{fields:{affected_node_id:l}},error:t})}});return await Q()?{stalled:0,waitingOnMail:0}:this.freezeLane.run(i,{fleet:e.fleet,candidates:n})}async classifyRow(i,e,n,r){const t=e.node_id;if(V(e)){if(H(e,await n.fleet.has(t)))return;if(C(e)&&!await n.fleet.has(t)&&!d(e.profile_id)&&!await E(t)&&!k(e,i)&&await p(t)){r.push({row:e,enact:"reopen"});return}if(e.pi_pid!=null){const a=await b(t);a!==null&&await v(a.executionId,{reason:"observed-dead"})}e.frozen_at!=null&&(e.final_report!=null||e.status==="dead"?await P(t):r.push({row:e,enact:"thaw"}));return}if(await n.fleet.has(t)){const a=await c(t);if(a?.runner!==void 0&&a.runner!=="process"&&a.state==="running"&&!d(e.profile_id)&&await p(t)){if(await K(a)==="lost")return}else a?.runner!==void 0&&a.runner!=="process"&&a.state==="running"&&await j(a);if(await n.fleet.has(t)){d(e.profile_id)?await n.fleet.interruptForProfilePause(t):await this.thawMark(e);return}}if(await J(t,i))return;if(d(e.profile_id)){await this.freezeLane.endEpisode(t);return}if(await E(t))return;const l=e.pi_pid==null?await w(t):null,f=l!==null&&M(l),m=l!==null&&!f&&N(l),h=e.pi_pid!=null?await b(t):null,_=f||m||h!==null;if(_&&!await n.fleet.hasProfilePauseInterruption(t)){const a=h??l;a!==null&&await v(a.executionId,{reason:"observed-dead"});const y=await c(t);if(y!==null&&y.executionId!==a?.executionId)return}if(!await O(e)){await this.thawMark(e),await this.settleParked(e);return}if(k(e,i))return;if(e.status==="idle"&&A(e)&&await p(t)){r.push({row:e,enact:"idle-release"});return}if(e.pi_pid==null&&(!f||e.frozen_at!=null)&&!m){if(e.respawn_not_before!=null){r.push({row:e,enact:"policy"});return}if(e.frozen_at!=null){r.push({row:e,enact:"thaw"});return}if(await n.fleet.isClaimed(t)||Y(e,i,await w(t)))return;I({level:"warn",event:"node.lifecycle.stranded_launch",node_id:t}),r.push({row:e,enact:"thaw"});return}if(!_)return;const u=S(await z(t),(await F(t))?.interrupted===!0,await U(t));if(u==="respawn-fresh"||u==="respawn-cycle"||u==="respawn-resume"){r.push({row:e,enact:"policy"});return}await n.fleet.applyDeadRowPolicy(t),await this.thawMark(e)}async thawMark(i){i.frozen_at!=null&&await P(i.node_id)}async settleParked(i){if(i.status!=="idle")return;await this.freezeLane.endEpisode(i.node_id);const e=await W(i.node_id,i.lifecycle);e!=="release"&&await T(i.node_id,e)}}export{X as LAUNCH_GRACE_MS,we as NodeLifecycleReconciler,Y as isLaunchInFlight};
1
+ var g=Object.defineProperty;var l=(s,a)=>g(s,"name",{value:a,configurable:!0});import{clearFrozen as w,getNode as z,getRow as L}from"../../../core/canvas/index.js";import{isSafeNodeId as N}from"../../../core/canvas/paths.js";import{recordedPidLiveness as x}from"../../../core/canvas/pid.js";import{endExecution as P,hasAbsorbedProfilePauseStop as M,hasObservedExit as D,latestExecutionForNode as v,liveExecutionForNode as c}from"../../../core/canvas/executions.js";import{emitEvent as E}from"../../../core/events/emit.js";import{operationIdContext as F}from"../../../core/events/operation-id.js";import{readInterruptedTurn as A}from"../../../core/canvas/recovery.js";import{isProfilePaused as d}from"../../../core/profiles/manifest.js";import{isRecoveryHeld as I}from"../../../core/runtime/recovery-hold.js";import{hasUnseenWakeMail as p}from"../../../core/canvas/deliveries.js";import{hasIdleReleaseIntent as C,isParkedResident as S}from"../../../core/runtime/lifecycle.js";import{classifyDeadNode as G}from"../../fleet.js";import{applyParkEvent as T,hasPendingWake as U,parkEvent as W}from"../live-obligation.js";import{FreezeLaneReconciler as B}from"./freeze-lane.js";import{isInBackoff as R}from"./respawn-policy.js";import{asNodePerson as H,NodePersonUnresolvedError as k}from"./node-person.js";import{handleTerminatingRow as O}from"./terminating.js";import{wantsExecution as q}from"./wants-execution.js";import{enactRequestedStops as j}from"./requested-stops.js";import{endRemoteExecutionIfGone as J,recoverLaunching as K,wakeResident as Q}from"./remote-wake.js";import{endGoneMachineExecutions as V}from"./machine-sweep.js";import{isDrained as X}from"../../drain.js";function Y(s){return s.status==="done"||s.status==="canceled"||s.status==="dead"}l(Y,"isTerminal");const Z=12e4;function $(s,a,e){const i=Math.max(...[s.created,s.launched_at].map(n=>n==null?0:Date.parse(n)||0));return i>0&&a-i<Z&&e?.state!=="exited"}l($,"isLaunchInFlight");async function b(s){const a=await c(s);return a!==null&&a.state==="running"&&a.pid!=null&&x(a.pid,a.processIdentity)==="dead"?a:null}l(b,"executionWithDeadPid");class Re{static{l(this,"NodeLifecycleReconciler")}freezeLane=new B;async run(a,e){await j(a);const i=await V();if(i.size===0)return await this.pass(a,e);const n=await Promise.all(e.rows.map(async t=>i.has(t.node_id)?await L(t.node_id)??t:t));return await this.pass(a,{...e,rows:n})}async runNode(a,e,i){await this.pass(a,{rows:[e],fleet:i})}async pass(a,e){const i=[];for(const n of e.rows)await F.fresh(async()=>{try{await H(n,()=>this.classifyRow(a,n,e,i))}catch(t){const o=n.node_id;E({level:t instanceof k?"warn":"error",event:t instanceof k?"node.lifecycle.person_unresolved":"node.lifecycle.classify_failed",...N(o)?{node_id:o}:{fields:{affected_node_id:o}},error:t})}});return await X()?{stalled:0,waitingOnMail:0}:this.freezeLane.run(a,{fleet:e.fleet,candidates:i})}async classifyRow(a,e,i,n){const t=e.node_id;if(Y(e)){if(O(e,await i.fleet.has(t)))return;if(S(e)&&!await i.fleet.has(t)&&!d(e.profile_id)&&!await I(t)&&!R(e,a)&&await p(t)){n.push({row:e,enact:"reopen"});return}if(e.pi_pid!=null){const r=await b(t);r!==null&&await P(r.executionId,{reason:"observed-dead"})}e.frozen_at!=null&&(e.final_report!=null||e.status==="dead"?await w(t):n.push({row:e,enact:"thaw"}));return}if(await i.fleet.has(t)){const r=await c(t);if(r?.runner!==void 0&&r.runner!=="process"&&r.state==="running"&&!d(e.profile_id)&&await p(t)){if(await Q(r)==="lost")return}else r?.runner==="blaxel"&&r.state==="running"&&await J(r);if(await i.fleet.has(t)){d(e.profile_id)?await i.fleet.interruptForProfilePause(t):await this.thawMark(e);return}}if(await K(t,a))return;if(d(e.profile_id)){await this.freezeLane.endEpisode(t);return}if(await I(t))return;const o=e.pi_pid==null?await v(t):null,f=o!==null&&D(o),m=o!==null&&!f&&M(o),h=e.pi_pid!=null?await b(t):null,_=f||m||h!==null;if(_&&!await i.fleet.hasProfilePauseInterruption(t)){const r=h??o;r!==null&&await P(r.executionId,{reason:"observed-dead"});const y=await c(t);if(y!==null&&y.executionId!==r?.executionId)return}if(!await q(e)){await this.thawMark(e),await this.settleParked(e);return}if(R(e,a))return;if(e.status==="idle"&&C(e)&&await p(t)){n.push({row:e,enact:"idle-release"});return}if(e.pi_pid==null&&(!f||e.frozen_at!=null)&&!m){if(e.respawn_not_before!=null){n.push({row:e,enact:"policy"});return}if(e.frozen_at!=null){n.push({row:e,enact:"thaw"});return}if(await i.fleet.isClaimed(t)||$(e,a,await v(t)))return;E({level:"warn",event:"node.lifecycle.stranded_launch",node_id:t}),n.push({row:e,enact:"thaw"});return}if(!_)return;const u=G(await z(t),(await A(t))?.interrupted===!0,await U(t));if(u==="respawn-fresh"||u==="respawn-cycle"||u==="respawn-resume"){n.push({row:e,enact:"policy"});return}await i.fleet.applyDeadRowPolicy(t),await this.thawMark(e)}async thawMark(a){a.frozen_at!=null&&await w(a.node_id)}async settleParked(a){if(a.status!=="idle")return;await this.freezeLane.endEpisode(a.node_id);const e=await W(a.node_id,a.lifecycle);e!=="release"&&await T(a.node_id,e)}}export{Z as LAUNCH_GRACE_MS,Re as NodeLifecycleReconciler,$ as isLaunchInFlight};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.662",
3
+ "version": "0.3.663",
4
4
  "description": "crtr — agent runtime with memory, plugins, and marketplaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -149,7 +149,7 @@
149
149
  },
150
150
  "license": "UNLICENSED",
151
151
  "dependencies": {
152
- "@north-light/identity": "0.3.662",
152
+ "@north-light/identity": "0.3.663",
153
153
  "@earendil-works/chord": "1.5.2",
154
154
  "@earendil-works/pi-agent-core": "1.5.2",
155
155
  "@earendil-works/pi-ai": "1.5.2",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.662",
3
+ "version": "0.3.663",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.662",
3
+ "version": "0.3.663",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.662",
9
+ "version": "0.3.663",
10
10
  "hasInstallScript": true,
11
11
  "license": "UNLICENSED",
12
12
  "workspaces": [
@@ -28,7 +28,7 @@
28
28
  "@milkdown/preset-gfm": "^7.22.3",
29
29
  "@milkdown/prose": "^7.22.3",
30
30
  "@milkdown/utils": "^7.22.3",
31
- "@north-light/identity": "0.3.662",
31
+ "@north-light/identity": "0.3.663",
32
32
  "cron-parser": "^5.6.0",
33
33
  "esbuild": "0.28.2",
34
34
  "jose": "^6.2.12",
@@ -10666,17 +10666,17 @@
10666
10666
  },
10667
10667
  "packages/crouter-api": {
10668
10668
  "name": "@north-light/api",
10669
- "version": "0.3.662",
10669
+ "version": "0.3.663",
10670
10670
  "license": "UNLICENSED"
10671
10671
  },
10672
10672
  "packages/crouter-env-docker": {
10673
10673
  "name": "@north-light/env-docker",
10674
- "version": "0.3.662",
10674
+ "version": "0.3.663",
10675
10675
  "license": "UNLICENSED"
10676
10676
  },
10677
10677
  "packages/crouter-identity": {
10678
10678
  "name": "@north-light/identity",
10679
- "version": "0.3.662",
10679
+ "version": "0.3.663",
10680
10680
  "license": "UNLICENSED",
10681
10681
  "dependencies": {
10682
10682
  "jose": "^6.2.1"
@@ -10684,21 +10684,21 @@
10684
10684
  },
10685
10685
  "packages/crouter-plugin": {
10686
10686
  "name": "@north-light/plugin",
10687
- "version": "0.3.662",
10687
+ "version": "0.3.663",
10688
10688
  "license": "UNLICENSED",
10689
10689
  "dependencies": {
10690
- "@north-light/api": "0.3.662",
10691
- "@north-light/identity": "0.3.662"
10690
+ "@north-light/api": "0.3.663",
10691
+ "@north-light/identity": "0.3.663"
10692
10692
  }
10693
10693
  },
10694
10694
  "packages/crouter-sdk": {
10695
10695
  "name": "@north-light/sdk",
10696
- "version": "0.3.662",
10696
+ "version": "0.3.663",
10697
10697
  "license": "UNLICENSED",
10698
10698
  "dependencies": {
10699
- "@north-light/api": "0.3.662",
10700
- "@north-light/identity": "0.3.662",
10701
- "@north-light/plugin": "0.3.662",
10699
+ "@north-light/api": "0.3.663",
10700
+ "@north-light/identity": "0.3.663",
10701
+ "@north-light/plugin": "0.3.663",
10702
10702
  "jose": "^6.2.1"
10703
10703
  },
10704
10704
  "bin": {