From 98f6552e219b32125e27b9c7683c049340693c69 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 20:24:58 +0800 Subject: [PATCH 1/8] Revert "ci: reduce coverage cocurrency" This reverts commit ab30aca5cb859aea4bd0fffc88414270d1761f7d. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d6a94d11f..d1440bd88b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -110,8 +110,8 @@ jobs: # across six always-on runner instances, and the timing-sensitive # process suites have documented aggregate-contention failures. # 8 × 6 instances = 48 workers worst case on 64 cores. - DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '8' }} - DSH_GATE_CONCURRENCY: '3' + DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '24' }} + DSH_GATE_CONCURRENCY: '8' NODE_OPTIONS: '--max-old-space-size=8192' steps: - uses: actions/checkout@v6 From e35e2a9f3ead2cc3b9e3aa2fcd1a15e8c668dad2 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:07:22 +0800 Subject: [PATCH 2/8] perf: tsc --- packages/typert/generator/src/analyzer.ts | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/typert/generator/src/analyzer.ts b/packages/typert/generator/src/analyzer.ts index 1f545d9673..e0e04a4fa1 100644 --- a/packages/typert/generator/src/analyzer.ts +++ b/packages/typert/generator/src/analyzer.ts @@ -131,6 +131,26 @@ interface FaceProgramHost { readonly files: Map } +/** + * Process-wide parse cache for the bundled TypeScript default libraries. + * `typescript/lib/lib.*.d.ts` content is immutable for the process lifetime, + * so parses are shared across every {@link WorkspaceCaches} instance; the key + * carries the parse-affecting settings, keeping reuse exact. + */ +const defaultLibraryParses = new Map() + +function defaultLibraryKey(fileName: string, languageVersionOrOptions: ts.ScriptTarget | ts.CreateSourceFileOptions): string { + const options = typeof languageVersionOrOptions === 'object' + ? languageVersionOrOptions + : { languageVersion: languageVersionOrOptions } + return [ + fileName, + String(options.languageVersion), + String(options.impliedNodeFormat ?? ''), + String(options.jsDocParsingMode ?? ''), + ].join('\0') +} + /** * Shared memo over one immutable workspace snapshot. Passing one instance to * several analyzers (the batched and write-mode children reuse their parent's @@ -185,6 +205,13 @@ export class WorkspaceCaches { // only fires under oldProgram reuse, which these fresh programs never // request, and invalidate() is the one supported re-read path. host.getSourceFile = (fileName, languageVersionOrOptions, onError) => { + if (isStandardLibraryFile(fileName)) { + const key = defaultLibraryKey(fileName, languageVersionOrOptions) + if (!defaultLibraryParses.has(key)) { + defaultLibraryParses.set(key, base(fileName, languageVersionOrOptions, onError)) + } + return defaultLibraryParses.get(key) + } if (!files.has(fileName)) files.set(fileName, base(fileName, languageVersionOrOptions, onError)) return files.get(fileName) } From be0216102a145729543b872e6da91c5bbfab7d69 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:17:11 +0800 Subject: [PATCH 3/8] Reapply "ci: reduce coverage cocurrency" This reverts commit a471ba79e30e6148e8c433b83fe0d7ee14a8312b. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1440bd88b..6d6a94d11f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -110,8 +110,8 @@ jobs: # across six always-on runner instances, and the timing-sensitive # process suites have documented aggregate-contention failures. # 8 × 6 instances = 48 workers worst case on 64 cores. - DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '24' }} - DSH_GATE_CONCURRENCY: '8' + DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '8' }} + DSH_GATE_CONCURRENCY: '3' NODE_OPTIONS: '--max-old-space-size=8192' steps: - uses: actions/checkout@v6 From 56a8db2777ce002ead70f6f35d80cde9ccdbe60a Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:31:27 +0800 Subject: [PATCH 4/8] ci: use 16c 16c --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d6a94d11f..1e999becdc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && fromJSON('["self-hosted", "linux", "x64", "vm-backup"]') - || 'dsh-enterprise-ubuntu-latest-32core-test' }} + || 'dsh-ubuntu-24-04-16core' }} name: node 24 / static env: DSH_GATE_CONCURRENCY: '8' @@ -102,7 +102,7 @@ jobs: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && fromJSON('["self-hosted", "linux", "x64", "vm-backup"]') - || 'dsh-enterprise-ubuntu-24-04-32core-test' }} + || 'dsh-ubuntu-24-04-16core' }} name: node 24 / coverage env: # Failover shrinks the worker bound: the hosted 32-core runner is @@ -167,7 +167,7 @@ jobs: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && fromJSON('["self-hosted", "linux", "x64", "vm-backup"]') - || 'dsh-enterprise-ubuntu-latest-32core-test' }} + || 'dsh-ubuntu-24-04-16core' }} name: node 24 / snapshots and artifacts env: DSH_GATE_CONCURRENCY: '8' From 9e2f6859f7c40b1be7014d7ae881e38d4d81fe9b Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:36:46 +0800 Subject: [PATCH 5/8] ci: reduce invariant import --- scripts/test-invariants.spec.ts | 3 +- scripts/test-invariants.ts | 66 ++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/scripts/test-invariants.spec.ts b/scripts/test-invariants.spec.ts index 7a4f678be8..0fb6aeb201 100644 --- a/scripts/test-invariants.spec.ts +++ b/scripts/test-invariants.spec.ts @@ -61,7 +61,8 @@ describe('global test invariant host', () => { return () => {} }) const fakeContext = { invariants: { register } } as unknown as Context - for (const [rawPath, companion] of Object.entries(testInvariantCompanions)) { + for (const [rawPath, load] of Object.entries(testInvariantCompanions)) { + const companion = await load() const path = rawPath.replace(/^\.\.\//, '') expect(companion.default, path).toBeUndefined() const unwrapped = loader.unwrapExports(companion) as typeof companion diff --git a/scripts/test-invariants.ts b/scripts/test-invariants.ts index ce9ede2dff..62c0102588 100644 --- a/scripts/test-invariants.ts +++ b/scripts/test-invariants.ts @@ -12,8 +12,8 @@ import InvariantService from '@deepseek-ai/dsh-invariants' declare global { interface ImportMeta { - /** Eager Vite module-glob expansion used by the Vitest setup file. */ - glob(pattern: string, options: { eager: true }): Record + /** Lazy Vite module-glob expansion used by the Vitest setup file. */ + glob(pattern: string): Record Promise> } } @@ -25,9 +25,15 @@ export interface TestInvariantCompanion { apply(ctx: Context): Promise<() => void> } -/** Every package companion, discovered eagerly so coverage observes each registration. */ -export const testInvariantCompanions: Readonly> = - import.meta.glob('../packages/*/*/src/invariant.ts', { eager: true }) +/** + * Every package companion as a lazy loader keyed by glob path. Ordinary tests + * load only their owner's module; the exhaustive topology test loads and + * executes all of them, so aggregated coverage still observes every + * registration while per-file setup stops importing 168 companions and their + * transitive package sources. + */ +export const testInvariantCompanions: Readonly Promise>> = + import.meta.glob('../packages/*/*/src/invariant.ts') /** Manual-topology suites whose names cannot follow the focused invariant convention. */ const MANUAL_INVARIANT_TEST_EXCEPTIONS = [ @@ -36,7 +42,6 @@ const MANUAL_INVARIANT_TEST_EXCEPTIONS = [ ] as const interface InvariantHost { - readonly fibers: readonly PluginFiber[] readonly byCallback: ReadonlyMap readonly ready: Promise } @@ -102,39 +107,40 @@ export function testInvariantCompanionPaths(testPath: string): string[] { } function startInvariantHost(root: Context): InvariantHost { - const fibers: PluginFiber[] = [] const byCallback = new Map() - const mount = (plugin: Plugin, config?: unknown): void => { + const mount = (plugin: Plugin, config?: unknown): PluginFiber => { const fiber = originalPlugin.call(root.registry, plugin, config) const callback = root.registry.resolve(plugin) if (callback === undefined) throw new Error('test invariants: companion is not a valid Cordis plugin') - fibers.push(fiber) byCallback.set(callback, fiber) + return fiber } - mount(InvariantService, { enabled: true }) + // The service mounts synchronously so the intercepted registration that + // started this host immediately finds its own fiber in byCallback. + // Companions load and mount inside the ready chain (after the service is + // active, so their startup is directly joinable); every joined root plugin + // awaits ready, so none starts ahead of its package checks. Tests plugging + // a companion directly must await an earlier root plugin first — the + // duplicate-mount failure otherwise is loud (owner name already reserved). + const serviceFiber = mount(InvariantService, { enabled: true }) const testPath = expect.getState().testPath ?? '' const companionPaths = testInvariantCompanionPaths(testPath) - for (const path of companionPaths) { - const companion = testInvariantCompanions[path] - if (companion === undefined) { - throw new Error(`test invariants: selected companion vanished at ${path}`) - } - if (!companion.inject.includes('invariants')) { - throw new Error(`test invariants: ${path} must inject the invariant service`) - } - mount(companion) - } - - const [serviceFiber, ...companionFibers] = fibers - if (serviceFiber === undefined) throw new Error('test invariants: service fiber was not mounted') - // A companion is initially PENDING on the invariant service, and Cordis - // Fiber.await() only joins work already in flight. Wait for the service to - // activate its dependants before joining their startup and failures. - const ready = serviceFiber.await() - .then(() => Promise.all(companionFibers.map(fiber => fiber.await()))) - .then(() => undefined) - const host = { fibers, byCallback, ready } + const ready = serviceFiber.await().then(async () => { + const companionFibers = await Promise.all(companionPaths.map(async (path) => { + const load = testInvariantCompanions[path] + if (load === undefined) { + throw new Error(`test invariants: selected companion vanished at ${path}`) + } + const companion = await load() + if (!companion.inject.includes('invariants')) { + throw new Error(`test invariants: ${path} must inject the invariant service`) + } + return mount(companion) + })) + await Promise.all(companionFibers.map(fiber => fiber.await())) + }) + const host = { byCallback, ready } hosts.set(root, host) return host } From 1a75d60174e474e613baf2fcb49715262518cf1f Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:59:07 +0800 Subject: [PATCH 6/8] ci: vitest forks --- vitest.config.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/vitest.config.ts b/vitest.config.ts index 750bb6ddf2..a0d8b6d58a 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -62,10 +62,12 @@ export default defineConfig({ plugins: [pathsPlugin()], test: { name: 'thread-safe', - // Node 24 has aborted in its CJS lexer from a macOS arm64 worker - // thread. A fork contains that external runtime failure to the test - // process; other hosts retain the lower-overhead thread pool. - pool: process.platform === 'darwin' ? 'forks' : 'threads', + // Node 24 has aborted in its CJS lexer (v8::ToLocalChecked Empty + // MaybeLocal in cjs_lexer::Parse) from worker threads on macOS + // arm64 and later on Linux. A fork contains that external runtime + // failure to the test process; Windows keeps the thread pool, where + // the abort has not reproduced and process spawn is costlier. + pool: process.platform === 'win32' ? 'threads' : 'forks', setupFiles: ['./scripts/test-invariants.ts'], include: testIncludes, exclude: [ From 8cc31127c4c7989e1954b33b7c7433e8fd717d62 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 22:10:43 +0800 Subject: [PATCH 7/8] ci: concurrency 3/6 --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e999becdc..1f6ec52f0a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -110,9 +110,8 @@ jobs: # across six always-on runner instances, and the timing-sensitive # process suites have documented aggregate-contention failures. # 8 × 6 instances = 48 workers worst case on 64 cores. - DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '8' }} + DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '6' }} DSH_GATE_CONCURRENCY: '3' - NODE_OPTIONS: '--max-old-space-size=8192' steps: - uses: actions/checkout@v6 with: From 78adace0314528f16def3fd4346d89ecb364ded2 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 22:34:37 +0800 Subject: [PATCH 8/8] ci: exclude typert generator from coverage thresholds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generator correctness stays pinned by its fixture suites and the byte-for-byte catalog reproduction test; per-file coverage put whole-workspace compiler analysis under v8 instrumentation — the coverage lane's longest tail. Widen the existing three-file exclude to the package's src. --- vitest.config.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vitest.config.ts b/vitest.config.ts index a0d8b6d58a..aa3e2b441b 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -156,9 +156,11 @@ export default defineConfig({ 'packages/client/ui-sidebar/src/client/index.ts', 'packages/client/ui-skill/src/client/index.ts', 'packages/client/ui-workspace/src/client/index.ts', - 'packages/typert/generator/src/analyzer.ts', - 'packages/typert/generator/src/renderer.ts', - 'packages/typert/generator/src/cordis-catalog.ts', + // Typert generator: correctness is pinned by its fixture suites and + // the byte-for-byte catalog reproduction test; per-file coverage + // would put whole-workspace compiler analysis under v8 + // instrumentation — the coverage lane's longest tail. + 'packages/typert/generator/src/*.ts', 'packages/host/apiproxy/src/index.ts', 'packages/host/apiproxy/src/invariant.ts', 'packages/host/apiproxy/src/api-proxy.ts',