Repository navigation
控制面优雅停机、带库连通的健康检查、单实例锁 - #85
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
joesmart
added a commit
that referenced
this pull request
Oct 23, 2026
#85 把单实例锁放在启动最前面,缺 TOOL_SECRET_KEY 时会先撞上连库失败,报错不再点名缺的变量。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
joesmart
added a commit
that referenced
this pull request
Oct 23, 2026
#85 把单实例锁放在启动最前面,缺 TOOL_SECRET_KEY 时会先撞上连库失败,报错不再点名缺的变量。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
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.
改了什么
main.ts注册 SIGTERM、SIGINT,调server.close()。走完以 0 退出;8 秒没走完,或者停机中又收到一次信号,以 1 强退。unhandledRejection、uncaughtException先记日志,再走同一套停机,以 1 退出。GET /api/health,不用登录。库连得上回 200{"ok":true};库连不上回 503连不上数据库;停机开始后(AgentHub.closing)回 503控制面正在停机。控制面在 main 上本来没有这条路由,Web 的 mock 和 Playwright 用的是 mock 里的同名路由。instance-lock.ts。启动时先用一条专用连接拿会话级pg_try_advisory_lock,拿不到就报「同一个库上已经有一个控制面在跑」,以 1 退出。这时还没开始监听,也还没执行startServer里把在线电脑写成休眠的那一步。持锁连接断了也按停机流程以 1 退出。这条连接关掉了max_lifetime,因为 postgres.js 默认 30 到 60 分钟轮换连接,会话锁会跟着丢。deploy/README.md新增「单实例、停机和探活」一节,docs/开发.md补一句:多个工作树要各用各的库。为什么
AgentHub.closing立不起来,「标记留给重启」的路径走不到。startServer,不经过main.ts。pnpm dev下 tsx watch 会等旧进程退出再起新的,热重载也不会和锁冲突。怎么验证的
新增
test/process.test.ts(真起src/main.ts子进程,共 6 条)和test/health.test.ts(2 条):先把 src 换回 main 的版本,上面 8 条全红;修复后 8 条全绿。另外做过一次变异:把拿锁挪到
startServer之后,「第二个实例」那条红在expected 'sleeping' to be 'online'。没动 web 和 shared,没跑 web 测试。
Closes #24
Closes #25
🤖 Generated with Claude Code
https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni