@hadoku/game-server 0.1.177 → 0.1.179
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/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/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/base-path.d.ts
CHANGED
|
@@ -16,9 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* So: compare them here, once, at boot, and say precisely what to change.
|
|
18
18
|
*/
|
|
19
|
-
import { type BasePathVerdict
|
|
20
|
-
export type { BasePathVerdict };
|
|
21
|
-
export { sendIndex };
|
|
19
|
+
import { type BasePathVerdict } from '@wolffm/service-kernel/http';
|
|
22
20
|
/**
|
|
23
21
|
* The embed bundle's two fixed-name files (D21): `apps/ui/vite.embed.config.ts`
|
|
24
22
|
* emits them, watchparty imports the `.js`. Every other file in the bundle is
|
package/dist/base-path.js
CHANGED
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* So: compare them here, once, at boot, and say precisely what to change.
|
|
18
18
|
*/
|
|
19
|
-
import { diagnosticPage as kernelDiagnosticPage
|
|
20
|
-
export { sendIndex };
|
|
19
|
+
import { diagnosticPage as kernelDiagnosticPage } from '@wolffm/service-kernel/http';
|
|
21
20
|
/**
|
|
22
21
|
* The embed bundle's two fixed-name files (D21): `apps/ui/vite.embed.config.ts`
|
|
23
22
|
* emits them, watchparty imports the `.js`. Every other file in the bundle is
|
package/dist/busy.d.ts
CHANGED
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
* until its deadline — at which point the deadline kills the real match anyway.
|
|
23
23
|
*/
|
|
24
24
|
import type { BusyReport } from '@wolffm/service-kernel/lifecycle';
|
|
25
|
-
export { isLocalProbe, type BusyReport, type BusyRun } from '@wolffm/service-kernel/lifecycle';
|
|
26
25
|
export interface BusySources {
|
|
27
26
|
matches(): ReadonlyArray<{
|
|
28
27
|
id: string;
|
package/dist/busy.js
CHANGED
package/dist/config.d.ts
CHANGED
|
@@ -38,11 +38,6 @@ import { type Tier } from '@wolffm/service-kernel/auth';
|
|
|
38
38
|
*/
|
|
39
39
|
export declare const APP_ROOT: string;
|
|
40
40
|
/** Resolve a configured path against the package root unless it is absolute. */
|
|
41
|
-
/** The in-clone paths a state dir replaces, for the boot move (`state-dir.ts`). */
|
|
42
|
-
export declare const LEGACY_STATE: {
|
|
43
|
-
readonly dataDir: string;
|
|
44
|
-
readonly logDir: string;
|
|
45
|
-
};
|
|
46
41
|
export interface CreateConfigOptions {
|
|
47
42
|
/** Every env var this factory reads is `<envPrefix>_<NAME>`. Default `'CARDTABLE'`. */
|
|
48
43
|
envPrefix?: string;
|
package/dist/config.js
CHANGED
|
@@ -40,9 +40,6 @@ const HERE = dirname(fileURLToPath(import.meta.url));
|
|
|
40
40
|
* tsx) it is `packages/game-server/src/`, and the app it configures is `apps/server` beside it.
|
|
41
41
|
*/
|
|
42
42
|
export const APP_ROOT = basename(HERE) === 'dist' ? dirname(HERE) : resolve(HERE, '../../../apps/server');
|
|
43
|
-
/** Resolve a configured path against the package root unless it is absolute. */
|
|
44
|
-
/** The in-clone paths a state dir replaces, for the boot move (`state-dir.ts`). */
|
|
45
|
-
export const LEGACY_STATE = { dataDir: resolve(APP_ROOT, 'data'), logDir: resolve(APP_ROOT, 'logs') };
|
|
46
43
|
/** Everything a game-server app needs that is not specific to any one game (w119 §C). */
|
|
47
44
|
export function createConfig(options = {}) {
|
|
48
45
|
const prefix = options.envPrefix ?? 'CARDTABLE';
|
package/dist/edge-auth.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Edge provenance and the tier floor — cardtable's binding of the platform
|
|
3
3
|
* kernel (`@hadoku/service-kernel/auth`). The shared `createEdgeAuth`/`createGate`
|
|
4
|
-
* instances live in `kernel.ts` (w93-Z)
|
|
5
|
-
*
|
|
4
|
+
* instances live in `kernel.ts` (w93-Z). The plain re-exports stay: some thirty
|
|
5
|
+
* files here and bomberman's server (`accountIdOf`, through the published
|
|
6
|
+
* `@wolffm/game-server/edge-auth`) import them from this path.
|
|
6
7
|
*
|
|
7
8
|
* edge-router resolves the caller's tier once and stamps every request it
|
|
8
9
|
* proxies with X-Edge-Auth: <EDGE_AUTH_SECRET> plus X-Hadoku-Tier / X-User-Id /
|
package/dist/edge-auth.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Edge provenance and the tier floor — cardtable's binding of the platform
|
|
3
3
|
* kernel (`@hadoku/service-kernel/auth`). The shared `createEdgeAuth`/`createGate`
|
|
4
|
-
* instances live in `kernel.ts` (w93-Z)
|
|
5
|
-
*
|
|
4
|
+
* instances live in `kernel.ts` (w93-Z). The plain re-exports stay: some thirty
|
|
5
|
+
* files here and bomberman's server (`accountIdOf`, through the published
|
|
6
|
+
* `@wolffm/game-server/edge-auth`) import them from this path.
|
|
6
7
|
*
|
|
7
8
|
* edge-router resolves the caller's tier once and stamps every request it
|
|
8
9
|
* proxies with X-Edge-Auth: <EDGE_AUTH_SECRET> plus X-Hadoku-Tier / X-User-Id /
|
package/dist/gate.d.ts
CHANGED
|
@@ -6,18 +6,6 @@
|
|
|
6
6
|
* HTTP's own copy is `requireMinTier`, bound in `edge-auth.ts` — both files
|
|
7
7
|
* bind the one shared `createGate` instance in `kernel.ts` (w93-Z).
|
|
8
8
|
*/
|
|
9
|
-
/** HTTP gates itself via `requireMinTier` (`edge-auth.ts`), which calls {@link floor} directly. */
|
|
10
|
-
export type GateSurface = 'draft-socket' | 'play-socket' | 'stream';
|
|
11
|
-
/** `minTier`: `CONFIG.minTier` in production. `surface`: the `reportSealRefused` label. */
|
|
12
|
-
export interface GateOptions {
|
|
13
|
-
minTier: string;
|
|
14
|
-
surface: GateSurface;
|
|
15
|
-
}
|
|
16
|
-
/** Sanitize `headers` in place against edge provenance, then rank the result against `minTier`. */
|
|
17
|
-
export declare const floor: (headers: Record<string, unknown>, minTier: string) => {
|
|
18
|
-
ok: boolean;
|
|
19
|
-
tier: string;
|
|
20
|
-
};
|
|
21
9
|
/** Provenance + the floor on a socket.io handshake. `next(new Error('not found'))` is the client's `connect_error`. */
|
|
22
10
|
export declare const gateSocketIo: (io: import("socket.io").Server, opts: import("@wolffm/service-kernel/http").GateOptions) => void;
|
|
23
11
|
/** The floor for a raw upgrade: no middleware chain runs, so the caller answers the refusal itself. */
|
package/dist/gate.js
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
* bind the one shared `createGate` instance in `kernel.ts` (w93-Z).
|
|
8
8
|
*/
|
|
9
9
|
import { gate } from './kernel.js';
|
|
10
|
-
/** Sanitize `headers` in place against edge provenance, then rank the result against `minTier`. */
|
|
11
|
-
export const floor = gate.floor;
|
|
12
10
|
/** Provenance + the floor on a socket.io handshake. `next(new Error('not found'))` is the client's `connect_error`. */
|
|
13
11
|
export const gateSocketIo = gate.gateSocketIo;
|
|
14
12
|
/** The floor for a raw upgrade: no middleware chain runs, so the caller answers the refusal itself. */
|
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
* as `client` events, under `svc: 'cardtable-client'`, keyed by page and user. Nothing is stored
|
|
8
8
|
* and nothing is answered but 204; `perf` lines are also rolled up into the 5-minute `frames` event.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* bits are `@hadoku/platform-wire/telemetry`'s schema, path and per-second cap, bound here — the kernel itself
|
|
10
|
+
* `malformedFacts` is re-exported only until `play/socket.ts` imports it from the kernel. The
|
|
11
|
+
* cardtable-specific bits are `@hadoku/platform-wire/telemetry`'s schema, path and per-second cap, bound here — the kernel itself
|
|
13
12
|
* never imports it.
|
|
14
13
|
*
|
|
15
14
|
* Read them with `grep -a '"svc":"cardtable-client"' ~/.pm2/logs/cardtable-ppe-out.log` (PPE) or
|
package/dist/http/page.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { RateLimitConfig } from '@wolffm/rooms-server';
|
|
15
15
|
import type { Express } from 'express';
|
|
16
|
-
import { type BasePathVerdict } from '
|
|
16
|
+
import { type BasePathVerdict } from '@wolffm/service-kernel/http';
|
|
17
17
|
export declare const PAGE_LOAD_RATE_LIMIT: RateLimitConfig;
|
|
18
18
|
export interface PageDeps {
|
|
19
19
|
indexHtml: string;
|
package/dist/http/page.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* eight hours) is refused with a 429 and `rate-limited` telemetry naming it,
|
|
12
12
|
* while the busiest real caller (20 a minute) never meets the ceiling.
|
|
13
13
|
*/
|
|
14
|
-
import {
|
|
14
|
+
import { sendIndex } from '@wolffm/service-kernel/http';
|
|
15
|
+
import { diagnosticPage } from '../base-path.js';
|
|
15
16
|
import { perCallerLimit } from './request.js';
|
|
16
17
|
export const PAGE_LOAD_RATE_LIMIT = {
|
|
17
18
|
capacity: 30,
|
package/dist/http/usage.d.ts
CHANGED
|
@@ -6,15 +6,12 @@
|
|
|
6
6
|
* with their own ordered trail. The tier reported is the edge's (`edgeTierOf`), so a member reads
|
|
7
7
|
* as a member, not as the friend cardtable's gates treat them as. Nothing is answered but 204.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* `@hadoku/platform-wire/telemetry`'s schema and path, bound here — the kernel itself never imports it.
|
|
9
|
+
* The cardtable-specific bits are `@hadoku/platform-wire/telemetry`'s schema and path, bound here —
|
|
10
|
+
* the kernel itself never imports it.
|
|
12
11
|
*/
|
|
13
12
|
import type { Router } from 'express';
|
|
14
|
-
import {
|
|
13
|
+
import { type UsageCounter } from '@wolffm/service-kernel/relays';
|
|
15
14
|
import { type Report } from '../telemetry.js';
|
|
16
|
-
export { MAX_BATCHES_PER_MINUTE, USAGE_TOP, USAGE_TRAIL_MAX, USAGE_WINDOW_MS };
|
|
17
|
-
export type { UsageCounter };
|
|
18
15
|
export interface UsageDeps {
|
|
19
16
|
report?: Report;
|
|
20
17
|
now?: () => number;
|
package/dist/http/usage.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { USAGE_PATH, UsageBatchSchema } from '@wolffm/platform-wire/telemetry';
|
|
2
|
-
import { attachUsage as kernelAttachUsage
|
|
2
|
+
import { attachUsage as kernelAttachUsage } from '@wolffm/service-kernel/relays';
|
|
3
3
|
import { edgeTierOf, userIdOf, userNameOf } from '../edge-auth.js';
|
|
4
4
|
import { report as defaultReport } from '../telemetry.js';
|
|
5
|
-
export { MAX_BATCHES_PER_MINUTE, USAGE_TOP, USAGE_TRAIL_MAX, USAGE_WINDOW_MS };
|
|
6
5
|
export function attachUsage(api, deps = {}) {
|
|
7
6
|
return kernelAttachUsage(api, {
|
|
8
7
|
schema: UsageBatchSchema,
|
package/dist/log.d.ts
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapter: cardtable's binding of `@hadoku/service-kernel/log`. `jsonLogger`
|
|
3
|
-
* and `JsonLog` are fully generic (no cardtable value baked in), so this is a
|
|
4
|
-
* pure re-export kept at this path for its one remaining importer,
|
|
5
|
-
* `http/rooms.ts` — claimed by another session (w95b) this wave, so its
|
|
6
|
-
* import line was not repointed. Every other importer now binds
|
|
7
|
-
* `@hadoku/service-kernel/log` directly (w93-Z).
|
|
8
|
-
*/
|
|
9
1
|
export { jsonLogger, type JsonLog } from '@wolffm/service-kernel/log';
|
package/dist/log.js
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Adapter: cardtable's binding of `@hadoku/service-kernel/log`. `jsonLogger`
|
|
3
|
-
* and `JsonLog` are fully generic (no cardtable value baked in), so this is a
|
|
4
|
-
* pure re-export kept at this path for its one remaining importer,
|
|
5
|
-
* `http/rooms.ts` — claimed by another session (w95b) this wave, so its
|
|
6
|
-
* import line was not repointed. Every other importer now binds
|
|
7
|
-
* `@hadoku/service-kernel/log` directly (w93-Z).
|
|
8
|
-
*/
|
|
1
|
+
/* Until `http/room-core.ts` and `room/session.ts` import `@hadoku/service-kernel/log` themselves; then this file goes. */
|
|
9
2
|
export { jsonLogger } from '@wolffm/service-kernel/log';
|
|
@@ -12,10 +12,7 @@
|
|
|
12
12
|
import { type ChildProcess } from 'node:child_process';
|
|
13
13
|
/**
|
|
14
14
|
* A process `EngineRuntime.spawn` handed back: just the pid and the two edges `local-jvm.ts`'s
|
|
15
|
-
* `LocalJvm` needs to watch — nothing of `node:child_process`'s own shape leaks past this
|
|
16
|
-
* engine that is not a `child_process` at all (a streamed desktop's "process" is a docker
|
|
17
|
-
* container `scripts/stream/container.sh` starts, not a pid this server forks) can still describe
|
|
18
|
-
* itself this way without pretending to BE a `ChildProcess`.
|
|
15
|
+
* `LocalJvm` needs to watch — nothing of `node:child_process`'s own shape leaks past this.
|
|
19
16
|
*/
|
|
20
17
|
export interface EngineProcess {
|
|
21
18
|
readonly pid: number;
|
|
@@ -27,37 +24,22 @@ export interface EngineProcess {
|
|
|
27
24
|
dispose(): void;
|
|
28
25
|
}
|
|
29
26
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* (`host.ts`) still places matches through `localJvmLauncher`'s `JvmLauncher`, never through
|
|
35
|
-
* `EngineRuntime` directly — lifting the POOL onto this seam, so a non-JVM engine shares the same
|
|
36
|
-
* coordinator, is still ahead of this.
|
|
27
|
+
* How the host launches an engine process: its argv and its spawn. `local-jvm.ts`'s `LocalJvm`
|
|
28
|
+
* launches through `forgeEngineRuntime` (the actual `child_process.spawn` call lives there, not in
|
|
29
|
+
* `LocalJvm`, which only builds the argv and hands it over). The coordinator itself (`host.ts`)
|
|
30
|
+
* still places matches through `localJvmLauncher`'s `JvmLauncher`, never through this directly.
|
|
37
31
|
*/
|
|
38
32
|
export interface EngineRuntime {
|
|
39
|
-
/** Paths (or other identifiers) of what the process needs, keyed for logging. */
|
|
40
|
-
artifacts: Record<string, string>;
|
|
41
33
|
/** The full argv (after the executable) to launch one process in run directory `dir`, sized to `size`. */
|
|
42
34
|
argv(dir: string, size: {
|
|
43
35
|
memoryMb: number;
|
|
44
36
|
}): string[];
|
|
45
|
-
/** RAM one idle process costs beyond what it hosts. */
|
|
46
|
-
overheadMb: number;
|
|
47
|
-
/** Matches (or jobs) one process hosts at most. */
|
|
48
|
-
perProcess: number;
|
|
49
|
-
/** Is the process in `dir` still healthy, or due for a recycle? */
|
|
50
|
-
health?(dir: string): {
|
|
51
|
-
recycle: boolean;
|
|
52
|
-
};
|
|
53
37
|
/**
|
|
54
38
|
* Launch `argv` (after the executable) with `cwd` and these three stdio fds — never a Node
|
|
55
39
|
* pipe; `local-jvm.ts`'s header says why a JVM's stdio has to be fds on named pipes, not
|
|
56
|
-
* something that dies with this process.
|
|
57
|
-
* server forks at all (a container another script starts) leaves it unset and is launched some
|
|
58
|
-
* other way.
|
|
40
|
+
* something that dies with this process.
|
|
59
41
|
*/
|
|
60
|
-
spawn
|
|
42
|
+
spawn(argv: string[], cwd: string, io: {
|
|
61
43
|
stdin: number;
|
|
62
44
|
stdout: number;
|
|
63
45
|
stderr: number;
|
|
@@ -146,8 +128,6 @@ export declare const PID_POLL_MS = 1000;
|
|
|
146
128
|
* stops existing (`process.exit` a statement away), where there is no later tick to confirm in.
|
|
147
129
|
*/
|
|
148
130
|
export declare function sleepSync(ms: number): void;
|
|
149
|
-
/** SIGKILL a pid we own, or say nothing: it may have gone between the check and here. */
|
|
150
|
-
export declare function killPid(pid: number): void;
|
|
151
131
|
/** One run directory under a `workDir`, as a real path. */
|
|
152
132
|
export interface RunDirEntry {
|
|
153
133
|
name: string;
|
|
@@ -199,11 +179,6 @@ export interface SweepResult {
|
|
|
199
179
|
run: string;
|
|
200
180
|
startedAt: string;
|
|
201
181
|
}[];
|
|
202
|
-
/**
|
|
203
|
-
* Live directories the sweep ENDED: a legacy one-process-per-run-dir layout nothing re-attaches
|
|
204
|
-
* any more, named by its own record's pid.
|
|
205
|
-
*/
|
|
206
|
-
killed: string[];
|
|
207
182
|
/** Set when the sweep did nothing, and why. */
|
|
208
183
|
skipped?: string;
|
|
209
184
|
}
|
|
@@ -236,15 +236,6 @@ export const PID_POLL_MS = 1000;
|
|
|
236
236
|
export function sleepSync(ms) {
|
|
237
237
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
238
238
|
}
|
|
239
|
-
/** SIGKILL a pid we own, or say nothing: it may have gone between the check and here. */
|
|
240
|
-
export function killPid(pid) {
|
|
241
|
-
try {
|
|
242
|
-
process.kill(pid, 'SIGKILL');
|
|
243
|
-
}
|
|
244
|
-
catch {
|
|
245
|
-
// ESRCH — already gone, which is the outcome we wanted.
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
239
|
/** Marks a pruned-down run directory as a crash record rather than scaffolding to remove outright. */
|
|
249
240
|
export const CRASH_MARKER = 'crash.json';
|
|
250
241
|
/** Our run directories directly under `workDir`, as real paths, matching `namePattern`. */
|
package/dist/play/host.d.ts
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,10 +120,9 @@
|
|
|
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
|
-
export { bridgeDiagnostics } from './diagnostics.js';
|
|
122
123
|
import type { JvmLauncher } from './jvm-transport.js';
|
|
123
124
|
import { type JvmHostConfig } from './local-jvm.js';
|
|
124
|
-
export {
|
|
125
|
+
export { FORGE_PREFERENCES, jvmHostConfig } from './local-jvm.js';
|
|
125
126
|
export interface SeatSpec {
|
|
126
127
|
/** Forge's player name. Shown to both seats, so never an identity. */
|
|
127
128
|
name: string;
|
|
@@ -291,9 +292,9 @@ export interface MatchHost<C extends {
|
|
|
291
292
|
* its epoch, so a re-attached client resyncs on the cursor it holds, and which participant owns
|
|
292
293
|
* each seat, so a re-attach cannot seat someone at the wrong hand. `checkpoint` is w105's: a
|
|
293
294
|
* per-engine mid-game save, opaque to the host — whatever `GameAdapter.classify`'s `{ t:
|
|
294
|
-
* 'checkpoint' }` line carried last (`match/shell.ts`'s `latestCheckpoint`),
|
|
295
|
-
*
|
|
296
|
-
*
|
|
295
|
+
* 'checkpoint' }` line carried last (`match/shell.ts`'s `latestCheckpoint`), beside Forge's own
|
|
296
|
+
* {@link TurnSnapshot} (`MatchRecord.snapshot`); when the two are the same value, `jvm.json` holds
|
|
297
|
+
* it once (`recordEntry`). Absent before a match's first checkpoint. `readJvmRecord`/`hostFace`'s `remember`
|
|
297
298
|
* pass through whatever the caller sent, never forcing it to `null` themselves.
|
|
298
299
|
*/
|
|
299
300
|
export interface Durable {
|
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/telemetry.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adapter: cardtable's binding of `@hadoku/service-kernel/telemetry` (w93-K3).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The plain re-exports stay because the published `@wolffm/game-server/telemetry` is a contract:
|
|
5
|
+
* bomberman's server imports `callerContext`, `report`, `installTelemetry` and `Report` from it.
|
|
6
|
+
* The cardtable-specific bits are the service id
|
|
7
7
|
* (`cardtable`, stamped on every event's `context.service` and in the posting User-Agent), the
|
|
8
8
|
* env var named in the disabled-reason log line (`CARDTABLE_SERVICE_KEY`), and the closed set of
|
|
9
9
|
* surfaces a seal refusal ever names — the kernel's own `reportSealRefused` takes an open string,
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type { Request } from 'express';
|
|
13
13
|
import type { JsonLog } from '@wolffm/service-kernel/log';
|
|
14
|
-
import { callerContext, installTelemetry, report, reportingAlerts,
|
|
15
|
-
export { callerContext, installTelemetry, report, reportingAlerts
|
|
16
|
-
export type { Level, Report, TelemetryContext
|
|
14
|
+
import { callerContext, installTelemetry, report, reportingAlerts, type Level, type Report, type TelemetryContext } from '@wolffm/service-kernel/telemetry';
|
|
15
|
+
export { callerContext, installTelemetry, report, reportingAlerts };
|
|
16
|
+
export type { Level, Report, TelemetryContext };
|
|
17
17
|
/**
|
|
18
18
|
* Which deployment a base path is: `/cardtable` is prod, `/cardtable-<site>` that site
|
|
19
19
|
* (`/cardtable-ppe` is ppe, as the PPE wrapper sets `CARDTABLE_BASE_PREFIX`). Any other
|
package/dist/telemetry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { callerContext, installTelemetry, monitoringSink as kernelMonitoringSink, report, reportingAlerts, reportSealRefused as kernelReportSealRefused, siteOf as kernelSiteOf,
|
|
2
|
-
export { callerContext, installTelemetry, report, reportingAlerts
|
|
1
|
+
import { callerContext, installTelemetry, monitoringSink as kernelMonitoringSink, report, reportingAlerts, reportSealRefused as kernelReportSealRefused, siteOf as kernelSiteOf, } from '@wolffm/service-kernel/telemetry';
|
|
2
|
+
export { callerContext, installTelemetry, report, reportingAlerts };
|
|
3
3
|
/**
|
|
4
4
|
* Which deployment a base path is: `/cardtable` is prod, `/cardtable-<site>` that site
|
|
5
5
|
* (`/cardtable-ppe` is ppe, as the PPE wrapper sets `CARDTABLE_BASE_PREFIX`). Any other
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.179",
|
|
4
|
+
"gitHead": "989dce1f6edefb23bc21cdde27935b9e8ef9d35a",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The server parts any hosted game shares, above the kernel: the app config and edge auth, the room core (identity, seats, sessions, membership, the room list, the generic room routes), match hosting (the host contract, local and remote JVMs, placement, the start queue, recordings, the in-process and relay runtimes), streams, erase, telemetry and usage. Knows no game; Magic plugs in from apps/server. MIT; imports only node built-ins, express, socket.io, @wolffm/* and the platform packages.",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"play/remote/"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.
|
|
21
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
22
|
-
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.
|
|
20
|
+
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.179",
|
|
21
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.179",
|
|
22
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.212",
|
|
23
23
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
|
|
24
24
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.145",
|
|
25
25
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.145",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `legacy-ids.done.json`: the record the R12 identity reset's one-off remap left behind on
|
|
3
|
-
* prod (old key-derived id → the userId it was moved to). Nothing reads it any more, but it
|
|
4
|
-
* names people by userId, so an erase removes the person's entries from it, and a merge points
|
|
5
|
-
* them at the kept account (an old id was that person's, and the person is now the kept account).
|
|
6
|
-
* Absent is fine.
|
|
7
|
-
*/
|
|
8
|
-
import type { EraseStep } from './index.js';
|
|
9
|
-
export declare function legacyIdsStep(file: string): EraseStep;
|
package/dist/erase/legacy-ids.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `legacy-ids.done.json`: the record the R12 identity reset's one-off remap left behind on
|
|
3
|
-
* prod (old key-derived id → the userId it was moved to). Nothing reads it any more, but it
|
|
4
|
-
* names people by userId, so an erase removes the person's entries from it, and a merge points
|
|
5
|
-
* them at the kept account (an old id was that person's, and the person is now the kept account).
|
|
6
|
-
* Absent is fine.
|
|
7
|
-
*/
|
|
8
|
-
import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
9
|
-
export function legacyIdsStep(file) {
|
|
10
|
-
/** Rewrite every entry that maps to `userId` (`to`: its new userId, or undefined to drop it). Answers how many. */
|
|
11
|
-
const rewrite = (userId, to) => {
|
|
12
|
-
if (!existsSync(file))
|
|
13
|
-
return 0;
|
|
14
|
-
const map = JSON.parse(readFileSync(file, 'utf8'));
|
|
15
|
-
const theirs = Object.keys(map).filter((old) => map[old] === userId);
|
|
16
|
-
if (theirs.length === 0)
|
|
17
|
-
return 0;
|
|
18
|
-
for (const old of theirs) {
|
|
19
|
-
if (to === undefined)
|
|
20
|
-
delete map[old];
|
|
21
|
-
else
|
|
22
|
-
map[old] = to;
|
|
23
|
-
}
|
|
24
|
-
writeFileSync(`${file}.tmp`, JSON.stringify(map));
|
|
25
|
-
renameSync(`${file}.tmp`, file);
|
|
26
|
-
return theirs.length;
|
|
27
|
-
};
|
|
28
|
-
return {
|
|
29
|
-
what: 'legacyIds',
|
|
30
|
-
erase: ({ userId }) => rewrite(userId, undefined),
|
|
31
|
-
merge: ({ from, into }) => rewrite(from.userId, into.userId),
|
|
32
|
-
};
|
|
33
|
-
}
|