Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ jobs:
uses: ./.github/actions/run-gate
with: { gate: daemon-wire-compat }

- name: Check numeric ranges
uses: ./.github/actions/run-gate
with: { gate: freerange }

# Shares fallow's `.fallow` cache directory with the audit, so it starts once the audit ends.
- name: Wait for the Fallow audit
wait: fallow-audit
Expand All @@ -277,11 +273,26 @@ jobs:
uses: ./.github/actions/run-gate
with: { gate: production-exports }

numeric-ranges:
name: Numeric Ranges
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 20
steps:
- name: Checkout
uses: useblacksmith/checkout@2b9fe87d796feea153b455ec2f3125b471a7b0e7 # v1.8.2

- name: Setup toolchain
uses: ./.github/actions/setup-node-pnpm

- name: Check numeric ranges
uses: ./.github/actions/run-gate
with: { gate: freerange }

# Runs the full unit + provider-integration suites under coverage with
# thresholds, so a separate unit-tests job would rerun the same tests.
coverage:
name: Coverage
runs-on: blacksmith-4vcpu-ubuntu-2404
runs-on: blacksmith-8vcpu-ubuntu-2404
timeout-minutes: 30
steps:
- name: Checkout
Expand Down
8 changes: 5 additions & 3 deletions packages/daemon-contracts/src/daemon-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@
const startedAt = Date.now();
const deadline = startedAt + options.timeoutMs;
const pollMs = options.pollMs ?? DAEMON_EXIT_POLL_MS;
const hasExited = (): boolean => {
if (!isProcessAlive(identity.pid)) return true;
const observed = readHostProcessIdentityObservations([identity.pid]).get(identity.pid);
return Boolean(
observed?.state.startsWith('Z') ||
(observed?.startTime && observed.startTime !== identity.startTime),
return (
Boolean(
observed?.state.startsWith('Z') ||
(observed?.startTime && observed.startTime !== identity.startTime),
) || !isProcessAlive(identity.pid)
);
};

Check warning on line 89 in packages/daemon-contracts/src/daemon-process.ts

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

minor: waitForDaemonExit's new liveness re-check does not re-read identity, so it can prove exit on a reused pid

If the daemon's pid is reassigned to a new process between `readHostProcessIdentityObservations` and the new `isProcessAlive` call in `hasExited()`, `kill(pid, 0)` can return ESRCH for the new pid, causing `|| !isProcessAlive(identity.pid)` to report `exited: true` on a process that never belonged to the daemon. The re-check observes the same pid-death race as the first check but is not paired with a fresh identity read, so any pid disappearance is credited to the daemon. Re-read the observation before declaring exit on the second liveness probe. ### Also raised here Also raised at this location by persona `senior-developer`: Duplicate liveness check inside hasExited is redundant and masks the race being fixed — Move the re-check of `isProcessAlive` out of the return expression and make the comment state the race it closes. As written, `hasExited` calls `isProcessAlive(pid)` twice per pass — once at the top and again as `|| !isProcessAlive(identity.pid)` at the end — and the second call reads as dead code to a maintainer because the first line already tests the same predicate. The real reason for the second call is the window during the synchronous `ps` snapshot inside `readHostProcessIdentityObservations`, where the pid can be released between the two probes; there is no comment saying so, and AGENTS.md asks for comments for constraints code cannot show. A comment (or restructuring the body so the snapshot sits between two clearly-purposed liveness probes) prevents a future cleanup from deleting the 'redundant' call and silently reintroducing the CI timeout this PR fixes.
Comment thread
thymikee marked this conversation as resolved.
Resolved
let exited = hasExited();
while (!exited && Date.now() < deadline) {
await sleep(Math.min(pollMs, Math.max(0, deadline - Date.now())));
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/daemon-exit-wait.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ test('an unreadable process start time does not prove exit', async () => {
});
});

test.each([
['missing', undefined],
['same-lifetime', OURS],
] as const)(
'a daemon reaped during a %s snapshot proves exit without a polling budget',
async (_label, startTime) => {
vi.spyOn(state.starts, 'get').mockImplementationOnce(() => {
state.alive.set(PID, false);
return startTime;
});
expect(await waitForDaemonExit({ pid: PID, startTime: OURS }, { timeoutMs: 0 })).toMatchObject({
exited: true,
});
},
);

test('a recycled pid proves the original exit even when its successor is a zombie', async () => {
state.starts.set(PID, RECYCLED);
state.states.set(PID, 'Z');
Expand Down
Loading