Repository navigation
test(orcad): wait for an idle-retiring daemon before deleting the serve-parity profile - #29669
Conversation
…ve-parity profile A terminal daemon that loses its last client deletes its pid record before it exits, so teardown that found daemons only through pid records skipped it and raced its open files (EBUSY on Windows ARM). Record the pid before stopping orcad and require that process's exit.
… and stop-request tests
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
14c60eec-073d-4760-b49c-29c45f1211fb
📒 Files selected for processing: 5
src/main/orcad/orcad-cli-launcher.integration.test.tssrc/main/orcad/orcad-daemon-teardown-fixture.tssrc/main/orcad/orcad-daemon-teardown-linux.test.tssrc/main/orcad/orcad-serve-parity.integration.test.tssrc/main/orcad/orcad-stop-request-shutdown.integration.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| const retiring = [...(recordedDaemonPids.get(daemonDir) ?? [])].filter( | ||
| (pid) => !daemons.some((daemon) => daemon.pid === pid) | ||
| ) | ||
| recordedDaemonPids.delete(daemonDir) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Keep recorded PIDs until teardown succeeds.
If a daemon removes its PID record but remains alive past the 10-second deadline, waitForProcessExit rejects after this line deletes its saved PID. A second killProfileDaemons call then sees neither the record nor the saved PID and can report success while the daemon still holds profile files open. Delete the saved entry only after all exit checks succeed.
| rmSync(join(root, 'daemon', 'daemon-v1.pid')) | ||
| vi.mocked(cleanupDaemonForProtocol).mockClear() | ||
| await killProfileDaemons(root) | ||
| expect(() => process.kill(retiring.pid!, 0)).toThrow(expect.objectContaining({ code: 'ESRCH' })) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Allow a zombie in the exit assertion.
If waitForProcessExit observes Linux state Z before the child is reaped, it correctly returns, but process.kill(pid, 0) can still succeed. The test can fail even though teardown met its exit contract. Accept either ESRCH or state Z at this assertion.
…s profile on Windows The terminal daemon runs with the profile as its cwd and its children inherit it, so a child that outlives the daemon keeps the profile directory busy (EBUSY on rmdir). Record the daemon's process tree before shutdown and require each recorded child's exit, naming any survivor at the deadline.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e5d0f2a3-82d7-4a3d-8634-a0b7227c6934
📒 Files selected for processing: 5
src/main/orcad/orcad-cli-launcher.integration.test.tssrc/main/orcad/orcad-daemon-teardown-fixture.tssrc/main/orcad/orcad-daemon-teardown-linux.test.tssrc/main/orcad/orcad-serve-parity.integration.test.tssrc/main/orcad/orcad-stop-request-shutdown.integration.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
| const record = await recordDaemonTree(daemonDir) | ||
| recordedProfiles.delete(daemonDir) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Keep the recorded profile entry until all exit checks succeed.
Line 216 deletes the recordedProfiles entry before any exit check runs. Two cases lose the record:
- A retiring daemon is still alive at the deadline.
- A recorded descendant is still alive at the deadline.
In both cases the record is already gone. A retry of killProfileDaemons then finds no PID record and no saved PIDs or descendants, so it reports success while files in the profile are still open. Delete the entry only when failures is empty after the descendant check.
Proposed fix
const record = await recordDaemonTree(daemonDir)
- recordedProfiles.delete(daemonDir)
const daemons = readProfileDaemons(daemonDir)
@@
if (failures.length > 0) {
throw new AggregateError(failures, 'Profile daemon shutdown incomplete')
}
+ recordedProfiles.delete(daemonDir)
}
ELI5
A Windows ARM CI test sometimes failed while cleaning up its temporary folder, because a background terminal process was still shutting down and holding files in it. Cleanup now waits for that process to finish first.
What Changed
CI-only fix.
orcad-serve-parity.integration.test.tsfailed intermittently onpersistence (windows-11-arm)withEBUSY: resource busy or locked, rmdir ...orcad-serve-parity-*, across many unrelated branches (about 20 of 69 runs of that job on 2026-10-16).Mechanism: when the test stops orcad, the terminal daemon loses its last client and retires. Its idle shutdown (
finishIdleShutdownindaemon-server-lifecycle.ts) deletes its pid record first and exits later. The teardown fixture found daemons only through pid records, sokillProfileDaemonsreturned immediately while the daemon was still alive with files open under the profile. The cleanup diagnostics added in #29607 show exactly this: the pid record is gone ~40 ms after the orcad kill while the daemon pid is still live.Now the fixture has
recordProfileDaemons(userData), called just before the test stops orcad.killProfileDaemonsadditionally waits (bounded, the existing 10 s exit deadline) for any recorded daemon whose pid record has already disappeared, before the profile is deleted.Why
The teardown rework in #29439 moved to authenticated daemon shutdown through the pid record, which is right for a live daemon but cannot see one that is already retiring. Recording the pid before the stop keeps the exit proof without changing daemon behavior. Retrying the delete for longer would only hide the race.
Linked Issue
N/A (CI flake, maintainer).
Visual Proof
N/A: test-only change, no UI or behavior change.
Testing
New unit test in
orcad-daemon-teardown-linux.test.ts(runs on every platform): a recorded process deletes its pid record while still alive; teardown must wait for its exit. Fails without the fix ("expected function to throw"), passes with it.pnpm tcandpnpm run check:code-quality:changedpass. The serve-parity integration test itself runs in the Windows ARM CI lane.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
Test-only. No product code, SSH, mobile, or compatibility impact.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)