Repository navigation
refactor(daemon): report startup progress over the launch channel instead of marker files - #4777
Conversation
…tead of marker files The detached daemon used to append JSON lines to daemon-startup-phases-<pid>.jsonl in the state dir: a per-pid file name, a claim-by-delete at entry, a newline-repair read, a sweep of dead pids by every new registration owner, removal after a joined exit, tail parsing, and a reproduced append-through-symlink bug. The launcher (launchDaemonProcess) now spawns the detached child with stdio ['ignore', logFd, logFd, 'ipc'] and the child reports each of the six phases as one typed message over that channel, closing it after 'registered'. The channel is unref'd on both sides so it holds neither the CLI nor the daemon alive. The client records the receipt time of each phase on the launcher clock, keeping the first receipt per phase and only for its own child's pid; unknown or malformed messages are ignored. The shrunken daemon-startup-phases module keeps only the vocabulary, the message type, its parser and the child-side sender, so no eager closure grows (module counts identical, weights flat). Sending is a no-op without a marked launch channel (embedded mode, direct fixture spawns, manual starts) and a failed send (launcher gone) is ignored, optionally one stderr line; a send failure never affects startup. All marker-file functions, the sweep, the claim-by-delete, the marker reads/writes in the client and the fixtures are deleted; no production code touches daemon-startup-phases-*.jsonl anymore, so a planted link with that name is never followed or modified. Kept unchanged: the launch handle and child join, the 60 s stall window, the default 120 s ceiling and env override, exit codes 75/78, the two-attempt launch budget, the contender path, the phases timings in daemon_startup_failed details, and the stall/ceiling hints. Co-Authored-By: Mistral Vibe <noreply@mistral.ai>
Size Report
Startup median (7 runs, lower is better):
|
…artup progress message The IPC channel connects one launcher to the child it spawned, so the message needs no pid. The parser now returns the phase; the vocabulary and message type stay module-private. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The R86 process-globals gate keeps process.env and the IPC channel at declared process entries. src/daemon.ts now opens the launch channel and passes it to the runtime as startupProgress; embedded hosts pass none. daemon-contracts keeps only the vocabulary, the message and its parser. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
openDaemonStartupProgress takes the env and the process it reports for, so the entry is one call and the channel rules (mark, unref, one failure line, close) have unit tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Apex Sentinel · ✅ Approve · review of
|
| Where | Finding |
|---|---|
packages/daemon-contracts/src/daemon-registration-owner.ts:95 |
Stale daemon-startup-phases-*.jsonl files in the state dir are now never cleaned up |
1 finding below minor hidden (user_settings.min_severity).
Reviewed with this repository's own Sentinel configuration (0ba31d87a14d).
💬 Talking to Sentinel
In a finding's thread, reply with:
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 0b49b19. The verdict and the full list are in the summary comment.
| @@ -93,7 +97,6 @@ export async function tryAcquireDaemonRegistration( | |||
| try { | |||
There was a problem hiding this comment.
🟡 Minor · Stale daemon-startup-phases-*.jsonl files in the state dir are now never cleaned up
Upgrading from a previous version leaves daemon-startup-phases-<pid>.jsonl files in the state directory forever: the new test at daemon-client-startup-budget.test.ts:386 asserts the leftover is left "byte-identical: never read, swept or removed." This PR removes every cleanup path for them (sweepDeadDaemonStartupPhasesFiles, the claim-by-delete in src/daemon.ts, removeDaemonStartupPhasesFile, and the runtime's removal after registered) without a migration or cleanup step to replace them, so the state dir retains the very symlink-named artifacts the old sweep existed to neutralize.
Suggested change
Add a one-time removal of daemon-startup-phases-*.jsonl entries (unlink without following) in the registration owner, or document in a release/migration note that upgrading leaves these files and how an operator removes them.
Details
persona: maintainability, senior-developer, javascript
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.
There was a problem hiding this comment.
Intentional. The maintainer decided this redesign does no legacy migration or cleanup of old state (#4649). Leftover daemon-startup-phases-<pid>.jsonl files are a few hundred bytes, inert, and never read again: nothing opens, follows or parses them, and the new acceptance test plants one as a symlink and asserts it stays untouched. A sweep would bring back a directory scan, pid liveness checks and a deletion path inside the state dir, which is exactly the code this PR removes. Users who want them gone can delete them by hand. No change.
|
This PR is ready at 0b49b19. CI is green: all 18 checks pass. There are no conflicts, and nothing blocks merge. Not blocking, and you can take or leave it: the test at src/daemon-entrypoint.test.ts:591 says the channel holds neither process alive, but the daemon disconnects right after Windows behavior and the ordering of the last IPC message against the child's The open inline thread on leftover |
…ent vocabulary 0.22 (#4621 bounded output) and main (#4777 startup progress) each grew packages/host-kit/src/internal/exec.ts, so the merged file passed its legacy 1032-line cap and lint failed. Re-home the kill/settle ordering — signalProcessGroupBestEffort, bindCommandLifecycle, the kill settlement, the abort watch, killProcessTree and destroyCommandStreams — into exec-trace.ts, which already owns the exec settlement vocabulary and sits in every closure that reaches exec.ts, so no eager closure grows. exec.ts now fits the 1000-line rule and its legacy cap entry is removed.
* origin/main: (70 commits) refactor(apple-runner): one RUNNER_ERROR_CODES row per runner error code with parity/docs gates (callstack#4774) fix(android): require acknowledgements for test IME typing (callstack#4722) feat(scroll): add scroll refresh for pull-to-refresh (callstack#4770) refactor(host-kit): add request Scope and use it for the wait capture deadline (callstack#4794) fix(android): let permission all change nothing on an app that declares no permissions (callstack#4796) fix(cli): replace the CLI session and generated remote config instead of rewriting them in place (callstack#4797) fix(host-kit): accept a group-writable script directory the user owns (callstack#4799) fix(cli): escape control characters at the CLI's stdout and stderr writes (callstack#4778) fix(audit): do not report rows under a persistent bar that scrolling reveals (callstack#4775) fix(daemon): refuse an unsafe state directory before first use (callstack#4783) refactor: settle remaining single-deadline races through settleWithin (callstack#4788) refactor(host-kit): settle deadline races via settleWithin with R87 race ratchet (callstack#4766) fix(android): authenticate and bound persistent snapshot helper sessions (callstack#4729) fix(daemon): bound upload ingress and finalization (callstack#4721) chore(gates): ratchet wire-published reason literals by value (R89) (callstack#4779) feat(audit): evaluate role-less clickable views on Android (callstack#4780) fix(mutation): keep umask-setting tests out of Stryker's thread pool (callstack#4785) feat(audit): report controls that share one accessible name (callstack#4771) fix(contracts): pair open runtime hints with their apply operation (callstack#4754) refactor(daemon): report startup progress over the launch channel instead of marker files (callstack#4777) ...
…ent vocabulary 0.22 (#4621 bounded output) and main (#4777 startup progress) each grew packages/host-kit/src/internal/exec.ts, so the merged file passed its legacy 1032-line cap and lint failed. Re-home the kill/settle ordering — signalProcessGroupBestEffort, bindCommandLifecycle, the kill settlement, the abort watch, killProcessTree and destroyCommandStreams — into exec-trace.ts, which already owns the exec settlement vocabulary and sits in every closure that reaches exec.ts, so no eager closure grows. exec.ts now fits the 1000-line rule and its legacy cap entry is removed.
…ent vocabulary 0.22 (#4621 bounded output) and main (#4777 startup progress) each grew packages/host-kit/src/internal/exec.ts, so the merged file passed its legacy 1032-line cap and lint failed. Re-home the kill/settle ordering — signalProcessGroupBestEffort, bindCommandLifecycle, the kill settlement, the abort watch, killProcessTree and destroyCommandStreams — into exec-trace.ts, which already owns the exec settlement vocabulary and sits in every closure that reaches exec.ts, so no eager closure grows. exec.ts now fits the 1000-line rule and its legacy cap entry is removed.
…ent vocabulary 0.22 (#4621 bounded output) and main (#4777 startup progress) each grew packages/host-kit/src/internal/exec.ts, so the merged file passed its legacy 1032-line cap and lint failed. Re-home the kill/settle ordering — signalProcessGroupBestEffort, bindCommandLifecycle, the kill settlement, the abort watch, killProcessTree and destroyCommandStreams — into exec-trace.ts, which already owns the exec settlement vocabulary and sits in every closure that reaches exec.ts, so no eager closure grows. exec.ts now fits the 1000-line rule and its legacy cap entry is removed.
…ent vocabulary 0.22 (#4621 bounded output) and main (#4777 startup progress) each grew packages/host-kit/src/internal/exec.ts, so the merged file passed its legacy 1032-line cap and lint failed. Re-home the kill/settle ordering — signalProcessGroupBestEffort, bindCommandLifecycle, the kill settlement, the abort watch, killProcessTree and destroyCommandStreams — into exec-trace.ts, which already owns the exec settlement vocabulary and sits in every closure that reaches exec.ts, so no eager closure grows. exec.ts now fits the 1000-line rule and its legacy cap entry is removed.
…ent vocabulary 0.22 (#4621 bounded output) and main (#4777 startup progress) each grew packages/host-kit/src/internal/exec.ts, so the merged file passed its legacy 1032-line cap and lint failed. Re-home the kill/settle ordering — signalProcessGroupBestEffort, bindCommandLifecycle, the kill settlement, the abort watch, killProcessTree and destroyCommandStreams — into exec-trace.ts, which already owns the exec settlement vocabulary and sits in every closure that reaches exec.ts, so no eager closure grows. exec.ts now fits the 1000-line rule and its legacy cap entry is removed.
…ent vocabulary 0.22 (callstack#4621 bounded output) and main (callstack#4777 startup progress) each grew packages/host-kit/src/internal/exec.ts, so the merged file passed its legacy 1032-line cap and lint failed. Re-home the kill/settle ordering — signalProcessGroupBestEffort, bindCommandLifecycle, the kill settlement, the abort watch, killProcessTree and destroyCommandStreams — into exec-trace.ts, which already owns the exec settlement vocabulary and sits in every closure that reaches exec.ts, so no eager closure grows. exec.ts now fits the 1000-line rule and its legacy cap entry is removed.
…ent vocabulary 0.22 (#4621 bounded output) and main (#4777 startup progress) each grew packages/host-kit/src/internal/exec.ts, so the merged file passed its legacy 1032-line cap and lint failed. Re-home the kill/settle ordering — signalProcessGroupBestEffort, bindCommandLifecycle, the kill settlement, the abort watch, killProcessTree and destroyCommandStreams — into exec-trace.ts, which already owns the exec settlement vocabulary and sits in every closure that reaches exec.ts, so no eager closure grows. exec.ts now fits the 1000-line rule and its legacy cap entry is removed.
Problem
A detached daemon reported startup progress by appending JSON lines to
daemon-startup-phases-<pid>.jsonlin the state directory. The client read the tail to tell "slow but progressing" from "stalled". That design needed a per-pid file name, a claim-by-delete at entry, a newline-repair read, a sweep of dead pids by every new registration owner, removal after a joined exit, and tail parsing — and had a reproduced bug where the append followed a planted link to an outside file.Change
The launcher (
launchDaemonProcessinpackages/daemon-contracts/src/daemon-registration-owner.ts) now spawns the detached child withstdio: ['ignore', logFd, logFd, 'ipc'](Node's cross-platform IPC channel). The child (src/daemon.ts,packages/daemon/src/server/http/daemon-runtime.ts) sends one typed message per phase — the six phase names are unchanged — and closes the channel afterregistered. The channel isunref'd on both sides, so it holds neither the CLI nor the daemon alive. The client records the receipt time of each phase on the launcher clock, keeping the first receipt per phase and only for this launch's own child pid; unknown or malformed messages are ignored. The shrunkendaemon-startup-phases.tskeeps only the vocabulary, the message type, its parser and the child-side sender, so no eager closure grows. Sending is a no-op without a marked launch channel (embedded mode, direct fixture spawns, manual starts — the launcher marks its child withAGENT_DEVICE_DAEMON_PROGRESS_CHANNEL=1), and a failed send (launcher gone) is ignored, at most one stderr line; it never affects startup.Deletions
resolveDaemonStartupPhasesPath,recordDaemonStartupMarker,endsWithoutNewline,removeDaemonStartupPhasesFile,sweepDeadDaemonStartupPhasesFiles,readDaemonStartupPhaseMarkersand their tests; the sweep call in the registration owner; the claim-by-delete, marker writes and the stderr marker-failure reporter insrc/daemon.ts;refreshStartupPhaseMarkers, the marker removals inretireStartupAttemptand the wholediscardExitedLaunchRecordin the client; marker reads/writes in the three test fixtures and the launch plan. Kept unchanged: launch handle and child join, 60 s stall window, default 120 s ceiling (AGENT_DEVICE_DAEMON_STARTUP_TIMEOUT_MS), exit codes 75/78, two-attempt budget, contender path,phasestimings indaemon_startup_faileddetails, stall/ceiling hints. TheAPPROVED_CLOSURE_ADDITIONSrow for the module stays (the module still exists, shrunken); no row was added.Acceptance results
git grep daemon-startup-phasesnow matches only the vocabulary module itself (source, package export, budget row) and test assertions that nodaemon-startup-phases-*.jsonlentry exists. No production code writes, reads, sweeps or removes such files.src/daemon-entrypoint.test.ts). A slow child that keeps sending phases is not stalled (budget test: 4 phases 20 s apart over 80 s virtual, success); a child that stops isstartup-stalledat the 60 s window; the env ceiling still givesstartup-ceiling./health, writes at most one failed-send line and noDaemon error, then reaps itself.registeredisstartup-exitedwith exit details (existing tests); a duplicate phase message keeps the first receipt (new budget test asserts the reported timing is the first one).daemon-startup-phases-<pid>.jsonlpointing outside the state dir is byte-identical and still a link after a full start, in both a client-driven start (budget test, planted under the child's pid) and a real launcher-driven start (entrypoint test).registered— the unref'd channel does not hold the event loop (entrypoint test).packages/*/srcandsrc(vseeff795f47): gross removed 208, gross added 167, net −41.src/cli.ts259,src/daemon.ts360,packages/daemon/src/index.ts359,packages/daemon-client/src/index.ts129; top-level statements 3871/4759/4755/2270 vs base 3871/4761/4754/2270 — flat).node bin/agent-device.mjs --version, median of 20 runs: base 110.4 ms (quiet host; 136.0 ms in a later quiet interleaved round), branch 134.0 ms (141.3 ms in the interleaved round); minimums 115.3 ms base vs 113.8 ms branch. The shared host ran another agent's vitest suite during measurement (medians swung ±3x on both trees), so the wall-clock delta is within host noise; closures are flat.Validation:
pnpm exec vitest run --project unit-coreon the six touched test files (70 tests) and onpackages/daemon-client packages/test-kit packages/daemon-contracts packages/host-kit src/__tests__ packages/daemon(915 files, 8175 tests) all pass;scripts/__tests__/eager-closure-budgets.test.ts(913 tests) passes;pnpm typecheck,pnpm lint(0 warnings),pnpm formatclean;pnpm install --frozen-lockfile && pnpm buildon base and branch. CI owns full validation.Part of #4649. Replaces part of #4704.
🤖 Generated with Mistral Vibe
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.