@powerhousedao/switchboard 6.2.3-dev.55 → 6.2.3-dev.56

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/CHANGELOG.md CHANGED
@@ -1,3 +1,47 @@
1
+ ## 6.2.3-dev.56 (2026-10-14)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **desktop:** @powerhousedao/desktop — the desktop runner productized (P6.1-P6.5) ([58ce9a0d4a](https://github.com/powerhouse-inc/powerhouse/commit/58ce9a0d4a))
6
+ - **clint,ph-cli:** one static-serve implementation — connect-server deleted (P5.7) ([c35b0341c6](https://github.com/powerhouse-inc/powerhouse/commit/c35b0341c6))
7
+ - **clint:** mastra-runner — remote reactor attach + OpenAI-compatible agent API (P5.5, P5.6) ([532cb2128f](https://github.com/powerhouse-inc/powerhouse/commit/532cb2128f))
8
+ - **clint:** port the ph-clint framework — core, integrations, TUI, testing + full suite (P5.2, P5.3) ([d1ace0688e](https://github.com/powerhouse-inc/powerhouse/commit/d1ace0688e))
9
+ - **clint:** scaffold @powerhousedao/clint — the ph-clint port lands here (P5.1) ([c7a3435588](https://github.com/powerhouse-inc/powerhouse/commit/c7a3435588))
10
+ - **host-core,ph-cli:** structural multi-reactor — backends drive the routing client (P4.1-P4.3) ([e7c71ca7ac](https://github.com/powerhouse-inc/powerhouse/commit/e7c71ca7ac))
11
+ - **host-core:** shared zod host schemas; bridges adopt strict reactor/profile (P2.1, P2.2) ([1bd9db67be](https://github.com/powerhouse-inc/powerhouse/commit/1bd9db67be))
12
+ - **vetra:** lint project subgraphs for types core or the package's models own ([6855c0ed91](https://github.com/powerhouse-inc/powerhouse/commit/6855c0ed91))
13
+ - **host-core:** generic run records and pid-probe (P1.3, P1.5, P1.6 foundation) ([9a6affd46e](https://github.com/powerhouse-inc/powerhouse/commit/9a6affd46e))
14
+ - **host-core:** move drive projection primitives; add projectDrivesIntoConnect (P1.4) ([6cd1d8ee6e](https://github.com/powerhouse-inc/powerhouse/commit/6cd1d8ee6e))
15
+ - **host-core:** scaffold @powerhousedao/host-core (P1.1) ([c7d9b415b5](https://github.com/powerhouse-inc/powerhouse/commit/c7d9b415b5))
16
+ - **reactor-api:** report background failures through a reportError option ([724796bcc1](https://github.com/powerhouse-inc/powerhouse/commit/724796bcc1))
17
+ - **switchboard:** configure the inspection throttle from PH_INSPECTION_* env ([4eefc0b8aa](https://github.com/powerhouse-inc/powerhouse/commit/4eefc0b8aa))
18
+ - **switchboard:** let INSPECTION_ENABLED=false keep /graphql/inspection unmounted ([aefe93b1e1](https://github.com/powerhouse-inc/powerhouse/commit/aefe93b1e1))
19
+ - **ph-cli:** uniform-runners flag helper and host.js loader (P0.1, P0.2, P0.12) ([4c04163009](https://github.com/powerhouse-inc/powerhouse/commit/4c04163009))
20
+ - ⚠️ **reactor-workflow:** lease warm piece children per request from one pool sized around the reactor's threads ([9ff3834198](https://github.com/powerhouse-inc/powerhouse/commit/9ff3834198))
21
+
22
+ ### 🩹 Fixes
23
+
24
+ - **ci:** read duration-watch timings from check runs and warn on API errors ([239683c51d](https://github.com/powerhouse-inc/powerhouse/commit/239683c51d))
25
+ - **switchboard:** new attachment tests use the granted-download helper ([0206932b66](https://github.com/powerhouse-inc/powerhouse/commit/0206932b66))
26
+ - **switchboard:** answer 404 for an attachment whose blob is missing, instead of crashing ([#3110](https://github.com/powerhouse-inc/powerhouse/pull/3110))
27
+ - **tsconfig:** dedup host-core from root references now that ph-cli references it (P1.2) ([988cbc574c](https://github.com/powerhouse-inc/powerhouse/commit/988cbc574c))
28
+ - **switchboard:** report the remaining logged-only background failures ([f20ff3eb16](https://github.com/powerhouse-inc/powerhouse/commit/f20ff3eb16))
29
+ - **switchboard:** fail boot on an invalid PH_INSPECTION_CALLS_PER_MINUTE ([4326aa0c1e](https://github.com/powerhouse-inc/powerhouse/commit/4326aa0c1e))
30
+ - **reactor-workflow:** journal a fire as it queues, re-read a workflow changed during a wait, and sweep up orphaned PENDING runs ([37e9c7917b](https://github.com/powerhouse-inc/powerhouse/commit/37e9c7917b))
31
+
32
+ ### ⚠️ Breaking Changes
33
+
34
+ - **reactor-workflow:** lease warm piece children per request from one pool sized around the reactor's threads ([9ff3834198](https://github.com/powerhouse-inc/powerhouse/commit/9ff3834198))
35
+
36
+ ### ❤️ Thank You
37
+
38
+ - acaldas
39
+ - Benjamin Jordan
40
+ - Claude Fable 5
41
+ - Claude Opus 5.5
42
+ - Frank @froid1911
43
+ - Wouter Kampmann
44
+
1
45
  ## 6.2.3-dev.55 (2026-10-13)
2
46
 
3
47
  ### 🚀 Features
package/README.md CHANGED
@@ -100,17 +100,19 @@ pnpm add -g @powerhousedao/switchboard
100
100
 
101
101
  ### Environment Variables
102
102
 
103
- | Variable | Description | Default |
104
- | --------------------------- | ---------------------------------- | --------------------- |
105
- | `PORT` | Server port | `4001` |
106
- | `DATABASE_URL` | Database connection string | `./.ph/drive-storage` |
107
- | `PH_REACTOR_DATABASE_URL` | PostgreSQL URL (takes precedence) | - |
108
- | `REACTOR_DB_POOL_SIZE_HOST` | Reactor host Postgres pool size | `16` |
109
- | `REDIS_URL` | Redis connection URL | - |
110
- | `REDIS_TLS_URL` | Redis TLS connection URL | - |
111
- | `PYROSCOPE_SERVER_ADDRESS` | Pyroscope server address | - |
112
- | `FEATURE_REACTORV2_ENABLED` | Enable Reactor v2 subgraph feature | `false` |
113
- | `MCP_ENABLED` | `false` keeps `/mcp` unmounted | `true` |
103
+ | Variable | Description | Default |
104
+ | -------------------------------- | ------------------------------------------------------------------------------ | --------------------- |
105
+ | `PORT` | Server port | `4001` |
106
+ | `DATABASE_URL` | Database connection string | `./.ph/drive-storage` |
107
+ | `PH_REACTOR_DATABASE_URL` | PostgreSQL URL (takes precedence) | - |
108
+ | `REACTOR_DB_POOL_SIZE_HOST` | Reactor host Postgres pool size | `16` |
109
+ | `REDIS_URL` | Redis connection URL | - |
110
+ | `REDIS_TLS_URL` | Redis TLS connection URL | - |
111
+ | `PYROSCOPE_SERVER_ADDRESS` | Pyroscope server address | - |
112
+ | `FEATURE_REACTORV2_ENABLED` | Enable Reactor v2 subgraph feature | `false` |
113
+ | `MCP_ENABLED` | `false` keeps `/mcp` unmounted | `true` |
114
+ | `INSPECTION_ENABLED` | `false` keeps inspection unmounted | `true` |
115
+ | `PH_INSPECTION_CALLS_PER_MINUTE` | `validateDocument`/`driveIntegrity` calls per caller per minute; admins exempt | `6` |
114
116
 
115
117
  See [Observability](#observability) below for Sentry and OpenTelemetry variables.
116
118
 
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c9eef974-47b1-5e45-aad6-5ebb1885b76a")}catch(e){}}();
4
- import { a as StoredDocumentsRefusedError, c as initProfilerFromEnv, i as startSwitchboard, l as parseForcePgVersion } from "./server-kc2kg0hU.mjs";
4
+ import { a as StoredDocumentsRefusedError, c as initProfilerFromEnv, i as startSwitchboard, l as parseForcePgVersion } from "./server-Cw2WnaCA.mjs";
5
5
  import { metrics } from "@opentelemetry/api";
6
6
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
7
7
  import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
@@ -1,22 +1,22 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ec03f0c0-5719-589a-9dcf-ef409bb7cc1d")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="99cead54-dc11-5711-a454-9efc98498890")}catch(e){}}();
3
3
  import { n as addDefaultReactorDrive, r as isPostgresUrl, t as addDefaultDrive } from "./utils-uaBlzyjS.mjs";
4
4
  import { createRequire, register } from "node:module";
5
5
  import { metrics, trace } from "@opentelemetry/api";
6
6
  import { ReactorInstrumentation } from "@powerhousedao/opentelemetry-instrumentation-reactor";
7
7
  import * as Sentry from "@sentry/node";
8
- import { childLogger, documentModelDocumentModelModule, setLogLevel } from "document-model";
8
+ import { childLogger, setLogLevel } from "document-model";
9
9
  import dotenv from "dotenv";
10
10
  import { getConfig } from "@powerhousedao/config/node";
11
11
  import { existsSync, promises, realpathSync } from "node:fs";
12
12
  import path, { resolve } from "node:path";
13
13
  import { createDurableNodeFs, preparePgliteDataDir, removeStalePgliteFiles, resolvePgliteFsync, syncTree } from "@powerhousedao/reactor-api/pglite-node";
14
14
  import { ChannelScheme, DriveCollectionId, EventBus, HardenedPGliteDialect, IN_MEMORY_PGLITE_STORAGE_FACTS, PGLITE_PATH_STORAGE_FACTS, POSTGRES_STORAGE_FACTS, REACTOR_SCHEMA, ReactorBuilder, ReactorClientBuilder, UnsupportedStoredProtocolError, createHybridProjectionCoordinatorFactory, instrumentPgPool, parseDriveUrl, supportsLiveReadModelRegistration } from "@powerhousedao/reactor";
15
- import { AuthorizationPolicy, BaseSubgraph, ForbiddenError, HttpPackageLoader, ImportPackageLoader, PGLITE_UTC_PARSERS, PackageManagementService, PackagesSubgraph, PrivacyPermissionAdapter, callerSubject, createCanonicalDocumentIdResolver, getUniqueDocumentModels, initializeAndStartAPI, resolveRenownConfig } from "@powerhousedao/reactor-api";
15
+ import { AuthorizationPolicy, BaseSubgraph, ForbiddenError, HttpPackageLoader, ImportPackageLoader, PGLITE_UTC_PARSERS, PackageManagementService, PackagesSubgraph, PrivacyPermissionAdapter, baseDocumentModels, callerSubject, createCanonicalDocumentIdResolver, getUniqueDocumentModels, initializeAndStartAPI, reportFailure, resolveRenownConfig, runDetached } from "@powerhousedao/reactor-api";
16
16
  import { httpsHooksPath } from "@powerhousedao/reactor-api/https-hooks";
17
17
  import { AttachmentAlreadyExists, AttachmentNotFound, AttachmentPending, AttachmentReferenceReadModel, AttachmentSchemaCompiler, HashMismatch, InvalidAttachmentMetadata, InvalidAttachmentRef, ReservationNotFound, SizeMismatch, UploadTooLarge, createRef, createRemoteAttachmentService, parseAttachmentDownloadTarget, parseRef, validateReserveMetadata } from "@powerhousedao/reactor-attachments";
18
18
  import { createAttachmentClient } from "@powerhousedao/reactor-attachments/client";
19
- import { DriveNodeView, NodeProcessor, REACTOR_DRIVE_SUBGRAPH_NAME, ReactorDriveClient, createReactorDriveResolvers, reactorDriveDocumentModelModule, reactorDriveSubgraphTypeDefs } from "@powerhousedao/reactor-drive";
19
+ import { DriveNodeView, NodeProcessor, REACTOR_DRIVE_SUBGRAPH_NAME, ReactorDriveClient, createReactorDriveResolvers, reactorDriveSubgraphTypeDefs } from "@powerhousedao/reactor-drive";
20
20
  import { DEFAULT_KEYPAIR_PATH, DEFAULT_RENOWN_URL, NodeKeyStorage, RENOWN_READ_MODEL_SUBGRAPH, RenownBuilder, RenownCryptoBuilder, createLocalCredentialVerifier, createRenownTrustPolicy, resolveSwitchboardEndpoint } from "@renown/sdk/node";
21
21
  import { Kysely, PostgresDialect } from "kysely";
22
22
  import net from "node:net";
@@ -25,8 +25,6 @@ import { Pool } from "pg";
25
25
  import { Readable } from "node:stream";
26
26
  import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
27
27
  import { DisclosureService, MIN_DEPLOYMENT_SECRET_BYTES, createModuleErasure, createPrivacySubgraph, registerSubjectDocumentsReadModel } from "@powerhousedao/reactor-privacy";
28
- import { ReactorGroupV1 } from "@powerhousedao/reactor-group";
29
- import { driveDocumentModelModule } from "@powerhousedao/shared/document-drive";
30
28
  import { DEFAULT_SIGNATURE_POLICY, isSignaturePolicy } from "@powerhousedao/shared/document-model";
31
29
  import { readFile } from "node:fs/promises";
32
30
  import os from "node:os";
@@ -396,9 +394,28 @@ function makeDownloadHandler(attachments, attachmentAccess, urlSigner) {
396
394
  res.setHeader("Content-Length", String(header.sizeBytes));
397
395
  res.setHeader("Content-Disposition", buildContentDisposition(header.fileName));
398
396
  res.setHeader("Attachment-Metadata", buildMetadataHeader(header));
399
- Readable.fromWeb(body).pipe(res);
397
+ const source = Readable.fromWeb(body);
398
+ source.once("error", (err) => handleDownloadStreamError(res, hash, err));
399
+ source.pipe(res);
400
400
  };
401
401
  }
402
+ function handleDownloadStreamError(res, hash, err) {
403
+ if (res.headersSent) {
404
+ logger$2.error("Attachment stream failed mid-download: @error", err);
405
+ res.destroy();
406
+ return;
407
+ }
408
+ res.removeHeader("Content-Length");
409
+ res.removeHeader("Content-Disposition");
410
+ res.removeHeader("Attachment-Metadata");
411
+ if (err?.code === "ENOENT") {
412
+ logger$2.warn("Attachment @hash is recorded as available but its blob is missing", hash);
413
+ sendJson(res, 404, ATTACHMENT_NOT_FOUND_BODY);
414
+ return;
415
+ }
416
+ logger$2.error("Attachment stream failed before sending: @error", err);
417
+ sendError(res, 500, "Internal error");
418
+ }
402
419
  function toAsciiJson(value) {
403
420
  return JSON.stringify(value).replace(/[\u007f-\uffff]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`);
404
421
  }
@@ -993,12 +1010,7 @@ async function startPrivacy(deps) {
993
1010
  */
994
1011
  /** The models switchboard always registers alongside package models. */
995
1012
  function switchboardBaseDocumentModels() {
996
- return [
997
- documentModelDocumentModelModule,
998
- driveDocumentModelModule,
999
- reactorDriveDocumentModelModule,
1000
- ReactorGroupV1
1001
- ];
1013
+ return baseDocumentModels.map(([, model]) => model);
1002
1014
  }
1003
1015
  function applySwitchboardReactorDefaults(reactorBuilder, clientBuilder, options = {}) {
1004
1016
  const baseModels = options.includeBaseModels !== false ? switchboardBaseDocumentModels() : [];
@@ -1023,6 +1035,51 @@ function applySwitchboardReactorDefaults(reactorBuilder, clientBuilder, options
1023
1035
  if (trust?.trustPolicy) reactorBuilder.withTrustPolicy(trust.trustPolicy, trust.workerTrustPolicy);
1024
1036
  }
1025
1037
  //#endregion
1038
+ //#region src/env.mts
1039
+ function parseNonNegativeInt(raw, name) {
1040
+ if (raw === void 0 || raw.trim() === "") return;
1041
+ const value = Number.parseInt(raw, 10);
1042
+ if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`${name} must be a non-negative integer, got "${raw}"`);
1043
+ return value;
1044
+ }
1045
+ //#endregion
1046
+ //#region src/projection-worker.mts
1047
+ const DEFAULT_DB_POOL_SIZE_PROJECTION = 8;
1048
+ const ON_TOKENS = [
1049
+ "1",
1050
+ "true",
1051
+ "on",
1052
+ "yes"
1053
+ ];
1054
+ const OFF_TOKENS = [
1055
+ "0",
1056
+ "false",
1057
+ "off",
1058
+ "no"
1059
+ ];
1060
+ /**
1061
+ * Enabled by REACTOR_PROJECTION_WORKER (1/true/on/yes, case-insensitive) or
1062
+ * `input.enabled`, which wins when defined; null when off (the default).
1063
+ */
1064
+ function resolveProjectionWorkerOptions(input, env) {
1065
+ if (!(input?.enabled ?? parseOnOff(env.REACTOR_PROJECTION_WORKER) ?? false)) return null;
1066
+ const dbPoolSize = input?.dbPoolSize ?? parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_PROJECTION, "REACTOR_DB_POOL_SIZE_PROJECTION") ?? DEFAULT_DB_POOL_SIZE_PROJECTION;
1067
+ if (dbPoolSize < 1) throw new Error("REACTOR_DB_POOL_SIZE_PROJECTION must be at least 1; the projection worker cannot run without a pool");
1068
+ return { dbPoolSize };
1069
+ }
1070
+ /** Same preconditions as the executor worker pool; message shape mirrors server.mts. */
1071
+ function assertProjectionWorkerSupported(args) {
1072
+ if (args.dev) throw new Error("The projection worker (REACTOR_PROJECTION_WORKER) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary");
1073
+ if (!args.reactorDbUrl || !isPostgresUrl(args.reactorDbUrl)) throw new Error("The projection worker (REACTOR_PROJECTION_WORKER) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.");
1074
+ }
1075
+ function parseOnOff(raw) {
1076
+ if (raw === void 0 || raw.trim() === "") return;
1077
+ const token = raw.trim().toLowerCase();
1078
+ if (ON_TOKENS.includes(token)) return true;
1079
+ if (OFF_TOKENS.includes(token)) return false;
1080
+ throw new Error(`REACTOR_PROJECTION_WORKER must be one of 1, true, on, yes, 0, false, off, no, got "${raw}"`);
1081
+ }
1082
+ //#endregion
1026
1083
  //#region src/worker-pool.mts
1027
1084
  const DEFAULT_DB_POOL_SIZE_PER_WORKER = 2;
1028
1085
  const DEFAULT_ACQUIRE_TIMEOUT_MS = 5e3;
@@ -1240,48 +1297,15 @@ function parseWorkerCount(raw) {
1240
1297
  if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`REACTOR_WORKERS must be "auto" or a non-negative integer, got "${raw}"`);
1241
1298
  return value;
1242
1299
  }
1243
- function parseNonNegativeInt(raw, name) {
1244
- if (raw === void 0 || raw.trim() === "") return;
1245
- const value = Number.parseInt(raw, 10);
1246
- if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`${name} must be a non-negative integer, got "${raw}"`);
1247
- return value;
1248
- }
1249
1300
  //#endregion
1250
- //#region src/projection-worker.mts
1251
- const DEFAULT_DB_POOL_SIZE_PROJECTION = 8;
1252
- const ON_TOKENS = [
1253
- "1",
1254
- "true",
1255
- "on",
1256
- "yes"
1257
- ];
1258
- const OFF_TOKENS = [
1259
- "0",
1260
- "false",
1261
- "off",
1262
- "no"
1263
- ];
1264
- /**
1265
- * Enabled by REACTOR_PROJECTION_WORKER (1/true/on/yes, case-insensitive) or
1266
- * `input.enabled`, which wins when defined; null when off (the default).
1267
- */
1268
- function resolveProjectionWorkerOptions(input, env) {
1269
- if (!(input?.enabled ?? parseOnOff(env.REACTOR_PROJECTION_WORKER) ?? false)) return null;
1270
- const dbPoolSize = input?.dbPoolSize ?? parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_PROJECTION, "REACTOR_DB_POOL_SIZE_PROJECTION") ?? DEFAULT_DB_POOL_SIZE_PROJECTION;
1271
- if (dbPoolSize < 1) throw new Error("REACTOR_DB_POOL_SIZE_PROJECTION must be at least 1; the projection worker cannot run without a pool");
1272
- return { dbPoolSize };
1273
- }
1274
- /** Same preconditions as the executor worker pool; message shape mirrors server.mts. */
1275
- function assertProjectionWorkerSupported(args) {
1276
- if (args.dev) throw new Error("The projection worker (REACTOR_PROJECTION_WORKER) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary");
1277
- if (!args.reactorDbUrl || !isPostgresUrl(args.reactorDbUrl)) throw new Error("The projection worker (REACTOR_PROJECTION_WORKER) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.");
1278
- }
1279
- function parseOnOff(raw) {
1280
- if (raw === void 0 || raw.trim() === "") return;
1281
- const token = raw.trim().toLowerCase();
1282
- if (ON_TOKENS.includes(token)) return true;
1283
- if (OFF_TOKENS.includes(token)) return false;
1284
- throw new Error(`REACTOR_PROJECTION_WORKER must be one of 1, true, on, yes, 0, false, off, no, got "${raw}"`);
1301
+ //#region src/inspection-throttle.mts
1302
+ const NAME = "PH_INSPECTION_CALLS_PER_MINUTE";
1303
+ /** Unset keeps reactor-api's default; an invalid value fails boot. */
1304
+ function inspectionThrottleFromEnv(env) {
1305
+ const callsPerMinute = parseNonNegativeInt(env[NAME], NAME);
1306
+ if (callsPerMinute === void 0) return {};
1307
+ if (callsPerMinute < 1) throw new Error(`${NAME} must be at least 1, got "${env[NAME]}"`);
1308
+ return { callsPerMinute };
1285
1309
  }
1286
1310
  //#endregion
1287
1311
  //#region src/feature-flags.ts
@@ -1291,6 +1315,17 @@ async function initFeatureFlags() {
1291
1315
  return OpenFeature.getClient();
1292
1316
  }
1293
1317
  //#endregion
1318
+ //#region src/inspection-flag.mts
1319
+ /** The env var and OpenFeature flag key that can keep the inspection subgraph unmounted. */
1320
+ const INSPECTION_ENABLED = "INSPECTION_ENABLED";
1321
+ /** Whether to mount `/graphql/inspection`. A host's `inspection: false` wins;
1322
+ * otherwise INSPECTION_ENABLED decides, falling back to the host's option and
1323
+ * then INSPECTION_ENABLED_DEFAULT. */
1324
+ async function resolveInspectionEnabled({ featureFlags, option }) {
1325
+ if (option === false) return false;
1326
+ return featureFlags.getBooleanValue(INSPECTION_ENABLED, option ?? true);
1327
+ }
1328
+ //#endregion
1294
1329
  //#region src/mcp-flag.mts
1295
1330
  /** The env var and OpenFeature flag key that can keep the MCP server unmounted. */
1296
1331
  const MCP_ENABLED = "MCP_ENABLED";
@@ -2457,6 +2492,7 @@ async function composeClaimed(engine, deps, lease, loss) {
2457
2492
  attachments: deps.attachments,
2458
2493
  canReadAttachmentRef: attachmentReadPolicy(deps.attachmentAccess),
2459
2494
  logger: deps.logger,
2495
+ ...deps.reactorThreads ? { reactorThreads: deps.reactorThreads } : {},
2460
2496
  ...deps.telemetry ? { telemetry: deps.telemetry } : {}
2461
2497
  });
2462
2498
  const routes = {};
@@ -3022,6 +3058,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
3022
3058
  }
3023
3059
  const reactorPgliteMajor = reactorPgliteDir ? resolvePgliteMajorForDir(reactorPgliteDir) : null;
3024
3060
  const readModelPgliteMajor = readModelPgliteDir ? resolvePgliteMajorForDir(readModelPgliteDir) : null;
3061
+ const inspectionThrottle = inspectionThrottleFromEnv(process.env);
3025
3062
  let workerPool = resolveWorkerPoolOptions(options.workerPool, process.env);
3026
3063
  if (workerPool && options.reactor) {
3027
3064
  logger.warn("Worker pool configuration ignored: the caller-provided reactor owns its own executor");
@@ -3227,12 +3264,22 @@ async function initServer(serverPort, options, renown, renownConfig) {
3227
3264
  const verifyCredential = renownConfig.source === "self" ? (params) => localCredentialCheck ? localCredentialCheck(params) : Promise.reject(/* @__PURE__ */ new Error("The local renown read model is not bound yet")) : void 0;
3228
3265
  let defaultDriveUrl = void 0;
3229
3266
  const basePath = process.cwd();
3267
+ const reportError = (error) => {
3268
+ Sentry.captureException(error);
3269
+ };
3270
+ const reporting = {
3271
+ logger,
3272
+ report: reportError
3273
+ };
3230
3274
  let vite;
3231
3275
  let viteLoader;
3232
3276
  if (dev) {
3233
3277
  const { VitePackageLoader, createViteLogger, startViteServer } = await import("@powerhousedao/reactor-api/vite");
3234
3278
  vite = await startViteServer(process.cwd(), createViteLogger(logger));
3235
- viteLoader = VitePackageLoader.build(vite, { resolveFrom: [import.meta.url] });
3279
+ viteLoader = VitePackageLoader.build(vite, {
3280
+ resolveFrom: [import.meta.url],
3281
+ reportError
3282
+ });
3236
3283
  }
3237
3284
  const vetraProcessorFactory = dev ? (await import("@powerhousedao/vetra/processors")).processorFactory : void 0;
3238
3285
  if (!options.disableLocalPackages) packages.push(basePath);
@@ -3267,7 +3314,9 @@ async function initServer(serverPort, options, renown, renownConfig) {
3267
3314
  processors: vetraProcessorFactory ? { "@powerhousedao/vetra": [vetraProcessorFactory] } : {},
3268
3315
  configFile: configPath,
3269
3316
  mcp: options.mcp ?? true,
3317
+ inspection: options.inspection === false ? false : { throttle: inspectionThrottle },
3270
3318
  logger: apiLogger,
3319
+ reportError,
3271
3320
  enableDocumentModelSubgraphs: options.enableDocumentModelSubgraphs,
3272
3321
  renown: renownConfig,
3273
3322
  verifyCredential
@@ -3304,6 +3353,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
3304
3353
  pieces: api.packageManager,
3305
3354
  pieceRegistryUrl: registryUrl,
3306
3355
  models: workerModels,
3356
+ reactorThreads: (workerPool?.numWorkers ?? 0) + (projectionWorker ? 1 : 0),
3307
3357
  logger: logger.child(["workflow-runtime"]),
3308
3358
  exclusiveJournal: readModelPgliteDir !== null,
3309
3359
  onSingletonLost: workflowSingletonLossHandler(logger),
@@ -3326,7 +3376,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
3326
3376
  attachments: api.attachmentClientProvider
3327
3377
  });
3328
3378
  return graphqlManager.registerSubgraphInstance(workflowSubgraph, "graphql", false).catch((error) => {
3329
- logger.error("Failed to register workflow-runtime subgraph: @error", error);
3379
+ reportFailure(reporting, error, "Failed to register workflow-runtime subgraph: @error");
3330
3380
  });
3331
3381
  };
3332
3382
  if (workflowsEnabled) try {
@@ -3353,7 +3403,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
3353
3403
  try {
3354
3404
  await graphqlManager.updateRouter(true);
3355
3405
  } catch (error) {
3356
- logger.error("Mounting the late workflow-runtime subgraph failed: @error", error);
3406
+ reportFailure(reporting, error, "Mounting the late workflow-runtime subgraph failed: @error");
3357
3407
  }
3358
3408
  },
3359
3409
  logger
@@ -3402,7 +3452,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
3402
3452
  });
3403
3453
  packageManagementService.setOnModelsChanged(() => {
3404
3454
  graphqlManager.regenerateDocumentModelSubgraphs().catch((error) => {
3405
- logger.error("Failed to regenerate document model subgraphs: @error", error);
3455
+ reportFailure(reporting, error, "Failed to regenerate document model subgraphs: @error");
3406
3456
  });
3407
3457
  });
3408
3458
  const packagesSubgraph = new PackagesSubgraph({
@@ -3418,7 +3468,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
3418
3468
  attachments: api.attachmentClientProvider
3419
3469
  });
3420
3470
  lateSubgraphs.push(graphqlManager.registerSubgraphInstance(packagesSubgraph, "graphql", false).catch((error) => {
3421
- logger.error("Failed to register packages subgraph: @error", error);
3471
+ reportFailure(reporting, error, "Failed to register packages subgraph: @error");
3422
3472
  }));
3423
3473
  }
3424
3474
  if (driveNodeView) {
@@ -3437,18 +3487,18 @@ async function initServer(serverPort, options, renown, renownConfig) {
3437
3487
  relationalDb: void 0
3438
3488
  };
3439
3489
  lateSubgraphs.push(graphqlManager.registerSubgraphInstance(reactorDriveSubgraph, "graphql", false).catch((error) => {
3440
- logger.error("Failed to register reactor-drive subgraph: @error", error);
3490
+ reportFailure(reporting, error, "Failed to register reactor-drive subgraph: @error");
3441
3491
  }));
3442
3492
  }
3443
- (async () => {
3444
- await Promise.all(lateSubgraphs);
3493
+ runDetached("Marking the API ready", async () => {
3494
+ await Promise.allSettled(lateSubgraphs);
3445
3495
  try {
3446
3496
  await graphqlManager.updateRouter(true);
3447
3497
  } catch (error) {
3448
- logger.error("Final router update before readiness failed: @error", error);
3498
+ reportFailure(reporting, error, "Final router update before readiness failed: @error");
3449
3499
  }
3450
3500
  api.readiness.markReady();
3451
- })();
3501
+ }, reporting);
3452
3502
  if (options.drive) {
3453
3503
  if (!renown) throw new Error("Cannot create default drive without Renown identity");
3454
3504
  if ((options.drive.documentType ?? "powerhouse/document-drive") === "powerhouse/reactor-drive") defaultDriveUrl = await addDefaultReactorDrive(client, options.drive, serverPort);
@@ -3489,6 +3539,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
3489
3539
  modelManifest: () => workerModels?.modelManifest() ?? [],
3490
3540
  privacy: privacy ? { erasure: privacy.erasure } : void 0,
3491
3541
  mcpEnabled: options.mcp !== false,
3542
+ inspectionEnabled: options.inspection !== false,
3492
3543
  renown,
3493
3544
  port: serverPort,
3494
3545
  shutdown
@@ -3523,6 +3574,10 @@ const startSwitchboard = async (options = {}) => {
3523
3574
  featureFlags,
3524
3575
  option: options.mcp
3525
3576
  });
3577
+ options.inspection = await resolveInspectionEnabled({
3578
+ featureFlags,
3579
+ option: options.inspection
3580
+ });
3526
3581
  const configPathForFlags = resolveConfigPath(options.configFile);
3527
3582
  const workflowsEnabled = await resolveWorkflowsEnabled({
3528
3583
  featureFlags,
@@ -3538,6 +3593,7 @@ const startSwitchboard = async (options = {}) => {
3538
3593
  logger.info("Feature flags: @flags", JSON.stringify({
3539
3594
  DOCUMENT_MODEL_SUBGRAPHS_ENABLED: enableDocumentModelSubgraphs,
3540
3595
  MCP_ENABLED: options.mcp,
3596
+ INSPECTION_ENABLED: options.inspection,
3541
3597
  PH_WORKFLOWS_ENABLED: workflowsEnabled
3542
3598
  }, null, 2));
3543
3599
  let renown = null;
@@ -3560,5 +3616,5 @@ if (import.meta.main) await startSwitchboard({ fatalErrorShutdown: true });
3560
3616
  //#endregion
3561
3617
  export { StoredDocumentsRefusedError as a, initProfilerFromEnv as c, startSwitchboard as i, parseForcePgVersion as l, deriveAttachmentServiceConfig as n, resolveUnsupportedStoredDocuments as o, isPortAvailable as r, applySwitchboardReactorDefaults as s, createReactorKysely as t };
3562
3618
 
3563
- //# sourceMappingURL=server-kc2kg0hU.mjs.map
3564
- //# debugId=ec03f0c0-5719-589a-9dcf-ef409bb7cc1d
3619
+ //# sourceMappingURL=server-Cw2WnaCA.mjs.map
3620
+ //# debugId=99cead54-dc11-5711-a454-9efc98498890