Files
gbrain/test
MasaandClaude Fable 5 9b720b04af fix(doctor): honor the recorded pid_file in supervisor_singleton check (#4006)
* fix(doctor): honor the recorded pid_file in supervisor_singleton check

`gbrain doctor`'s `supervisor_singleton` check (#1849) compares the local
pidfile holder against the queue-scoped DB lock holder. It read
`readSupervisorPid(DEFAULT_PID_FILE)` unconditionally, even though the
supervisor's own 'started' audit event already records the pid-file path
actually in use (`this.opts.pidFile`). A supervisor launched with a custom
`--pid-file` (e.g. a launchd-managed deployment) would then get a false
"singleton mismatch" warning against its own healthy, single instance,
because the pidfile doctor read was never the one the supervisor wrote.

- doctor.ts now prefers `lastStarted.pid_file` when present, falling back
  to `DEFAULT_PID_FILE` for events that predate the field.
- supervisor.ts resolves `pid_file` to an absolute path at emit time (the
  only cwd context in which a relative `--pid-file` is meaningful), so a
  later reader running from a different cwd doesn't misresolve it. The
  process's own internal pidfile guard/read/write paths are untouched.

The DB lock (`gbrain_cycle_locks`) remains the sole singleton authority per
#1849 — this only corrects which pidfile the diagnostic display reads.

Added test/doctor-supervisor-singleton-pidfile.test.ts covering the fixed
path, the still-mismatching absent-pidfile case, and a source-grep pin for
the compatibility fallback.

* docs(comments): correct pid_file fallback rationale and drop unsupported claims

The 'started' audit event has carried pid_file since the supervisor's
introduction, so the fallback comment no longer claims a predate case;
DEFAULT_PID_FILE is env-overridable (GBRAIN_SUPERVISOR_PID_FILE), so the
comments stop calling it HOME-derived; and the custom --pid-file scenario
is now described as an example rather than asserted as common.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0126D3zLWL5RE3CVxnPANiiU

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-13 06:02:23 -07:00
..