@absolutejs/runtime 0.0.1 → 0.2.0
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/README.md +21 -6
- package/dist/index.d.ts +112 -9
- package/dist/index.js +191 -19
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,18 +27,29 @@ runtime.stats(); // { running, total }
|
|
|
27
27
|
await runtime.dispose();
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
##
|
|
30
|
+
## Surface (0.1.0)
|
|
31
31
|
|
|
32
32
|
| API | Purpose |
|
|
33
33
|
|---|---|
|
|
34
34
|
| `createRuntime(options)` | Factory. Returns a `Runtime`. |
|
|
35
|
-
| `runtime.ensure(key)` | Spawn-or-reuse. Single-flight on concurrent calls to the same key. Returns `{ key, port, pid, startedAt, lastTouchedAt }`. |
|
|
35
|
+
| `runtime.ensure(key)` | Spawn-or-reuse. Single-flight on concurrent calls to the same key. Throws fast if `key` is in a back-off window. Returns `{ key, port, pid, startedAt, lastTouchedAt }`. |
|
|
36
36
|
| `runtime.touch(key)` | Bump the idle clock for an active tenant. Cheap; call before/after each request. |
|
|
37
|
-
| `runtime.stats()` | `{ running, total }` snapshot. |
|
|
37
|
+
| `runtime.stats()` | `{ running, total, draining, backoff }` snapshot. |
|
|
38
38
|
| `runtime.kill(key)` | Force-kill. No-op if not running. |
|
|
39
|
+
| `runtime.restart(key)` | Kill + spawn fresh in one call. For deploys that swap to a new release. |
|
|
40
|
+
| `runtime.clearBackoff(key)` | Forget consecutive-failure state. |
|
|
41
|
+
| `runtime.drain()` | Refuse new `ensure()` spawns; existing tenants keep running. For graceful shard shutdown. |
|
|
39
42
|
| `runtime.dispose()` | Kill all + stop the sweeper. Idempotent. |
|
|
40
43
|
|
|
41
|
-
###
|
|
44
|
+
### Back-off on spawn failures
|
|
45
|
+
|
|
46
|
+
A spawn that fails (spawn fn threw, or readiness timed out) records a per-key `{ attempt, retryAt, lastError }` and the next `ensure(key)` throws fast until `retryAt`. After `maxFailures` (default 10) consecutive failures, the key stays refused until `clearBackoff(key)`. Defaults: `baseMs=1000`, `maxMs=60_000`, `maxFailures=10`. Override via the `backoff` option. Without this, one broken tenant thrashes the host with rapid spawn retries.
|
|
47
|
+
|
|
48
|
+
### Observation (Linux-only)
|
|
49
|
+
|
|
50
|
+
When `observeIntervalMs > 0` (default `30_000`), the sweeper periodically reads `/proc/<pid>/stat` (utime + stime) and `/proc/<pid>/status` (VmRSS) per running tenant and emits `{ type: 'observation', key, pid, cpuMs, rssBytes, at }` via `onMetrics`. This is the per-tenant data `@absolutejs/metering` consumes to attribute idle hibernation cost. Silently skips on non-Linux.
|
|
51
|
+
|
|
52
|
+
### Hibernation strategy
|
|
42
53
|
|
|
43
54
|
**Idle-kill at the process layer**, plus the JSC-context hibernation any tenant gets for free via `@absolutejs/isolated-jsc`'s `createHibernatingIsolatePool`. Bun has no process-level snapshot/resume primitive shipped or tracked in an open issue as of 2026-05-29; when one lands we'll add an opt-in `hibernate: 'process-snapshot'` mode and keep idle-kill as the default.
|
|
44
55
|
|
|
@@ -46,7 +57,11 @@ The trade-off the default makes explicit: first call after idle pays a full Bun
|
|
|
46
57
|
|
|
47
58
|
### Observability hooks
|
|
48
59
|
|
|
49
|
-
`onLog`, `onMetrics`, and `onTransition` are pluggable. `onLog` receives newline-split stdout/stderr from every child; `onMetrics` fires on spawn with `
|
|
60
|
+
`onLog`, `onMetrics`, and `onTransition` are pluggable. `onLog` receives newline-split stdout/stderr from every child; `onMetrics` fires on spawn (`{ type: 'spawn', durationMs }`) and periodically with observations on Linux (`{ type: 'observation', cpuMs, rssBytes }`); `onTransition` fires on every state change: `spawn`, `ready`, `idle-kill`, `lru-evict`, `exit` (with a structured `reason`), `backoff`, `drain`.
|
|
61
|
+
|
|
62
|
+
### Exit reasons
|
|
63
|
+
|
|
64
|
+
The `exit` transition's `reason` field is one of: `crashed`, `exited-clean`, `idle-killed`, `lru-evicted`, `killed`, `readiness-timeout`, `disposed`, `restarted`. The meter / control plane uses this to decide whether to charge, retry, or alert.
|
|
50
65
|
|
|
51
66
|
### Pluggable spawn + readiness
|
|
52
67
|
|
|
@@ -62,4 +77,4 @@ The trade-off the default makes explicit: first call after idle pays a full Bun
|
|
|
62
77
|
|
|
63
78
|
## License
|
|
64
79
|
|
|
65
|
-
|
|
80
|
+
BSL 1.1 with a named carveout for the hosted multi-tenant Bun runtime / PaaS substrate category (Convex, Liveblocks, Vercel, Render, Fly, Cloudflare Workers). See [LICENSE](./LICENSE). Change Date: 4 years from first release; Change License: Apache 2.0.
|
package/dist/index.d.ts
CHANGED
|
@@ -12,10 +12,9 @@
|
|
|
12
12
|
* and `@absolutejs/isolated-jsc` — those libraries solve different
|
|
13
13
|
* layers of the same stack.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* open issue tracking one. When that primitive lands we'll add an
|
|
15
|
+
* Hibernation strategy (per STRATEGY-CLOUD.md §9.5): idle-kill at the
|
|
16
|
+
* process layer. Bun has no shipped process-level snapshot/resume
|
|
17
|
+
* primitive as of 2026-05-29. When that primitive lands we'll add an
|
|
19
18
|
* opt-in `hibernate: 'process-snapshot'` mode and keep idle-kill as
|
|
20
19
|
* the default.
|
|
21
20
|
*
|
|
@@ -29,6 +28,7 @@
|
|
|
29
28
|
* maxConcurrent: 100,
|
|
30
29
|
* onMetrics: (event) => prometheus.observe(event),
|
|
31
30
|
* onLog: (event) => loki.write(event),
|
|
31
|
+
* observeIntervalMs: 30_000,
|
|
32
32
|
* });
|
|
33
33
|
*
|
|
34
34
|
* // First call: spawns `bun run start` in /srv/tenants/tenant-42,
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* // Subsequent calls reuse the running process.
|
|
40
40
|
* runtime.touch('tenant-42'); // bump idle clock
|
|
41
41
|
*
|
|
42
|
-
* runtime.stats(); // { running, total }
|
|
42
|
+
* runtime.stats(); // { running, total, draining }
|
|
43
43
|
* await runtime.dispose();
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
@@ -67,6 +67,16 @@ export type RuntimeMetricEvent = {
|
|
|
67
67
|
pid: number;
|
|
68
68
|
port: number;
|
|
69
69
|
durationMs: number;
|
|
70
|
+
} | {
|
|
71
|
+
/** Periodic observation emitted by the sweeper (Linux-only; see `observeIntervalMs`). */
|
|
72
|
+
type: "observation";
|
|
73
|
+
key: string;
|
|
74
|
+
pid: number;
|
|
75
|
+
/** Cumulative CPU ms used by the child since spawn, derived from `/proc/<pid>/stat`. */
|
|
76
|
+
cpuMs: number;
|
|
77
|
+
/** Resident set size in bytes, derived from `/proc/<pid>/status` VmRSS. */
|
|
78
|
+
rssBytes: number;
|
|
79
|
+
at: number;
|
|
70
80
|
};
|
|
71
81
|
export type RuntimeLogEvent = {
|
|
72
82
|
key: string;
|
|
@@ -76,6 +86,19 @@ export type RuntimeLogEvent = {
|
|
|
76
86
|
line: string;
|
|
77
87
|
at: number;
|
|
78
88
|
};
|
|
89
|
+
/**
|
|
90
|
+
* Why a tenant process ended. Used by `RuntimeTransitionEvent` of type
|
|
91
|
+
* `'exit'` to give the consumer enough info to charge or restart correctly:
|
|
92
|
+
* - `crashed` — the process exited on its own with a non-zero code
|
|
93
|
+
* - `exited-clean` — the process exited 0 (probably a graceful self-stop)
|
|
94
|
+
* - `idle-killed` — the sweeper killed it after `idleAfterMs` with no `touch()`
|
|
95
|
+
* - `lru-evicted` — `ensure()` for a new tenant evicted this one
|
|
96
|
+
* - `killed` — explicit `runtime.kill(key)` call
|
|
97
|
+
* - `readiness-timeout` — readiness check failed; we killed during spawn
|
|
98
|
+
* - `disposed` — `runtime.dispose()` killed it
|
|
99
|
+
* - `restarted` — `runtime.restart(key)` killed it on purpose
|
|
100
|
+
*/
|
|
101
|
+
export type ExitReason = "crashed" | "exited-clean" | "idle-killed" | "lru-evicted" | "killed" | "readiness-timeout" | "disposed" | "restarted";
|
|
79
102
|
export type RuntimeTransitionEvent = {
|
|
80
103
|
type: "spawn";
|
|
81
104
|
key: string;
|
|
@@ -103,6 +126,16 @@ export type RuntimeTransitionEvent = {
|
|
|
103
126
|
key: string;
|
|
104
127
|
pid: number;
|
|
105
128
|
exitCode: number | null;
|
|
129
|
+
reason: ExitReason;
|
|
130
|
+
} | {
|
|
131
|
+
/** A spawn was deferred because the key is in the back-off window after a failure. */
|
|
132
|
+
type: "backoff";
|
|
133
|
+
key: string;
|
|
134
|
+
attempt: number;
|
|
135
|
+
retryAfterMs: number;
|
|
136
|
+
} | {
|
|
137
|
+
type: "drain";
|
|
138
|
+
reason: "drain-requested";
|
|
106
139
|
};
|
|
107
140
|
export type ReadinessCheck = (args: {
|
|
108
141
|
key: string;
|
|
@@ -116,6 +149,14 @@ export type SpawnFn = (args: {
|
|
|
116
149
|
onLogLine: (event: RuntimeLogEvent) => void;
|
|
117
150
|
key: string;
|
|
118
151
|
}) => Promise<Subprocess>;
|
|
152
|
+
export type SpawnBackoff = {
|
|
153
|
+
/** First retry waits this long. Default 1000 ms. */
|
|
154
|
+
baseMs?: number;
|
|
155
|
+
/** Maximum back-off (the cap on the doubled wait). Default 60_000 ms. */
|
|
156
|
+
maxMs?: number;
|
|
157
|
+
/** After this many consecutive failures, `ensure()` throws immediately for this key until reset. Default 10. */
|
|
158
|
+
maxFailures?: number;
|
|
159
|
+
};
|
|
119
160
|
/** Options for {@link createRuntime}. */
|
|
120
161
|
export type RuntimeOptions = {
|
|
121
162
|
/** Where to find tenant project directories. */
|
|
@@ -138,9 +179,16 @@ export type RuntimeOptions = {
|
|
|
138
179
|
* exit cleanly.
|
|
139
180
|
*/
|
|
140
181
|
sweepIntervalMs?: number;
|
|
182
|
+
/**
|
|
183
|
+
* How often the sweeper observes CPU + RSS per running tenant. Default
|
|
184
|
+
* 30_000 ms. Set to `0` to disable; observation only works on Linux
|
|
185
|
+
* (`/proc/<pid>` derived) — the sweeper silently skips on other OSes.
|
|
186
|
+
* Output goes to `onMetrics` as `{ type: 'observation', ... }`.
|
|
187
|
+
*/
|
|
188
|
+
observeIntervalMs?: number;
|
|
141
189
|
/**
|
|
142
190
|
* Override the readiness check. Default: HTTP GET to
|
|
143
|
-
* `http://
|
|
191
|
+
* `http://127.0.0.1:${port}/` with a 100ms retry loop, give up after
|
|
144
192
|
* 30s with a `Tenant readiness timed out` error.
|
|
145
193
|
*/
|
|
146
194
|
readiness?: ReadinessCheck;
|
|
@@ -151,11 +199,13 @@ export type RuntimeOptions = {
|
|
|
151
199
|
* use this to inject a fixture without writing to disk.
|
|
152
200
|
*/
|
|
153
201
|
spawn?: SpawnFn;
|
|
154
|
-
/**
|
|
202
|
+
/** Exponential-backoff policy for consecutive spawn failures. */
|
|
203
|
+
backoff?: SpawnBackoff;
|
|
204
|
+
/** Operational metrics — spawn/ready durations + periodic observations. */
|
|
155
205
|
onMetrics?: (event: RuntimeMetricEvent) => void;
|
|
156
206
|
/** stdout/stderr stream. Bounded internally; backpressure to the host. */
|
|
157
207
|
onLog?: (event: RuntimeLogEvent) => void;
|
|
158
|
-
/** Lifecycle events — spawn/ready/idle-kill/lru-evict/exit. */
|
|
208
|
+
/** Lifecycle events — spawn/ready/idle-kill/lru-evict/exit/backoff/drain. */
|
|
159
209
|
onTransition?: (event: RuntimeTransitionEvent) => void;
|
|
160
210
|
/**
|
|
161
211
|
* Command to run when spawning. Default `['bun', 'run', 'start']`.
|
|
@@ -166,6 +216,35 @@ export type RuntimeOptions = {
|
|
|
166
216
|
export type RuntimeStats = {
|
|
167
217
|
running: number;
|
|
168
218
|
total: number;
|
|
219
|
+
/** True when the runtime is draining — refusing new ensure() calls. */
|
|
220
|
+
draining: boolean;
|
|
221
|
+
/** Number of keys currently in the back-off window. */
|
|
222
|
+
backoff: number;
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Operator-shaped metrics returned by {@link Runtime.metrics}. Combines
|
|
226
|
+
* the point-in-time {@link RuntimeStats} fields with cumulative counters
|
|
227
|
+
* since `createRuntime()`. Survives `dispose()` so post-shutdown
|
|
228
|
+
* introspection still reads the totals. Added in 0.2.0.
|
|
229
|
+
*
|
|
230
|
+
* - `totalSpawns` — successful `spawn()` calls (failed spawns hit
|
|
231
|
+
* `recordBackoff` instead and bump `totalBackoffEntries`).
|
|
232
|
+
* - `totalExits` — exits keyed by `ExitReason`. A climbing
|
|
233
|
+
* `crashed` means a tenant is unhealthy; `idle-killed` is the
|
|
234
|
+
* expected steady-state for hibernation; `lru-evicted` means the
|
|
235
|
+
* `maxRunning` cap is biting.
|
|
236
|
+
* - `totalBackoffEntries` — `recordBackoff` calls. Distinct from the
|
|
237
|
+
* point-in-time `backoff` (current keys in window): a single key
|
|
238
|
+
* that fails 5 times bumps `totalBackoffEntries` by 5 but only
|
|
239
|
+
* contributes 1 to `backoff`.
|
|
240
|
+
* - `lastSpawnMs` — wall-clock of the most recent spawn. A climb
|
|
241
|
+
* here is the operator's "is spawning getting slow" signal.
|
|
242
|
+
*/
|
|
243
|
+
export type RuntimeMetrics = RuntimeStats & {
|
|
244
|
+
totalSpawns: number;
|
|
245
|
+
totalExits: Record<ExitReason, number>;
|
|
246
|
+
totalBackoffEntries: number;
|
|
247
|
+
lastSpawnMs: number;
|
|
169
248
|
};
|
|
170
249
|
export type Runtime = {
|
|
171
250
|
/**
|
|
@@ -173,6 +252,9 @@ export type Runtime = {
|
|
|
173
252
|
* for readiness, returns the live {@link Tenant} including the bound
|
|
174
253
|
* `port`. Concurrent calls to the same key share a single-flight
|
|
175
254
|
* spawn — N callers don't create N processes.
|
|
255
|
+
*
|
|
256
|
+
* If `key` is in the back-off window after a recent failure, throws
|
|
257
|
+
* immediately (without spawning). Use `clearBackoff(key)` to retry early.
|
|
176
258
|
*/
|
|
177
259
|
ensure: (key: string) => Promise<Tenant>;
|
|
178
260
|
/**
|
|
@@ -182,10 +264,31 @@ export type Runtime = {
|
|
|
182
264
|
* tenant.
|
|
183
265
|
*/
|
|
184
266
|
touch: (key: string) => void;
|
|
185
|
-
/** Synchronous snapshot. */
|
|
267
|
+
/** Synchronous point-in-time snapshot — back-compat alias of metrics() shape (subset). */
|
|
186
268
|
stats: () => RuntimeStats;
|
|
269
|
+
/**
|
|
270
|
+
* Operator-shaped point-in-time + cumulative metrics (since
|
|
271
|
+
* `createRuntime()`). Use this — `stats()` is kept for back-compat
|
|
272
|
+
* but doesn't carry the cumulative counters. Added in 0.2.0.
|
|
273
|
+
*/
|
|
274
|
+
metrics: () => RuntimeMetrics;
|
|
187
275
|
/** Force-kill `key`. No-op if not running. */
|
|
188
276
|
kill: (key: string) => Promise<void>;
|
|
277
|
+
/**
|
|
278
|
+
* Kill `key` and respawn it. Used by deploys to swap to a new release
|
|
279
|
+
* after the `current` symlink has been updated. Concurrent restart
|
|
280
|
+
* calls for the same key share a single-flight respawn.
|
|
281
|
+
*/
|
|
282
|
+
restart: (key: string) => Promise<Tenant>;
|
|
283
|
+
/** Forget any consecutive-failure state for `key`. Next `ensure()` retries immediately. */
|
|
284
|
+
clearBackoff: (key: string) => void;
|
|
285
|
+
/**
|
|
286
|
+
* Begin draining: refuse new `ensure()` calls (they throw immediately).
|
|
287
|
+
* In-flight spawns and existing tenants are untouched — wait for
|
|
288
|
+
* `stats().running` to reach 0, or call `dispose()` for hard shutdown.
|
|
289
|
+
* Useful for graceful shard shutdown before a host reboot.
|
|
290
|
+
*/
|
|
291
|
+
drain: () => void;
|
|
189
292
|
/** Dispose every running child + stop the sweep. Idempotent. */
|
|
190
293
|
dispose: () => Promise<void>;
|
|
191
294
|
};
|
package/dist/index.js
CHANGED
|
@@ -38,14 +38,38 @@ var splitLines = (() => {
|
|
|
38
38
|
return parts;
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
|
-
var
|
|
41
|
+
var isLinux = typeof process !== "undefined" && process.platform === "linux";
|
|
42
|
+
var readProcStats = async (pid) => {
|
|
43
|
+
if (!isLinux)
|
|
44
|
+
return null;
|
|
45
|
+
try {
|
|
46
|
+
const statText = await Bun.file(`/proc/${pid}/stat`).text();
|
|
47
|
+
const statusText = await Bun.file(`/proc/${pid}/status`).text();
|
|
48
|
+
const closeParen = statText.lastIndexOf(")");
|
|
49
|
+
if (closeParen === -1)
|
|
50
|
+
return null;
|
|
51
|
+
const after = statText.slice(closeParen + 2).split(" ");
|
|
52
|
+
const utime = Number(after[11]);
|
|
53
|
+
const stime = Number(after[12]);
|
|
54
|
+
if (!Number.isFinite(utime) || !Number.isFinite(stime))
|
|
55
|
+
return null;
|
|
56
|
+
const ticksPerSec = globalThis.Bun?.clockTicksPerSecond ?? 100;
|
|
57
|
+
const cpuMs = (utime + stime) / ticksPerSec * 1000;
|
|
58
|
+
const match = statusText.match(/^VmRSS:\s+(\d+)\s+kB/m);
|
|
59
|
+
const rssBytes = match && match[1] ? Number(match[1]) * 1024 : 0;
|
|
60
|
+
return { cpuMs, rssBytes };
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var defaultSpawn = (command) => async ({
|
|
42
66
|
cwd,
|
|
43
67
|
env,
|
|
44
68
|
onLogLine,
|
|
45
69
|
key
|
|
46
70
|
}) => {
|
|
47
71
|
const child = Bun.spawn({
|
|
48
|
-
cmd: [
|
|
72
|
+
cmd: [...command],
|
|
49
73
|
cwd,
|
|
50
74
|
env,
|
|
51
75
|
stderr: "pipe",
|
|
@@ -86,14 +110,38 @@ var createRuntime = (options) => {
|
|
|
86
110
|
const idleAfterMs = options.idleAfterMs ?? 5 * 60 * 1000;
|
|
87
111
|
const maxConcurrent = options.maxConcurrent ?? 100;
|
|
88
112
|
const sweepIntervalMs = options.sweepIntervalMs ?? 1e4;
|
|
113
|
+
const observeIntervalMs = options.observeIntervalMs ?? 30000;
|
|
89
114
|
const readiness = options.readiness ?? defaultReadiness;
|
|
90
|
-
const
|
|
115
|
+
const command = options.command ?? ["bun", "run", "start"];
|
|
116
|
+
const spawn = options.spawn ?? defaultSpawn(command);
|
|
91
117
|
const onMetrics = options.onMetrics;
|
|
92
118
|
const onLog = options.onLog;
|
|
93
119
|
const onTransition = options.onTransition;
|
|
120
|
+
const backoffOptions = {
|
|
121
|
+
baseMs: options.backoff?.baseMs ?? 1000,
|
|
122
|
+
maxFailures: options.backoff?.maxFailures ?? 10,
|
|
123
|
+
maxMs: options.backoff?.maxMs ?? 60000
|
|
124
|
+
};
|
|
94
125
|
const entries = new Map;
|
|
126
|
+
const backoffs = new Map;
|
|
127
|
+
const exitReasons = new Map;
|
|
95
128
|
let sweepTimer;
|
|
129
|
+
let lastObserveAt = 0;
|
|
96
130
|
let disposed = false;
|
|
131
|
+
let draining = false;
|
|
132
|
+
let totalSpawns = 0;
|
|
133
|
+
const totalExits = {
|
|
134
|
+
crashed: 0,
|
|
135
|
+
"exited-clean": 0,
|
|
136
|
+
"idle-killed": 0,
|
|
137
|
+
"lru-evicted": 0,
|
|
138
|
+
killed: 0,
|
|
139
|
+
"readiness-timeout": 0,
|
|
140
|
+
disposed: 0,
|
|
141
|
+
restarted: 0
|
|
142
|
+
};
|
|
143
|
+
let totalBackoffEntries = 0;
|
|
144
|
+
let lastSpawnMs = 0;
|
|
97
145
|
const emitMetric = (event) => {
|
|
98
146
|
if (onMetrics === undefined)
|
|
99
147
|
return;
|
|
@@ -121,10 +169,12 @@ var createRuntime = (options) => {
|
|
|
121
169
|
}
|
|
122
170
|
throw new Error(`Unsupported tenant source kind: ${source.kind}`);
|
|
123
171
|
};
|
|
124
|
-
const
|
|
172
|
+
const killChildWithReason = async (entry, reason) => {
|
|
125
173
|
const child = entry.child;
|
|
126
174
|
if (child === null)
|
|
127
175
|
return;
|
|
176
|
+
entry.pendingExitReason = reason;
|
|
177
|
+
exitReasons.set(child.pid, reason);
|
|
128
178
|
try {
|
|
129
179
|
child.kill();
|
|
130
180
|
} catch {}
|
|
@@ -132,9 +182,40 @@ var createRuntime = (options) => {
|
|
|
132
182
|
await child.exited;
|
|
133
183
|
} catch {}
|
|
134
184
|
};
|
|
135
|
-
const removeEntry = async (key, entry) => {
|
|
185
|
+
const removeEntry = async (key, entry, reason) => {
|
|
136
186
|
entries.delete(key);
|
|
137
|
-
await
|
|
187
|
+
await killChildWithReason(entry, reason);
|
|
188
|
+
};
|
|
189
|
+
const recordBackoff = (key, error) => {
|
|
190
|
+
const prev = backoffs.get(key);
|
|
191
|
+
const attempt = (prev?.attempt ?? 0) + 1;
|
|
192
|
+
const wait = Math.min(backoffOptions.maxMs, backoffOptions.baseMs * 2 ** (attempt - 1));
|
|
193
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
194
|
+
backoffs.set(key, { attempt, lastError: message, retryAt: Date.now() + wait });
|
|
195
|
+
totalBackoffEntries += 1;
|
|
196
|
+
};
|
|
197
|
+
const observeRunning = async () => {
|
|
198
|
+
if (!isLinux || observeIntervalMs <= 0 || onMetrics === undefined)
|
|
199
|
+
return;
|
|
200
|
+
const now = Date.now();
|
|
201
|
+
if (now - lastObserveAt < observeIntervalMs)
|
|
202
|
+
return;
|
|
203
|
+
lastObserveAt = now;
|
|
204
|
+
for (const [key, entry] of entries) {
|
|
205
|
+
if (entry.tenant === null)
|
|
206
|
+
continue;
|
|
207
|
+
const stats = await readProcStats(entry.tenant.pid);
|
|
208
|
+
if (stats === null)
|
|
209
|
+
continue;
|
|
210
|
+
emitMetric({
|
|
211
|
+
at: now,
|
|
212
|
+
cpuMs: stats.cpuMs,
|
|
213
|
+
key,
|
|
214
|
+
pid: entry.tenant.pid,
|
|
215
|
+
rssBytes: stats.rssBytes,
|
|
216
|
+
type: "observation"
|
|
217
|
+
});
|
|
218
|
+
}
|
|
138
219
|
};
|
|
139
220
|
const startSweepIfNeeded = () => {
|
|
140
221
|
if (sweepTimer !== undefined || disposed)
|
|
@@ -157,9 +238,10 @@ var createRuntime = (options) => {
|
|
|
157
238
|
reason: "idle-threshold",
|
|
158
239
|
type: "idle-kill"
|
|
159
240
|
});
|
|
160
|
-
removeEntry(key, entry).catch(() => {});
|
|
241
|
+
removeEntry(key, entry, "idle-killed").catch(() => {});
|
|
161
242
|
}
|
|
162
243
|
}
|
|
244
|
+
observeRunning().catch(() => {});
|
|
163
245
|
if (entries.size === 0 && sweepTimer !== undefined) {
|
|
164
246
|
clearInterval(sweepTimer);
|
|
165
247
|
sweepTimer = undefined;
|
|
@@ -189,12 +271,14 @@ var createRuntime = (options) => {
|
|
|
189
271
|
reason: "max-concurrent",
|
|
190
272
|
type: "lru-evict"
|
|
191
273
|
});
|
|
192
|
-
removeEntry(oldestKey, oldestEntry).catch(() => {});
|
|
274
|
+
removeEntry(oldestKey, oldestEntry, "lru-evicted").catch(() => {});
|
|
193
275
|
}
|
|
194
276
|
};
|
|
195
277
|
const spawnFresh = async (key) => {
|
|
196
278
|
if (disposed)
|
|
197
279
|
throw new Error("runtime has been disposed");
|
|
280
|
+
if (draining)
|
|
281
|
+
throw new Error("runtime is draining; ensure() refused");
|
|
198
282
|
evictLruIfNeeded();
|
|
199
283
|
const port = allocateEphemeralPort();
|
|
200
284
|
const startedAt = Date.now();
|
|
@@ -204,18 +288,33 @@ var createRuntime = (options) => {
|
|
|
204
288
|
NODE_ENV: "production",
|
|
205
289
|
PORT: String(port)
|
|
206
290
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
291
|
+
let child;
|
|
292
|
+
const spawnStart = Date.now();
|
|
293
|
+
try {
|
|
294
|
+
child = await spawn({
|
|
295
|
+
cwd,
|
|
296
|
+
env,
|
|
297
|
+
key,
|
|
298
|
+
onLogLine: emitLog
|
|
299
|
+
});
|
|
300
|
+
} catch (error) {
|
|
301
|
+
entries.delete(key);
|
|
302
|
+
recordBackoff(key, error);
|
|
303
|
+
throw error;
|
|
304
|
+
}
|
|
305
|
+
totalSpawns += 1;
|
|
306
|
+
lastSpawnMs = Date.now() - spawnStart;
|
|
213
307
|
emitTransition({ key, pid: child.pid, port, type: "spawn" });
|
|
214
308
|
child.exited.then((exitCode) => {
|
|
309
|
+
const stashed = exitReasons.get(child.pid);
|
|
310
|
+
const reason = stashed ?? (exitCode === 0 ? "exited-clean" : "crashed");
|
|
311
|
+
exitReasons.delete(child.pid);
|
|
312
|
+
totalExits[reason] += 1;
|
|
215
313
|
emitTransition({
|
|
216
314
|
exitCode: exitCode ?? null,
|
|
217
315
|
key,
|
|
218
316
|
pid: child.pid,
|
|
317
|
+
reason,
|
|
219
318
|
type: "exit"
|
|
220
319
|
});
|
|
221
320
|
const current = entries.get(key);
|
|
@@ -226,10 +325,15 @@ var createRuntime = (options) => {
|
|
|
226
325
|
try {
|
|
227
326
|
await readiness({ key, port, startedAt });
|
|
228
327
|
} catch (error) {
|
|
328
|
+
const entry2 = entries.get(key);
|
|
329
|
+
if (entry2 !== undefined) {
|
|
330
|
+
entry2.pendingExitReason = "readiness-timeout";
|
|
331
|
+
}
|
|
229
332
|
try {
|
|
230
333
|
child.kill();
|
|
231
334
|
} catch {}
|
|
232
335
|
entries.delete(key);
|
|
336
|
+
recordBackoff(key, error);
|
|
233
337
|
throw error;
|
|
234
338
|
}
|
|
235
339
|
const tenant = {
|
|
@@ -245,6 +349,7 @@ var createRuntime = (options) => {
|
|
|
245
349
|
entry.child = child;
|
|
246
350
|
entry.pending = null;
|
|
247
351
|
}
|
|
352
|
+
backoffs.delete(key);
|
|
248
353
|
const durationMs = Date.now() - startedAt;
|
|
249
354
|
emitMetric({
|
|
250
355
|
durationMs,
|
|
@@ -263,6 +368,24 @@ var createRuntime = (options) => {
|
|
|
263
368
|
startSweepIfNeeded();
|
|
264
369
|
return tenant;
|
|
265
370
|
};
|
|
371
|
+
const checkBackoff = (key) => {
|
|
372
|
+
const state = backoffs.get(key);
|
|
373
|
+
if (state === undefined)
|
|
374
|
+
return;
|
|
375
|
+
if (state.attempt >= backoffOptions.maxFailures) {
|
|
376
|
+
throw new Error(`Tenant "${key}" exceeded ${backoffOptions.maxFailures} consecutive spawn failures; clearBackoff() to retry. Last error: ${state.lastError}`);
|
|
377
|
+
}
|
|
378
|
+
const remaining = state.retryAt - Date.now();
|
|
379
|
+
if (remaining > 0) {
|
|
380
|
+
emitTransition({
|
|
381
|
+
attempt: state.attempt,
|
|
382
|
+
key,
|
|
383
|
+
retryAfterMs: remaining,
|
|
384
|
+
type: "backoff"
|
|
385
|
+
});
|
|
386
|
+
throw new Error(`Tenant "${key}" is backing off after ${state.attempt} failure(s); retry in ${remaining}ms. Last error: ${state.lastError}`);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
266
389
|
return {
|
|
267
390
|
async ensure(key) {
|
|
268
391
|
if (disposed)
|
|
@@ -277,10 +400,14 @@ var createRuntime = (options) => {
|
|
|
277
400
|
return existing.pending;
|
|
278
401
|
}
|
|
279
402
|
}
|
|
403
|
+
if (draining)
|
|
404
|
+
throw new Error("runtime is draining; ensure() refused");
|
|
405
|
+
checkBackoff(key);
|
|
280
406
|
const fresh = {
|
|
281
407
|
child: null,
|
|
282
408
|
key,
|
|
283
409
|
pending: null,
|
|
410
|
+
pendingExitReason: null,
|
|
284
411
|
tenant: null
|
|
285
412
|
};
|
|
286
413
|
const promise = spawnFresh(key);
|
|
@@ -300,13 +427,58 @@ var createRuntime = (options) => {
|
|
|
300
427
|
if (entry.tenant !== null)
|
|
301
428
|
running += 1;
|
|
302
429
|
}
|
|
303
|
-
return { running, total: entries.size };
|
|
430
|
+
return { backoff: backoffs.size, draining, running, total: entries.size };
|
|
431
|
+
},
|
|
432
|
+
metrics() {
|
|
433
|
+
let running = 0;
|
|
434
|
+
for (const entry of entries.values()) {
|
|
435
|
+
if (entry.tenant !== null)
|
|
436
|
+
running += 1;
|
|
437
|
+
}
|
|
438
|
+
return {
|
|
439
|
+
backoff: backoffs.size,
|
|
440
|
+
draining,
|
|
441
|
+
lastSpawnMs,
|
|
442
|
+
running,
|
|
443
|
+
total: entries.size,
|
|
444
|
+
totalBackoffEntries,
|
|
445
|
+
totalExits: { ...totalExits },
|
|
446
|
+
totalSpawns
|
|
447
|
+
};
|
|
304
448
|
},
|
|
305
449
|
async kill(key) {
|
|
306
450
|
const entry = entries.get(key);
|
|
307
451
|
if (entry === undefined)
|
|
308
452
|
return;
|
|
309
|
-
await removeEntry(key, entry);
|
|
453
|
+
await removeEntry(key, entry, "killed");
|
|
454
|
+
},
|
|
455
|
+
async restart(key) {
|
|
456
|
+
if (disposed)
|
|
457
|
+
throw new Error("runtime has been disposed");
|
|
458
|
+
const entry = entries.get(key);
|
|
459
|
+
if (entry !== undefined) {
|
|
460
|
+
await removeEntry(key, entry, "restarted");
|
|
461
|
+
}
|
|
462
|
+
const fresh = {
|
|
463
|
+
child: null,
|
|
464
|
+
key,
|
|
465
|
+
pending: null,
|
|
466
|
+
pendingExitReason: null,
|
|
467
|
+
tenant: null
|
|
468
|
+
};
|
|
469
|
+
const promise = spawnFresh(key);
|
|
470
|
+
fresh.pending = promise;
|
|
471
|
+
entries.set(key, fresh);
|
|
472
|
+
return promise;
|
|
473
|
+
},
|
|
474
|
+
clearBackoff(key) {
|
|
475
|
+
backoffs.delete(key);
|
|
476
|
+
},
|
|
477
|
+
drain() {
|
|
478
|
+
if (draining)
|
|
479
|
+
return;
|
|
480
|
+
draining = true;
|
|
481
|
+
emitTransition({ reason: "drain-requested", type: "drain" });
|
|
310
482
|
},
|
|
311
483
|
async dispose() {
|
|
312
484
|
if (disposed)
|
|
@@ -316,9 +488,9 @@ var createRuntime = (options) => {
|
|
|
316
488
|
clearInterval(sweepTimer);
|
|
317
489
|
sweepTimer = undefined;
|
|
318
490
|
}
|
|
319
|
-
const snapshot = [...entries.
|
|
491
|
+
const snapshot = [...entries.entries()];
|
|
320
492
|
entries.clear();
|
|
321
|
-
await Promise.all(snapshot.map((entry) =>
|
|
493
|
+
await Promise.all(snapshot.map(([_key, entry]) => killChildWithReason(entry, "disposed")));
|
|
322
494
|
}
|
|
323
495
|
};
|
|
324
496
|
};
|
|
@@ -326,5 +498,5 @@ export {
|
|
|
326
498
|
createRuntime
|
|
327
499
|
};
|
|
328
500
|
|
|
329
|
-
//# debugId=
|
|
501
|
+
//# debugId=69E9060DA8050AB664756E2164756E21
|
|
330
502
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * `@absolutejs/runtime` — multi-tenant Bun runtime substrate.\n *\n * Wraps Bun's `spawn` so that \"run this tenant's `bun run start` inside\n * a hibernating, metric-emitting child process\" is one function call.\n * Built for PaaS providers that want to host many small Bun apps under\n * one host process.\n *\n * Architectural role: SB-6's `@absolutejs/runtime` library. Consumers\n * include the hosted `absolutejs.ai` PaaS (eventual) and anyone else\n * who needs the same shape. Stays decoupled from `@absolutejs/sync`\n * and `@absolutejs/isolated-jsc` — those libraries solve different\n * layers of the same stack.\n *\n * v0.0.1 hibernation strategy (per the design doc, STRATEGY-CLOUD.md\n * §9.5): idle-kill at the process layer. Bun has no shipped\n * process-level snapshot/resume primitive as of 2026-05-29, and no\n * open issue tracking one. When that primitive lands we'll add an\n * opt-in `hibernate: 'process-snapshot'` mode and keep idle-kill as\n * the default.\n *\n * @example\n * ```ts\n * import { createRuntime } from '@absolutejs/runtime';\n *\n * const runtime = createRuntime({\n * source: { kind: 'directory', root: '/srv/tenants' },\n * idleAfterMs: 5 * 60 * 1000, // 5 min\n * maxConcurrent: 100,\n * onMetrics: (event) => prometheus.observe(event),\n * onLog: (event) => loki.write(event),\n * });\n *\n * // First call: spawns `bun run start` in /srv/tenants/tenant-42,\n * // injects PORT, waits for readiness, returns the bound port.\n * const tenant = await runtime.ensure('tenant-42');\n * fetch(`http://localhost:${tenant.port}/`);\n *\n * // Subsequent calls reuse the running process.\n * runtime.touch('tenant-42'); // bump idle clock\n *\n * runtime.stats(); // { running, total }\n * await runtime.dispose();\n * ```\n */\n\nimport type { Subprocess } from \"bun\";\n\nexport type TenantSource =\n | { kind: \"directory\"; root: string }\n // Future: { kind: 's3'; bucket: string; prefix: string };\n // Future: { kind: 'git'; remote: string };\n ;\n\n/** Identity of a single tenant process at a point in time. */\nexport type Tenant = {\n /** The key the consumer used to address this tenant. */\n key: string;\n /** The port the child process bound to, discovered after readiness. */\n port: number;\n /** OS process id. */\n pid: number;\n /** Wall-clock when the child was spawned. */\n startedAt: number;\n /** Last time the consumer marked this tenant active. */\n lastTouchedAt: number;\n};\n\nexport type RuntimeMetricEvent = {\n type: \"spawn\";\n key: string;\n pid: number;\n port: number;\n durationMs: number;\n};\n// Future: cpu / memory observation events emitted by the sweeper.\n\nexport type RuntimeLogEvent = {\n key: string;\n pid: number;\n stream: \"stdout\" | \"stderr\";\n /** A single line of output (newline-terminated lines are split client-side). */\n line: string;\n at: number;\n};\n\nexport type RuntimeTransitionEvent =\n | { type: \"spawn\"; key: string; pid: number; port: number }\n | { type: \"ready\"; key: string; pid: number; port: number; durationMs: number }\n | {\n type: \"idle-kill\";\n key: string;\n pid: number;\n reason: \"idle-threshold\";\n idleMs: number;\n }\n | { type: \"lru-evict\"; key: string; pid: number; reason: \"max-concurrent\" }\n | { type: \"exit\"; key: string; pid: number; exitCode: number | null };\n\nexport type ReadinessCheck = (args: {\n key: string;\n port: number;\n /** Wall-clock spawn time so the check can compute its own elapsed. */\n startedAt: number;\n}) => Promise<boolean>;\n\nexport type SpawnFn = (args: {\n cwd: string;\n env: Record<string, string>;\n onLogLine: (event: RuntimeLogEvent) => void;\n key: string;\n}) => Promise<Subprocess>;\n\n/** Options for {@link createRuntime}. */\nexport type RuntimeOptions = {\n /** Where to find tenant project directories. */\n source: TenantSource;\n /**\n * Kill the child process after this many ms with no `touch()` call.\n * Default 5 minutes. Set to `0` to disable idle-kill (only LRU and\n * explicit `kill()` shed processes then).\n */\n idleAfterMs?: number;\n /**\n * Max concurrent tenant processes. When a fresh `ensure()` would\n * push past this, the least-recently-touched process is killed\n * first. Default 100.\n */\n maxConcurrent?: number;\n /**\n * Background sweep interval. Default 10_000 ms. The sweep runs only\n * when the runtime is non-empty and is unrefed so the process can\n * exit cleanly.\n */\n sweepIntervalMs?: number;\n /**\n * Override the readiness check. Default: HTTP GET to\n * `http://localhost:${port}/` with a 100ms retry loop, give up after\n * 30s with a `Tenant readiness timed out` error.\n */\n readiness?: ReadinessCheck;\n /**\n * Override how a child process is spawned. Default: `Bun.spawn` with\n * `['bun', 'run', 'start']`, stdio piped through `onLogLine`, env\n * carrying `PORT=${allocatedPort}` and `NODE_ENV=production`. Tests\n * use this to inject a fixture without writing to disk.\n */\n spawn?: SpawnFn;\n /** Operational metrics — spawn/ready durations etc. */\n onMetrics?: (event: RuntimeMetricEvent) => void;\n /** stdout/stderr stream. Bounded internally; backpressure to the host. */\n onLog?: (event: RuntimeLogEvent) => void;\n /** Lifecycle events — spawn/ready/idle-kill/lru-evict/exit. */\n onTransition?: (event: RuntimeTransitionEvent) => void;\n /**\n * Command to run when spawning. Default `['bun', 'run', 'start']`.\n * Tests use this to point at a fixture script.\n */\n command?: readonly string[];\n};\n\nexport type RuntimeStats = {\n running: number;\n total: number;\n};\n\nexport type Runtime = {\n /**\n * Resolve `key` to a running tenant. Spawns if not running, waits\n * for readiness, returns the live {@link Tenant} including the bound\n * `port`. Concurrent calls to the same key share a single-flight\n * spawn — N callers don't create N processes.\n */\n ensure: (key: string) => Promise<Tenant>;\n /**\n * Mark `key` as active right now. Bumps the idle clock; the next\n * sweep won't consider it for idle-kill until `idleAfterMs` again.\n * Cheap; safe to call before/after each request you route to this\n * tenant.\n */\n touch: (key: string) => void;\n /** Synchronous snapshot. */\n stats: () => RuntimeStats;\n /** Force-kill `key`. No-op if not running. */\n kill: (key: string) => Promise<void>;\n /** Dispose every running child + stop the sweep. Idempotent. */\n dispose: () => Promise<void>;\n};\n\n/* ─── internals ──────────────────────────────────────────────────────── */\n\ntype Entry = {\n key: string;\n /** Set while the spawn is in-flight; concurrent ensure() callers await it. */\n pending: Promise<Tenant> | null;\n tenant: Tenant | null;\n child: Subprocess | null;\n};\n\nconst defaultReadiness: ReadinessCheck = async ({ port, startedAt }) => {\n const deadline = startedAt + 30_000;\n while (Date.now() < deadline) {\n try {\n const res = await fetch(`http://127.0.0.1:${port}/`, {\n signal: AbortSignal.timeout(2_000),\n });\n // Any response — even 404 — means the server bound the port.\n void res;\n return true;\n } catch {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n throw new Error(\"Tenant readiness timed out after 30s\");\n};\n\n/**\n * Ask the OS for a currently-free TCP port by binding 0 + closing.\n * Race window: another process can grab the port between close and\n * the child's bind. Acceptable for v0.0.1; production deployments\n * should use a coordinated port allocator (or have the child bind 0\n * and report back via stdout, which is a v0.0.2 follow-up).\n */\nconst allocateEphemeralPort = (): number => {\n const server = Bun.listen({\n hostname: \"127.0.0.1\",\n port: 0,\n socket: {\n data: () => {},\n open: () => {},\n },\n });\n const port = server.port;\n server.stop(true);\n return port;\n};\n\nconst splitLines = (() => {\n // Per-stream remainder, keyed by child pid + stream label.\n const remainders = new Map<string, string>();\n return (key: string, chunk: string): string[] => {\n const prior = remainders.get(key) ?? \"\";\n const combined = prior + chunk;\n const parts = combined.split(\"\\n\");\n remainders.set(key, parts.pop() ?? \"\");\n return parts;\n };\n})();\n\nconst defaultSpawn: SpawnFn = async ({\n cwd,\n env,\n onLogLine,\n key,\n}) => {\n const child = Bun.spawn({\n cmd: [\"bun\", \"run\", \"start\"],\n cwd,\n env,\n stderr: \"pipe\",\n stdout: \"pipe\",\n });\n\n // Stream stdout/stderr into onLogLine as newline-terminated lines.\n const readStream = (\n stream: ReadableStream<Uint8Array> | undefined | null,\n label: \"stdout\" | \"stderr\",\n ): void => {\n if (stream === undefined || stream === null) return;\n void (async () => {\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n const splitKey = `${child.pid}:${label}`;\n try {\n while (true) {\n const { value, done } = await reader.read();\n if (done) break;\n const text = decoder.decode(value, { stream: true });\n for (const line of splitLines(splitKey, text)) {\n onLogLine({\n at: Date.now(),\n key,\n line,\n pid: child.pid,\n stream: label,\n });\n }\n }\n } catch {\n // stream errored on child exit; nothing to surface\n }\n })();\n };\n readStream(child.stdout as ReadableStream<Uint8Array> | undefined, \"stdout\");\n readStream(child.stderr as ReadableStream<Uint8Array> | undefined, \"stderr\");\n\n return child;\n};\n\nexport const createRuntime = (options: RuntimeOptions): Runtime => {\n const source = options.source;\n const idleAfterMs = options.idleAfterMs ?? 5 * 60 * 1000;\n const maxConcurrent = options.maxConcurrent ?? 100;\n const sweepIntervalMs = options.sweepIntervalMs ?? 10_000;\n const readiness = options.readiness ?? defaultReadiness;\n const spawn = options.spawn ?? defaultSpawn;\n const onMetrics = options.onMetrics;\n const onLog = options.onLog;\n const onTransition = options.onTransition;\n\n const entries = new Map<string, Entry>();\n let sweepTimer: ReturnType<typeof setInterval> | undefined;\n let disposed = false;\n\n const emitMetric = (event: RuntimeMetricEvent): void => {\n if (onMetrics === undefined) return;\n try {\n onMetrics(event);\n } catch {\n /* observational only */\n }\n };\n const emitTransition = (event: RuntimeTransitionEvent): void => {\n if (onTransition === undefined) return;\n try {\n onTransition(event);\n } catch {\n /* observational only */\n }\n };\n const emitLog = (event: RuntimeLogEvent): void => {\n if (onLog === undefined) return;\n try {\n onLog(event);\n } catch {\n /* observational only */\n }\n };\n\n const tenantCwd = (key: string): string => {\n if (source.kind === \"directory\") {\n return `${source.root}/${key}`;\n }\n throw new Error(\n `Unsupported tenant source kind: ${(source as { kind: string }).kind}`,\n );\n };\n\n const killChild = async (entry: Entry): Promise<void> => {\n const child = entry.child;\n if (child === null) return;\n try {\n child.kill();\n } catch {\n /* already dead */\n }\n try {\n await child.exited;\n } catch {\n /* ignore */\n }\n };\n\n const removeEntry = async (key: string, entry: Entry): Promise<void> => {\n entries.delete(key);\n await killChild(entry);\n };\n\n const startSweepIfNeeded = (): void => {\n if (sweepTimer !== undefined || disposed) return;\n sweepTimer = setInterval(() => {\n if (disposed) return;\n const now = Date.now();\n for (const [key, entry] of entries) {\n if (entry.tenant === null) continue;\n if (idleAfterMs <= 0) continue;\n const idleMs = now - entry.tenant.lastTouchedAt;\n if (idleMs >= idleAfterMs) {\n emitTransition({\n idleMs,\n key,\n pid: entry.tenant.pid,\n reason: \"idle-threshold\",\n type: \"idle-kill\",\n });\n void removeEntry(key, entry).catch(() => {});\n }\n }\n if (entries.size === 0 && sweepTimer !== undefined) {\n clearInterval(sweepTimer);\n sweepTimer = undefined;\n }\n }, sweepIntervalMs);\n if (typeof sweepTimer === \"object\" && sweepTimer !== null) {\n (sweepTimer as { unref?: () => void }).unref?.();\n }\n };\n\n const evictLruIfNeeded = (): void => {\n if (entries.size < maxConcurrent) return;\n let oldestKey: string | undefined;\n let oldestEntry: Entry | undefined;\n for (const [key, entry] of entries) {\n if (entry.tenant === null) continue; // mid-spawn; don't evict\n if (\n oldestEntry === undefined ||\n oldestEntry.tenant === null ||\n entry.tenant.lastTouchedAt < oldestEntry.tenant.lastTouchedAt\n ) {\n oldestKey = key;\n oldestEntry = entry;\n }\n }\n if (oldestKey !== undefined && oldestEntry !== undefined && oldestEntry.tenant !== null) {\n emitTransition({\n key: oldestKey,\n pid: oldestEntry.tenant.pid,\n reason: \"max-concurrent\",\n type: \"lru-evict\",\n });\n void removeEntry(oldestKey, oldestEntry).catch(() => {});\n }\n };\n\n const spawnFresh = async (key: string): Promise<Tenant> => {\n if (disposed) throw new Error(\"runtime has been disposed\");\n evictLruIfNeeded();\n\n const port = allocateEphemeralPort();\n const startedAt = Date.now();\n const cwd = tenantCwd(key);\n const env: Record<string, string> = {\n ...(process.env as Record<string, string>),\n NODE_ENV: \"production\",\n PORT: String(port),\n };\n\n const child = await spawn({\n cwd,\n env,\n key,\n onLogLine: emitLog,\n });\n\n emitTransition({ key, pid: child.pid, port, type: \"spawn\" });\n\n // Reap the entry when the process exits — whether we killed it or\n // it died on its own. Single source of truth for \"is this tenant\n // running\": the entry's `tenant` field.\n void child.exited\n .then((exitCode) => {\n emitTransition({\n exitCode: exitCode ?? null,\n key,\n pid: child.pid,\n type: \"exit\",\n });\n // Only delete if THIS entry is still the live one. A consumer\n // who killed + immediately re-ensured may have replaced it.\n const current = entries.get(key);\n if (current !== undefined && current.child === child) {\n entries.delete(key);\n }\n })\n .catch(() => {});\n\n try {\n await readiness({ key, port, startedAt });\n } catch (error) {\n try {\n child.kill();\n } catch {\n /* ignore */\n }\n entries.delete(key);\n throw error;\n }\n\n const tenant: Tenant = {\n key,\n lastTouchedAt: Date.now(),\n pid: child.pid,\n port,\n startedAt,\n };\n const entry = entries.get(key);\n if (entry !== undefined) {\n entry.tenant = tenant;\n entry.child = child;\n entry.pending = null;\n }\n const durationMs = Date.now() - startedAt;\n emitMetric({\n durationMs,\n key,\n pid: child.pid,\n port,\n type: \"spawn\",\n });\n emitTransition({\n durationMs,\n key,\n pid: child.pid,\n port,\n type: \"ready\",\n });\n startSweepIfNeeded();\n return tenant;\n };\n\n return {\n async ensure(key) {\n if (disposed) throw new Error(\"runtime has been disposed\");\n const existing = entries.get(key);\n if (existing !== undefined) {\n if (existing.tenant !== null) {\n existing.tenant.lastTouchedAt = Date.now();\n return existing.tenant;\n }\n if (existing.pending !== null) {\n return existing.pending;\n }\n }\n const fresh: Entry = {\n child: null,\n key,\n pending: null,\n tenant: null,\n };\n const promise = spawnFresh(key);\n fresh.pending = promise;\n entries.set(key, fresh);\n return promise;\n },\n\n touch(key) {\n const entry = entries.get(key);\n if (entry === undefined || entry.tenant === null) return;\n entry.tenant.lastTouchedAt = Date.now();\n },\n\n stats() {\n let running = 0;\n for (const entry of entries.values()) {\n if (entry.tenant !== null) running += 1;\n }\n return { running, total: entries.size };\n },\n\n async kill(key) {\n const entry = entries.get(key);\n if (entry === undefined) return;\n await removeEntry(key, entry);\n },\n\n async dispose() {\n if (disposed) return;\n disposed = true;\n if (sweepTimer !== undefined) {\n clearInterval(sweepTimer);\n sweepTimer = undefined;\n }\n const snapshot = [...entries.values()];\n entries.clear();\n await Promise.all(snapshot.map((entry) => killChild(entry)));\n },\n };\n};\n"
|
|
5
|
+
"/**\n * `@absolutejs/runtime` — multi-tenant Bun runtime substrate.\n *\n * Wraps Bun's `spawn` so that \"run this tenant's `bun run start` inside\n * a hibernating, metric-emitting child process\" is one function call.\n * Built for PaaS providers that want to host many small Bun apps under\n * one host process.\n *\n * Architectural role: SB-6's `@absolutejs/runtime` library. Consumers\n * include the hosted `absolutejs.ai` PaaS (eventual) and anyone else\n * who needs the same shape. Stays decoupled from `@absolutejs/sync`\n * and `@absolutejs/isolated-jsc` — those libraries solve different\n * layers of the same stack.\n *\n * Hibernation strategy (per STRATEGY-CLOUD.md §9.5): idle-kill at the\n * process layer. Bun has no shipped process-level snapshot/resume\n * primitive as of 2026-05-29. When that primitive lands we'll add an\n * opt-in `hibernate: 'process-snapshot'` mode and keep idle-kill as\n * the default.\n *\n * @example\n * ```ts\n * import { createRuntime } from '@absolutejs/runtime';\n *\n * const runtime = createRuntime({\n * source: { kind: 'directory', root: '/srv/tenants' },\n * idleAfterMs: 5 * 60 * 1000, // 5 min\n * maxConcurrent: 100,\n * onMetrics: (event) => prometheus.observe(event),\n * onLog: (event) => loki.write(event),\n * observeIntervalMs: 30_000,\n * });\n *\n * // First call: spawns `bun run start` in /srv/tenants/tenant-42,\n * // injects PORT, waits for readiness, returns the bound port.\n * const tenant = await runtime.ensure('tenant-42');\n * fetch(`http://localhost:${tenant.port}/`);\n *\n * // Subsequent calls reuse the running process.\n * runtime.touch('tenant-42'); // bump idle clock\n *\n * runtime.stats(); // { running, total, draining }\n * await runtime.dispose();\n * ```\n */\n\nimport type { Subprocess } from \"bun\";\n\nexport type TenantSource =\n | { kind: \"directory\"; root: string };\n\n/** Identity of a single tenant process at a point in time. */\nexport type Tenant = {\n /** The key the consumer used to address this tenant. */\n key: string;\n /** The port the child process bound to, discovered after readiness. */\n port: number;\n /** OS process id. */\n pid: number;\n /** Wall-clock when the child was spawned. */\n startedAt: number;\n /** Last time the consumer marked this tenant active. */\n lastTouchedAt: number;\n};\n\nexport type RuntimeMetricEvent =\n | {\n type: \"spawn\";\n key: string;\n pid: number;\n port: number;\n durationMs: number;\n }\n | {\n /** Periodic observation emitted by the sweeper (Linux-only; see `observeIntervalMs`). */\n type: \"observation\";\n key: string;\n pid: number;\n /** Cumulative CPU ms used by the child since spawn, derived from `/proc/<pid>/stat`. */\n cpuMs: number;\n /** Resident set size in bytes, derived from `/proc/<pid>/status` VmRSS. */\n rssBytes: number;\n at: number;\n };\n\nexport type RuntimeLogEvent = {\n key: string;\n pid: number;\n stream: \"stdout\" | \"stderr\";\n /** A single line of output (newline-terminated lines are split client-side). */\n line: string;\n at: number;\n};\n\n/**\n * Why a tenant process ended. Used by `RuntimeTransitionEvent` of type\n * `'exit'` to give the consumer enough info to charge or restart correctly:\n * - `crashed` — the process exited on its own with a non-zero code\n * - `exited-clean` — the process exited 0 (probably a graceful self-stop)\n * - `idle-killed` — the sweeper killed it after `idleAfterMs` with no `touch()`\n * - `lru-evicted` — `ensure()` for a new tenant evicted this one\n * - `killed` — explicit `runtime.kill(key)` call\n * - `readiness-timeout` — readiness check failed; we killed during spawn\n * - `disposed` — `runtime.dispose()` killed it\n * - `restarted` — `runtime.restart(key)` killed it on purpose\n */\nexport type ExitReason =\n | \"crashed\"\n | \"exited-clean\"\n | \"idle-killed\"\n | \"lru-evicted\"\n | \"killed\"\n | \"readiness-timeout\"\n | \"disposed\"\n | \"restarted\";\n\nexport type RuntimeTransitionEvent =\n | { type: \"spawn\"; key: string; pid: number; port: number }\n | {\n type: \"ready\";\n key: string;\n pid: number;\n port: number;\n durationMs: number;\n }\n | {\n type: \"idle-kill\";\n key: string;\n pid: number;\n reason: \"idle-threshold\";\n idleMs: number;\n }\n | { type: \"lru-evict\"; key: string; pid: number; reason: \"max-concurrent\" }\n | {\n type: \"exit\";\n key: string;\n pid: number;\n exitCode: number | null;\n reason: ExitReason;\n }\n | {\n /** A spawn was deferred because the key is in the back-off window after a failure. */\n type: \"backoff\";\n key: string;\n attempt: number;\n retryAfterMs: number;\n }\n | { type: \"drain\"; reason: \"drain-requested\" };\n\nexport type ReadinessCheck = (args: {\n key: string;\n port: number;\n /** Wall-clock spawn time so the check can compute its own elapsed. */\n startedAt: number;\n}) => Promise<boolean>;\n\nexport type SpawnFn = (args: {\n cwd: string;\n env: Record<string, string>;\n onLogLine: (event: RuntimeLogEvent) => void;\n key: string;\n}) => Promise<Subprocess>;\n\nexport type SpawnBackoff = {\n /** First retry waits this long. Default 1000 ms. */\n baseMs?: number;\n /** Maximum back-off (the cap on the doubled wait). Default 60_000 ms. */\n maxMs?: number;\n /** After this many consecutive failures, `ensure()` throws immediately for this key until reset. Default 10. */\n maxFailures?: number;\n};\n\n/** Options for {@link createRuntime}. */\nexport type RuntimeOptions = {\n /** Where to find tenant project directories. */\n source: TenantSource;\n /**\n * Kill the child process after this many ms with no `touch()` call.\n * Default 5 minutes. Set to `0` to disable idle-kill (only LRU and\n * explicit `kill()` shed processes then).\n */\n idleAfterMs?: number;\n /**\n * Max concurrent tenant processes. When a fresh `ensure()` would\n * push past this, the least-recently-touched process is killed\n * first. Default 100.\n */\n maxConcurrent?: number;\n /**\n * Background sweep interval. Default 10_000 ms. The sweep runs only\n * when the runtime is non-empty and is unrefed so the process can\n * exit cleanly.\n */\n sweepIntervalMs?: number;\n /**\n * How often the sweeper observes CPU + RSS per running tenant. Default\n * 30_000 ms. Set to `0` to disable; observation only works on Linux\n * (`/proc/<pid>` derived) — the sweeper silently skips on other OSes.\n * Output goes to `onMetrics` as `{ type: 'observation', ... }`.\n */\n observeIntervalMs?: number;\n /**\n * Override the readiness check. Default: HTTP GET to\n * `http://127.0.0.1:${port}/` with a 100ms retry loop, give up after\n * 30s with a `Tenant readiness timed out` error.\n */\n readiness?: ReadinessCheck;\n /**\n * Override how a child process is spawned. Default: `Bun.spawn` with\n * `['bun', 'run', 'start']`, stdio piped through `onLogLine`, env\n * carrying `PORT=${allocatedPort}` and `NODE_ENV=production`. Tests\n * use this to inject a fixture without writing to disk.\n */\n spawn?: SpawnFn;\n /** Exponential-backoff policy for consecutive spawn failures. */\n backoff?: SpawnBackoff;\n /** Operational metrics — spawn/ready durations + periodic observations. */\n onMetrics?: (event: RuntimeMetricEvent) => void;\n /** stdout/stderr stream. Bounded internally; backpressure to the host. */\n onLog?: (event: RuntimeLogEvent) => void;\n /** Lifecycle events — spawn/ready/idle-kill/lru-evict/exit/backoff/drain. */\n onTransition?: (event: RuntimeTransitionEvent) => void;\n /**\n * Command to run when spawning. Default `['bun', 'run', 'start']`.\n * Tests use this to point at a fixture script.\n */\n command?: readonly string[];\n};\n\nexport type RuntimeStats = {\n running: number;\n total: number;\n /** True when the runtime is draining — refusing new ensure() calls. */\n draining: boolean;\n /** Number of keys currently in the back-off window. */\n backoff: number;\n};\n\n/**\n * Operator-shaped metrics returned by {@link Runtime.metrics}. Combines\n * the point-in-time {@link RuntimeStats} fields with cumulative counters\n * since `createRuntime()`. Survives `dispose()` so post-shutdown\n * introspection still reads the totals. Added in 0.2.0.\n *\n * - `totalSpawns` — successful `spawn()` calls (failed spawns hit\n * `recordBackoff` instead and bump `totalBackoffEntries`).\n * - `totalExits` — exits keyed by `ExitReason`. A climbing\n * `crashed` means a tenant is unhealthy; `idle-killed` is the\n * expected steady-state for hibernation; `lru-evicted` means the\n * `maxRunning` cap is biting.\n * - `totalBackoffEntries` — `recordBackoff` calls. Distinct from the\n * point-in-time `backoff` (current keys in window): a single key\n * that fails 5 times bumps `totalBackoffEntries` by 5 but only\n * contributes 1 to `backoff`.\n * - `lastSpawnMs` — wall-clock of the most recent spawn. A climb\n * here is the operator's \"is spawning getting slow\" signal.\n */\nexport type RuntimeMetrics = RuntimeStats & {\n totalSpawns: number;\n totalExits: Record<ExitReason, number>;\n totalBackoffEntries: number;\n lastSpawnMs: number;\n};\n\nexport type Runtime = {\n /**\n * Resolve `key` to a running tenant. Spawns if not running, waits\n * for readiness, returns the live {@link Tenant} including the bound\n * `port`. Concurrent calls to the same key share a single-flight\n * spawn — N callers don't create N processes.\n *\n * If `key` is in the back-off window after a recent failure, throws\n * immediately (without spawning). Use `clearBackoff(key)` to retry early.\n */\n ensure: (key: string) => Promise<Tenant>;\n /**\n * Mark `key` as active right now. Bumps the idle clock; the next\n * sweep won't consider it for idle-kill until `idleAfterMs` again.\n * Cheap; safe to call before/after each request you route to this\n * tenant.\n */\n touch: (key: string) => void;\n /** Synchronous point-in-time snapshot — back-compat alias of metrics() shape (subset). */\n stats: () => RuntimeStats;\n /**\n * Operator-shaped point-in-time + cumulative metrics (since\n * `createRuntime()`). Use this — `stats()` is kept for back-compat\n * but doesn't carry the cumulative counters. Added in 0.2.0.\n */\n metrics: () => RuntimeMetrics;\n /** Force-kill `key`. No-op if not running. */\n kill: (key: string) => Promise<void>;\n /**\n * Kill `key` and respawn it. Used by deploys to swap to a new release\n * after the `current` symlink has been updated. Concurrent restart\n * calls for the same key share a single-flight respawn.\n */\n restart: (key: string) => Promise<Tenant>;\n /** Forget any consecutive-failure state for `key`. Next `ensure()` retries immediately. */\n clearBackoff: (key: string) => void;\n /**\n * Begin draining: refuse new `ensure()` calls (they throw immediately).\n * In-flight spawns and existing tenants are untouched — wait for\n * `stats().running` to reach 0, or call `dispose()` for hard shutdown.\n * Useful for graceful shard shutdown before a host reboot.\n */\n drain: () => void;\n /** Dispose every running child + stop the sweep. Idempotent. */\n dispose: () => Promise<void>;\n};\n\n/* ─── internals ──────────────────────────────────────────────────────── */\n\ntype Entry = {\n key: string;\n /** Set while the spawn is in-flight; concurrent ensure() callers await it. */\n pending: Promise<Tenant> | null;\n tenant: Tenant | null;\n child: Subprocess | null;\n /** Set by code that's about to kill the child, read by the exit handler. */\n pendingExitReason: ExitReason | null;\n};\n\ntype BackoffState = {\n attempt: number;\n retryAt: number;\n lastError: string;\n};\n\nconst defaultReadiness: ReadinessCheck = async ({ port, startedAt }) => {\n const deadline = startedAt + 30_000;\n while (Date.now() < deadline) {\n try {\n const res = await fetch(`http://127.0.0.1:${port}/`, {\n signal: AbortSignal.timeout(2_000),\n });\n void res;\n return true;\n } catch {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n throw new Error(\"Tenant readiness timed out after 30s\");\n};\n\nconst allocateEphemeralPort = (): number => {\n const server = Bun.listen({\n hostname: \"127.0.0.1\",\n port: 0,\n socket: {\n data: () => {},\n open: () => {},\n },\n });\n const port = server.port;\n server.stop(true);\n return port;\n};\n\nconst splitLines = (() => {\n const remainders = new Map<string, string>();\n return (key: string, chunk: string): string[] => {\n const prior = remainders.get(key) ?? \"\";\n const combined = prior + chunk;\n const parts = combined.split(\"\\n\");\n remainders.set(key, parts.pop() ?? \"\");\n return parts;\n };\n})();\n\nconst isLinux = typeof process !== \"undefined\" && process.platform === \"linux\";\n\n/**\n * Read CPU + RSS for a pid from `/proc`. Returns `null` if the pid is gone\n * or we're not on Linux. The math: `utime + stime` from `/proc/<pid>/stat`\n * is in clock ticks; we divide by `Bun.clockTicksPerSecond` (or fall back\n * to 100 — the universal default for Linux kernels).\n */\nconst readProcStats = async (pid: number): Promise<{ cpuMs: number; rssBytes: number } | null> => {\n if (!isLinux) return null;\n try {\n const statText = await Bun.file(`/proc/${pid}/stat`).text();\n const statusText = await Bun.file(`/proc/${pid}/status`).text();\n // /proc/<pid>/stat: ... (comm) ... and utime/stime are fields 14 and 15\n // counting from 1; but `comm` can contain spaces, so we anchor on the\n // closing paren.\n const closeParen = statText.lastIndexOf(\")\");\n if (closeParen === -1) return null;\n const after = statText.slice(closeParen + 2).split(\" \");\n // After (comm), the fields are: state ppid pgrp session ... utime stime ...\n // utime = field 14 of the whole line = index (14 - 3 - 1) = 10 of `after`.\n const utime = Number(after[11]);\n const stime = Number(after[12]);\n if (!Number.isFinite(utime) || !Number.isFinite(stime)) return null;\n const ticksPerSec = (globalThis as { Bun?: { clockTicksPerSecond?: number } }).Bun?.clockTicksPerSecond ?? 100;\n const cpuMs = ((utime + stime) / ticksPerSec) * 1000;\n const match = statusText.match(/^VmRSS:\\s+(\\d+)\\s+kB/m);\n const rssBytes = match && match[1] ? Number(match[1]) * 1024 : 0;\n return { cpuMs, rssBytes };\n } catch {\n return null;\n }\n};\n\nconst defaultSpawn = (command: readonly string[]): SpawnFn => async ({\n cwd,\n env,\n onLogLine,\n key,\n}) => {\n const child = Bun.spawn({\n cmd: [...command],\n cwd,\n env,\n stderr: \"pipe\",\n stdout: \"pipe\",\n });\n\n const readStream = (\n stream: ReadableStream<Uint8Array> | undefined | null,\n label: \"stdout\" | \"stderr\",\n ): void => {\n if (stream === undefined || stream === null) return;\n void (async () => {\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n const splitKey = `${child.pid}:${label}`;\n try {\n while (true) {\n const { value, done } = await reader.read();\n if (done) break;\n const text = decoder.decode(value, { stream: true });\n for (const line of splitLines(splitKey, text)) {\n onLogLine({\n at: Date.now(),\n key,\n line,\n pid: child.pid,\n stream: label,\n });\n }\n }\n } catch {\n /* stream errored on child exit; nothing to surface */\n }\n })();\n };\n readStream(child.stdout as ReadableStream<Uint8Array> | undefined, \"stdout\");\n readStream(child.stderr as ReadableStream<Uint8Array> | undefined, \"stderr\");\n\n return child;\n};\n\nexport const createRuntime = (options: RuntimeOptions): Runtime => {\n const source = options.source;\n const idleAfterMs = options.idleAfterMs ?? 5 * 60 * 1000;\n const maxConcurrent = options.maxConcurrent ?? 100;\n const sweepIntervalMs = options.sweepIntervalMs ?? 10_000;\n const observeIntervalMs = options.observeIntervalMs ?? 30_000;\n const readiness = options.readiness ?? defaultReadiness;\n const command = options.command ?? [\"bun\", \"run\", \"start\"];\n const spawn = options.spawn ?? defaultSpawn(command);\n const onMetrics = options.onMetrics;\n const onLog = options.onLog;\n const onTransition = options.onTransition;\n const backoffOptions: Required<SpawnBackoff> = {\n baseMs: options.backoff?.baseMs ?? 1_000,\n maxFailures: options.backoff?.maxFailures ?? 10,\n maxMs: options.backoff?.maxMs ?? 60_000,\n };\n\n const entries = new Map<string, Entry>();\n const backoffs = new Map<string, BackoffState>();\n /** Pending exit reasons keyed by child pid — read by the .then exit handler. */\n const exitReasons = new Map<number, ExitReason>();\n let sweepTimer: ReturnType<typeof setInterval> | undefined;\n let lastObserveAt = 0;\n let disposed = false;\n let draining = false;\n // 0.2.0: cumulative operator counters surfaced via metrics(). Survive\n // dispose() so post-shutdown introspection still reads totals.\n let totalSpawns = 0;\n const totalExits: Record<ExitReason, number> = {\n 'crashed': 0,\n 'exited-clean': 0,\n 'idle-killed': 0,\n 'lru-evicted': 0,\n 'killed': 0,\n 'readiness-timeout': 0,\n 'disposed': 0,\n 'restarted': 0\n };\n let totalBackoffEntries = 0;\n let lastSpawnMs = 0;\n\n const emitMetric = (event: RuntimeMetricEvent): void => {\n if (onMetrics === undefined) return;\n try {\n onMetrics(event);\n } catch {\n /* observational only */\n }\n };\n const emitTransition = (event: RuntimeTransitionEvent): void => {\n if (onTransition === undefined) return;\n try {\n onTransition(event);\n } catch {\n /* observational only */\n }\n };\n const emitLog = (event: RuntimeLogEvent): void => {\n if (onLog === undefined) return;\n try {\n onLog(event);\n } catch {\n /* observational only */\n }\n };\n\n const tenantCwd = (key: string): string => {\n if (source.kind === \"directory\") {\n return `${source.root}/${key}`;\n }\n throw new Error(\n `Unsupported tenant source kind: ${(source as { kind: string }).kind}`,\n );\n };\n\n const killChildWithReason = async (entry: Entry, reason: ExitReason): Promise<void> => {\n const child = entry.child;\n if (child === null) return;\n entry.pendingExitReason = reason;\n exitReasons.set(child.pid, reason);\n try {\n child.kill();\n } catch {\n /* already dead */\n }\n try {\n await child.exited;\n } catch {\n /* ignore */\n }\n };\n\n const removeEntry = async (key: string, entry: Entry, reason: ExitReason): Promise<void> => {\n entries.delete(key);\n await killChildWithReason(entry, reason);\n };\n\n const recordBackoff = (key: string, error: unknown): void => {\n const prev = backoffs.get(key);\n const attempt = (prev?.attempt ?? 0) + 1;\n const wait = Math.min(backoffOptions.maxMs, backoffOptions.baseMs * 2 ** (attempt - 1));\n const message = error instanceof Error ? error.message : String(error);\n backoffs.set(key, { attempt, lastError: message, retryAt: Date.now() + wait });\n totalBackoffEntries += 1;\n };\n\n const observeRunning = async (): Promise<void> => {\n if (!isLinux || observeIntervalMs <= 0 || onMetrics === undefined) return;\n const now = Date.now();\n if (now - lastObserveAt < observeIntervalMs) return;\n lastObserveAt = now;\n for (const [key, entry] of entries) {\n if (entry.tenant === null) continue;\n const stats = await readProcStats(entry.tenant.pid);\n if (stats === null) continue;\n emitMetric({\n at: now,\n cpuMs: stats.cpuMs,\n key,\n pid: entry.tenant.pid,\n rssBytes: stats.rssBytes,\n type: \"observation\",\n });\n }\n };\n\n const startSweepIfNeeded = (): void => {\n if (sweepTimer !== undefined || disposed) return;\n sweepTimer = setInterval(() => {\n if (disposed) return;\n const now = Date.now();\n for (const [key, entry] of entries) {\n if (entry.tenant === null) continue;\n if (idleAfterMs <= 0) continue;\n const idleMs = now - entry.tenant.lastTouchedAt;\n if (idleMs >= idleAfterMs) {\n emitTransition({\n idleMs,\n key,\n pid: entry.tenant.pid,\n reason: \"idle-threshold\",\n type: \"idle-kill\",\n });\n void removeEntry(key, entry, \"idle-killed\").catch(() => {});\n }\n }\n void observeRunning().catch(() => {});\n if (entries.size === 0 && sweepTimer !== undefined) {\n clearInterval(sweepTimer);\n sweepTimer = undefined;\n }\n }, sweepIntervalMs);\n if (typeof sweepTimer === \"object\" && sweepTimer !== null) {\n (sweepTimer as { unref?: () => void }).unref?.();\n }\n };\n\n const evictLruIfNeeded = (): void => {\n if (entries.size < maxConcurrent) return;\n let oldestKey: string | undefined;\n let oldestEntry: Entry | undefined;\n for (const [key, entry] of entries) {\n if (entry.tenant === null) continue;\n if (\n oldestEntry === undefined ||\n oldestEntry.tenant === null ||\n entry.tenant.lastTouchedAt < oldestEntry.tenant.lastTouchedAt\n ) {\n oldestKey = key;\n oldestEntry = entry;\n }\n }\n if (oldestKey !== undefined && oldestEntry !== undefined && oldestEntry.tenant !== null) {\n emitTransition({\n key: oldestKey,\n pid: oldestEntry.tenant.pid,\n reason: \"max-concurrent\",\n type: \"lru-evict\",\n });\n void removeEntry(oldestKey, oldestEntry, \"lru-evicted\").catch(() => {});\n }\n };\n\n const spawnFresh = async (key: string): Promise<Tenant> => {\n if (disposed) throw new Error(\"runtime has been disposed\");\n if (draining) throw new Error(\"runtime is draining; ensure() refused\");\n evictLruIfNeeded();\n\n const port = allocateEphemeralPort();\n const startedAt = Date.now();\n const cwd = tenantCwd(key);\n const env: Record<string, string> = {\n ...(process.env as Record<string, string>),\n NODE_ENV: \"production\",\n PORT: String(port),\n };\n\n let child: Subprocess;\n const spawnStart = Date.now();\n try {\n child = await spawn({\n cwd,\n env,\n key,\n onLogLine: emitLog,\n });\n } catch (error) {\n entries.delete(key);\n recordBackoff(key, error);\n throw error;\n }\n\n totalSpawns += 1;\n lastSpawnMs = Date.now() - spawnStart;\n emitTransition({ key, pid: child.pid, port, type: \"spawn\" });\n\n // Reap the entry when the process exits. We capture the entry's\n // `pendingExitReason` if some code path set one; otherwise classify\n // by exit code.\n void child.exited\n .then((exitCode) => {\n const stashed = exitReasons.get(child.pid);\n const reason: ExitReason =\n stashed ?? (exitCode === 0 ? \"exited-clean\" : \"crashed\");\n exitReasons.delete(child.pid);\n totalExits[reason] += 1;\n emitTransition({\n exitCode: exitCode ?? null,\n key,\n pid: child.pid,\n reason,\n type: \"exit\",\n });\n const current = entries.get(key);\n if (current !== undefined && current.child === child) {\n entries.delete(key);\n }\n })\n .catch(() => {});\n\n try {\n await readiness({ key, port, startedAt });\n } catch (error) {\n const entry = entries.get(key);\n if (entry !== undefined) {\n entry.pendingExitReason = \"readiness-timeout\";\n }\n try {\n child.kill();\n } catch {\n /* ignore */\n }\n entries.delete(key);\n recordBackoff(key, error);\n throw error;\n }\n\n const tenant: Tenant = {\n key,\n lastTouchedAt: Date.now(),\n pid: child.pid,\n port,\n startedAt,\n };\n const entry = entries.get(key);\n if (entry !== undefined) {\n entry.tenant = tenant;\n entry.child = child;\n entry.pending = null;\n }\n backoffs.delete(key);\n const durationMs = Date.now() - startedAt;\n emitMetric({\n durationMs,\n key,\n pid: child.pid,\n port,\n type: \"spawn\",\n });\n emitTransition({\n durationMs,\n key,\n pid: child.pid,\n port,\n type: \"ready\",\n });\n startSweepIfNeeded();\n return tenant;\n };\n\n const checkBackoff = (key: string): void => {\n const state = backoffs.get(key);\n if (state === undefined) return;\n if (state.attempt >= backoffOptions.maxFailures) {\n throw new Error(\n `Tenant \"${key}\" exceeded ${backoffOptions.maxFailures} consecutive spawn failures; clearBackoff() to retry. Last error: ${state.lastError}`,\n );\n }\n const remaining = state.retryAt - Date.now();\n if (remaining > 0) {\n emitTransition({\n attempt: state.attempt,\n key,\n retryAfterMs: remaining,\n type: \"backoff\",\n });\n throw new Error(\n `Tenant \"${key}\" is backing off after ${state.attempt} failure(s); retry in ${remaining}ms. Last error: ${state.lastError}`,\n );\n }\n };\n\n return {\n async ensure(key) {\n if (disposed) throw new Error(\"runtime has been disposed\");\n const existing = entries.get(key);\n if (existing !== undefined) {\n if (existing.tenant !== null) {\n existing.tenant.lastTouchedAt = Date.now();\n return existing.tenant;\n }\n if (existing.pending !== null) {\n return existing.pending;\n }\n }\n // From here we'd spawn a fresh process — drain only refuses NEW spawns.\n if (draining) throw new Error(\"runtime is draining; ensure() refused\");\n checkBackoff(key);\n const fresh: Entry = {\n child: null,\n key,\n pending: null,\n pendingExitReason: null,\n tenant: null,\n };\n const promise = spawnFresh(key);\n fresh.pending = promise;\n entries.set(key, fresh);\n return promise;\n },\n\n touch(key) {\n const entry = entries.get(key);\n if (entry === undefined || entry.tenant === null) return;\n entry.tenant.lastTouchedAt = Date.now();\n },\n\n stats() {\n let running = 0;\n for (const entry of entries.values()) {\n if (entry.tenant !== null) running += 1;\n }\n return { backoff: backoffs.size, draining, running, total: entries.size };\n },\n\n metrics() {\n let running = 0;\n for (const entry of entries.values()) {\n if (entry.tenant !== null) running += 1;\n }\n return {\n backoff: backoffs.size,\n draining,\n lastSpawnMs,\n running,\n total: entries.size,\n totalBackoffEntries,\n totalExits: { ...totalExits },\n totalSpawns\n };\n },\n\n async kill(key) {\n const entry = entries.get(key);\n if (entry === undefined) return;\n await removeEntry(key, entry, \"killed\");\n },\n\n async restart(key) {\n if (disposed) throw new Error(\"runtime has been disposed\");\n const entry = entries.get(key);\n if (entry !== undefined) {\n await removeEntry(key, entry, \"restarted\");\n }\n // Same single-flight contract as ensure().\n const fresh: Entry = {\n child: null,\n key,\n pending: null,\n pendingExitReason: null,\n tenant: null,\n };\n const promise = spawnFresh(key);\n fresh.pending = promise;\n entries.set(key, fresh);\n return promise;\n },\n\n clearBackoff(key) {\n backoffs.delete(key);\n },\n\n drain() {\n if (draining) return;\n draining = true;\n emitTransition({ reason: \"drain-requested\", type: \"drain\" });\n },\n\n async dispose() {\n if (disposed) return;\n disposed = true;\n if (sweepTimer !== undefined) {\n clearInterval(sweepTimer);\n sweepTimer = undefined;\n }\n const snapshot = [...entries.entries()];\n entries.clear();\n await Promise.all(snapshot.map(([_key, entry]) => killChildWithReason(entry, \"disposed\")));\n },\n };\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;AAuMA,IAAM,mBAAmC,SAAS,MAAM,gBAAgB;AAAA,EACtE,MAAM,WAAW,YAAY;AAAA,EAC7B,OAAO,KAAK,IAAI,IAAI,UAAU;AAAA,IAC5B,IAAI;AAAA,MACF,MAAM,MAAM,MAAM,MAAM,oBAAoB,SAAS;AAAA,QACnD,QAAQ,YAAY,QAAQ,IAAK;AAAA,MACnC,CAAC;AAAA,MAGD,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG,CAAC;AAAA;AAAA,EAE3D;AAAA,EACA,MAAM,IAAI,MAAM,sCAAsC;AAAA;AAUxD,IAAM,wBAAwB,MAAc;AAAA,EAC1C,MAAM,SAAS,IAAI,OAAO;AAAA,IACxB,UAAU;AAAA,IACV,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,MAAM,MAAM;AAAA,MACZ,MAAM,MAAM;AAAA,IACd;AAAA,EACF,CAAC;AAAA,EACD,MAAM,OAAO,O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M,WAAW,CAAC,GAAG,QAAQ,QAAQ,CAAC;AAAA,MACtC,QAAQ,MAAM;AAAA,MACd,MAAM,QAAQ,IAAI,SAAS,IAAI,EAAE,MAAM,WAAW,oBAAoB,OAAO,UAAU,CAAC,CAAC;AAAA;AAAA,EAE7F;AAAA;",
|
|
8
|
+
"debugId": "69E9060DA8050AB664756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absolutejs/runtime",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Multi-tenant Bun runtime substrate for PaaS providers — spawn isolated child Bun processes per tenant, idle-kill, metric emit. The library SB-6 surfaces between isolated-jsc + sync and the hosted product downstream.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|