Skip to content

fix(daemon): carry --__daemonized identity marker through exec-restart (#2739) - #2743

Merged
topcheer merged 1 commit into
mainfrom
fix/issue-2739
Sep 25, 2026
Merged

topcheer merged 1 commit into
mainfrom
fix/issue-2739

Conversation

@topcheer

Copy link
Copy Markdown
Owner

Fixes #2739

exec-restart (IM /restart, terminal r) rebuilds the argv from scratch, dropping the --__daemonized marker ForkIntoBackground writes. daemonIdentityMatches keys on that marker (or the ggcode[ argv[0] display name); a restarted daemon's live PID therefore looked like an unrelated process reusing the PID - CheckExistingDaemon deleted the PID file and admitted a SECOND daemon on the next ggcode daemon -b.

Fix: append --__daemonized to the rebuilt argv (daemon.go exec-restart path).

Design notes:

  • argv[0] display-name rewriting deliberately NOT replicated: ExecSelf treats args as the flag list AFTER argv[0] - an injected display name would become a stray positional argument and break cobra parsing. Contains-based identity matching needs the flag alone.
  • daemonized=true branch is behaviorally identical for the restart path: the fork-vs-exec distinguishing parameter is currently ignored (_ bool).

Tests: flag-combo parse pin (cmd/ggcode) + identity match/miss via the same-package cmdline hook (internal/daemon, positive with marker / negative without). Both suites green (22s cmd / 0.2s daemon).

#2739)

exec-restart rebuilds the argv from scratch, dropping the --__daemonized
marker ForkIntoBackground writes. daemonIdentityMatches keys on that
marker (or the ggcode[ argv[0] display name); a restarted daemon's live
PID therefore looked like an unrelated process reusing the PID -
CheckExistingDaemon deleted the PID file and admitted a SECOND daemon on
the next 'ggcode daemon -b'.

Fix: append --__daemonized to the rebuilt argv. argv[0] display-name
rewriting is deliberately NOT replicated: ExecSelf treats args as the
flag list AFTER argv[0], so an injected display name would become a
stray positional argument and break cobra parsing; Contains-based
identity matching needs the flag alone. The daemonized=true branch the
flag selects is behaviorally identical for the restart path (the
distinguishing parameter is ignored).

Tests: flag-combo parse pin (cmd) + identity match/miss table via the
same-package cmdline hook (internal/daemon); both suites green.
@topcheer

Copy link
Copy Markdown
Owner Author

合并说明:main_fullstack_agent 平台域复核 approve(双核对实证:daemonIdentityMatches Contains 位置无关+尾部 append 与 FIB 写入语义等价;runDaemon 第 6 参 _ bool 零使用 daemonized=true 行为零差别;设计决策① argv[0] 不复刻合理——ExecSelf args 纯 flag 表 append 成杂散参;darwin/windows 双 vet+探针 2/2;Windows PID 观察非阻塞预先存在)。CI 全绿。执行合并,#2739 随链关闭。

@topcheer
topcheer merged commit 3394083 into main Sep 25, 2026
9 checks passed
@topcheer
topcheer deleted the fix/issue-2739 branch September 25, 2026 02:03
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.

[code-review] daemon exec-restart 重建的 argv 丢失 --__daemonized 身份标记:后续 CheckExistingDaemon 判为无关进程并放行双 daemon

1 participant