@hadoku/game-server 0.1.178 → 0.1.180
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/dist/base-path.d.ts +1 -3
- package/dist/base-path.js +1 -2
- package/dist/busy.d.ts +0 -1
- package/dist/busy.js +0 -1
- package/dist/config.d.ts +0 -5
- package/dist/config.js +0 -3
- package/dist/edge-auth.d.ts +3 -2
- package/dist/edge-auth.js +3 -2
- package/dist/gate.d.ts +0 -12
- package/dist/gate.js +0 -2
- package/dist/http/client-events.d.ts +2 -3
- package/dist/http/page.d.ts +1 -1
- package/dist/http/page.js +2 -1
- package/dist/http/room-core.d.ts +5 -5
- package/dist/http/room-core.js +33 -12
- package/dist/http/usage.d.ts +3 -6
- package/dist/http/usage.js +1 -2
- package/dist/log.d.ts +0 -8
- package/dist/log.js +1 -8
- package/dist/play/engine-runtime.d.ts +7 -32
- package/dist/play/engine-runtime.js +0 -9
- package/dist/play/host.d.ts +7 -6
- package/dist/play/host.js +82 -14
- package/dist/play/jvm-transport.d.ts +5 -0
- package/dist/play/local-jvm.d.ts +5 -6
- package/dist/play/local-jvm.js +10 -46
- package/dist/play/runtimes/relay-match.d.ts +2 -0
- package/dist/play/runtimes/relay-match.js +3 -0
- package/dist/play/runtimes/streamed.d.ts +2 -24
- package/dist/play/runtimes/streamed.js +2 -37
- package/dist/relay-game.d.ts +4 -1
- package/dist/relay-game.js +16 -3
- package/dist/room/lobby.d.ts +6 -7
- package/dist/room/lobby.js +11 -9
- package/dist/room/session.d.ts +1 -1
- package/dist/room/session.js +1 -1
- package/dist/room/watching.d.ts +7 -0
- package/dist/room/watching.js +28 -6
- package/dist/telemetry.d.ts +6 -6
- package/dist/telemetry.js +2 -2
- package/package.json +5 -5
- package/dist/erase/legacy-ids.d.ts +0 -9
- package/dist/erase/legacy-ids.js +0 -33
package/dist/play/host.js
CHANGED
|
@@ -60,7 +60,9 @@
|
|
|
60
60
|
* comes back identical. A line is kept as the bridge wrote it, `match` stamp and all, through
|
|
61
61
|
* a descriptor held open for the match's life; each append is synchronous, so the file is
|
|
62
62
|
* whole for any reader the moment `persist` returns — this process's own `attach`, or the next
|
|
63
|
-
* server's after a crash.
|
|
63
|
+
* server's after a crash. A match that ends takes its stream with it; a JVM whose launcher
|
|
64
|
+
* does not settle its directory (a claw's mirror) takes that directory at its exit, and one left
|
|
65
|
+
* by a JVM that ended under no server goes once discovery has answered (`sweepMirrors`).
|
|
64
66
|
* - **One record per JVM**, `<dir>/jvm.json` (`JvmRecord`): its host id, when it started, when it
|
|
65
67
|
* was handed over, and every match on it with its epoch, its seats' owners and its spec. A
|
|
66
68
|
* client therefore resyncs on the cursor it already held, and seat 2 cannot come back as seat 1.
|
|
@@ -118,13 +120,13 @@
|
|
|
118
120
|
* stdin. Its class comment has the list. Stdout carries nothing else, so a line that is not JSON
|
|
119
121
|
* is a bug and is logged, not parsed.
|
|
120
122
|
*/
|
|
121
|
-
import { appendFileSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync } from 'node:fs';
|
|
123
|
+
import { appendFileSync, closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync } from 'node:fs';
|
|
122
124
|
import { randomBytes } from 'node:crypto';
|
|
123
125
|
import { join } from 'node:path';
|
|
124
126
|
import { jsonLogger } from '@wolffm/service-kernel/log';
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
export {
|
|
127
|
+
import { JVM_HEAP_MB, MATCHES_PER_JVM, RUN_DIR_NAME, localJvmLauncher, writeFileAtomic } from './local-jvm.js';
|
|
128
|
+
// Until auto.test.ts, draftRooms.jvm.test.ts and scripts/agent/{claw-acceptance,local-e2e}.ts import these from local-jvm.
|
|
129
|
+
export { FORGE_PREFERENCES, jvmHostConfig } from './local-jvm.js';
|
|
128
130
|
const LIFECYCLE_T = new Set(['ready', 'fatal', 'frame', 'snapshot']);
|
|
129
131
|
/** Narrows any engine's line onto the four the host itself understands. See {@link HostLifecycleLine}. */
|
|
130
132
|
export function isLifecycle(line) {
|
|
@@ -193,7 +195,7 @@ export function readJvmRecord(dir) {
|
|
|
193
195
|
const r = parsed;
|
|
194
196
|
if (typeof r.hostId !== 'string' || !Array.isArray(r.matches))
|
|
195
197
|
return null;
|
|
196
|
-
const matches = r.matches.filter((m) => typeof m === 'object' && m !== null && typeof m.matchId === 'string' && Array.isArray(m.spec?.seats)
|
|
198
|
+
const matches = r.matches.filter((m) => typeof m === 'object' && m !== null && typeof m.matchId === 'string' && Array.isArray(m.spec?.seats));
|
|
197
199
|
return {
|
|
198
200
|
hostId: r.hostId,
|
|
199
201
|
startedAt: typeof r.startedAt === 'string' ? r.startedAt : new Date(0).toISOString(),
|
|
@@ -207,9 +209,9 @@ export function readJvmRecord(dir) {
|
|
|
207
209
|
// record holds — absent on a record written before checkpoints existed decodes as
|
|
208
210
|
// null, never dropped.
|
|
209
211
|
checkpoint: m.checkpoint ?? null,
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
...(isTurnSnapshot(m.snapshot) ? { snapshot: m.snapshot } : {}),
|
|
212
|
+
// Written beside the checkpoint only when it is a different value (`recordEntry`); Forge's
|
|
213
|
+
// checkpoint IS its turn-start snapshot.
|
|
214
|
+
...(isTurnSnapshot(m.snapshot) ? { snapshot: m.snapshot } : isTurnSnapshot(m.checkpoint) ? { snapshot: m.checkpoint } : {}),
|
|
213
215
|
spec: m.spec,
|
|
214
216
|
...(isClockMs(m.clockMs) ? { clockMs: m.clockMs } : {}),
|
|
215
217
|
...(m.clockPaused === true ? { clockPaused: true } : {}),
|
|
@@ -217,6 +219,13 @@ export function readJvmRecord(dir) {
|
|
|
217
219
|
})),
|
|
218
220
|
};
|
|
219
221
|
}
|
|
222
|
+
/** A match's entry as `jvm.json` holds it: a snapshot that is its checkpoint is written once, as the checkpoint (`readJvmRecord`). */
|
|
223
|
+
function recordEntry(entry) {
|
|
224
|
+
if (entry.snapshot !== entry.checkpoint)
|
|
225
|
+
return entry;
|
|
226
|
+
const { snapshot: _same, ...once } = entry;
|
|
227
|
+
return once;
|
|
228
|
+
}
|
|
220
229
|
/** The config object the bridge reads from a `start` line. `matchId` first: a refusal quotes the line's first 200 characters. */
|
|
221
230
|
function bridgeConfig(matchId, spec, aiFlatMc) {
|
|
222
231
|
return { matchId, ...spec, aiFlatMc };
|
|
@@ -270,19 +279,19 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
270
279
|
hostId: jvm.hostId,
|
|
271
280
|
startedAt: jvm.startedAt,
|
|
272
281
|
...(jvm.orphanedAt === null ? {} : { orphanedAt: jvm.orphanedAt }),
|
|
273
|
-
matches: hosted.map((h) => h.entry),
|
|
282
|
+
matches: hosted.map((h) => recordEntry(h.entry)),
|
|
274
283
|
};
|
|
275
284
|
try {
|
|
276
285
|
writeFileAtomic(join(jvm.dir, JVM_RECORD_FILE), `${JSON.stringify(record, null, 2)}\n`);
|
|
277
286
|
for (const h of hosted)
|
|
278
|
-
h.
|
|
287
|
+
h.changed = false;
|
|
279
288
|
}
|
|
280
289
|
catch (err) {
|
|
281
290
|
// The old record is whole (`writeFileAtomic`), so it names each match as it was. One whose
|
|
282
291
|
// entry changed since cannot be re-attached as it is now, and must not be handed over.
|
|
283
292
|
poolLog({ evt: 'jvm-record-failed', id: jvm.hostId, error: err.message });
|
|
284
293
|
for (const h of hosted)
|
|
285
|
-
if (h.
|
|
294
|
+
if (h.changed)
|
|
286
295
|
degrade(h, `its record could not be written (${err.message})`);
|
|
287
296
|
}
|
|
288
297
|
}
|
|
@@ -314,6 +323,21 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
314
323
|
(h.events?.log ?? poolLog)({ evt: 'match-stream-close-failed', matchId: h.id, error: err.message });
|
|
315
324
|
}
|
|
316
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Remove an ended match's stream: nothing replays a match that is over. Not a handed-over match's
|
|
328
|
+
* (the next server replays it), not a degraded one's (moved aside for a reader), and not one that
|
|
329
|
+
* never started (`held`): the file at its path is still its old copy's.
|
|
330
|
+
*/
|
|
331
|
+
function dropStream(h) {
|
|
332
|
+
if (h.held !== null || h.handed || h.degraded !== null)
|
|
333
|
+
return;
|
|
334
|
+
try {
|
|
335
|
+
rmSync(streamFile(h.jvm.dir, h.id), { force: true });
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
(h.events?.log ?? poolLog)({ evt: 'match-stream-remove-failed', matchId: h.id, error: err.message });
|
|
339
|
+
}
|
|
340
|
+
}
|
|
317
341
|
/** The match has a hole now, so it can never be replayed: it plays on here, but cannot outlive us. */
|
|
318
342
|
function degrade(h, cause) {
|
|
319
343
|
if (h.degraded !== null)
|
|
@@ -534,6 +558,8 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
534
558
|
if (h.stopTimer !== null)
|
|
535
559
|
clearTimeout(h.stopTimer);
|
|
536
560
|
closeStream(h);
|
|
561
|
+
// Before a restore waiting behind it starts: that one's stream has the same path.
|
|
562
|
+
dropStream(h);
|
|
537
563
|
if (pending.get(h.id) === h)
|
|
538
564
|
pending.delete(h.id);
|
|
539
565
|
const jvm = h.jvm;
|
|
@@ -584,6 +610,15 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
584
610
|
}
|
|
585
611
|
jvm.matches.clear();
|
|
586
612
|
jvm.waiting.clear();
|
|
613
|
+
// A claw's mirror of its record and streams: nothing re-attaches a JVM that is gone.
|
|
614
|
+
if (launcher.settlesRunDirs !== true && !lost.some((h) => h.handed)) {
|
|
615
|
+
try {
|
|
616
|
+
rmSync(jvm.dir, { recursive: true, force: true });
|
|
617
|
+
}
|
|
618
|
+
catch (err) {
|
|
619
|
+
poolLog({ evt: 'jvm-dir-remove-failed', id: jvm.hostId, dir: jvm.dir, error: err.message });
|
|
620
|
+
}
|
|
621
|
+
}
|
|
587
622
|
if (reaping)
|
|
588
623
|
return;
|
|
589
624
|
if (lost.some((h) => !h.stopping)) {
|
|
@@ -750,6 +785,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
750
785
|
...(state.clockPaused === true ? { clockPaused: true } : {}),
|
|
751
786
|
...(state.clockSeated === true ? { clockSeated: true } : {}),
|
|
752
787
|
};
|
|
788
|
+
h.changed = true;
|
|
753
789
|
writeRecord(h.jvm);
|
|
754
790
|
},
|
|
755
791
|
handOver: () => {
|
|
@@ -836,7 +872,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
836
872
|
jvm,
|
|
837
873
|
events,
|
|
838
874
|
entry: { matchId, startedAt: new Date().toISOString(), epoch: null, owners: [], checkpoint: null, spec },
|
|
839
|
-
|
|
875
|
+
changed: true,
|
|
840
876
|
stopping: false,
|
|
841
877
|
ended: false,
|
|
842
878
|
handed: false,
|
|
@@ -925,7 +961,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
925
961
|
jvm,
|
|
926
962
|
events: null,
|
|
927
963
|
entry,
|
|
928
|
-
|
|
964
|
+
changed: false,
|
|
929
965
|
stopping: false,
|
|
930
966
|
ended: false,
|
|
931
967
|
handed: false,
|
|
@@ -949,6 +985,37 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
949
985
|
if (jvm.matches.size === 0)
|
|
950
986
|
idle(jvm);
|
|
951
987
|
}
|
|
988
|
+
/**
|
|
989
|
+
* A launcher that does not settle its JVMs' directories (a claw's mirror) leaves one behind for
|
|
990
|
+
* every JVM that ended while no server held it. Once discovery has answered, a directory no
|
|
991
|
+
* running JVM and no JVM of this pool claims is nobody's: removed.
|
|
992
|
+
*/
|
|
993
|
+
function sweepMirrors(running) {
|
|
994
|
+
if (launcher.settlesRunDirs === true)
|
|
995
|
+
return;
|
|
996
|
+
const claimed = new Set([...running, ...[...jvms].map((j) => j.hostId)]);
|
|
997
|
+
const removed = [];
|
|
998
|
+
let entries;
|
|
999
|
+
try {
|
|
1000
|
+
entries = readdirSync(config.workDir);
|
|
1001
|
+
}
|
|
1002
|
+
catch {
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
for (const name of entries.sort()) {
|
|
1006
|
+
if (!RUN_DIR_NAME.test(name) || claimed.has(name))
|
|
1007
|
+
continue;
|
|
1008
|
+
try {
|
|
1009
|
+
rmSync(join(config.workDir, name), { recursive: true, force: true });
|
|
1010
|
+
removed.push(name);
|
|
1011
|
+
}
|
|
1012
|
+
catch (err) {
|
|
1013
|
+
poolLog({ evt: 'jvm-dir-remove-failed', id: name, error: err.message });
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
if (removed.length > 0)
|
|
1017
|
+
poolLog({ evt: 'jvm-mirrors-swept', workDir: config.workDir, removed });
|
|
1018
|
+
}
|
|
952
1019
|
/** Nobody came back for these. See "A match outlives its server". */
|
|
953
1020
|
function dropUnclaimed() {
|
|
954
1021
|
for (const h of [...pending.values()]) {
|
|
@@ -964,6 +1031,7 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
964
1031
|
const found = launcher
|
|
965
1032
|
.running()
|
|
966
1033
|
.then((hostIds) => {
|
|
1034
|
+
sweepMirrors(hostIds);
|
|
967
1035
|
for (const hostId of hostIds) {
|
|
968
1036
|
try {
|
|
969
1037
|
adopt(hostId);
|
|
@@ -34,4 +34,9 @@ export interface JvmLauncher {
|
|
|
34
34
|
* claw held the event loop past every other claw's fencing window.
|
|
35
35
|
*/
|
|
36
36
|
unavailable?(): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* The launcher settles each JVM's directory itself once it ends (the local one: removed, or kept
|
|
39
|
+
* as a crash record). Absent, the pool removes it at the JVM's exit (a claw's mirror).
|
|
40
|
+
*/
|
|
41
|
+
readonly settlesRunDirs?: boolean;
|
|
37
42
|
}
|
package/dist/play/local-jvm.d.ts
CHANGED
|
@@ -30,9 +30,8 @@
|
|
|
30
30
|
* process left, and spares a directory some process is standing in (`/proc/<pid>/cwd` — so
|
|
31
31
|
* another server's live JVM survives), one changed in the last `RUN_DIR_FRESH_MS`, and crash
|
|
32
32
|
* records within the bound. A live directory whose `launch.json` pid IS the process standing in
|
|
33
|
-
* it is one of ours, and `running()` offers it back.
|
|
34
|
-
*
|
|
35
|
-
* cannot be read the sweep does nothing and says so.
|
|
33
|
+
* it is one of ours, and `running()` offers it back. Where `/proc` cannot be read the sweep
|
|
34
|
+
* does nothing and says so.
|
|
36
35
|
*
|
|
37
36
|
* ## A JVM outlives its server (Wave 22, §E)
|
|
38
37
|
*
|
|
@@ -289,6 +288,8 @@ export declare const RUN_DIR_FRESH_MS = 60000;
|
|
|
289
288
|
* coordinator's record of the matches it hosted, with their decks, so one can be replayed.
|
|
290
289
|
*/
|
|
291
290
|
export declare const CRASH_RECORD_FILES: readonly ["bridge.stderr.txt", "jvm.json", "crash.json"];
|
|
291
|
+
/** A JVM's host id (`h-…`, `host.ts`'s `launch`), which names its run directory. Nothing else under `workDir` is ours. */
|
|
292
|
+
export declare const RUN_DIR_NAME: RegExp;
|
|
292
293
|
/** Why a JVM that did not end cleanly ended — written as `crash.json`. */
|
|
293
294
|
export interface CrashRecord {
|
|
294
295
|
id: string;
|
|
@@ -338,6 +339,4 @@ export declare function localJvmLauncher(config: JvmHostConfig, options?: LocalL
|
|
|
338
339
|
* spawn appends `'--host', hostId` itself, after exactly these flags — the interface doesn't carry
|
|
339
340
|
* a host id to launch with.
|
|
340
341
|
*/
|
|
341
|
-
export declare function forgeEngineRuntime(config: JvmHostConfig, log: (entry: Record<string, unknown>) => void): EngineRuntime
|
|
342
|
-
spawn: NonNullable<EngineRuntime['spawn']>;
|
|
343
|
-
};
|
|
342
|
+
export declare function forgeEngineRuntime(config: JvmHostConfig, log: (entry: Record<string, unknown>) => void): EngineRuntime;
|
package/dist/play/local-jvm.js
CHANGED
|
@@ -30,9 +30,8 @@
|
|
|
30
30
|
* process left, and spares a directory some process is standing in (`/proc/<pid>/cwd` — so
|
|
31
31
|
* another server's live JVM survives), one changed in the last `RUN_DIR_FRESH_MS`, and crash
|
|
32
32
|
* records within the bound. A live directory whose `launch.json` pid IS the process standing in
|
|
33
|
-
* it is one of ours, and `running()` offers it back.
|
|
34
|
-
*
|
|
35
|
-
* cannot be read the sweep does nothing and says so.
|
|
33
|
+
* it is one of ours, and `running()` offers it back. Where `/proc` cannot be read the sweep
|
|
34
|
+
* does nothing and says so.
|
|
36
35
|
*
|
|
37
36
|
* ## A JVM outlives its server (Wave 22, §E)
|
|
38
37
|
*
|
|
@@ -80,7 +79,7 @@ import { homedir, tmpdir } from 'node:os';
|
|
|
80
79
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
81
80
|
import { createInterface } from 'node:readline';
|
|
82
81
|
import { bridgeDiagnostics } from './diagnostics.js';
|
|
83
|
-
import { CRASH_MARKER, IN_FIFO, JVM_TMP_DIR, OUT_FIFO, PID_POLL_MS, REAP_CONFIRM_MS, cwdIsUnder, defaultJava,
|
|
82
|
+
import { CRASH_MARKER, IN_FIFO, JVM_TMP_DIR, OUT_FIFO, PID_POLL_MS, REAP_CONFIRM_MS, cwdIsUnder, defaultJava, makeFifos, openJvmIo, pidIsRunning, pidIsStandingIn, pidIsStandingInRun, positiveInt, processCwds, pruneCrashRecords, runDirs, sleepSync, wrapChildProcess, } from './engine-runtime.js';
|
|
84
83
|
/**
|
|
85
84
|
* Forge's server drops a client it has read nothing from for this long
|
|
86
85
|
* (`FServerManager.HEARTBEAT_TIMEOUT_SECONDS`, `forge.net.heartbeatTimeout`, default 45 s;
|
|
@@ -437,13 +436,8 @@ function runDirDiagnostics(run) {
|
|
|
437
436
|
closeSync(fd);
|
|
438
437
|
}
|
|
439
438
|
}
|
|
440
|
-
/**
|
|
441
|
-
|
|
442
|
-
* matches per JVM, which a boot still ends and removes. Nothing else under `workDir` is ours.
|
|
443
|
-
*/
|
|
444
|
-
const RUN_DIR_NAME = /^(h|m|spare)-[0-9a-f]{12}$/;
|
|
445
|
-
/** A run directory from before many matches per JVM: one match each, re-attached by nothing now. */
|
|
446
|
-
const LEGACY_RUN_DIR = /^(m|spare)-/;
|
|
439
|
+
/** A JVM's host id (`h-…`, `host.ts`'s `launch`), which names its run directory. Nothing else under `workDir` is ours. */
|
|
440
|
+
export const RUN_DIR_NAME = /^h-[0-9a-f]{12}$/;
|
|
447
441
|
/** Keep the diagnostics, drop Forge's scaffolding (the `res` symlink is unlinked, never followed). */
|
|
448
442
|
function keepCrashRecord(run, record) {
|
|
449
443
|
const keep = new Set(CRASH_RECORD_FILES);
|
|
@@ -465,27 +459,13 @@ export function readLaunchRecord(run) {
|
|
|
465
459
|
return null;
|
|
466
460
|
}
|
|
467
461
|
}
|
|
468
|
-
/** The pid a one-match JVM's own record named (`jvm.json`, or `jvm.degraded.json` once its stream broke). */
|
|
469
|
-
function legacyPid(run) {
|
|
470
|
-
for (const file of ['jvm.json', 'jvm.degraded.json']) {
|
|
471
|
-
try {
|
|
472
|
-
const pid = JSON.parse(readFileSync(join(run, file), 'utf8')).pid;
|
|
473
|
-
if (typeof pid === 'number')
|
|
474
|
-
return pid;
|
|
475
|
-
}
|
|
476
|
-
catch {
|
|
477
|
-
// Not this one; the other, or none.
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
462
|
/**
|
|
483
463
|
* Remove the run directories an earlier process left behind, and hand back the JVMs that are
|
|
484
464
|
* still running. See "The run directory" and "A JVM outlives its server" in the module header for
|
|
485
465
|
* what it spares and why.
|
|
486
466
|
*/
|
|
487
467
|
export function sweepRunDirs(workDir, now = Date.now()) {
|
|
488
|
-
const result = { removed: [], live: [], fresh: [], crashes: { kept: [], removed: [] }, running: []
|
|
468
|
+
const result = { removed: [], live: [], fresh: [], crashes: { kept: [], removed: [] }, running: [] };
|
|
489
469
|
const cwds = processCwds();
|
|
490
470
|
if (cwds === null)
|
|
491
471
|
return { ...result, skipped: '/proc is not readable, so a live run directory cannot be told from a dead one' };
|
|
@@ -496,20 +476,9 @@ export function sweepRunDirs(workDir, now = Date.now()) {
|
|
|
496
476
|
// whose it is, answered by the directory's own record: a pid that IS the process
|
|
497
477
|
// standing here. Its `run` string is deliberately not compared — `runDirs` resolves
|
|
498
478
|
// `workDir` through `realpath` and the writer did not.
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
killPid(pid);
|
|
503
|
-
rmSync(dir, { recursive: true, force: true });
|
|
504
|
-
result.killed.push(name);
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
else {
|
|
509
|
-
const launch = readLaunchRecord(dir);
|
|
510
|
-
if (launch !== null && launch.hostId === name && pidIsStandingIn(launch.pid, dir) === true) {
|
|
511
|
-
result.running.push({ hostId: name, pid: launch.pid, run: dir, startedAt: launch.startedAt });
|
|
512
|
-
}
|
|
479
|
+
const launch = readLaunchRecord(dir);
|
|
480
|
+
if (launch !== null && launch.hostId === name && pidIsStandingIn(launch.pid, dir) === true) {
|
|
481
|
+
result.running.push({ hostId: name, pid: launch.pid, run: dir, startedAt: launch.startedAt });
|
|
513
482
|
}
|
|
514
483
|
result.live.push(name);
|
|
515
484
|
continue;
|
|
@@ -768,7 +737,6 @@ export function localJvmLauncher(config, options = {}) {
|
|
|
768
737
|
removed: swept.removed.length,
|
|
769
738
|
live: swept.live,
|
|
770
739
|
fresh: swept.fresh,
|
|
771
|
-
killed: swept.killed,
|
|
772
740
|
running: [...found.keys()],
|
|
773
741
|
crashRecords: swept.crashes.kept.length,
|
|
774
742
|
crashRecordsRemoved: swept.crashes.removed.length,
|
|
@@ -782,6 +750,7 @@ export function localJvmLauncher(config, options = {}) {
|
|
|
782
750
|
}
|
|
783
751
|
return {
|
|
784
752
|
swept,
|
|
753
|
+
settlesRunDirs: true,
|
|
785
754
|
launch(hostId, opts) {
|
|
786
755
|
const run = join(config.workDir, hostId);
|
|
787
756
|
try {
|
|
@@ -818,7 +787,6 @@ export function localJvmLauncher(config, options = {}) {
|
|
|
818
787
|
*/
|
|
819
788
|
export function forgeEngineRuntime(config, log) {
|
|
820
789
|
return {
|
|
821
|
-
artifacts: { jar: config.jar, res: config.res, bridgeSource: config.bridgeSource },
|
|
822
790
|
argv: (dir, size) => {
|
|
823
791
|
const bridge = bridgeLaunch(config, log);
|
|
824
792
|
return [
|
|
@@ -830,10 +798,6 @@ export function forgeEngineRuntime(config, log) {
|
|
|
830
798
|
...bridge.args,
|
|
831
799
|
];
|
|
832
800
|
},
|
|
833
|
-
// ~172 MB live idle (JVM_HEAP_MB's doc, above: Wave 9 lane D; 4–9 MB in hosting-test-plan B3).
|
|
834
|
-
overheadMb: 172,
|
|
835
|
-
perProcess: config.perJvm ?? MATCHES_PER_JVM,
|
|
836
|
-
health: () => ({ recycle: false }),
|
|
837
801
|
// `detached` puts it in its own process group, so a signal aimed at ours never reaches it;
|
|
838
802
|
// `unref` keeps it off our event loop — the same two reasons `LocalJvm`'s own spawn call
|
|
839
803
|
// used to carry, now exercised here instead of at the call site.
|
|
@@ -163,6 +163,8 @@ export interface RelayMatchRegistry {
|
|
|
163
163
|
*/
|
|
164
164
|
register(id: string, seatCount: number, deps: RelayMatchDeps): RelayMatch;
|
|
165
165
|
get(id: string): RelayMatch | undefined;
|
|
166
|
+
/** The room is gone: its match is not looked up again, and its end registers no next one. */
|
|
167
|
+
forget(id: string): void;
|
|
166
168
|
}
|
|
167
169
|
/**
|
|
168
170
|
* A registry of `RelayMatch`es, keyed by match (room) id. A match that ends is replaced by the
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The streamed desktop (Forge's own GUI, in a container — `../../stream/**`),
|
|
3
|
-
*
|
|
4
|
-
* the "start it, track it, a failed start is the match's fatal, tear it down" shape any engine's
|
|
5
|
-
* host needs. `stream/alloc.ts` already provisions and reclaims a room's containers; this file is
|
|
2
|
+
* The streamed desktop (Forge's own GUI, in a container — `../../stream/**`), in the "start it,
|
|
3
|
+
* track it, a failed start is the match's fatal, tear it down" shape any engine's host needs. `stream/alloc.ts` already provisions and reclaims a room's containers; this file is
|
|
6
4
|
* what turns that into the same start/track/stop vocabulary, and `plugins/stream.ts` (the one
|
|
7
5
|
* caller, in `ensureRoomStreams`) is wired through it rather than calling `RoomStreams.allocate`
|
|
8
6
|
* directly.
|
|
@@ -20,15 +18,6 @@
|
|
|
20
18
|
* `stream/alloc.ts` and `stream/index.ts` — the platform allocator — import neither this file's
|
|
21
19
|
* env names nor any Forge path; only this file and `plugins/stream.ts` (the composition point) do.
|
|
22
20
|
*
|
|
23
|
-
* ## Not a `child_process.spawn`
|
|
24
|
-
*
|
|
25
|
-
* A streamed desktop's "process" is a docker container `scripts/stream/container.sh` starts; this
|
|
26
|
-
* server never forks it directly, so {@link streamedEngineRuntime}'s `argv` returns nothing and it
|
|
27
|
-
* leaves `spawn` unset — `EngineRuntime.spawn` is optional for exactly this case (see
|
|
28
|
-
* `engine-runtime.ts`'s own doc). `perProcess` is 1: one container is one seat, with none of the
|
|
29
|
-
* Forge JVM pool's sharing (a streamed room gets one container per seat; a shared screen is
|
|
30
|
-
* cheaper and is not a game).
|
|
31
|
-
*
|
|
32
21
|
* ## Tracked, not pooled through `host.ts`
|
|
33
22
|
*
|
|
34
23
|
* `host.ts`/`match.ts` still place every Forge match through `localJvmLauncher`'s `JvmLauncher`;
|
|
@@ -40,10 +29,7 @@
|
|
|
40
29
|
* `RoomStreamsOptions.onEnded`, which `plugins/stream.ts` wires to the matching host's `settled()`,
|
|
41
30
|
* so every ending reaches this file's vocabulary, not only an explicit `stop()`.
|
|
42
31
|
*/
|
|
43
|
-
import type { EngineRuntime } from '../engine-runtime.js';
|
|
44
32
|
import type { RoomStreams } from '../../stream/alloc.js';
|
|
45
|
-
/** Measured 2026-09-19, `docs/spikes/streaming.md`, "the host" section: "Budget 1.3 GiB per streamed desktop." */
|
|
46
|
-
export declare const STREAMED_CONTAINER_MB = 1331;
|
|
47
33
|
/** The two Magic-specific paths a streamed desktop's container mounts. See the module header. */
|
|
48
34
|
export interface StreamedMagicConfig {
|
|
49
35
|
forgeJar: string;
|
|
@@ -72,14 +58,6 @@ export declare function streamedEngineConfig(env?: NodeJS.ProcessEnv): StreamedA
|
|
|
72
58
|
* mounts.
|
|
73
59
|
*/
|
|
74
60
|
export declare function streamedContainerEnv(config: StreamedMagicConfig): Record<string, string>;
|
|
75
|
-
/**
|
|
76
|
-
* `EngineRuntime` (`../engine-runtime.ts`) for the streamed desktop: what it costs, in the same
|
|
77
|
-
* vocabulary the JVM pool's `forgeEngineRuntime` (`../local-jvm.ts`) uses, so a reader comparing
|
|
78
|
-
* the two engines this host runs sees one shape, not two. `argv`/`spawn` are left as the
|
|
79
|
-
* interface's own no-op/unset for an engine whose process is a container, not something this
|
|
80
|
-
* server forks — see the module header, "Not a `child_process.spawn`".
|
|
81
|
-
*/
|
|
82
|
-
export declare function streamedEngineRuntime(config: StreamedMagicConfig): EngineRuntime;
|
|
83
61
|
/**
|
|
84
62
|
* What a seat's containers coming up or going down tells the host, in the same three-part
|
|
85
63
|
* vocabulary `host.ts`'s `HostEvents` uses (a line, an exit, a log entry) without importing that
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The streamed desktop (Forge's own GUI, in a container — `../../stream/**`),
|
|
3
|
-
*
|
|
4
|
-
* the "start it, track it, a failed start is the match's fatal, tear it down" shape any engine's
|
|
5
|
-
* host needs. `stream/alloc.ts` already provisions and reclaims a room's containers; this file is
|
|
2
|
+
* The streamed desktop (Forge's own GUI, in a container — `../../stream/**`), in the "start it,
|
|
3
|
+
* track it, a failed start is the match's fatal, tear it down" shape any engine's host needs. `stream/alloc.ts` already provisions and reclaims a room's containers; this file is
|
|
6
4
|
* what turns that into the same start/track/stop vocabulary, and `plugins/stream.ts` (the one
|
|
7
5
|
* caller, in `ensureRoomStreams`) is wired through it rather than calling `RoomStreams.allocate`
|
|
8
6
|
* directly.
|
|
@@ -20,15 +18,6 @@
|
|
|
20
18
|
* `stream/alloc.ts` and `stream/index.ts` — the platform allocator — import neither this file's
|
|
21
19
|
* env names nor any Forge path; only this file and `plugins/stream.ts` (the composition point) do.
|
|
22
20
|
*
|
|
23
|
-
* ## Not a `child_process.spawn`
|
|
24
|
-
*
|
|
25
|
-
* A streamed desktop's "process" is a docker container `scripts/stream/container.sh` starts; this
|
|
26
|
-
* server never forks it directly, so {@link streamedEngineRuntime}'s `argv` returns nothing and it
|
|
27
|
-
* leaves `spawn` unset — `EngineRuntime.spawn` is optional for exactly this case (see
|
|
28
|
-
* `engine-runtime.ts`'s own doc). `perProcess` is 1: one container is one seat, with none of the
|
|
29
|
-
* Forge JVM pool's sharing (a streamed room gets one container per seat; a shared screen is
|
|
30
|
-
* cheaper and is not a game).
|
|
31
|
-
*
|
|
32
21
|
* ## Tracked, not pooled through `host.ts`
|
|
33
22
|
*
|
|
34
23
|
* `host.ts`/`match.ts` still place every Forge match through `localJvmLauncher`'s `JvmLauncher`;
|
|
@@ -42,8 +31,6 @@
|
|
|
42
31
|
*/
|
|
43
32
|
import { existsSync } from 'node:fs';
|
|
44
33
|
import { resolve } from 'node:path';
|
|
45
|
-
/** Measured 2026-09-19, `docs/spikes/streaming.md`, "the host" section: "Budget 1.3 GiB per streamed desktop." */
|
|
46
|
-
export const STREAMED_CONTAINER_MB = 1331;
|
|
47
34
|
/**
|
|
48
35
|
* Resolve the streamed desktop's Magic config from the environment, validated the way
|
|
49
36
|
* `jvmHostConfig` (`../local-jvm.ts`) validates the JVM pool's: a missing or malformed jar/res is a
|
|
@@ -75,28 +62,6 @@ export function streamedEngineConfig(env = process.env) {
|
|
|
75
62
|
export function streamedContainerEnv(config) {
|
|
76
63
|
return { CARDTABLE_STREAM_FORGE_JAR: config.forgeJar, CARDTABLE_STREAM_FORGE_RES: config.forgeRes };
|
|
77
64
|
}
|
|
78
|
-
/**
|
|
79
|
-
* `EngineRuntime` (`../engine-runtime.ts`) for the streamed desktop: what it costs, in the same
|
|
80
|
-
* vocabulary the JVM pool's `forgeEngineRuntime` (`../local-jvm.ts`) uses, so a reader comparing
|
|
81
|
-
* the two engines this host runs sees one shape, not two. `argv`/`spawn` are left as the
|
|
82
|
-
* interface's own no-op/unset for an engine whose process is a container, not something this
|
|
83
|
-
* server forks — see the module header, "Not a `child_process.spawn`".
|
|
84
|
-
*/
|
|
85
|
-
export function streamedEngineRuntime(config) {
|
|
86
|
-
return {
|
|
87
|
-
artifacts: { jar: config.forgeJar, res: config.forgeRes },
|
|
88
|
-
// Nothing here builds a java command line: the container's own entrypoint launches Forge's
|
|
89
|
-
// desktop itself from the jar/res it was handed as a mount, not an argv this process picks.
|
|
90
|
-
argv: () => [],
|
|
91
|
-
overheadMb: STREAMED_CONTAINER_MB,
|
|
92
|
-
// One seat, one container, always — unlike the JVM pool's `MATCHES_PER_JVM`, nothing shares.
|
|
93
|
-
perProcess: 1,
|
|
94
|
-
// `stream/alloc.ts`'s own idle/room-gone sweep is this engine's recycle policy; a crashed
|
|
95
|
-
// container looks the same as a reclaimed one to the allocator (both just stop answering
|
|
96
|
-
// `portOf`), so this hook has nothing further to add.
|
|
97
|
-
health: () => ({ recycle: false }),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
65
|
/**
|
|
101
66
|
* Starts (or finds already-live) a room's seats' containers through `rooms`
|
|
102
67
|
* (`../../stream/alloc.ts`'s `RoomStreams`), and reports back in {@link StreamedHostEvents}'s
|
package/dist/relay-game.d.ts
CHANGED
|
@@ -59,7 +59,10 @@ export interface RelayGameState {
|
|
|
59
59
|
lobby: RelayLobby;
|
|
60
60
|
people: People;
|
|
61
61
|
starts: Starts;
|
|
62
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Each `/room` connection's friend key, by participant id: the key its round results are reported
|
|
64
|
+
* under. A credential, so held only while its participant is connected there or in a room.
|
|
65
|
+
*/
|
|
63
66
|
userKeys: Map<string, string>;
|
|
64
67
|
}
|
|
65
68
|
export type RelayGamePlugin = GamePlugin<Record<string, never>, RelayGameState>;
|
package/dist/relay-game.js
CHANGED
|
@@ -120,8 +120,10 @@ export async function startRelayGame(options) {
|
|
|
120
120
|
ctx.state.lobby = lobby;
|
|
121
121
|
ctx.gauge('rooms', () => lobby.list().length);
|
|
122
122
|
lobby.onChange((roomId) => {
|
|
123
|
-
if (lobby.get(roomId)
|
|
124
|
-
|
|
123
|
+
if (lobby.get(roomId) !== undefined)
|
|
124
|
+
return;
|
|
125
|
+
starts.forget(roomId);
|
|
126
|
+
relayMatches.forget(roomId);
|
|
125
127
|
});
|
|
126
128
|
// A room IS its match: one relay match per room, opened as the room is.
|
|
127
129
|
lobby.onRelayRoomOpened((roomId, seatCount) => {
|
|
@@ -293,12 +295,23 @@ export async function startRelayGame(options) {
|
|
|
293
295
|
});
|
|
294
296
|
// Each connection's own friend key, from ITS handshake (sanitized by the relay's provenance
|
|
295
297
|
// check above): the key its round results are reported under.
|
|
296
|
-
ctx.io.of('/room')
|
|
298
|
+
const roomSockets = ctx.io.of('/room');
|
|
299
|
+
const forgetGoneKeys = () => {
|
|
300
|
+
const connected = new Set([...roomSockets.sockets.values()].map((s) => identityFromHeaders(s.request.headers, s.id)));
|
|
301
|
+
const rooms = lobby.list();
|
|
302
|
+
for (const participantId of ctx.state.userKeys.keys()) {
|
|
303
|
+
if (!connected.has(participantId) && !rooms.some((r) => lobby.isMember(r.id, participantId)))
|
|
304
|
+
ctx.state.userKeys.delete(participantId);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
roomSockets.on('connection', (socket) => {
|
|
308
|
+
socket.on('disconnect', forgetGoneKeys);
|
|
297
309
|
const key = socket.request.headers['x-user-key'];
|
|
298
310
|
if (typeof key !== 'string' || key === '')
|
|
299
311
|
return;
|
|
300
312
|
ctx.state.userKeys.set(identityFromHeaders(socket.request.headers, socket.id), key);
|
|
301
313
|
});
|
|
314
|
+
lobby.onChange(forgetGoneKeys);
|
|
302
315
|
const feed = attachRoomFeed(ctx.io, { lobby, log: jsonLogger(`${id}-feed`) });
|
|
303
316
|
feedChanged = (roomId) => feed.changed(roomId);
|
|
304
317
|
roomHere = served.here;
|
package/dist/room/lobby.d.ts
CHANGED
|
@@ -128,8 +128,6 @@ export interface RoomTypeHooks<G, I extends RoomCreateInput = RoomCreateInput> {
|
|
|
128
128
|
};
|
|
129
129
|
/** The game part as stored. */
|
|
130
130
|
encode(room: LobbyRoom<G>): unknown;
|
|
131
|
-
/** The stored `app` as written: anything the type writes beside it (a copy an older build reads). Default: as it is. */
|
|
132
|
-
writes?(app: StoredRoomApp): object;
|
|
133
131
|
/**
|
|
134
132
|
* The stored `app` read back: its game seats and its game part, as stored. Throws to quarantine the room;
|
|
135
133
|
* the message names the field, never a value. `version` is the app blob's own (`ROOM_APP_VERSION` or older).
|
|
@@ -397,7 +395,7 @@ export interface LobbyCoreOptions<I extends RoomCreateInput> {
|
|
|
397
395
|
* type. Its errors name the FIELD, never a value: the message reaches the quarantine reason and the
|
|
398
396
|
* log, and a value here could be the hash.
|
|
399
397
|
*/
|
|
400
|
-
export declare function roomAppCodec(typeOf: (gameType: string) => Pick<RoomTypeHooks<unknown>, 'decode'
|
|
398
|
+
export declare function roomAppCodec(typeOf: (gameType: string) => Pick<RoomTypeHooks<unknown>, 'decode'> | undefined): RoomCodec<StoredRoomApp, unknown>;
|
|
401
399
|
/**
|
|
402
400
|
* The lobby core. `V` is the view a room of the hosting game reads as (the platform's fields and
|
|
403
401
|
* the type's part); `I` the create input. A game's lobby extends it with its own operations, which
|
|
@@ -422,8 +420,8 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
|
|
|
422
420
|
/** Tell every `onChange` listener `roomId` reads differently now, with nothing written. */
|
|
423
421
|
protected changed(roomId: string): void;
|
|
424
422
|
/**
|
|
425
|
-
* Be told every time a room is written, created or forgotten
|
|
426
|
-
*
|
|
423
|
+
* Be told every time a room is written, created or forgotten, or a member's name, avatar or look
|
|
424
|
+
* changes (none of which is written), so this is every change a read could see and nothing else: a read (`touch`, `get`,
|
|
427
425
|
* `list`) never fires it. Returns the unsubscribe.
|
|
428
426
|
*/
|
|
429
427
|
onChange(listener: (roomId: string) => void): () => void;
|
|
@@ -511,7 +509,8 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
|
|
|
511
509
|
/**
|
|
512
510
|
* Call `caller.id` by `caller.name` in every room they are a member of. The name was copied once, at
|
|
513
511
|
* join, so a key renamed in the registry kept its first name in every room it had joined
|
|
514
|
-
* (2026-10-26).
|
|
512
|
+
* (2026-10-26). Tells only the rooms whose copy moved, and writes none: a name is never stored (R12),
|
|
513
|
+
* so a rename is not a change to the room and leaves its age alone.
|
|
515
514
|
*/
|
|
516
515
|
rename(caller: Pick<Caller, 'id' | 'name'>): void;
|
|
517
516
|
/** false when there is no such room or the caller is not a member. Persisted. */
|
|
@@ -520,7 +519,7 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
|
|
|
520
519
|
* The member's OWN avatar, and nobody else's: `memberId` is always a derived participant id, so a
|
|
521
520
|
* browser cannot name a row that is not its own. Three states in, two stored: a non-blank string
|
|
522
521
|
* sets it; `null`, `''`, whitespace, an over-long value and a non-string clear it (`avatarIdOf`).
|
|
523
|
-
* `false` only when there is no such room or member.
|
|
522
|
+
* `false` only when there is no such room or member. Never written (R12): told to the room when it changed.
|
|
524
523
|
*/
|
|
525
524
|
setAvatar(roomId: string, memberId: string, avatarId: string | null): boolean;
|
|
526
525
|
/** Each member's registry userId, for looking up how they look. Never part of a view. */
|