Repository navigation
Conversation
pnpm dev ran the control plane through tsx, so every agent worker fork transpiled the worker dependency graph in the child (5-7s per session on this machine). Mirror apps/server/src to apps/server/.dev-dist next to the sources and fork it with plain Node; the mirror keeps each file's directory depth so import.meta.url trust paths resolve the same way. A freshness check rebuilds on source changes and PI_SCIENCE_DEV_WORKER=0 restores the tsx path. Log the measured fork-to-ready time once per worker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
开发模式下(没有
apps/server/dist),每次建会话都会 fork 一个node --import tsx …/worker/main.ts,把「Node 启动 + tsx 转译整个 worker 依赖图」算进POST /api/sessions的响应时间。实测:直接 import 整个 worker 图 5.5–7.1 s(5 次:6492 / 6527 / 5163 / 6001 / 6230 ms),3 并发 8.1–8.7 s;对照
node --import tsx -e "process.exit(0)"只要 0.36–0.39 s。所以这 6 秒几乎全是转译,不是业务逻辑。改动
apps/server/src/runtime/agent/worker/dev-build.ts:用 esbuild 把apps/server/src/**镜像到apps/server/.dev-dist/**,保持目录深度,所以import.meta.url相对路径不用改workerEntry()三级回退:编译版worker/main.js→ dev 镜像 → tsx 源码;PI_SCIENCE_DEV_WORKER=0可关掉dev脚本改成「先预编译一次再 watch」;.dev-dist/进.gitignorestartupMs与Agent worker ready in Xms日志,以后能直接量效果
剩下的 ~7.5 s 是 worker 自身的
loadSkills+loadPromptTemplates+ MCP 工具发现,另单处理。验证
.dev-dist镜像 2.5 MB 生成成功pnpm --filter @pi-science/server exec tscexit 012b73fcd后复跑dev-build.test.ts5 passed,server tsc exit 0需要维护者判断的两点
dev脚本。合并后pnpm dev会先跑一次 esbuild 预编译(首次约 1–2 s),再tsx watch。不想改 dev 流程的话,这个 PR 可以只保留workerEntry()的三级回退与dev-build.ts,dev脚本我自己回退掉——告诉我一声就行。.dev-dist/是新的构建产物目录,已经进.gitignore,不产生提交。已知局限
src/runtime/agent批测试有 8 条超时失败,归因是当时 load 6.4 且NODE_ENV=test走老路径;只对照了一个文件,没做完整隔离复跑。dist,不走这条路径。rebase 时保留的上游内容
冲突处两边的改动都保留:上游的
build:native/build(含build-workspace-discovery-native.mjs)与approvalLeases字段原样留下,dev里也保留了上游新增的 native 构建步骤,本 PR 只在它后面追加预编译。.gitignore同理,/work/live-tests/与.dev-dist/都在。