Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

perf: load harness catalog parsers on demand (#6350)

[._.]/ Adam Eivybe05b11c9424
diff --git a/server/lib/aiToolkit/internal/modelFetchers.js b/server/lib/aiToolkit/internal/modelFetchers.js
index eed975380d..9c83a20f59 100644
--- a/server/lib/aiToolkit/internal/modelFetchers.js
+++ b/server/lib/aiToolkit/internal/modelFetchers.js
@@ -1,4 +1,4 @@
-import { isPiCommand } from './pi.js';
+import { commandBasename } from './commandBasename.js';
/**
* The single per-vendor table behind model refresh.
*
@@ -124,8 +124,8 @@ export const MODEL_FETCHERS = [
fetch: '_fetchGatewayModels',
},
{
- key: 'pi', cliMatch: (p) => isPiCommand(p?.command),
- tuiMatch: (p) => isPiCommand(p?.command), fetch: '_fetchPiModels',
+ key: 'pi', cliMatch: (p) => commandBasename(p?.command) === 'pi',
+ tuiMatch: (p) => commandBasename(p?.command) === 'pi', fetch: '_fetchPiModels',
},
{
key: 'cursor',
diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.js
index d05a567c2d..214b40fc7a 100644
--- a/server/lib/aiToolkit/providers.js
+++ b/server/lib/aiToolkit/providers.js
@@ -1,4 +1,3 @@
-import { PI_COMMAND, parsePiModelList } from './internal/pi.js';
import { readFile, rename } from 'fs/promises';
import { existsSync } from 'fs';
import { join, dirname, delimiter, isAbsolute } from 'path';
@@ -1364,6 +1363,7 @@ export function createProviderService(config = {}) {
},
async _fetchPiModels(provider) {
+ const { PI_COMMAND, parsePiModelList } = await import('./internal/pi.js');
return this._execCliModelList(provider, PI_COMMAND, parsePiModelList, ['--list-models'],
(stdout) => /No models available/i.test(stdout) && /\/login/.test(stdout));
},
diff --git a/server/lib/importScoping.test.js b/server/lib/importScoping.test.js
index 763ac6b089..01f44733b2 100644
--- a/server/lib/importScoping.test.js
+++ b/server/lib/importScoping.test.js
@@ -39,6 +39,8 @@ const reaches = (entry, target) => staticImportClosure(abs(entry)).files.has(abs
// Each row: the entry that was narrowed, the module it must no longer
// statically reach, and why the entry only ever needed a slice of it.
const NARROWED = [
+ ['services/providerRuntimeInstaller.js', 'lib/harnessOutput.js',
+ 'loads version and catalog parsers only when probing a harness'],
['lib/db.js', 'lib/db/schema/index.js',
'the DDL composer is boot-only — ensureSchemaImpl() imports it lazily'],
['lib/pipelineValidation.js', 'lib/editorial/checkRegistry.js',
@@ -173,7 +175,11 @@ describe('deferred imports stay deferred (#6156)', () => {
* inch it up by a hundred each time. It stays thousands below what ONE eager
* edge into a heavy subtree costs, which is what actually has to fail here.
*/
-const MAX_STATIC_INSTANTIATIONS = 88000;
+// #6350: Pi's vendor leaf is necessarily reached by the shared dispatcher.
+// Deferring catalog/version parsers removes 296 instantiations (88,360 →
+// 88,064). Restore the documented ~1.5k allowance for ordinary leaf growth;
+// keep the negative runtime-installer guard above so eager parsing cannot return.
+const MAX_STATIC_INSTANTIATIONS = 89500;
const SKIP_DIRS = new Set(['node_modules', 'coverage', 'dist', 'data']);
const serverTestFiles = (dir = SERVER_DIR, out = []) => {
diff --git a/server/services/providerRuntimeInstaller.js b/server/services/providerRuntimeInstaller.js
index 9295f23be0..1859dfb380 100644
--- a/server/services/providerRuntimeInstaller.js
+++ b/server/services/providerRuntimeInstaller.js
@@ -40,7 +40,6 @@
import { spawn } from '../lib/childProcess.js';
import { killProcessTree, prepareCliSpawn } from '../lib/bufferedSpawn.js';
import { commandOutput } from '../lib/commandExists.js';
-import { parseHarnessVersion } from '../lib/harnessOutput.js';
import { adoptNpmGlobalBinDir } from '../lib/npmGlobalBin.js';
import { findCommandOnPath, safeChildProcessEnv, safeChildProcessOptions } from '../lib/processEnv.js';
import { PROVIDER_VENDORS } from '../lib/providerVendors.js';
@@ -236,6 +235,7 @@ async function probeRuntimeStatus(runtime, findCommand, probeCommand) {
? await probeCommand(versionProbe.command, versionProbe.args, { timeoutMs: PROBE_TIMEOUT_MS })
: null;
const installed = typeof probed === 'string';
+ const { parseHarnessVersion } = await import('../lib/harnessOutput.js');
const version = parseHarnessVersion(probed);
// Windows-only gap: the script-installed vendors publish a PowerShell