Skip to content

fix(guardian): reclaim stale Docker locks after container replace - #1177

Draft
RainMona wants to merge 1 commit into
TraderAlice:devfrom
RainMona:cursor/docker-stale-lock-upstream-743d
Draft

fix(guardian): reclaim stale Docker locks after container replace#1177
RainMona wants to merge 1 commit into
TraderAlice:devfrom
RainMona:cursor/docker-stale-lock-upstream-743d

Conversation

@RainMona

Copy link
Copy Markdown
Contributor

Docker 换容器后残留 guardian.lock / runtime.lock 被当成“另一台机器还在跑”,Compose restart: unless-stopped 会死循环。

这笔修复基于当前 TraderAlice/dev,从 fork RainMona/OpenAlice 提过来,便于主仓库审计。未合并。

现象

容器重建后 /etc/machine-id 变了,卷里留下的 lock 仍写着旧 hostname / PID / heartbeat。Guardian 先做 machineId 比对,对不上就判 active,过期心跳也不回收;--takeover 以前还会拒绝(不能对外机 PID 发信号)。进程非零退出,Compose 一直重启。

现场三把锁:

  • $OPENALICE_HOME/state/guardian.lock
  • $OPENALICE_HOME/state/runtime.lock
  • $AQ_LAUNCHER_ROOT/state/runtime.lock

把它们挪走就能恢复。根因是锁策略,不是 compose。

设计

桌面 / CLI 仍拒绝“心跳过期就自动抢外机卷”,也仍然不对外机 PID 发信号。Docker 按单写者合同:

  1. 首次启动把身份写进 /data/state/machine-id,之后重建容器还是同一身份。
  2. 外机 lock + 心跳已过期时,Docker Guardian 只隔离 lock,不发信号。
  3. --takeover / OPENALICE_TAKEOVER=1 对外机 lock 也改为隔离、不发信号。

请按 review:deep 审计。

Verification

  • pnpm -F @traderalice/guardian-runtime test on current upstream dev + this commit (59 passed, including the existing terminateProcessTree spec)

Docker recreate changes /etc/machine-id, so leftover guardian/runtime
locks look foreign. The previous owner is gone, but startup treated the
home as still owned by another machine and exited. Compose
restart: unless-stopped then crash-looped.

Persist a volume-stable machine id for Docker, quarantine stale foreign
locks without signaling, and let --takeover reclaim a foreign lock the
same way. Desktop/CLI still refuse automatic cross-machine reclaim.

Co-authored-by: RainMona <RainMona@users.noreply.github.com>
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

@cursoragent is attempting to deploy a commit to the luokerenx4's Team Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants