@nimbus-sh/worker 0.2.3 → 0.3.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/dist/_shared/session-router.d.ts +8 -0
- package/dist/_shared/session-router.d.ts.map +1 -1
- package/dist/_shared/session-router.js +8 -0
- package/dist/facets/cirrus-real.js +1 -1
- package/dist/facets/manager.d.ts +40 -126
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +97 -313
- package/dist/facets/opencode-staging.d.ts +1 -1
- package/dist/facets/opencode-staging.d.ts.map +1 -1
- package/dist/facets/opencode-staging.js +4 -0
- package/dist/facets/vite-dev-server.d.ts +2 -2
- package/dist/facets/vite-dev-server.js +4 -4
- package/dist/git/commands.d.ts +8 -0
- package/dist/git/commands.d.ts.map +1 -1
- package/dist/git/commands.js +41 -9
- package/dist/git/network-facet.d.ts +1 -1
- package/dist/git/network-facet.d.ts.map +1 -1
- package/dist/git/network-facet.js +35 -12
- package/dist/git-bundle.generated.d.ts +2 -2
- package/dist/git-bundle.generated.d.ts.map +1 -1
- package/dist/git-bundle.generated.js +3 -3
- package/dist/index.js +1 -1
- package/dist/loaders/child-process/spawn-facet.js +1 -1
- package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -1
- package/dist/loaders/child-process/spawn-pool.js +2 -2
- package/dist/loaders/generated-workers.d.ts +1 -1
- package/dist/loaders/generated-workers.d.ts.map +1 -1
- package/dist/loaders/generated-workers.js +2 -2
- package/dist/loaders/npm-resolve-preamble.d.ts +3 -3
- package/dist/loaders/npm-resolve-preamble.js +3 -3
- package/dist/loaders/pre-bundle-preamble.d.ts +5 -5
- package/dist/loaders/pre-bundle-preamble.js +6 -6
- package/dist/loaders/process-host.d.ts +6 -107
- package/dist/loaders/process-host.d.ts.map +1 -1
- package/dist/loaders/process-host.js +6 -405
- package/dist/npm/install-batch-facet.js +1 -1
- package/dist/npm/installer.d.ts +4 -4
- package/dist/npm/installer.js +18 -18
- package/dist/npm/pre-bundle-facet.d.ts +2 -2
- package/dist/npm/pre-bundle-facet.js +5 -5
- package/dist/npm/resolve-facet.d.ts +1 -1
- package/dist/npm/resolve-facet.js +1 -1
- package/dist/npm/resolve-one-facet.d.ts +5 -5
- package/dist/npm/resolve-one-facet.js +5 -5
- package/dist/router/index.js +1 -1
- package/dist/router/remote-api.js +8 -0
- package/dist/runtime/bun-repl.d.ts +1 -1
- package/dist/runtime/bun-repl.js +3 -3
- package/dist/runtime/facet-loader-host.d.ts +5 -8
- package/dist/runtime/facet-loader-host.d.ts.map +1 -1
- package/dist/runtime/facet-loader-host.js +7 -11
- package/dist/runtime/node-repl.js +2 -2
- package/dist/runtime/python-repl.js +3 -3
- package/dist/runtime/ruby-repl.js +2 -2
- package/dist/runtime/ruby-resident.js +1 -1
- package/dist/session/hibernation.d.ts +18 -51
- package/dist/session/hibernation.d.ts.map +1 -1
- package/dist/session/hibernation.js +49 -186
- package/dist/session/init-phases.d.ts +2 -2
- package/dist/session/init-phases.d.ts.map +1 -1
- package/dist/session/init-phases.js +1 -1
- package/dist/session/init.d.ts.map +1 -1
- package/dist/session/init.js +6 -3
- package/dist/session/keys.d.ts +14 -37
- package/dist/session/keys.d.ts.map +1 -1
- package/dist/session/keys.js +17 -37
- package/dist/session/nimbus-session.d.ts +10 -4
- package/dist/session/nimbus-session.d.ts.map +1 -1
- package/dist/session/nimbus-session.js +20 -11
- package/dist/session/port-capability.d.ts +43 -0
- package/dist/session/port-capability.d.ts.map +1 -0
- package/dist/session/port-capability.js +49 -0
- package/dist/session/programmatic.d.ts +41 -5
- package/dist/session/programmatic.d.ts.map +1 -1
- package/dist/session/programmatic.js +147 -15
- package/dist/session/routes.d.ts +2 -0
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +91 -16
- package/dist/session/rpc.d.ts +35 -8
- package/dist/session/rpc.d.ts.map +1 -1
- package/dist/session/rpc.js +73 -14
- package/dist/session/start-real-vite.d.ts.map +1 -1
- package/dist/session/start-real-vite.js +2 -0
- package/dist/session/state-store.d.ts +3 -2
- package/dist/session/state-store.d.ts.map +1 -1
- package/dist/session/state-store.js +3 -2
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +5 -0
- package/dist/session/ws.d.ts +2 -2
- package/dist/session/ws.d.ts.map +1 -1
- package/dist/session/ws.js +2 -2
- package/dist/wrangler/nimbus-wrangler.js +1 -1
- package/package.json +3 -2
- package/dist/facets/inner-do-registry.d.ts +0 -41
- package/dist/facets/inner-do-registry.d.ts.map +0 -1
- package/dist/facets/inner-do-registry.js +0 -51
- package/dist/facets/launch-pacer.d.ts +0 -111
- package/dist/facets/launch-pacer.d.ts.map +0 -1
- package/dist/facets/launch-pacer.js +0 -130
- package/dist/loaders/fanout-pool.d.ts +0 -207
- package/dist/loaders/fanout-pool.d.ts.map +0 -1
- package/dist/loaders/fanout-pool.js +0 -363
- package/dist/loaders/loader-pool.d.ts +0 -294
- package/dist/loaders/loader-pool.d.ts.map +0 -1
- package/dist/loaders/loader-pool.js +0 -642
- package/dist/loaders/process-fabric.d.ts +0 -509
- package/dist/loaders/process-fabric.d.ts.map +0 -1
- package/dist/loaders/process-fabric.js +0 -360
- package/dist/loaders/vendor/errors.d.ts +0 -24
- package/dist/loaders/vendor/errors.d.ts.map +0 -1
- package/dist/loaders/vendor/errors.js +0 -46
- package/dist/loaders/vendor/serialize.d.ts +0 -3
- package/dist/loaders/vendor/serialize.d.ts.map +0 -1
- package/dist/loaders/vendor/serialize.js +0 -25
- package/dist/loaders/vendor/types.d.ts +0 -69
- package/dist/loaders/vendor/types.d.ts.map +0 -1
- package/dist/loaders/vendor/types.js +0 -4
- package/dist/loaders/workerd-facet-host.d.ts +0 -141
- package/dist/loaders/workerd-facet-host.d.ts.map +0 -1
- package/dist/loaders/workerd-facet-host.js +0 -284
- package/dist/session/bindings.d.ts +0 -209
- package/dist/session/bindings.d.ts.map +0 -1
- package/dist/session/bindings.js +0 -680
- package/dist/session/ctx-exports.d.ts +0 -16
- package/dist/session/ctx-exports.d.ts.map +0 -1
- package/dist/session/ctx-exports.js +0 -22
- package/dist/session/ws-hibernation-config.d.ts +0 -64
- package/dist/session/ws-hibernation-config.d.ts.map +0 -1
- package/dist/session/ws-hibernation-config.js +0 -89
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* resolve-facet.ts — shared wire types for the per-packument resolver facet.
|
|
3
3
|
*
|
|
4
|
-
* The npm resolver phase runs inside a
|
|
4
|
+
* The npm resolver phase runs inside a LoaderPool isolate so the
|
|
5
5
|
* supervisor DO heap stays flat while large packuments are decoded. The
|
|
6
6
|
* per-packument task body lives in resolve-one-facet.ts; this module holds
|
|
7
7
|
* the types exchanged between supervisor and facet over RPC.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* resolve-facet.ts — shared wire types for the per-packument resolver facet.
|
|
3
3
|
*
|
|
4
|
-
* The npm resolver phase runs inside a
|
|
4
|
+
* The npm resolver phase runs inside a LoaderPool isolate so the
|
|
5
5
|
* supervisor DO heap stays flat while large packuments are decoded. The
|
|
6
6
|
* per-packument task body lives in resolve-one-facet.ts; this module holds
|
|
7
7
|
* the types exchanged between supervisor and facet over RPC.
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* independent fanout tasks. This file is the per-task body: one packument
|
|
8
8
|
* fetch, one version pick, and edge extraction.
|
|
9
9
|
*
|
|
10
|
-
* Each task runs inside a Worker Loader isolate (
|
|
10
|
+
* Each task runs inside a Worker Loader isolate (FanoutPool routes
|
|
11
11
|
* automatically: <5 = in-DO, ≥5 = peer-DO). The isolate is short-lived;
|
|
12
12
|
* task body has its own ~128 MiB envelope. Parallelism = layer width
|
|
13
|
-
* (capped at 32 by
|
|
13
|
+
* (capped at 32 by FanoutPool's MAX_PEER_FANOUT).
|
|
14
14
|
*
|
|
15
15
|
* Stability invariants (cloudflare-parallel serialises via fn.toString)
|
|
16
16
|
* ───────────────────────────────────────────────────────────────────
|
|
@@ -180,13 +180,13 @@ export interface ResolveOneResult {
|
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* Per-package fanout task body. Serialised via fn.toString() and
|
|
183
|
-
* dispatched by
|
|
183
|
+
* dispatched by FanoutPool.submitMany — see installer.ts
|
|
184
184
|
* resolveTreeViaFanout.
|
|
185
185
|
*
|
|
186
|
-
* Function signature MUST be `(spec, env)` so
|
|
186
|
+
* Function signature MUST be `(spec, env)` so FanoutPool's
|
|
187
187
|
* submitMany invocation `fn(item, env)` lines up.
|
|
188
188
|
*
|
|
189
|
-
* `env` is the loader-isolate env supplied by
|
|
189
|
+
* `env` is the loader-isolate env supplied by FanoutPool.
|
|
190
190
|
* `env.SUPERVISOR` is the supervisor-rpc binding (putRegistryEntries,
|
|
191
191
|
* getPackument).
|
|
192
192
|
*/
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* independent fanout tasks. This file is the per-task body: one packument
|
|
8
8
|
* fetch, one version pick, and edge extraction.
|
|
9
9
|
*
|
|
10
|
-
* Each task runs inside a Worker Loader isolate (
|
|
10
|
+
* Each task runs inside a Worker Loader isolate (FanoutPool routes
|
|
11
11
|
* automatically: <5 = in-DO, ≥5 = peer-DO). The isolate is short-lived;
|
|
12
12
|
* task body has its own ~128 MiB envelope. Parallelism = layer width
|
|
13
|
-
* (capped at 32 by
|
|
13
|
+
* (capped at 32 by FanoutPool's MAX_PEER_FANOUT).
|
|
14
14
|
*
|
|
15
15
|
* Stability invariants (cloudflare-parallel serialises via fn.toString)
|
|
16
16
|
* ───────────────────────────────────────────────────────────────────
|
|
@@ -61,13 +61,13 @@
|
|
|
61
61
|
*/
|
|
62
62
|
/**
|
|
63
63
|
* Per-package fanout task body. Serialised via fn.toString() and
|
|
64
|
-
* dispatched by
|
|
64
|
+
* dispatched by FanoutPool.submitMany — see installer.ts
|
|
65
65
|
* resolveTreeViaFanout.
|
|
66
66
|
*
|
|
67
|
-
* Function signature MUST be `(spec, env)` so
|
|
67
|
+
* Function signature MUST be `(spec, env)` so FanoutPool's
|
|
68
68
|
* submitMany invocation `fn(item, env)` lines up.
|
|
69
69
|
*
|
|
70
|
-
* `env` is the loader-isolate env supplied by
|
|
70
|
+
* `env` is the loader-isolate env supplied by FanoutPool.
|
|
71
71
|
* `env.SUPERVISOR` is the supervisor-rpc binding (putRegistryEntries,
|
|
72
72
|
* getPackument).
|
|
73
73
|
*/
|
package/dist/router/index.js
CHANGED
|
@@ -35,7 +35,7 @@ import { generateSessionId, isValidSessionId, } from '../_shared/session-id.js';
|
|
|
35
35
|
import { buildPreviewHost, isPreviewHostSafeSid, parsePreviewHost, readPreviewHostSuffix, } from '../_shared/preview-host.js';
|
|
36
36
|
import { parseSessionRoute, forwardToSession, renderInvalidSessionHtml, SESSION_ROUTE_PREFIX, LEGACY_PUBLIC_DO_SEGMENT, } from '../_shared/session-router.js';
|
|
37
37
|
import { issueNimbusToken, verifyNimbusToken, verifyRequestToken, requireScopes, requireSessionPin, authErrorResponse, setNimbusTokenCookie, NIMBUS_TOKEN_QUERY, NimbusAuthError, NimbusBootstrapConsumedError, NimbusTokenClaimsError, DEFAULT_TOKEN_TTL_MS, ATTACH_BOOTSTRAP_TTL_MS, } from '../auth/index.js';
|
|
38
|
-
import { setCtxExports } from '
|
|
38
|
+
import { setCtxExports } from '@nimbus-sh/fabric/ctx-exports.js';
|
|
39
39
|
import { handleNimbusRemoteApi, } from './remote-api.js';
|
|
40
40
|
import { parseAgentOAuthStateParam } from '../session/agent.js';
|
|
41
41
|
/**
|
|
@@ -242,6 +242,14 @@ function requireAnyScope(ctx, scopes) {
|
|
|
242
242
|
}
|
|
243
243
|
function execOptions(ctx, value) {
|
|
244
244
|
const options = objectArg(value);
|
|
245
|
+
// The remote boundary authenticates a SESSION, not a user inside it, so a
|
|
246
|
+
// token holder does not get to name the uid its command runs as. Refused
|
|
247
|
+
// rather than dropped: silently running as somebody other than the caller
|
|
248
|
+
// asked for is worse than an error. A colocated embedder holds the DO stub
|
|
249
|
+
// and is trusted with `cred` the same way it is trusted with kernel writes.
|
|
250
|
+
if (options.cred !== undefined) {
|
|
251
|
+
throw apiError('cred is not accepted over the remote API', 'E_ARG_SHAPE', 400);
|
|
252
|
+
}
|
|
245
253
|
return {
|
|
246
254
|
...options,
|
|
247
255
|
cwd: typeof options.cwd === 'string' ? options.cwd : ctx.root,
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* functions / imports persist.
|
|
8
8
|
*
|
|
9
9
|
* Design:
|
|
10
|
-
* - One child-facet per REPL session (
|
|
10
|
+
* - One child-facet per REPL session (LoaderPool with
|
|
11
11
|
* concurrency=1, omitSupervisor=true).
|
|
12
12
|
* - Facet-side: globalThis.__nimbus_bun_ctx caches a vm.createContext()
|
|
13
13
|
* dict; each push() runs vm.runInContext(line, ctx) and returns
|
package/dist/runtime/bun-repl.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* functions / imports persist.
|
|
8
8
|
*
|
|
9
9
|
* Design:
|
|
10
|
-
* - One child-facet per REPL session (
|
|
10
|
+
* - One child-facet per REPL session (LoaderPool with
|
|
11
11
|
* concurrency=1, omitSupervisor=true).
|
|
12
12
|
* - Facet-side: globalThis.__nimbus_bun_ctx caches a vm.createContext()
|
|
13
13
|
* dict; each push() runs vm.runInContext(line, ctx) and returns
|
|
@@ -125,8 +125,8 @@ class BunReplAdapter {
|
|
|
125
125
|
// Preamble: install the Bun shim global at facet startup so the
|
|
126
126
|
// REPL context has Bun.* available like real Bun does.
|
|
127
127
|
const preamble = BUN_SHIM_PREAMBLE;
|
|
128
|
-
const {
|
|
129
|
-
this.pool = new
|
|
128
|
+
const { LoaderPool } = await import('@nimbus-sh/fabric/loader-pool.js');
|
|
129
|
+
this.pool = new LoaderPool(env, ctx, {
|
|
130
130
|
tag: 'bun-repl',
|
|
131
131
|
concurrency: 1,
|
|
132
132
|
omitSupervisor: true,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The workerd {@link FacetHost}: a facet is a dynamic worker.
|
|
3
3
|
*
|
|
4
|
-
* The whole adapter is the option renames below, because `
|
|
4
|
+
* The whole adapter is the option renames below, because `LoaderPool`
|
|
5
5
|
* already IS the port's shape — `submit` and `dispose`, with the same meanings.
|
|
6
6
|
* The one thing it spells differently is the supervisor capability, which it
|
|
7
7
|
* takes as a pid plus a separate flag saying whether to bind one at all; the
|
|
@@ -13,13 +13,10 @@ import type { FacetHost } from '@nimbus-sh/core/runtime/facet-host.js';
|
|
|
13
13
|
import type { FacetManager } from '../facets/manager.js';
|
|
14
14
|
export declare function loaderFacetHost(env: unknown, ctx: DurableObjectState): FacetHost;
|
|
15
15
|
/**
|
|
16
|
-
* The two objects a
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* needs the same reach-through. Reflect.get rather than a cast: the shape is
|
|
21
|
-
* checked here once, and a FacetManager built on something other than a
|
|
22
|
-
* DurableObjectState fails with a sentence instead of at the first RPC.
|
|
16
|
+
* The two objects a LoaderPool needs from a FacetManager, via the manager's
|
|
17
|
+
* own `loaderHost()` accessor. The runtime guard stays: harnesses build
|
|
18
|
+
* FacetManagers on mock contexts, and one built on something other than a
|
|
19
|
+
* DurableObjectState should fail with a sentence instead of at the first RPC.
|
|
23
20
|
*/
|
|
24
21
|
export declare function getFacetManagerLoaderHost(facetMgr: FacetManager): {
|
|
25
22
|
env: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facet-loader-host.d.ts","sourceRoot":"","sources":["../../src/runtime/facet-loader-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAIV,SAAS,EAEV,MAAM,uCAAuC,CAAC;AAG/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,GAAG,SAAS,CA6BhF;AAED
|
|
1
|
+
{"version":3,"file":"facet-loader-host.d.ts","sourceRoot":"","sources":["../../src/runtime/facet-loader-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAIV,SAAS,EAEV,MAAM,uCAAuC,CAAC;AAG/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,GAAG,SAAS,CA6BhF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,YAAY,GACrB;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,kBAAkB,CAAA;CAAE,CAM3C;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAGrE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { manifestVfs } from '@nimbus-sh/core/runtime/vfs-manifest.js';
|
|
2
|
-
import {
|
|
2
|
+
import { LoaderPool } from '@nimbus-sh/fabric/loader-pool.js';
|
|
3
3
|
export function loaderFacetHost(env, ctx) {
|
|
4
4
|
return {
|
|
5
5
|
// workerd suspends a guest through JSPI, which is what lets a syscall reach
|
|
@@ -14,7 +14,7 @@ export function loaderFacetHost(env, ctx) {
|
|
|
14
14
|
return manifestVfs(vfs, root, options);
|
|
15
15
|
},
|
|
16
16
|
open(spec) {
|
|
17
|
-
return new
|
|
17
|
+
return new LoaderPool(env, ctx, {
|
|
18
18
|
tag: spec.tag,
|
|
19
19
|
concurrency: spec.concurrency,
|
|
20
20
|
preamble: spec.preamble,
|
|
@@ -27,17 +27,13 @@ export function loaderFacetHost(env, ctx) {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* The two objects a
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* needs the same reach-through. Reflect.get rather than a cast: the shape is
|
|
35
|
-
* checked here once, and a FacetManager built on something other than a
|
|
36
|
-
* DurableObjectState fails with a sentence instead of at the first RPC.
|
|
30
|
+
* The two objects a LoaderPool needs from a FacetManager, via the manager's
|
|
31
|
+
* own `loaderHost()` accessor. The runtime guard stays: harnesses build
|
|
32
|
+
* FacetManagers on mock contexts, and one built on something other than a
|
|
33
|
+
* DurableObjectState should fail with a sentence instead of at the first RPC.
|
|
37
34
|
*/
|
|
38
35
|
export function getFacetManagerLoaderHost(facetMgr) {
|
|
39
|
-
const env =
|
|
40
|
-
const ctx = Reflect.get(facetMgr, 'ctx');
|
|
36
|
+
const { env, ctx } = facetMgr.loaderHost();
|
|
41
37
|
if (!isDurableObjectState(ctx)) {
|
|
42
38
|
throw new Error('a loader-backed runtime requires a FacetManager with DurableObjectState context');
|
|
43
39
|
}
|
|
@@ -113,8 +113,8 @@ class NodeReplAdapter {
|
|
|
113
113
|
const { facetMgr } = this.deps;
|
|
114
114
|
const env = facetMgr.env;
|
|
115
115
|
const ctx = facetMgr.ctx;
|
|
116
|
-
const {
|
|
117
|
-
this.pool = new
|
|
116
|
+
const { LoaderPool } = await import('@nimbus-sh/fabric/loader-pool.js');
|
|
117
|
+
this.pool = new LoaderPool(env, ctx, {
|
|
118
118
|
tag: 'node-repl',
|
|
119
119
|
concurrency: 1,
|
|
120
120
|
omitSupervisor: true,
|
|
@@ -207,7 +207,7 @@ class PythonReplAdapter {
|
|
|
207
207
|
snapshot.files[stdlibPath.replace(/^\/+/, '')] = btoa(bin);
|
|
208
208
|
this.fsSnapshot = snapshot;
|
|
209
209
|
this.pythonHome = `/${installRoot.replace(/^\/+/, '')}`;
|
|
210
|
-
const {
|
|
210
|
+
const { LoaderPool } = await import('@nimbus-sh/fabric/loader-pool.js');
|
|
211
211
|
const host = getFacetManagerLoaderHost(facetMgr);
|
|
212
212
|
// A prompt where `open(path, "w")` silently does nothing is worse than one
|
|
213
213
|
// that refuses to start, so the pid decides which pool this is. Written as
|
|
@@ -225,11 +225,11 @@ class PythonReplAdapter {
|
|
|
225
225
|
};
|
|
226
226
|
const pid = this.deps.pid;
|
|
227
227
|
this.pool = (typeof pid === 'number' && pid > 0
|
|
228
|
-
? new
|
|
228
|
+
? new LoaderPool(host.env, host.ctx, { ...base, supervisorPid: pid })
|
|
229
229
|
// The install-time warm-up has no invoking process. It boots the
|
|
230
230
|
// interpreter and never touches a file, so it asks for no supervisor
|
|
231
231
|
// rather than binding one it cannot authenticate to.
|
|
232
|
-
: new
|
|
232
|
+
: new LoaderPool(host.env, host.ctx, { ...base, omitSupervisor: true }));
|
|
233
233
|
}
|
|
234
234
|
async submit(userCode) {
|
|
235
235
|
const result = await this.pool.submit(pythonReplStepFacetFn, {
|
|
@@ -156,10 +156,10 @@ class RubyReplAdapter {
|
|
|
156
156
|
// drifted (it lacked the language-prelude const __rubyRun requires, so
|
|
157
157
|
// every REPL eval died on boot) — compose it in exactly one place.
|
|
158
158
|
const preamble = buildRubyPreamble();
|
|
159
|
-
const {
|
|
159
|
+
const { LoaderPool } = await import('@nimbus-sh/fabric/loader-pool.js');
|
|
160
160
|
const env = facetMgr.env;
|
|
161
161
|
const ctx = facetMgr.ctx;
|
|
162
|
-
this.pool = new
|
|
162
|
+
this.pool = new LoaderPool(env, ctx, {
|
|
163
163
|
tag: 'ruby-repl',
|
|
164
164
|
concurrency: 1,
|
|
165
165
|
omitSupervisor: true,
|
|
@@ -48,7 +48,7 @@ export function rubyResidentStart(facetMgr) {
|
|
|
48
48
|
}
|
|
49
49
|
const boot = parsed.data;
|
|
50
50
|
if (boot.state === 'listening' && typeof boot.port === 'number' && boot.port > 0) {
|
|
51
|
-
facetMgr.registerPort(spawned.pid, Number(boot.port));
|
|
51
|
+
await facetMgr.registerPort(spawned.pid, Number(boot.port));
|
|
52
52
|
const routeablePorts = await facetMgr.waitForRouteablePorts(spawned.pid);
|
|
53
53
|
const routeablePort = routeablePorts.includes(Number(boot.port)) ? Number(boot.port) : routeablePorts[0];
|
|
54
54
|
if (!routeablePort) {
|
|
@@ -18,11 +18,15 @@
|
|
|
18
18
|
* w9_proc_logs + w9_proc_exits.
|
|
19
19
|
* - scheduleHibFlush(host, ctx) — debounced setTimeout + best-effort
|
|
20
20
|
* setAlarm for post-hibernation drain.
|
|
21
|
-
* - dispatchAlarm(host) — alarm() handler body
|
|
22
|
-
*
|
|
23
|
-
* counter once per fresh isolate.
|
|
21
|
+
* - dispatchAlarm(host) — alarm() handler body: the fabric's generic
|
|
22
|
+
* reason dispatcher with this session's handlers registered.
|
|
24
23
|
* - flushOnClose(host) — synchronous flush on ws close.
|
|
25
24
|
*
|
|
25
|
+
* The alarm multiplexer itself (reason map, scheduleAlarm, the per-instance
|
|
26
|
+
* chain) and maybeBumpIsolateGen are fabric machinery —
|
|
27
|
+
* `@nimbus-sh/fabric/alarms.js`; this module registers the session's reasons
|
|
28
|
+
* ('w9-flush' | 'log-janitor' | 'resident-launch') on top of it.
|
|
29
|
+
*
|
|
26
30
|
* **`ctx` taken as a separate arg from `host`** because the parent
|
|
27
31
|
* `CloudflareDurableObject` class declares `ctx` as `protected`, which
|
|
28
32
|
* is nominal-typed in TS and cannot appear on a public interface
|
|
@@ -35,7 +39,8 @@
|
|
|
35
39
|
* wireProcessLogPersist again.
|
|
36
40
|
*/
|
|
37
41
|
import type { SessionProcessSupervisor } from '@nimbus-sh/core/runtime/session-process-supervisor.js';
|
|
38
|
-
import { type WsHibernationConfigResult } from '
|
|
42
|
+
import { type WsHibernationConfigResult } from '@nimbus-sh/fabric/ws-hibernation-config.js';
|
|
43
|
+
import { type AlarmHost, type IsolateGenHost } from '@nimbus-sh/fabric/alarms.js';
|
|
39
44
|
export type { WsHibernationConfigResult };
|
|
40
45
|
/**
|
|
41
46
|
* Minimal host shape. `_w9*` fields drop `private` on the class so
|
|
@@ -44,10 +49,8 @@ export type { WsHibernationConfigResult };
|
|
|
44
49
|
*
|
|
45
50
|
* `ctx` is NOT in this interface — passed as a separate arg.
|
|
46
51
|
*/
|
|
47
|
-
export interface HibHost {
|
|
52
|
+
export interface HibHost extends AlarmHost, IsolateGenHost {
|
|
48
53
|
processes: SessionProcessSupervisor;
|
|
49
|
-
_w9IsolateGen: number;
|
|
50
|
-
_w9IsolateGenPersisted: boolean;
|
|
51
54
|
_w9SchemaInit: boolean;
|
|
52
55
|
_w9PersistWired: boolean;
|
|
53
56
|
_w9FlushTimer: any;
|
|
@@ -55,8 +58,6 @@ export interface HibHost {
|
|
|
55
58
|
_w1JanitorArmed: boolean;
|
|
56
59
|
/** W1: destroyed-session tombstone — never re-arm alarms while set. */
|
|
57
60
|
_w1SessionDestroyed: boolean;
|
|
58
|
-
/** W1: serializes every alarm-map read-modify-write (see scheduleAlarm). */
|
|
59
|
-
_w1AlarmChain?: Promise<unknown>;
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Run at DO ctor time. Returns the result for the class to assign to
|
|
@@ -104,35 +105,12 @@ export declare function ensureLogJanitor(host: HibHost, ctx: any): void;
|
|
|
104
105
|
/** W9: idempotent SQL schema bootstrap. */
|
|
105
106
|
export declare function ensureHibSchema(host: HibHost, ctx: any): void;
|
|
106
107
|
/**
|
|
107
|
-
* W1: canonical alarm-reason strings
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
108
|
+
* W1: this session's canonical alarm-reason strings, registered on the
|
|
109
|
+
* fabric's reason map. Forward-compat: the dispatcher silently drops unknown
|
|
110
|
+
* reasons so a rollback from a future deploy that added new reasons doesn't
|
|
111
|
+
* leave the alarm stuck.
|
|
111
112
|
*/
|
|
112
113
|
export type AlarmReason = 'w9-flush' | 'log-janitor' | 'resident-launch';
|
|
113
|
-
/**
|
|
114
|
-
* W1: schedule (or re-schedule) an alarm reason. Coordinated via a
|
|
115
|
-
* single map in DO storage so multiple subsystems (W9 debounced flush +
|
|
116
|
-
* W1 log-janitor sweep) don't clobber each other's `setAlarm()` calls.
|
|
117
|
-
*
|
|
118
|
-
* Semantics:
|
|
119
|
-
* - Reads the existing reasons map.
|
|
120
|
-
* - Sets `map[reason] = whenMs` IF `whenMs` is sooner than the
|
|
121
|
-
* currently-pending deadline for that reason (or no entry exists).
|
|
122
|
-
* Later-than-pending requests are silently ignored — the existing
|
|
123
|
-
* alarm will fire and re-arm anyway.
|
|
124
|
-
* - Writes the map back and calls `ctx.storage.setAlarm(min(deadlines))`.
|
|
125
|
-
*
|
|
126
|
-
* Cost: 1 storage read + 1 storage write + 1 setAlarm per call. setAlarm
|
|
127
|
-
* itself is billed as 1 row written per DO pricing. At W1's 60s
|
|
128
|
-
* cadence, this is ~$0.05/mo/session at scale — dwarfed by the
|
|
129
|
-
* hibernation duration savings.
|
|
130
|
-
*
|
|
131
|
-
* Fail-soft: any throw is swallowed with a warn. On older runtimes /
|
|
132
|
-
* wrangler-dev where setAlarm is unavailable, this is a no-op (the
|
|
133
|
-
* subsystem's in-isolate setTimeout fallback continues to work).
|
|
134
|
-
*/
|
|
135
|
-
export declare function scheduleAlarm(host: HibHost, ctx: any, reason: AlarmReason, whenMs: number): Promise<boolean>;
|
|
136
114
|
/**
|
|
137
115
|
* W9: ensure the alarm is set for the next flush window. Cheap to
|
|
138
116
|
* call repeatedly — we only schedule the in-isolate flush timer if
|
|
@@ -141,29 +119,18 @@ export declare function scheduleAlarm(host: HibHost, ctx: any, reason: AlarmReas
|
|
|
141
119
|
*/
|
|
142
120
|
export declare function scheduleHibFlush(host: HibHost, ctx: any): void;
|
|
143
121
|
/**
|
|
144
|
-
* W1:
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* For each pending reason whose deadline has passed, run its handler.
|
|
148
|
-
* Reasons supported today:
|
|
122
|
+
* W1: this session's alarm() handler body — the fabric's multi-reason
|
|
123
|
+
* dispatcher with this session's handlers registered:
|
|
149
124
|
* - `'w9-flush'` → processes.flushLogs()
|
|
125
|
+
* - `'resident-launch'` → pumpResidentLaunches()
|
|
150
126
|
* - `'log-janitor'` → processes.dropLogsOlderThan(orphanCheck); re-arm
|
|
151
|
-
* for next 60s cycle.
|
|
127
|
+
* for next 60s cycle while the session still has anything to sweep.
|
|
152
128
|
*
|
|
153
129
|
* `janitorOrphanCheck` is the orphan-pid predicate provided by the
|
|
154
130
|
* caller (typically `(pid) => !host.processes.get(pid)`). Decoupled
|
|
155
131
|
* so HibHost doesn't need to import ProcessTable.
|
|
156
|
-
*
|
|
157
|
-
* After running fireable reasons, re-arms `ctx.storage.setAlarm` at the
|
|
158
|
-
* earliest remaining deadline. If no reasons remain, deletes the map
|
|
159
|
-
* key and does NOT call setAlarm — the DO becomes hibernation-eligible
|
|
160
|
-
* after the 10s idle window.
|
|
161
|
-
*
|
|
162
|
-
* Forward/back-compat: unknown reasons silently dropped.
|
|
163
132
|
*/
|
|
164
133
|
export declare function dispatchAlarm(host: HibHost, ctx: any, janitorOrphanCheck?: (pid: number) => boolean, pumpResidentLaunches?: () => Promise<void>): Promise<void>;
|
|
165
|
-
/** W9: increment + persist isolate-gen counter once per fresh isolate. */
|
|
166
|
-
export declare function maybeBumpIsolateGen(host: HibHost, ctx: any): Promise<void>;
|
|
167
134
|
/**
|
|
168
135
|
* W9: synchronous flush of the process-log ring on session close.
|
|
169
136
|
* Wraps `processes.flushLogs()` in a try/catch so a flush failure
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hibernation.d.ts","sourceRoot":"","sources":["../../src/session/hibernation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hibernation.d.ts","sourceRoot":"","sources":["../../src/session/hibernation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EAA0B,KAAK,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACpH,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,6BAA6B,CAAC;AAGrC,YAAY,EAAE,yBAAyB,EAAE,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,OAAQ,SAAQ,SAAS,EAAE,cAAc;IACxD,SAAS,EAAE,wBAAwB,CAAC;IACpC,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;IACnB,4EAA4E;IAC5E,eAAe,EAAE,OAAO,CAAC;IACzB,uEAAuE;IACvE,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,GAAG,GAAG,yBAAyB,CAY9E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CA6GnE;AAED;;;;;;;;;;GAUG;AACH;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAMrE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAc9D;AAED,2CAA2C;AAC3C,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAqB7D;AAED;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,aAAa,GAAG,iBAAiB,CAAC;AAEzE;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAqB9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,GAAG,EACR,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,EAC7C,oBAAoB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GACzC,OAAO,CAAC,IAAI,CAAC,CAuCf;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAMhD"}
|