@threadedstack/wmd-web 0.1.30 → 0.1.32

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 (62) hide show
  1. package/README.md +23 -2
  2. package/RELEASE.json +123 -16
  3. package/guest/arm64/Image +1 -1
  4. package/guest/arm64/Image-4k +1 -1
  5. package/guest/arm64/initramfs.cpio.gz +0 -0
  6. package/package.json +3 -3
  7. package/src/boot.js +47 -2
  8. package/src/edge/bridge.js +297 -0
  9. package/src/edge/codes.js +10 -0
  10. package/src/edge/ctl.js +199 -0
  11. package/src/edge/error-kind.js +4 -0
  12. package/src/edge/frame.html +4 -0
  13. package/src/edge/frame.js +48 -0
  14. package/src/edge/fs-route.js +301 -0
  15. package/src/edge/hist.js +46 -0
  16. package/src/edge/msg.js +106 -0
  17. package/src/edge/node-args.js +194 -0
  18. package/src/edge/node-guest-opts.js +108 -0
  19. package/src/edge/node-opts.js +82 -0
  20. package/src/edge/own/adapter.js +271 -0
  21. package/src/edge/own/capi.js +200 -0
  22. package/src/edge/own/child-host.js +196 -0
  23. package/src/edge/own/fs-bridge.js +71 -0
  24. package/src/edge/own/fs-own-route.js +356 -0
  25. package/src/edge/own/guest-spawner.js +235 -0
  26. package/src/edge/own/hub.js +430 -0
  27. package/src/edge/own/loader.js +81 -0
  28. package/src/edge/own/memcap.js +95 -0
  29. package/src/edge/own/payload-size.js +15 -0
  30. package/src/edge/own/pool.js +160 -0
  31. package/src/edge/own/procfs.js +84 -0
  32. package/src/edge/own/serdes-codec.js +317 -0
  33. package/src/edge/own/service-receiver.js +98 -0
  34. package/src/edge/own/shim-post.js +185 -0
  35. package/src/edge/own/stack-fix.js +36 -0
  36. package/src/edge/own/stdio-pipe.js +80 -0
  37. package/src/edge/own/v8-serdes.js +970 -0
  38. package/src/edge/own/wasm-counters.js +144 -0
  39. package/src/edge/own/worker.js +97 -0
  40. package/src/edge/page.js +162 -0
  41. package/src/edge/plan.js +65 -0
  42. package/src/edge/resolve.js +44 -0
  43. package/src/edge/runtime.js +94 -0
  44. package/src/edge/sdk/adapter.js +151 -0
  45. package/src/edge/sdk/forward.js +80 -0
  46. package/src/edge/sdk/napi-stub.js +50 -0
  47. package/src/edge/sdk/relay.js +17 -0
  48. package/src/edge/service-host.js +382 -0
  49. package/src/edge/service-port.js +245 -0
  50. package/src/edge/shim.js +161 -0
  51. package/src/edge/site.js +106 -0
  52. package/src/edge/spawn-guard.js +80 -0
  53. package/src/edge/tz.js +103 -0
  54. package/src/edge/worker.js +121 -0
  55. package/src/edge/workers.js +27 -0
  56. package/src/host/chan-service.js +75 -8
  57. package/src/host/chan-services.js +77 -3
  58. package/src/host/ctl.js +26 -5
  59. package/src/host/edge-go.js +7 -3
  60. package/src/host/edge-host.js +327 -0
  61. package/src/host/yamux.js +21 -8
  62. package/wmdpack.wasm +0 -0
@@ -29,6 +29,12 @@
29
29
  // {t:'collect', files:[{port, path}]} reply {t:'collected', files: {"port:path": text|null}}
30
30
  // {t:'export-upper', id, port} W62: reply {t:'upper', id, bytes, entries, files, whiteouts,
31
31
  // opaque, dataBytes, ms} (the pack, transferred) or {t:'upper', id, error}
32
+ // {t:'edge-fs', port9p, mounts, root, ports:[MessagePort], yieldMs?} X5 (edge=1 only): node's file
33
+ // requests on those ports are answered from the 9P port's Overlay (src/edge/service-port.js);
34
+ // yieldMs shortens the loop's yield while ports are open
35
+ // {t:'edge-release', run} X5 (edge=1 only): the run's ports are closed and its open handles released
36
+ // {t:'edge-msg', id, ev, ...} X5 (edge=1 only): the page's answer to a node start, and its output, exit (src/edge/service-host.js)
37
+ // {t:'edge-yield', yieldMs?} X5 (edge=1 only): sets the yield again (none = the default 10 ms)
32
38
  // test hooks: {t:'die'} (self.close() at once), {t:'crash'} (throw in the loop),
33
39
  // {t:'stall', ms} (busy for ms inside the loop)
34
40
  // Messages out: {t:'ready'}, {t:'locked'}, {t:'stats', stats}, {t:'console-bytes', n},
@@ -43,6 +49,8 @@ import { Pack, bytesSource } from '../fs/pack.js'
43
49
  import { Overlay } from '../fs/overlay.js'
44
50
  import { seedEntry } from '../fs/seed.js'
45
51
  import { exportUpper } from '../fs/upper-pack.js'
52
+ // X5 (edge=1 only): the edge modules are loaded by init() when the machine has `edge`, and by nothing else (check5 F8)
53
+ let EdgePorts, EdgeService, EdgeHost, checkpointRefusal
46
54
 
47
55
  let host = null
48
56
  let sab = null
@@ -55,6 +63,10 @@ let spinCur = 0 // W51: the window after 9P work, us (adapts between 0 and spinU
55
63
  const spin = { hits: 0, sleeps: 0 }
56
64
  let lastP9 = 0
57
65
  let lastP9At = -Infinity
66
+ let edgeHost = null // X5 (edge=1): the stream side (src/host/edge-host.js), for its stats
67
+ let edgeSvc = null // X5 (edge=1): the guest's node requests (src/edge/service-host.js), null unless init gave `edge`
68
+ let edge = null // X5 (edge=1): the file route's ports, null until the page sends 'edge-fs'
69
+ let yieldMs = 10 // the longest the loop runs before it lets messages in (shorter while edge ports are open)
58
70
  let goEdge = null // X6 (default off): the compiler hand-off
59
71
  let goPort = null // ... and its port to the twin Worker
60
72
 
@@ -97,6 +109,9 @@ self.onmessage = e => {
97
109
  // P-B9: the 9P trees and fid tables as bytes (the guest is stopped at its checkpoint point)
98
110
  const t0 = nowMs()
99
111
  try {
112
+ // a stub that is connected (it waits for the page's reply, or its node runs in the page) cannot be carried over a checkpoint
113
+ const refuse = edgeHost ? checkpointRefusal(edgeHost) : ''
114
+ if (refuse) throw new Error(refuse)
100
115
  const ports = host.snapshotState()
101
116
  const out = {}
102
117
  const transfer = []
@@ -135,6 +150,39 @@ self.onmessage = e => {
135
150
  self.postMessage({ t: 'collected', files })
136
151
  break
137
152
  }
153
+ case 'edge-fs': {
154
+ // X5 (edge=1 only): node's file requests, answered between 9P requests
155
+ if (!host) throw new Error('the channel service has not started')
156
+ edge ||= new EdgePorts(host.fsFor(m.port9p), { mounts: m.mounts, root: m.root || '' })
157
+ if (m.own) {
158
+ // the own runtime's port (src/edge/own/): its file messages and its children (a raw stream to the stub of this run)
159
+ for (const p of m.ports || []) edge.attachOwn(p, { run: m.run || 0, root: m.root || '', job: m.job || 0, openExec: id => edgeSvc.openExec(id), onTraffic: kick, kickAll: !!m.kickAll, onSignalTaken: (n, handled) => edgeSvc.post({ t: 'edge', ev: 'signal-taken', id: m.job || 0, n, handled }) })
160
+ } else {
161
+ const route = edge.routeFor({ mounts: m.mounts, root: m.root || '' }) // this run's own table (see EdgePorts.routeFor)
162
+ for (const p of m.ports || []) edge.attach(p, route, m.run || 0)
163
+ }
164
+ yieldMs = m.yieldMs || 10 // each run says its own; none = the default
165
+ break
166
+ }
167
+ case 'edge-release':
168
+ edge?.release(m.run || 0) // X5 (edge=1 only): a run ended: its ports, handles and route state go
169
+ break
170
+ case 'edge-msg':
171
+ // one message of the page (it carries what a frame sent): whatever is wrong with it ends that run, never this service (check4 F2)
172
+ try {
173
+ edgeSvc?.message(m)
174
+ } catch (err) {
175
+ try {
176
+ edgeSvc?.abort(m && m.id, err)
177
+ } catch {
178
+ // the run is already gone
179
+ }
180
+ }
181
+ kick()
182
+ break
183
+ case 'edge-yield':
184
+ yieldMs = m.yieldMs || 10 // X5 (edge=1 only): the last port closed, back to the default
185
+ break
138
186
  case 'die':
139
187
  self.close() // ends at once, mid-whatever; the lock tells the page
140
188
  break
@@ -231,6 +279,17 @@ async function init(m) {
231
279
  }
232
280
  const restore = {}
233
281
  for (const svc of m.services || []) if (svc.restore) restore[svc.port] = new Uint8Array(svc.restore)
282
+ let edgeAccept = null
283
+ if (m.edge) {
284
+ const [port, service, hosted] = await Promise.all([import('../edge/service-port.js'), import('../edge/service-host.js'), import('./edge-host.js')])
285
+ ;({ EdgePorts } = port)
286
+ ;({ EdgeService } = service)
287
+ ;({ EdgeHost, checkpointRefusal } = hosted)
288
+ // X5 (edge=1 only): streams the guest opens on the control session are node starts (src/host/edge-host.js)
289
+ edgeSvc = new EdgeService({ fs: fs[m.edge.port9p], root: m.edge.root || '', rt: m.edge.rt || '', post: msg => self.postMessage(msg) })
290
+ const eh = (edgeHost = new EdgeHost({ start: (h, ctx) => edgeSvc.start(h, ctx) }))
291
+ edgeAccept = s => (eh.accept(s), kick())
292
+ }
234
293
  // X6 (default off): the compiler hand-off, for the 9P service that has a gowasm table
235
294
  const goSvc = m.gowasmPort ? (m.services || []).find(s => s.gowasm && fs[s.port]) : null
236
295
  let goMod = null
@@ -263,7 +322,7 @@ async function init(m) {
263
322
  goEdge.pruneBundle() // an image with no Go compile: its stub mounts go out of the bundle before the guest starts the container
264
323
  bindGoPort(m.gowasmPort)
265
324
  }
266
- host = new ChanHost(sab, { fs, consoleInputBytes: m.consoleInputBytes, yamuxPorts, netPost, restore, edge: goEdge })
325
+ host = new ChanHost(sab, { fs, consoleInputBytes: m.consoleInputBytes, yamuxPorts, netPost, restore, edge: goEdge, edgeAccept })
267
326
  if (m.lockName && self.navigator?.locks?.request) {
268
327
  self.navigator.locks.request(m.lockName, () => {
269
328
  self.postMessage({ t: 'locked' })
@@ -300,15 +359,22 @@ async function loadWithin(load, limitMs, what) {
300
359
  * X6 fix 5, item 4 (F4): the twin cannot be used on this machine (its module did not load). The bundle's config binds the stub over
301
360
  * each tool, so the stub's mounts go out of it before the guest starts the container (the machine then starts as it does without
302
361
  * the switch: nothing is bound, no compile asks the page), the twin's Worker is stopped and one event says why. GoEdge.pruneBundle
303
- * does the part of this that depends on the tools, and is not here to be asked.
362
+ * does the part of this that depends on the tools, and is not here to be asked. Mounts in the stub folder that are not a Go tool's
363
+ * stay, and the folder with them: with the page switch edge=1 (X5) the image's node runs through the same stub.
304
364
  */
305
365
  function noTwin(fsx, tools, why) {
366
+ twinOffWhy = why // fix 11 (F-N): no GoEdge exists to count it; the stats carry it as gowasmOff
306
367
  const file = 'bundle/config/config.json'
307
368
  try {
308
369
  const spec = JSON.parse(new TextDecoder().decode(fsx.readFile(file)))
309
370
  if (spec && Array.isArray(spec.mounts)) {
310
- const paths = new Set(Object.values(tools || {}).map(t => t && t.path))
311
- const keep = spec.mounts.filter(m => !(m.destination === EDGE_CONTAINER_DIR || String(m.destination).startsWith(`${EDGE_CONTAINER_DIR}/`) || (paths.has(m.destination) && m.source === EDGE_STUB)))
371
+ // the Go tools' own mounts only: with the page switch edge=1 (X5) the image's node has its stub in the same folder, and it stays
372
+ const list = Object.values(tools || {}).filter(t => t)
373
+ const paths = new Set(list.map(t => t.path))
374
+ const reals = new Set(list.map(t => `${EDGE_CONTAINER_DIR}/${t.name}`))
375
+ let keep = spec.mounts.filter(m => !(reals.has(m.destination) || (paths.has(m.destination) && m.source === EDGE_STUB)))
376
+ // the stub folder goes with the last thing in it
377
+ if (!keep.some(m => String(m.destination).startsWith(`${EDGE_CONTAINER_DIR}/`))) keep = keep.filter(m => m.destination !== EDGE_CONTAINER_DIR)
312
378
  if (keep.length !== spec.mounts.length) {
313
379
  spec.mounts = keep
314
380
  fsx.writeFile(file, JSON.stringify(spec, null, 2) + '\n')
@@ -331,8 +397,9 @@ function bindGoPort(p) {
331
397
  }
332
398
  }
333
399
 
400
+ let twinOffWhy = null // fix 11 (F-N): why the twin's module did not load (noTwin), for the stats
334
401
  let lastStats = ''
335
- const withSpin = s => ({ ...s, spin: { ...spin, curUs: spinCur } })
402
+ const withSpin = s => ({ ...s, spin: { ...spin, curUs: spinCur }, ...(twinOffWhy ? { gowasmOff: twinOffWhy } : {}), ...(edgeHost ? { edge: { ...edgeHost.stats, fallbackWhy: { ...edgeHost.stats.fallbackWhy }, look: { ...edgeSvc.stats }, route: edge ? (({ runs, ports, released, handles, requests, bad, children, ring, wait, waitByMethod, serdes }) => ({ runs, ports, released, handles, requests, bad, children, ring, wait, waitByMethod, serdes }))(edge.stats()) : null } } : {}) })
336
403
  let lastStatsAt = 0
337
404
  function maybePostStats() {
338
405
  const t = nowMs()
@@ -366,7 +433,7 @@ async function loop() {
366
433
  postCtl()
367
434
  if (host.stopped) return
368
435
  const t = nowMs()
369
- if (t - lastYield > 10) {
436
+ if (t - lastYield > yieldMs) {
370
437
  maybePostStats()
371
438
  await yieldTask()
372
439
  lastYield = nowMs()
@@ -380,8 +447,8 @@ async function loop() {
380
447
  if (p9 !== lastP9) (lastP9 = p9), (lastP9At = t)
381
448
  const p9Served = t - lastP9At < (2 * spinUs) / 1000
382
449
  const spinWin = Math.min(spinUs, p9Served ? Math.max(spinCur, SPIN_BASE_US) : SPIN_BASE_US)
383
- const capped = lastYield + 10 < t + spinWin / 1000 // the yield, not the window, ends this spin
384
- const spinEnd = capped ? lastYield + 10 : t + spinWin / 1000
450
+ const capped = lastYield + yieldMs < t + spinWin / 1000 // the yield, not the window, ends this spin
451
+ const spinEnd = capped ? lastYield + yieldMs : t + spinWin / 1000
385
452
  if (Atomics.load(i32, H_DOORBELL) !== bell) continue // rang during the step: not a spin hit
386
453
  while (Atomics.load(i32, H_DOORBELL) === bell && nowMs() < spinEnd) {}
387
454
  if (Atomics.load(i32, H_DOORBELL) !== bell) {
@@ -210,6 +210,79 @@ class ConsoleSession {
210
210
  }
211
211
  }
212
212
 
213
+ const EDGE_LINE_LIMIT = 4096
214
+ const edgeLineDec = new TextDecoder()
215
+
216
+ /**
217
+ * The hook for the streams the guest init opens on the control session. Two things answer them: X6's compiler hand-off (page
218
+ * option gowasm=1, `go`: src/host/edge-go.js GoEdge) and X5's node host (page switch edge=1, `node`: a function that takes the
219
+ * stream). With one of them every stream is its own, unread, as before. With both the stream's first line says whose it is. The
220
+ * init writes that line itself, before any byte of the stub (cmd/init/edge.go): `{"op":"edge"}` (with `hold` for the holder)
221
+ * for a node or python session is X5's; the judged line of a Go compile, the init's one-line notes (`edge-refused`,
222
+ * `edge-missed`) and anything else are X6's, which serves, counts or refuses them. The taker gets the stream with every byte
223
+ * that came, the line too, and nothing is consumed before that: the takers read the line themselves and give the window back.
224
+ * @param {{accept: (s: import('./yamux.js').YamuxStream) => any} | null} go
225
+ * @param {((s: import('./yamux.js').YamuxStream) => any) | null} node
226
+ * @returns {((s: import('./yamux.js').YamuxStream) => any) | null} null: the session refuses the guest's streams
227
+ */
228
+ export function edgeTaker(go, node) {
229
+ if (!go) return node || null
230
+ if (!node) return s => go.accept(s)
231
+ const toGo = s => go.accept(s)
232
+ return stream => {
233
+ let kept = []
234
+ let size = 0
235
+ const hand = (to, fin) => {
236
+ const pieces = kept
237
+ kept = null
238
+ stream.onData = stream.onFin = stream.onClose = null
239
+ try {
240
+ to(stream)
241
+ for (const u8 of pieces) {
242
+ if (stream.closed) return
243
+ stream.onData?.(u8)
244
+ }
245
+ if (fin && !stream.closed) stream.onFin?.()
246
+ } catch {
247
+ // a taker that throws: the stream is reset, the error is counted, and the exception stays out of the yamux feed (fix 11, F-B)
248
+ stream.session.stats.takerErrors++
249
+ stream.abort('edge: the taker failed')
250
+ }
251
+ }
252
+ stream.onData = u8 => {
253
+ const nl = u8.indexOf(10)
254
+ const before = size
255
+ kept.push(u8)
256
+ size += u8.length
257
+ if (nl < 0) {
258
+ if (size > EDGE_LINE_LIMIT) {
259
+ kept = []
260
+ stream.abort('edge: no request line')
261
+ }
262
+ return
263
+ }
264
+ const line = new Uint8Array(before + nl)
265
+ let at = 0
266
+ for (const k of kept) {
267
+ const part = k.subarray(0, Math.min(k.length, line.length - at))
268
+ line.set(part, at)
269
+ at += part.length
270
+ }
271
+ let req = null
272
+ try {
273
+ req = JSON.parse(edgeLineDec.decode(line))
274
+ } catch {}
275
+ const plain = !!req && typeof req === 'object' && !Array.isArray(req) && req.op === 'edge' && !Object.hasOwn(req, 'judged')
276
+ hand(plain ? node : toGo, false)
277
+ }
278
+ // ended before a whole line: X6 closes such a stream
279
+ stream.onFin = () => hand(toGo, true)
280
+ stream.onClose = () => {
281
+ kept = []
282
+ }
283
+ }
284
+ }
285
+
213
286
  /**
214
287
  * P-B11: the control port as a yamux session (the guest init is the server). One per
215
288
  * open of the port; the page's streams (keys k) live on the host's ctl state, so a
@@ -225,8 +298,8 @@ class ControlSession {
225
298
  send: u8 => sess.out.push(u8),
226
299
  keepAliveMs: host.ctlKeepAliveMs,
227
300
  onClose: why => host.ctlSessionDown(this, why),
228
- // X6 (default off): streams the guest init opens ({"op":"edge"}) go to the compiler hand-off
229
- accept: host.edge ? s => host.edge.accept(s) : null,
301
+ // streams the guest init opens ({"op":"edge"}): X6's compiler hand-off (default off) and X5's node host (edge=1 only)
302
+ accept: edgeTaker(host.edge, host.edgeAccept),
230
303
  })
231
304
  ctl.session = this
232
305
  host.ctlEvent({ ev: 'session', up: true, epoch: this.epoch })
@@ -344,7 +417,7 @@ export class ChanHost {
344
417
  * @param {number} [o.consoleInputBytes] console input (page -> guest) held at most (CONSOLE_IN_LIMIT)
345
418
  * @param {{accept: (s: object) => void, snapshot: () => object}} [o.edge] X6: takes the streams the guest opens on the control session (edge-go.js GoEdge)
346
419
  */
347
- constructor(sab, { fs = {}, onConsole, consoleInputBytes = CONSOLE_IN_LIMIT, yamuxPorts = [], ctlKeepAliveMs = 5000, netPost = null, restore = {}, edge = null } = {}) {
420
+ constructor(sab, { fs = {}, onConsole, consoleInputBytes = CONSOLE_IN_LIMIT, yamuxPorts = [], ctlKeepAliveMs = 5000, netPost = null, restore = {}, edge = null, edgeAccept = null } = {}) {
348
421
  this.v = chanView(sab)
349
422
  this.edge = edge
350
423
  // P-B10: the network Worker (postMessage to it), and the net channel's session
@@ -358,6 +431,7 @@ export class ChanHost {
358
431
  this.restoredServers.set(Number(port), loadService(bytes, fs[port]))
359
432
  }
360
433
  this.yamuxPorts = new Set(yamuxPorts)
434
+ this.edgeAccept = edgeAccept // X5 (edge=1 only): called with each stream the guest opens on the control session; none: refused
361
435
  this.ctlKeepAliveMs = ctlKeepAliveMs
362
436
  // P-B11: the control session and the page's streams on it (k -> YamuxStream)
363
437
  this.ctl = { session: null, epoch: 0, streams: new Map(), events: [], opened: 0, refusedOpens: 0 }
package/src/host/ctl.js CHANGED
@@ -17,6 +17,27 @@
17
17
  // 4. Other ops: one JSON response line {"ok","error","exit_code","titles","rows","stats","ids"}.
18
18
  // A stream that ends without an exit frame is exit 125 (control.go runProcessExit).
19
19
 
20
+ // The edge stub's places (internal/engine/edge.go edgeGuestDir, edgeContainerDir, edgeStub), used by containerBundle for X5 (edge=1: the
21
+ // image's node, src/edge/plan.js re-exports them) and for X6 (gowasm=1: the Go compile, src/host/edge-go.js)
22
+ export const EDGE_CONTAINER_DIR = '/dev/.wmd-edge'
23
+ export const EDGE_GUEST_DIR = '/run/wmd-edge'
24
+ export const EDGE_STUB = '/sbin/wmd-edgestub'
25
+
26
+ /**
27
+ * The three mounts internal/engine/edge.go edgeMounts adds for a node at `node`, as containerBundle's spec mounts:
28
+ * the socket directory, the image's own node beside it (for the stub's fallback), and the stub over the image's node.
29
+ * @param {string} node the container path of the image's node
30
+ * @param {string} rootfsPath where the guest sees the container's root (GUEST_9P_MOUNT + '/rootfs')
31
+ */
32
+ export function edgeSpecMounts(node, rootfsPath) {
33
+ return [
34
+ { destination: EDGE_CONTAINER_DIR, type: 'bind', source: EDGE_GUEST_DIR, options: ['rbind', 'rw'] },
35
+ { destination: EDGE_CONTAINER_DIR + '/node', type: 'bind', source: rootfsPath + node, options: ['bind', 'ro'] },
36
+ { destination: node, type: 'bind', source: EDGE_STUB, options: ['bind', 'ro'] },
37
+ ]
38
+ }
39
+
40
+
20
41
  export const STREAM_CONTROL = 0
21
42
  export const STREAM_STDIN = 1
22
43
  export const STREAM_STDOUT = 2
@@ -717,10 +738,6 @@ export function checkProcessRequest(req, liveIds = new Set()) {
717
738
  // ---------------------------------------------------------------------------
718
739
 
719
740
  export const GUEST_9P_MOUNT = '/run/wmd9p'
720
- /** The edge stub's places (internal/engine/edge.go edgeGuestDir, edgeContainerDir, edgeStub). */
721
- export const EDGE_GUEST_DIR = '/run/wmd-edge'
722
- export const EDGE_CONTAINER_DIR = '/dev/.wmd-edge'
723
- export const EDGE_STUB = '/sbin/wmd-edgestub'
724
741
  export const DEFAULT_CAPS = [
725
742
  'CAP_CHOWN', 'CAP_DAC_OVERRIDE', 'CAP_FSETID', 'CAP_FOWNER', 'CAP_MKNOD', 'CAP_NET_RAW', 'CAP_SETGID',
726
743
  'CAP_SETUID', 'CAP_SETFCAP', 'CAP_SETPCAP', 'CAP_NET_BIND_SERVICE', 'CAP_SYS_CHROOT', 'CAP_KILL', 'CAP_AUDIT_WRITE',
@@ -772,6 +789,8 @@ function defaultMounts() {
772
789
  * after its command ends; args may be [] (nothing runs until ControlClient.startCommand). Send the
773
790
  * run request with command: true and stop_signal (see runOptions).
774
791
  * @param {string} [o.stopSignal] the image's STOPSIGNAL (default SIGTERM), for runOptions
792
+ * @param {string} [o.edgeNode] X5 (page switch edge=1 only): the container path of the image's node when the page's plan
793
+ * takes the path (src/edge/plan.js): the three mounts of internal/engine/edge.go edgeMounts, the stub over node
775
794
  * @param {{tools: {name: string, path: string}[]}} [o.edge] X6 (default off): the guest's edge stub stands in the container
776
795
  * for each tool (path inside the container; name: the real binary is bound at /dev/.wmd-edge/<name>), as
777
796
  * internal/engine/edge.go edgeMounts does for node and python; the page answers its requests (src/host/edge-go.js)
@@ -815,11 +834,13 @@ export function containerBundle(o) {
815
834
  // as dockerd binds its docker-init (internal/engine/ocispec.go): the guest's tini, or its own init for keep-running
816
835
  spec.mounts.push({ destination: DOCKER_INIT, type: 'bind', source: o.keepRunning ? '/sbin/init' : '/sbin/tini', options: ['bind', 'ro'] })
817
836
  }
837
+ if (o.edgeNode) spec.mounts.push(...edgeSpecMounts(o.edgeNode, spec.root.path))
818
838
  for (const name of ETC_FILES) {
819
839
  spec.mounts.push({ destination: `/etc/${name}`, type: 'bind', source: `${GUEST_9P_MOUNT}/bundle/etc/${name}`, options: ['rbind', 'rprivate', 'rw'] })
820
840
  }
821
841
  if (o.edge?.tools?.length) {
822
- spec.mounts.push({ destination: EDGE_CONTAINER_DIR, type: 'bind', source: EDGE_GUEST_DIR, options: ['rbind', 'rw'] })
842
+ // the stub folder once: with edge=1 and gowasm=1 together X5's mounts above already have it
843
+ if (!spec.mounts.some(m => m.destination === EDGE_CONTAINER_DIR)) spec.mounts.push({ destination: EDGE_CONTAINER_DIR, type: 'bind', source: EDGE_GUEST_DIR, options: ['rbind', 'rw'] })
823
844
  for (const t of o.edge.tools) {
824
845
  spec.mounts.push({ destination: `${EDGE_CONTAINER_DIR}/${t.name}`, type: 'bind', source: `${GUEST_9P_MOUNT}/rootfs${t.path}`, options: ['bind', 'ro'] })
825
846
  spec.mounts.push({ destination: t.path, type: 'bind', source: EDGE_STUB, options: ['bind', 'ro'] })
@@ -295,6 +295,7 @@ export class GoEdge {
295
295
  this.failures = 0 // failures of the twin since its last good compile
296
296
  this.ruleSeen = new Set() // the rules (see #rule) that have raised their event on this machine
297
297
  this.ruleWhy = {} // rule -> the reason text of the first time
298
+ this.offWhy = null // fix 11 (F-N): the reason it is off, once it is
298
299
  this.off = false // turned off for the machine (FAIL_LIMIT failures in a row, or a module that is not the one tools.json names)
299
300
  this.lastBeat = 0
300
301
  this.watch = null // the timer of the watchdog, there while a run is out or the Worker has not said ready
@@ -319,7 +320,7 @@ export class GoEdge {
319
320
  }
320
321
 
321
322
  snapshot() {
322
- return { ...this.stats, reasons: { ...this.stats.reasons }, rules: { ...this.stats.rules }, ruleWhy: { ...this.ruleWhy }, ready: this.ready, off: this.off, failures: this.failures, queued: this.queue.length, open: this.open.size }
323
+ return { ...this.stats, reasons: { ...this.stats.reasons }, rules: { ...this.stats.rules }, ruleWhy: { ...this.ruleWhy }, ready: this.ready, off: this.off, offWhy: this.offWhy, failures: this.failures, queued: this.queue.length, open: this.open.size }
323
324
  }
324
325
 
325
326
  /** How many stubs wait for an answer now (for the report; a checkpoint no longer waits for them, see checkpointBlock). */
@@ -595,7 +596,8 @@ export class GoEdge {
595
596
  /**
596
597
  * The bundle (the container's config the guest reads when it starts the container) binds the stub over each tool, and the real
597
598
  * tool at /dev/.wmd-edge/<name>. An image that has no such tool (no Go in it) makes that bind fail and the container not start.
598
- * So the mounts of the tools this image does not have are taken out of the bundle's config, and with the last one the stub folder:
599
+ * So the mounts of the tools this image does not have are taken out of the bundle's config, and with the last one the stub folder
600
+ * (unless something else is mounted in it: X5's node, when the page switch edge=1 is on too):
599
601
  * an image with no Go compile starts as it does with the switch off. Called once, before the guest starts the container.
600
602
  */
601
603
  pruneBundle() {
@@ -627,8 +629,9 @@ export class GoEdge {
627
629
  }
628
630
  }
629
631
  if (!dropped) return { kept, dropped }
630
- if (!kept) drop.add(EDGE_DIR)
631
632
  spec.mounts = spec.mounts.filter(m => !drop.has(m.destination) && !dropReal.some(d => d.dest === m.destination && typeof m.source === 'string' && m.source.endsWith(d.src)))
633
+ // the stub folder goes with the last thing in it. Another stub may live there: with the page switch edge=1 (X5) the image's node does
634
+ if (!kept && !spec.mounts.some(m => typeof m.destination === 'string' && m.destination.startsWith(`${EDGE_DIR}/`))) spec.mounts = spec.mounts.filter(m => m.destination !== EDGE_DIR)
632
635
  this.fs.writeFile(file, JSON.stringify(spec, null, 2) + '\n')
633
636
  return { kept, dropped }
634
637
  }
@@ -1115,6 +1118,7 @@ export class GoEdge {
1115
1118
  #turnOff(why) {
1116
1119
  if (this.off) return
1117
1120
  this.off = true
1121
+ this.offWhy = why // fix 11 (F-N): the counters say why, not only the event
1118
1122
  this.ready = false
1119
1123
  this.dead = true
1120
1124
  this.sent.clear()