@lensmcp/cluster 1.25.56 → 1.25.58
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.
package/devserver-notifier.d.ts
CHANGED
|
@@ -31,7 +31,18 @@ export declare class DevserverNotifier {
|
|
|
31
31
|
private building;
|
|
32
32
|
/** The pod generation this build's tree was started as — said on every notice (notice-generation.ts). */
|
|
33
33
|
private readonly generation;
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The testimony is OWED to the parent until this time: a notice that carried it did not reach this tree's parent
|
|
36
|
+
* ({@link owe}). 0: nothing is owed.
|
|
37
|
+
*/
|
|
38
|
+
private owedUntil;
|
|
39
|
+
private owedTimer;
|
|
40
|
+
private readonly owedPollMs;
|
|
41
|
+
private readonly owedForMs;
|
|
42
|
+
constructor(port: number, secure?: boolean, controlSock?: string, managed?: boolean, generation?: number | undefined, owed?: {
|
|
43
|
+
pollMs?: number;
|
|
44
|
+
forMs?: number;
|
|
45
|
+
});
|
|
35
46
|
/**
|
|
36
47
|
* Deliver to the parent's CONTROL SOCKET first (`$TMPDIR[/<wsKey>]/<service>-devserver/parent.sock`), then
|
|
37
48
|
* the TCP port. The socket path is bind-STOLEN by whichever parent generation started last, so during a
|
|
@@ -43,6 +54,31 @@ export declare class DevserverNotifier {
|
|
|
43
54
|
* — it rejects with {@link NotThisGeneration} and is never retried on the port, which is the same other parent's.
|
|
44
55
|
*/
|
|
45
56
|
private post;
|
|
57
|
+
/**
|
|
58
|
+
* A notice that carries the testimony — `/webpack/watching`, or `/webpack/reload` with it in its body. One that does
|
|
59
|
+
* not reach this tree's parent leaves the testimony owed ({@link owe}); one that does pays what was owed.
|
|
60
|
+
*/
|
|
61
|
+
private tell;
|
|
62
|
+
/**
|
|
63
|
+
* The testimony did not reach this tree's parent, so it is sent again once the parent answers on the control socket
|
|
64
|
+
* (issues/closed/overseer-16). Two ways it is missed, every time:
|
|
65
|
+
* - A FIRST build ends before its parent exists: the serve executor forks the devserver parent only after the first
|
|
66
|
+
* good build, so that build's `watchRun` and `built` find no control socket.
|
|
67
|
+
* - A rolling recycle's STANDBY builds while the generation it replaces still holds the socket: that parent answers
|
|
68
|
+
* 409 (not this generation) until the standby's own parent starts and takes the socket over.
|
|
69
|
+
* Either way the parent started with no testimony, so its pods answered `/__lensmcp/alive` with no `watcher` until
|
|
70
|
+
* their watcher next woke — which a file the bundle does not import never does. At the next source-set change the
|
|
71
|
+
* gateway read them as unverifiable and recycled them (`LENSMCP_POD_WATCHER_UNVERIFIED=recycle`): one file added under
|
|
72
|
+
* FoodGuard's shared/contracts recycled seven pods in one sweep. Sent again, the testimony makes them read «silent»,
|
|
73
|
+
* which the gateway keeps (`LENSMCP_POD_WATCHER_SILENT=keep`).
|
|
74
|
+
*
|
|
75
|
+
* Only the testimony is sent again — never a reload: a parent that starts after a build loads that build. Bounded:
|
|
76
|
+
* {@link OWED_FOR_MS} after the last miss, it is let go. Not for a frozen service (`LENSMCP_FREEZE=1`): it compiles
|
|
77
|
+
* once and has no watcher, and its testimony would read as one that will see a change.
|
|
78
|
+
*/
|
|
79
|
+
private owe;
|
|
80
|
+
private paid;
|
|
81
|
+
private payOwed;
|
|
46
82
|
/** The current testimony snapshot (the wire shape the parent receives). */
|
|
47
83
|
snapshot(): PodWatcherTestimonyWire;
|
|
48
84
|
/** The watcher started a run for these changed paths. */
|
package/devserver-notifier.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var g=(a,t)=>v(a,"name",{value:t,configurable:!0});var m=Object.defineProperty,h=g((a,t)=>m(a,"name",{value:t,configurable:!0}),"h");Object.defineProperty(exports,"__esModule",{value:!0}),exports.DevserverNotifier=void 0,exports.devserverControlSock=devserverControlSock;const tslib_1=require("tslib"),fs=tslib_1.__importStar(require("node:fs")),os=tslib_1.__importStar(require("node:os")),path=tslib_1.__importStar(require("node:path")),notice_generation_1=require("./notice-generation");class DevserverNotifier{static{g(this,"DevserverNotifier")}static{h(this,"DevserverNotifier")}static{this.RECENT_PATH_CAP=32}static{this.BUILD_PATH_CAP=50}constructor(t,e=!1,i,o=Number(process.env.LENSMCP_GATEWAY_PID??0)>0,c=(0,notice_generation_1.generationFromEnv)(),l={}){this.testimony={schemaVersion:1,lastWatchRunAt:0,lastBuildAt:0,buildsSinceSpawn:0,degraded:!1,recentPaths:[]},this.owedUntil=0,this.managed=o,this.owedPollMs=l.pollMs??OWED_POLL_MS,this.owedForMs=l.forMs??OWED_FOR_MS,this.secure=e,this.base=`${e?"https":"http"}://localhost:${t}`,this.controlSock=i,this.generation=c}post(t,e){const i=JSON.stringify(e),o={"content-type":"application/json",...this.generation!==void 0?{[notice_generation_1.NOTICE_GENERATION_HEADER]:String(this.generation)}:{}},c=h((s,n,r)=>{if(s.statusCode!==409||this.generation===void 0){s.resume(),s.on("end",n);return}let d="";s.setEncoding("utf8"),s.on("data",u=>{d+=u}),s.on("end",()=>{let u;try{u=JSON.parse(d).generation}catch{}r(new notice_generation_1.NotThisGeneration(this.generation,u))})},"answered"),l=h(()=>new Promise((s,n)=>{const r=(this.secure?require("node:https"):require("node:http")).request(`${this.base}${t}`,{method:"POST",headers:o,rejectUnauthorized:!1},d=>c(d,s,n));r.on("error",n),r.end(i)}),"viaTcp"),w=this.controlSock;return!w||!fs.existsSync(w)?this.managed?Promise.reject(new Error("the devserver control socket is not up yet")):l():new Promise((s,n)=>{const r=require("node:http").request({socketPath:w,path:t,method:"POST",headers:o},d=>c(d,s,n));r.on("error",n),r.end(i)}).catch(s=>{if(this.managed||s instanceof notice_generation_1.NotThisGeneration)throw s;return l()})}tell(t,e){return this.post(t,e).then(()=>{this.paid()},i=>{throw this.managed&&this.owe(),i})}owe(){process.env.LENSMCP_FREEZE==="1"||!this.controlSock||(this.owedUntil=Date.now()+this.owedForMs,!this.owedTimer&&(this.owedTimer=setTimeout(()=>this.payOwed(),this.owedPollMs),this.owedTimer.unref?.()))}paid(){this.owedUntil=0,this.owedTimer&&clearTimeout(this.owedTimer),this.owedTimer=void 0}payOwed(){if(this.owedTimer=void 0,!this.owedUntil)return;const t=h(()=>{if(Date.now()>=this.owedUntil){this.owedUntil=0;return}this.owedTimer=setTimeout(()=>this.payOwed(),this.owedPollMs),this.owedTimer.unref?.()},"again");if(!this.controlSock||!fs.existsSync(this.controlSock)){t();return}this.post("/webpack/watching",this.snapshot()).then(()=>{this.owedUntil&&(this.paid(),console.log("[DevServerReloadPlugin] the devserver is up \u2014 sent it the watcher testimony it missed while it was starting"))},t)}snapshot(){return{...this.testimony,recentPaths:[...this.testimony.recentPaths]}}watchRun(t){if(this.testimony.lastWatchRunAt=Date.now(),t.length){const e=[...this.testimony.recentPaths,...t];this.testimony.recentPaths=e.slice(-DevserverNotifier.RECENT_PATH_CAP)}this.building??={startedAt:this.testimony.lastWatchRunAt,changed:new Set,more:0};for(const e of t)this.building.changed.has(e)||(this.building.changed.size>=DevserverNotifier.BUILD_PATH_CAP?this.building.more+=1:this.building.changed.add(e));this.testimony.building=this.buildAccount(),this.tellWatching()}buildAccount(){if(this.building)return{startedAt:this.building.startedAt,changedFiles:[...this.building.changed],...this.building.more>0?{moreChanged:this.building.more}:{}}}failed(t){const e=Date.now(),i=this.buildAccount()??(t!==void 0?{startedAt:e,changedFiles:[]}:void 0);this.building=void 0,delete this.testimony.building,this.testimony.lastFailedAt=e;const o=i?{...i,endedAt:e,...t?{error:t.slice(0,FAILURE_TEXT_CAP)}:{}}:void 0;this.tell("/webpack/watching",{...this.testimony,...o?{failed:o}:{}}).catch(()=>{})}degrade(t){this.testimony.degraded=t,this.tellWatching()}tellWatching(){this.tell("/webpack/watching",this.testimony).catch(()=>{})}async built(t=!0){this.testimony.lastBuildAt=Date.now(),this.testimony.buildsSinceSpawn+=1;const e=this.buildAccount();if(this.building=void 0,delete this.testimony.building,!t){const i=e?{...e,endedAt:this.testimony.lastBuildAt}:void 0;this.tell("/webpack/watching",{...this.testimony,...i?{unchanged:i}:{}}).catch(()=>{});return}try{await this.tell("/webpack/reload",{watcher:this.testimony,...e?{build:{...e,endedAt:this.testimony.lastBuildAt}}:{}}),console.log("[DevServerReloadPlugin] notified devserver to reload")}catch(i){i instanceof notice_generation_1.NotThisGeneration?console.log(`[DevServerReloadPlugin] not this generation's devserver (${i.message}) \u2014 not reloaded; this generation's devserver loads the build when it starts`):console.log("[DevServerReloadPlugin] devserver not running yet")}}}exports.DevserverNotifier=DevserverNotifier;const FAILURE_TEXT_CAP=500,OWED_POLL_MS=500,OWED_FOR_MS=3*6e4;function devserverControlSock(a,t=process.env){const e=t.LENSMCP_SOCK_NS||t.LENSMCP_WS_KEY||"",i=e?path.join(os.tmpdir(),e,`${a}-devserver`):path.join(os.tmpdir(),`${a}-devserver`);return path.join(i,"parent.sock")}g(devserverControlSock,"devserverControlSock"),h(devserverControlSock,"devserverControlSock");
|
|
@@ -98,7 +98,7 @@ export declare function forwardedGraphInChild(root: string, env: NodeJS.ProcessE
|
|
|
98
98
|
* guest's is computed in ({@link forwardedGraphInChild}, {@link guestGraphEnv} — no nx daemon, plugins in-process). The
|
|
99
99
|
* store falls back to it once a computation in the gateway's own process has failed (project-graph-store.ts
|
|
100
100
|
* `setFallback`): nx's state in a long-lived process can stay broken after one failure, and FoodGuard's did for four
|
|
101
|
-
* hours, until a restart (issues/
|
|
101
|
+
* hours, until a restart (issues/closed/overseer-16). A fresh process starts clean every time.
|
|
102
102
|
*
|
|
103
103
|
* The admission a guest's graph passes refuses this root (the gateway reads its own graph itself), so the checks it
|
|
104
104
|
* still needs are made here: the size, the format, that it describes this root, and its shape. The store fingerprints
|
|
@@ -33,7 +33,7 @@ export interface ProjectGraphStore {
|
|
|
33
33
|
/**
|
|
34
34
|
* The computation to use once the store's own has failed: the graph in a FRESH process. The gateway's own store is
|
|
35
35
|
* made by the executor (gateway.impl.ts), which computes in its own long-lived process, and nx's state there can stay
|
|
36
|
-
* broken after one failure (issues/
|
|
36
|
+
* broken after one failure (issues/closed/overseer-16); the gateway hands it this when it starts (server.ts).
|
|
37
37
|
*/
|
|
38
38
|
setFallback?(compute: ComputeProjectGraph): void;
|
|
39
39
|
}
|
|
@@ -94,7 +94,7 @@ export declare function declaringFiles(root: string, graph: ProjectGraph): strin
|
|
|
94
94
|
*/
|
|
95
95
|
export declare function computeProjectGraphInProcess(root: string): Promise<ComputedProjectGraph>;
|
|
96
96
|
/**
|
|
97
|
-
* A FAILED refresh is retried (issues/
|
|
97
|
+
* A FAILED refresh is retried (issues/closed/overseer-16). It always was — every sweep tick, in the same process, and a
|
|
98
98
|
* repeat said nothing — and on FoodGuard that was not enough: once nx in the gateway's process had failed (its daemon
|
|
99
99
|
* disabled, «Failed to load 7 Nx plugin(s): The "path" argument must be of type string»), every computation there
|
|
100
100
|
* failed the same way for four hours, until the gateway restarted. The snapshot stayed the one from before nx.json
|
|
@@ -616,7 +616,7 @@ export declare const POD_ROLL_READY_MS: number;
|
|
|
616
616
|
*
|
|
617
617
|
* The same number bounds the recycles that cannot roll — a tree started through `nx run`, or
|
|
618
618
|
* `LENSMCP_POD_RECYCLE_MODE=in-place`: no more of them go kill-first in one sweep, and the rest go on the
|
|
619
|
-
* next sweeps (issues/
|
|
619
|
+
* next sweeps (issues/closed/overseer-16 — one file added under foodguard's shared/contracts killed seven).
|
|
620
620
|
*/
|
|
621
621
|
export declare const POD_MAX_CONCURRENT_ROLLS: number;
|
|
622
622
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/cluster",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.58",
|
|
4
4
|
"description": "Run your Nx workspace as a local production cluster: pods on unix sockets with true HMR, one https gateway with per-project domains, scale-from-zero, autoscale, idle-kill, local-CA TLS — observed by the LensMCP lens.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@lensmcp/core": "1.25.
|
|
62
|
-
"@lensmcp/node-instrumentation": "1.25.
|
|
63
|
-
"@lensmcp/nx-plugin": "1.25.
|
|
61
|
+
"@lensmcp/core": "1.25.58",
|
|
62
|
+
"@lensmcp/node-instrumentation": "1.25.58",
|
|
63
|
+
"@lensmcp/nx-plugin": "1.25.58",
|
|
64
64
|
"fastify": "^5.8.5",
|
|
65
65
|
"@fastify/reply-from": "^12.6.2",
|
|
66
66
|
"@typescript/native-preview": "^7.0.0-dev.20260707.2",
|