From e5ee621288a4e36bcebc781f1d7c3df0e77b94ce Mon Sep 17 00:00:00 2001 From: Richard R Date: Tue, 26 May 2026 18:05:45 -0600 Subject: [PATCH] refactor(docstore): improve docstore directory resolution for monorepo setups Refactored docstore directory logic to dynamically locate the monorepo root by searching for a pnpm-workspace.yaml marker. If found, the docstore directory is anchored at the monorepo root; otherwise, it defaults to the current working directory. This enhances consistency when running in different environments. Also updated process shutdown and SeaweedFS launch arguments in the entrypoint script for improved reliability and log filtering. --- compute/core/src/platform/docstore.ts | 20 +++++++++++++++++++- scripts/openreader-entrypoint.mjs | 10 +++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/compute/core/src/platform/docstore.ts b/compute/core/src/platform/docstore.ts index 7d7dd6b..6681f37 100644 --- a/compute/core/src/platform/docstore.ts +++ b/compute/core/src/platform/docstore.ts @@ -1,6 +1,24 @@ +import fs from 'fs'; import path from 'path'; -export const DOCSTORE_DIR = path.join(process.cwd(), 'docstore'); +function findMonorepoRoot(startDir: string): string | null { + let current = path.resolve(startDir); + for (;;) { + const marker = path.join(current, 'pnpm-workspace.yaml'); + if (fs.existsSync(marker)) return current; + const parent = path.dirname(current); + if (parent === current) return null; + current = parent; + } +} + +function resolveDocstoreDir(): string { + const repoRoot = findMonorepoRoot(process.cwd()); + if (repoRoot) return path.join(repoRoot, 'docstore'); + return path.join(process.cwd(), 'docstore'); +} + +export const DOCSTORE_DIR = resolveDocstoreDir(); export function getDocstoreDir(): string { return DOCSTORE_DIR; diff --git a/scripts/openreader-entrypoint.mjs b/scripts/openreader-entrypoint.mjs index f21feb7..9223bf6 100644 --- a/scripts/openreader-entrypoint.mjs +++ b/scripts/openreader-entrypoint.mjs @@ -345,7 +345,7 @@ async function main() { shutdownPromise = (async () => { await Promise.all([ terminateChild(appProc, signal, 4000), - terminateChild(workerProc, 'SIGTERM', 4000, true), + terminateChild(workerProc, 'SIGTERM', 4000), terminateChild(natsProc, 'SIGTERM', 4000), terminateChild(weedProc, 'SIGTERM', 4000), ]); @@ -397,7 +397,12 @@ async function main() { const waitTimeout = Number.isFinite(waitSec) ? waitSec : 20; const launchWeed = (endpointUrl) => { const parsedEndpoint = parseS3Endpoint(endpointUrl); - const weedArgs = ['mini', `-dir=${runtimeEnv.WEED_MINI_DIR}`]; + const weedArgs = [ + '-alsologtostderr=false', + '-stderrthreshold=WARNING', + 'mini', + `-dir=${runtimeEnv.WEED_MINI_DIR}`, + ]; weedArgs.push(`-s3.port=${parsedEndpoint.port}`); if (runningInDocker) { weedArgs.push('-ip.bind=0.0.0.0'); @@ -512,7 +517,6 @@ async function main() { env: workerEnv, stdio: ['ignore', 'pipe', 'pipe'], shell: process.platform === 'win32', - detached: process.platform !== 'win32', }, ); stopWorkerStdoutForward = forwardChildStream(workerProc.stdout, process.stdout);