@nimbus-sh/core 0.5.0 → 0.7.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 +47 -26
- package/dist/_shared/byte-stream.d.ts +5 -4
- package/dist/_shared/byte-stream.d.ts.map +1 -1
- package/dist/_shared/cache-stats.d.ts +23 -1
- package/dist/_shared/cache-stats.d.ts.map +1 -1
- package/dist/_shared/cache-stats.js +13 -1
- package/dist/_shared/exports-resolver.d.ts +1 -1
- package/dist/_shared/exports-resolver.js +1 -1
- package/dist/_shared/real-node-imports.d.ts +7 -0
- package/dist/_shared/real-node-imports.d.ts.map +1 -1
- package/dist/_shared/real-node-imports.js +8 -0
- package/dist/_shared/retry.js +1 -1
- package/dist/_shared/tarball.d.ts +23 -5
- package/dist/_shared/tarball.d.ts.map +1 -1
- package/dist/_shared/tarball.js +38 -5
- package/dist/_shared/vfs-write-ledger.d.ts.map +1 -1
- package/dist/_shared/vfs-write-ledger.js +22 -16
- package/dist/constants.d.ts +5 -11
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +16 -56
- package/dist/runtime/assets-loader.js +1 -1
- package/dist/runtime/comment-strip.d.ts +0 -35
- package/dist/runtime/comment-strip.d.ts.map +1 -1
- package/dist/runtime/comment-strip.js +48 -20
- package/dist/runtime/esbuild-service.d.ts +38 -42
- package/dist/runtime/esbuild-service.d.ts.map +1 -1
- package/dist/runtime/esbuild-service.js +494 -197
- package/dist/runtime/javascript-ast.d.ts.map +1 -1
- package/dist/runtime/javascript-ast.js +45 -7
- package/dist/runtime/opentui-wasm-backend.d.ts.map +1 -1
- package/dist/runtime/opentui-wasm-backend.js +18 -16
- package/dist/runtime/port-registry.d.ts +4 -2
- package/dist/runtime/port-registry.d.ts.map +1 -1
- package/dist/runtime/port-registry.js +60 -8
- package/dist/runtime/virtual-socket-kernel.generated.d.ts +1 -1
- package/dist/runtime/virtual-socket-kernel.generated.js +1 -1
- package/dist/shell/stdin-adapter.d.ts +11 -0
- package/dist/shell/stdin-adapter.d.ts.map +1 -0
- package/dist/shell/stdin-adapter.js +59 -0
- package/dist/shell/unix-commands.d.ts +2 -1
- package/dist/shell/unix-commands.d.ts.map +1 -1
- package/dist/shell/unix-commands.js +1078 -50
- package/dist/substrate/lifo/commands/io/dd.js +1 -1
- package/dist/substrate/lifo/commands/net/curl.d.ts.map +1 -1
- package/dist/substrate/lifo/commands/net/curl.js +270 -54
- package/dist/substrate/lifo/commands/system/npm.d.ts +18 -1
- package/dist/substrate/lifo/commands/system/npm.d.ts.map +1 -1
- package/dist/substrate/lifo/commands/system/npm.js +26 -43
- package/dist/substrate/lifo/commands/text/head.d.ts.map +1 -1
- package/dist/substrate/lifo/commands/text/head.js +2 -1
- package/dist/substrate/lifo/commands/text/sed.d.ts.map +1 -1
- package/dist/substrate/lifo/commands/text/sed.js +499 -117
- package/dist/substrate/lifo/commands/types.d.ts +8 -4
- package/dist/substrate/lifo/commands/types.d.ts.map +1 -1
- package/dist/substrate/lifo/node-compat/zlib.d.ts +37 -18
- package/dist/substrate/lifo/node-compat/zlib.d.ts.map +1 -1
- package/dist/substrate/lifo/node-compat/zlib.js +122 -23
- package/dist/substrate/lifo/shell/interpreter.d.ts +9 -1
- package/dist/substrate/lifo/shell/interpreter.d.ts.map +1 -1
- package/dist/substrate/lifo/shell/interpreter.js +79 -29
- package/dist/substrate/lifo/shell/pipe.d.ts +16 -0
- package/dist/substrate/lifo/shell/pipe.d.ts.map +1 -1
- package/dist/substrate/lifo/shell/pipe.js +62 -18
- package/dist/substrate/lifo/shell/terminal-stdin.d.ts +20 -3
- package/dist/substrate/lifo/shell/terminal-stdin.d.ts.map +1 -1
- package/dist/substrate/lifo/shell/terminal-stdin.js +60 -24
- package/dist/vfs/seed-project.d.ts.map +1 -1
- package/dist/vfs/seed-project.js +1 -1
- package/dist/vfs/sqlite-vfs.d.ts +21 -30
- package/dist/vfs/sqlite-vfs.d.ts.map +1 -1
- package/dist/vfs/sqlite-vfs.js +113 -29
- package/dist/workspace/nimbus-workspace.d.ts +15 -0
- package/dist/workspace/nimbus-workspace.d.ts.map +1 -1
- package/dist/workspace/nimbus-workspace.js +20 -3
- package/dist/workspace/supervisor-op.d.ts +23 -0
- package/dist/workspace/supervisor-op.d.ts.map +1 -0
- package/dist/workspace/supervisor-op.js +92 -0
- package/package.json +3 -2
- package/src/_shared/byte-stream.ts +5 -4
- package/src/_shared/cache-stats.ts +27 -1
- package/src/_shared/exports-resolver.ts +1 -1
- package/src/_shared/real-node-imports.ts +8 -0
- package/src/_shared/retry.ts +1 -1
- package/src/_shared/tarball.ts +56 -5
- package/src/_shared/vfs-write-ledger.ts +22 -16
- package/src/constants.ts +30 -60
- package/src/runtime/assets-loader.ts +1 -1
- package/src/runtime/comment-strip.ts +42 -23
- package/src/runtime/esbuild-service.ts +566 -217
- package/src/runtime/javascript-ast.ts +40 -9
- package/src/runtime/opentui-wasm-backend.ts +19 -17
- package/src/runtime/port-registry.ts +66 -8
- package/src/runtime/virtual-socket-kernel.generated.ts +1 -1
- package/src/shell/stdin-adapter.ts +58 -0
- package/src/shell/unix-commands.ts +1054 -50
- package/src/substrate/lifo/commands/io/dd.ts +2 -2
- package/src/substrate/lifo/commands/net/curl.ts +310 -58
- package/src/substrate/lifo/commands/system/npm.ts +58 -38
- package/src/substrate/lifo/commands/text/head.ts +2 -1
- package/src/substrate/lifo/commands/text/sed.ts +519 -109
- package/src/substrate/lifo/commands/types.ts +8 -5
- package/src/substrate/lifo/node-compat/zlib.ts +155 -26
- package/src/substrate/lifo/shell/interpreter.ts +74 -27
- package/src/substrate/lifo/shell/pipe.ts +65 -24
- package/src/substrate/lifo/shell/terminal-stdin.ts +66 -30
- package/src/vfs/seed-project.ts +3 -3
- package/src/vfs/sqlite-vfs.ts +128 -64
- package/src/workspace/nimbus-workspace.ts +26 -2
- package/src/workspace/supervisor-op.ts +117 -0
- package/dist/_shared/install-phase.d.ts +0 -47
- package/dist/_shared/install-phase.d.ts.map +0 -1
- package/dist/_shared/install-phase.js +0 -1
- package/dist/_shared/rpc-dispose.d.ts +0 -4
- package/dist/_shared/rpc-dispose.d.ts.map +0 -1
- package/dist/_shared/rpc-dispose.js +0 -30
- package/dist/_shared/w7-frame.d.ts +0 -79
- package/dist/_shared/w7-frame.d.ts.map +0 -1
- package/dist/_shared/w7-frame.js +0 -840
- package/dist/_shared/weighted-credit-pool.d.ts +0 -61
- package/dist/_shared/weighted-credit-pool.d.ts.map +0 -1
- package/dist/_shared/weighted-credit-pool.js +0 -196
- package/dist/observability/diag-counters.d.ts +0 -236
- package/dist/observability/diag-counters.d.ts.map +0 -1
- package/dist/observability/diag-counters.js +0 -195
- package/dist/observability/heap-estimate.d.ts +0 -225
- package/dist/observability/heap-estimate.d.ts.map +0 -1
- package/dist/observability/heap-estimate.js +0 -185
- package/dist/observability/heavy-alloc-coord.d.ts +0 -93
- package/dist/observability/heavy-alloc-coord.d.ts.map +0 -1
- package/dist/observability/heavy-alloc-coord.js +0 -181
- package/dist/observability/oom-classify.d.ts +0 -138
- package/dist/observability/oom-classify.d.ts.map +0 -1
- package/dist/observability/oom-classify.js +0 -268
- package/dist/observability/oom-discriminator.d.ts +0 -176
- package/dist/observability/oom-discriminator.d.ts.map +0 -1
- package/dist/observability/oom-discriminator.js +0 -272
- package/src/_shared/install-phase.ts +0 -56
- package/src/_shared/rpc-dispose.ts +0 -31
- package/src/_shared/w7-frame.ts +0 -1013
- package/src/_shared/weighted-credit-pool.ts +0 -244
- package/src/observability/diag-counters.ts +0 -343
- package/src/observability/heap-estimate.ts +0 -331
- package/src/observability/heavy-alloc-coord.ts +0 -241
- package/src/observability/oom-classify.ts +0 -260
- package/src/observability/oom-discriminator.ts +0 -405
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supervisor-local byte-budget back-pressure for transient allocations.
|
|
3
|
-
*
|
|
4
|
-
* A DO can share its isolate's 128 MiB platform ceiling with peer DOs, so
|
|
5
|
-
* independent "safe" allocations cannot each assume the full ceiling.
|
|
6
|
-
* Module scope gives every allocator in one supervisor isolate a single FIFO
|
|
7
|
-
* budget. Full-budget owners are exclusive; weighted owners may overlap only
|
|
8
|
-
* while their retained-byte claims fit together.
|
|
9
|
-
*/
|
|
10
|
-
import { type ResizableCreditLease, type WeightedCreditPoolOptions } from '../_shared/weighted-credit-pool.js';
|
|
11
|
-
export interface SupervisorAllocationBudgetStats {
|
|
12
|
-
readonly capacity: number;
|
|
13
|
-
readonly current: number;
|
|
14
|
-
readonly peak: number;
|
|
15
|
-
readonly queued: number;
|
|
16
|
-
}
|
|
17
|
-
interface AllocationBudgetLifecycle {
|
|
18
|
-
onActive?: () => void;
|
|
19
|
-
onIdle?: () => void;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Reusable contract behind the supervisor singleton. A separate instance is
|
|
23
|
-
* useful in tests and keeps the invariant independent of Nimbus internals.
|
|
24
|
-
*/
|
|
25
|
-
export declare class SupervisorAllocationBudget {
|
|
26
|
-
readonly capacity: number;
|
|
27
|
-
private readonly lifecycle;
|
|
28
|
-
private readonly credits;
|
|
29
|
-
private active;
|
|
30
|
-
/**
|
|
31
|
-
* Leases that drive the disposable-cache lifecycle. Occupancy cannot stand
|
|
32
|
-
* in for this: a read holds credit too, and a read must not sacrifice the
|
|
33
|
-
* cache it is filling.
|
|
34
|
-
*/
|
|
35
|
-
private lifecycleHolders;
|
|
36
|
-
constructor(capacity: number, lifecycle?: AllocationBudgetLifecycle, reserve?: WeightedCreditPoolOptions);
|
|
37
|
-
get stats(): SupervisorAllocationBudgetStats;
|
|
38
|
-
/**
|
|
39
|
-
* Reserve bytes and, while held, mark the budget active so observers can
|
|
40
|
-
* free heap headroom. For owners whose payload is what the headroom is for:
|
|
41
|
-
* installs, clones, pre-bundles, boot payloads, streamed writes.
|
|
42
|
-
*/
|
|
43
|
-
acquire(bytes: number, signal?: AbortSignal): Promise<ResizableCreditLease>;
|
|
44
|
-
/**
|
|
45
|
-
* Reserve bytes WITHOUT driving the cache lifecycle, for owners that are
|
|
46
|
-
* filling the disposable cache rather than competing with it. Shrinking a
|
|
47
|
-
* chunk cache to serve a chunk read is circular: sequentially the budget
|
|
48
|
-
* empties between every read, so an occupancy-edged observer fires once per
|
|
49
|
-
* read and the cache is pinned at its shrunk floor for the whole workload,
|
|
50
|
-
* never warming. The byte credit is still taken — back-pressure is what
|
|
51
|
-
* stops a large read overlapping a large write.
|
|
52
|
-
*/
|
|
53
|
-
acquireWithoutLifecycle(bytes: number, signal?: AbortSignal): Promise<ResizableCreditLease>;
|
|
54
|
-
private _acquire;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* A registered observer (typically a SqliteVFS) receives shrink/restore
|
|
58
|
-
* signals when the shared budget transitions idle↔active.
|
|
59
|
-
*/
|
|
60
|
-
interface AllocObserver {
|
|
61
|
-
/** Called when budget occupancy transitions idle → active. */
|
|
62
|
-
onAcquire?: () => void;
|
|
63
|
-
/** Called when budget occupancy transitions active → idle. */
|
|
64
|
-
onRelease?: () => void;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Register an observer that fires when the shared allocation budget
|
|
68
|
-
* transitions idle → active and active → idle.
|
|
69
|
-
* Returns an unsubscribe function. Idempotent: registering the same
|
|
70
|
-
* observer twice is a no-op (Set semantics).
|
|
71
|
-
*
|
|
72
|
-
* NimbusSession uses this to shrink the disposable VFS LRU while transient
|
|
73
|
-
* payloads are admitted.
|
|
74
|
-
*/
|
|
75
|
-
export declare function registerAllocObserver(o: AllocObserver): () => void;
|
|
76
|
-
/**
|
|
77
|
-
* Reserve an exact number of supervisor-resident bytes.
|
|
78
|
-
*/
|
|
79
|
-
export declare function acquireSupervisorAllocation(bytes: number, signal?: AbortSignal): Promise<ResizableCreditLease>;
|
|
80
|
-
/**
|
|
81
|
-
* Reserve bytes for a filesystem READ. Takes the same byte credit as any
|
|
82
|
-
* other owner but does not shrink the disposable VFS cache, which reads are
|
|
83
|
-
* there to fill.
|
|
84
|
-
*/
|
|
85
|
-
export declare function acquireSupervisorReadAllocation(bytes: number, signal?: AbortSignal): Promise<ResizableCreditLease>;
|
|
86
|
-
/**
|
|
87
|
-
* Reserve the full budget for an allocation whose retained size is not known
|
|
88
|
-
* accurately enough to overlap safely with other heavy work.
|
|
89
|
-
*/
|
|
90
|
-
export declare function acquireHeavyAlloc(signal?: AbortSignal): Promise<() => void>;
|
|
91
|
-
export declare function readSupervisorAllocationBudget(): SupervisorAllocationBudgetStats;
|
|
92
|
-
export {};
|
|
93
|
-
//# sourceMappingURL=heavy-alloc-coord.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"heavy-alloc-coord.d.ts","sourceRoot":"","sources":["../../src/observability/heavy-alloc-coord.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC/B,MAAM,oCAAoC,CAAC;AAE5C,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,UAAU,yBAAyB;IACjC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,0BAA0B;IAWnC,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAX5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,MAAM,CAAS;IACvB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB,CAAK;gBAGlB,QAAQ,EAAE,MAAM,EACR,SAAS,GAAE,yBAA8B,EAC1D,OAAO,GAAE,yBAA8B;IAKzC,IAAI,KAAK,IAAI,+BAA+B,CAK3C;IAED;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAI3E;;;;;;;;OAQG;IACH,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAI7E,QAAQ;CAmCvB;AAED;;;GAGG;AACH,UAAU,aAAa;IACrB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAiBD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,IAAI,CAWlE;AAqCD;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAMjF;AAED,wBAAgB,8BAA8B,IAAI,+BAA+B,CAEhF"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supervisor-local byte-budget back-pressure for transient allocations.
|
|
3
|
-
*
|
|
4
|
-
* A DO can share its isolate's 128 MiB platform ceiling with peer DOs, so
|
|
5
|
-
* independent "safe" allocations cannot each assume the full ceiling.
|
|
6
|
-
* Module scope gives every allocator in one supervisor isolate a single FIFO
|
|
7
|
-
* budget. Full-budget owners are exclusive; weighted owners may overlap only
|
|
8
|
-
* while their retained-byte claims fit together.
|
|
9
|
-
*/
|
|
10
|
-
import { CHUNK_SIZE, SUPERVISOR_IN_FLIGHT_ALLOCATION_BUDGET_BYTES, SUPERVISOR_READ_RESERVE_BYTES, } from '../constants.js';
|
|
11
|
-
import { WeightedCreditPool, } from '../_shared/weighted-credit-pool.js';
|
|
12
|
-
/**
|
|
13
|
-
* Reusable contract behind the supervisor singleton. A separate instance is
|
|
14
|
-
* useful in tests and keeps the invariant independent of Nimbus internals.
|
|
15
|
-
*/
|
|
16
|
-
export class SupervisorAllocationBudget {
|
|
17
|
-
capacity;
|
|
18
|
-
lifecycle;
|
|
19
|
-
credits;
|
|
20
|
-
active = false;
|
|
21
|
-
/**
|
|
22
|
-
* Leases that drive the disposable-cache lifecycle. Occupancy cannot stand
|
|
23
|
-
* in for this: a read holds credit too, and a read must not sacrifice the
|
|
24
|
-
* cache it is filling.
|
|
25
|
-
*/
|
|
26
|
-
lifecycleHolders = 0;
|
|
27
|
-
constructor(capacity, lifecycle = {}, reserve = {}) {
|
|
28
|
-
this.capacity = capacity;
|
|
29
|
-
this.lifecycle = lifecycle;
|
|
30
|
-
this.credits = new WeightedCreditPool(capacity, reserve);
|
|
31
|
-
}
|
|
32
|
-
get stats() {
|
|
33
|
-
return {
|
|
34
|
-
capacity: this.capacity,
|
|
35
|
-
...this.credits.stats,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Reserve bytes and, while held, mark the budget active so observers can
|
|
40
|
-
* free heap headroom. For owners whose payload is what the headroom is for:
|
|
41
|
-
* installs, clones, pre-bundles, boot payloads, streamed writes.
|
|
42
|
-
*/
|
|
43
|
-
acquire(bytes, signal) {
|
|
44
|
-
return this._acquire(bytes, signal, true);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Reserve bytes WITHOUT driving the cache lifecycle, for owners that are
|
|
48
|
-
* filling the disposable cache rather than competing with it. Shrinking a
|
|
49
|
-
* chunk cache to serve a chunk read is circular: sequentially the budget
|
|
50
|
-
* empties between every read, so an occupancy-edged observer fires once per
|
|
51
|
-
* read and the cache is pinned at its shrunk floor for the whole workload,
|
|
52
|
-
* never warming. The byte credit is still taken — back-pressure is what
|
|
53
|
-
* stops a large read overlapping a large write.
|
|
54
|
-
*/
|
|
55
|
-
acquireWithoutLifecycle(bytes, signal) {
|
|
56
|
-
return this._acquire(bytes, signal, false);
|
|
57
|
-
}
|
|
58
|
-
async _acquire(bytes, signal, drivesLifecycle) {
|
|
59
|
-
const credit = await this.credits.acquire(bytes, signal);
|
|
60
|
-
if (drivesLifecycle) {
|
|
61
|
-
this.lifecycleHolders++;
|
|
62
|
-
if (!this.active) {
|
|
63
|
-
this.active = true;
|
|
64
|
-
this.lifecycle.onActive?.();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
let released = false;
|
|
68
|
-
return {
|
|
69
|
-
get bytes() {
|
|
70
|
-
return credit.bytes;
|
|
71
|
-
},
|
|
72
|
-
shrinkTo: (nextBytes) => {
|
|
73
|
-
credit.shrinkTo(nextBytes);
|
|
74
|
-
},
|
|
75
|
-
release: () => {
|
|
76
|
-
if (released)
|
|
77
|
-
return;
|
|
78
|
-
released = true;
|
|
79
|
-
credit.release();
|
|
80
|
-
if (!drivesLifecycle)
|
|
81
|
-
return;
|
|
82
|
-
this.lifecycleHolders--;
|
|
83
|
-
if (this.lifecycleHolders === 0 && this.active) {
|
|
84
|
-
this.active = false;
|
|
85
|
-
this.lifecycle.onIdle?.();
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const coord = { observers: new Set(), active: false };
|
|
92
|
-
function getCoord() {
|
|
93
|
-
return coord;
|
|
94
|
-
}
|
|
95
|
-
function errorMessage(error) {
|
|
96
|
-
return error instanceof Error ? error.message : String(error);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Register an observer that fires when the shared allocation budget
|
|
100
|
-
* transitions idle → active and active → idle.
|
|
101
|
-
* Returns an unsubscribe function. Idempotent: registering the same
|
|
102
|
-
* observer twice is a no-op (Set semantics).
|
|
103
|
-
*
|
|
104
|
-
* NimbusSession uses this to shrink the disposable VFS LRU while transient
|
|
105
|
-
* payloads are admitted.
|
|
106
|
-
*/
|
|
107
|
-
export function registerAllocObserver(o) {
|
|
108
|
-
const c = getCoord();
|
|
109
|
-
const isNew = !c.observers.has(o);
|
|
110
|
-
c.observers.add(o);
|
|
111
|
-
if (isNew && c.active) {
|
|
112
|
-
try {
|
|
113
|
-
o.onAcquire?.();
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
// eslint-disable-next-line no-console
|
|
117
|
-
console.error('[heavy-alloc-coord] observer.onAcquire threw:', errorMessage(error));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return () => { c.observers.delete(o); };
|
|
121
|
-
}
|
|
122
|
-
function fireOnAcquire() {
|
|
123
|
-
const c = getCoord();
|
|
124
|
-
c.active = true;
|
|
125
|
-
for (const o of c.observers) {
|
|
126
|
-
try {
|
|
127
|
-
o.onAcquire?.();
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
// Observer errors must NOT break the heavy-alloc protocol.
|
|
131
|
-
// Log and continue.
|
|
132
|
-
// eslint-disable-next-line no-console
|
|
133
|
-
console.error('[heavy-alloc-coord] observer.onAcquire threw:', errorMessage(error));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function fireOnRelease() {
|
|
138
|
-
const c = getCoord();
|
|
139
|
-
c.active = false;
|
|
140
|
-
for (const o of c.observers) {
|
|
141
|
-
try {
|
|
142
|
-
o.onRelease?.();
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
// eslint-disable-next-line no-console
|
|
146
|
-
console.error('[heavy-alloc-coord] observer.onRelease threw:', errorMessage(error));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const supervisorAllocationBudget = new SupervisorAllocationBudget(SUPERVISOR_IN_FLIGHT_ALLOCATION_BUDGET_BYTES, {
|
|
151
|
-
onActive: fireOnAcquire,
|
|
152
|
-
onIdle: fireOnRelease,
|
|
153
|
-
},
|
|
154
|
-
// A chunk-sized read draws on this rather than queueing behind a
|
|
155
|
-
// multi-megabyte owner for a wait unrelated to its own cost.
|
|
156
|
-
{ smallRequestBytes: CHUNK_SIZE, reserve: SUPERVISOR_READ_RESERVE_BYTES });
|
|
157
|
-
/**
|
|
158
|
-
* Reserve an exact number of supervisor-resident bytes.
|
|
159
|
-
*/
|
|
160
|
-
export function acquireSupervisorAllocation(bytes, signal) {
|
|
161
|
-
return supervisorAllocationBudget.acquire(bytes, signal);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Reserve bytes for a filesystem READ. Takes the same byte credit as any
|
|
165
|
-
* other owner but does not shrink the disposable VFS cache, which reads are
|
|
166
|
-
* there to fill.
|
|
167
|
-
*/
|
|
168
|
-
export function acquireSupervisorReadAllocation(bytes, signal) {
|
|
169
|
-
return supervisorAllocationBudget.acquireWithoutLifecycle(bytes, signal);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Reserve the full budget for an allocation whose retained size is not known
|
|
173
|
-
* accurately enough to overlap safely with other heavy work.
|
|
174
|
-
*/
|
|
175
|
-
export async function acquireHeavyAlloc(signal) {
|
|
176
|
-
const lease = await acquireSupervisorAllocation(SUPERVISOR_IN_FLIGHT_ALLOCATION_BUDGET_BYTES, signal);
|
|
177
|
-
return lease.release;
|
|
178
|
-
}
|
|
179
|
-
export function readSupervisorAllocationBudget() {
|
|
180
|
-
return supervisorAllocationBudget.stats;
|
|
181
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* oom-classify.ts — discriminator for OOM-like errors at Nimbus
|
|
3
|
-
* boundaries.
|
|
4
|
-
*
|
|
5
|
-
* Why this exists
|
|
6
|
-
* ───────────────
|
|
7
|
-
* Nimbus has at least five distinct "the work failed" failure modes
|
|
8
|
-
* that all surface today as either a thrown JS Error or a console
|
|
9
|
-
* line:
|
|
10
|
-
*
|
|
11
|
-
* 1. SQLITE_NOMEM at the storage layer (per-DO SQLite cap, post-
|
|
12
|
-
* STOR/SPEC: Address SQLITE_NOMEM issues).
|
|
13
|
-
* 2. Isolate memory exhaustion → 'oom'.
|
|
14
|
-
* 3. Isolate CPU-budget exhaustion → 'cpu_exceeded'.
|
|
15
|
-
* 4. Structured-clone refusal (`Cannot deserialize cloned data`)
|
|
16
|
-
* between supervisor ↔ facet RPC (32 MiB cap).
|
|
17
|
-
* 5. RPC timeout (TimeoutError from facet-pool's per-task race).
|
|
18
|
-
*
|
|
19
|
-
* Plus a few platform-side terminations (subrequest cap, condemnation,
|
|
20
|
-
* hard eviction) that the user sees but Nimbus has no first-party
|
|
21
|
-
* signal for.
|
|
22
|
-
*
|
|
23
|
-
* Memory and CPU are separate buckets
|
|
24
|
-
* ───────────────────────────────────
|
|
25
|
-
* workerd models them as distinct trace outcomes — `exceededMemory` vs
|
|
26
|
-
* `exceededCpu` (EventOutcome, workerd/io/outcome.capnp) — and words the
|
|
27
|
-
* two message families so neither one's signature appears in the other:
|
|
28
|
-
*
|
|
29
|
-
* memory "Worker has exceeded memory limit."
|
|
30
|
-
* "Worker exceeded memory limit."
|
|
31
|
-
* "broken.exceededMemory; jsg.Error: Durable Object's isolate
|
|
32
|
-
* exceeded its memory limit …"
|
|
33
|
-
* "Memory limit exceeded" (RangeError)
|
|
34
|
-
* cpu "Worker exceeded CPU time limit."
|
|
35
|
-
* "Durable Object exceeded its CPU time limit and was reset."
|
|
36
|
-
* "Python Worker exceeded CPU time limit"
|
|
37
|
-
*
|
|
38
|
-
* Read a low 'cpu_exceeded' count carefully: neither condition reliably
|
|
39
|
-
* produces a message. Both are uncatchable inside the isolate that died,
|
|
40
|
-
* so the string is only observable by a CALLER across an RPC boundary,
|
|
41
|
-
* and Nimbus has repeatedly measured isolates vanishing with no throw at
|
|
42
|
-
* all. Absence of 'cpu_exceeded' entries is therefore NOT evidence that
|
|
43
|
-
* CPU was not the cause — confirm against `wrangler tail` either way.
|
|
44
|
-
*
|
|
45
|
-
* Without a classifier, every recordFailure() call has to stringify-
|
|
46
|
-
* match its own error site. With this module, we pin the regex once
|
|
47
|
-
* and reuse it everywhere.
|
|
48
|
-
*
|
|
49
|
-
* Inputs we accept
|
|
50
|
-
* ────────────────
|
|
51
|
-
* The classifier accepts:
|
|
52
|
-
* - Error instances (read e.message)
|
|
53
|
-
* - plain strings (use directly — for stderr-line classification at
|
|
54
|
-
* facet-exit boundaries where we don't have an Error)
|
|
55
|
-
* - anything else (return 'unknown')
|
|
56
|
-
*
|
|
57
|
-
* Output values
|
|
58
|
-
* ─────────────
|
|
59
|
-
* Same set used by `DiagFailure.cause` in oom-discriminator.ts. Keep
|
|
60
|
-
* the union narrow and additive — adding a new value is fine, but
|
|
61
|
-
* never re-purpose an existing one.
|
|
62
|
-
*/
|
|
63
|
-
declare const OOM_CAUSES: readonly ["sqlite_nomem", "oom", "cpu_exceeded", "clone_refused", "rpc_timeout", "subrequest_cap", "dynamic_worker_cap", "condemnation", "hard_evict", "unknown"];
|
|
64
|
-
export type OomCause = typeof OOM_CAUSES[number];
|
|
65
|
-
export declare function isOomCause(input: unknown): input is OomCause;
|
|
66
|
-
/**
|
|
67
|
-
* Classify an error or message string into an OomCause. Returns
|
|
68
|
-
* 'unknown' when no signature matches — callers should still record
|
|
69
|
-
* the message via DiagFailure.message so a human can later widen the
|
|
70
|
-
* classifier rules.
|
|
71
|
-
*/
|
|
72
|
-
export declare function classifyError(input: unknown): OomCause;
|
|
73
|
-
/**
|
|
74
|
-
* Variant for callers that already have the message string. Prefer
|
|
75
|
-
* classifyError() at boundaries; this is exposed for cases where the
|
|
76
|
-
* message has already been extracted (e.g. truncated / sanitised).
|
|
77
|
-
*/
|
|
78
|
-
export declare function classifyMessage(msg: string): OomCause;
|
|
79
|
-
/**
|
|
80
|
-
* Transient Durable Object reset — the object was reset by the platform
|
|
81
|
-
* mid-request for a reason unrelated to the request's own resource use:
|
|
82
|
-
* a code deploy rolling over, or a storage-subsystem cold-start hiccup.
|
|
83
|
-
* The in-flight request/RPC rejects, but the work itself never ran to a
|
|
84
|
-
* conclusion and is safe to re-attempt.
|
|
85
|
-
*
|
|
86
|
-
* Deliberately narrow: it must NOT match resource kills ("isolate exceeded
|
|
87
|
-
* its memory limit and was reset", "Durable Object exceeded its CPU time
|
|
88
|
-
* limit and was reset"), which classifyMessage() routes to 'oom' and
|
|
89
|
-
* 'cpu_exceeded' — those recur on retry and must surface, not loop. Note
|
|
90
|
-
* both end in "and was reset"; the checks below key on the CAUSE clause,
|
|
91
|
-
* never on the reset itself.
|
|
92
|
-
* Observed verbatim signatures:
|
|
93
|
-
* - "Durable Object reset because its code was updated."
|
|
94
|
-
* - "Internal error while starting up Durable Object storage caused
|
|
95
|
-
* object to be reset; reference = ..."
|
|
96
|
-
* - "Internal error in Durable Object storage caused object to be reset;
|
|
97
|
-
* reference = ..."
|
|
98
|
-
* - "Durable Object storage operation exceeded timeout which caused
|
|
99
|
-
* the object to be reset."
|
|
100
|
-
*
|
|
101
|
-
* The second and third are the SAME condition worded for two moments —
|
|
102
|
-
* startup versus a live write — and only the first was matched here, which is
|
|
103
|
-
* why an object reset mid-write still failed a whole install. Nimbus has
|
|
104
|
-
* measured the live-write wording twice: a 45.7 MB single-turn write reset the
|
|
105
|
-
* object once and the same write then succeeded 12/12 on retry
|
|
106
|
-
* (`vfs/facet-resident-store.ts`), and it reset a session DO mid-npm-install
|
|
107
|
-
* on 2026-08-10 (probe `agentic-cli/new/pi-official-installer`). Retrying is
|
|
108
|
-
* bounded, so the one case that is NOT transient — crossing the object's
|
|
109
|
-
* storage budget, which the platform also reports this way
|
|
110
|
-
* (`loaders/process-fabric.ts`) — recurs, exhausts the budget and surfaces.
|
|
111
|
-
*/
|
|
112
|
-
export declare function isTransientDoReset(input: unknown): boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Workerd shed the call because the target Durable Object's input-gate
|
|
115
|
-
* queue was too deep or too old: "Durable Object is overloaded."
|
|
116
|
-
*
|
|
117
|
-
* Distinct from `isTransientDoReset` on purpose. The object is alive and
|
|
118
|
-
* the work never started, so the call is safe to re-attempt — but the
|
|
119
|
-
* cause is queue pressure, so the only useful retry is one that backs off
|
|
120
|
-
* long enough for the queue to drain. Callers pair this with a longer
|
|
121
|
-
* backoff than a reset retry uses.
|
|
122
|
-
*/
|
|
123
|
-
export declare function isDoOverloaded(input: unknown): boolean;
|
|
124
|
-
/**
|
|
125
|
-
* One line about a failure, in terms someone can act on.
|
|
126
|
-
*
|
|
127
|
-
* npm install's catch sites each wrote `e?.remoteMessage || e?.message ||
|
|
128
|
-
* String(e)`. That reduces a failure to a bare sentence, and when the platform
|
|
129
|
-
* declines to describe a rejected Durable Object call the sentence is the word
|
|
130
|
-
* `internal error` — which is how `resolver-fanout layer 2 failed: internal
|
|
131
|
-
* error` reached users for months carrying nothing at all. The message is
|
|
132
|
-
* often the least we know: the error's class, whether the description came
|
|
133
|
-
* from a remote isolate, and which condition it classifies as are all still in
|
|
134
|
-
* hand, and naming them costs nothing and invents nothing.
|
|
135
|
-
*/
|
|
136
|
-
export declare function describeError(input: unknown): string;
|
|
137
|
-
export {};
|
|
138
|
-
//# sourceMappingURL=oom-classify.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oom-classify.d.ts","sourceRoot":"","sources":["../../src/observability/oom-classify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,QAAA,MAAM,UAAU,mKAWN,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAEjD,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAItD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CA0DrD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAO1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEtD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAgBpD"}
|