Skip to content

test(orcad): wait for an idle-retiring daemon before deleting the serve-parity profile - #29669

Merged
Jinwoo-H merged 4 commits into
mainfrom
test/serve-parity-retiring-daemon-wait
Oct 16, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
test/serve-parity-retiring-daemon-wait

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​73 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​103

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.ts failed intermittently on persistence (windows-11-arm) with EBUSY: 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 (finishIdleShutdown in daemon-server-lifecycle.ts) deletes its pid record first and exits later. The teardown fixture found daemons only through pid records, so killProfileDaemons returned 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. killProfileDaemons additionally 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 tc and pnpm run check:code-quality:changed pass. 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Test-only. No product code, SSH, mobile, or compatibility impact.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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.
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The teardown fixture records profile daemon PIDs and Windows descendants before shutdown. During cleanup, it waits for recorded daemons whose PID records have disappeared and continues cleanup for daemons whose records remain. It checks recorded descendants after successful daemon cleanup. Tests cover missing PID records, descendant waits, and descendant timeout reporting. Integration tests record profile daemon PIDs before stopping orcad or requesting shutdown.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 62ee0

This change only affects test teardown. A failed cleanup that is retried could miss a daemon that is still running, and one new Linux test could be flaky. Neither affects product behavior, but both are worth fixing before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: waiting for an idle-retiring daemon before deleting the serve-parity profile.
Description check Passed The description includes the required explanation, change details, rationale, linked-issue exception, visual-proof statement, testing information, notes, and checklist. It clearly explains the Windows…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes the required explanation, change details, rationale, linked-issue exception, visual-proof statement, testing information, notes, and checklist. It clearly explains the Windows CI failure and the teardown fix. Some full validation commands remain unchecked, but this is acceptable because CI coverage is indicated.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 14c60eec-073d-4760-b49c-29c45f1211fb
📥 Commits

Reviewing files that changed from the base of the PR and between 469ae09 and 7131081.

📒 Files selected for processing: 5
  • src/main/orcad/orcad-cli-launcher.integration.test.ts
  • src/main/orcad/orcad-daemon-teardown-fixture.ts
  • src/main/orcad/orcad-daemon-teardown-linux.test.ts
  • src/main/orcad/orcad-serve-parity.integration.test.ts
  • src/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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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' }))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e5d0f2a3-82d7-4a3d-8634-a0b7227c6934
📥 Commits

Reviewing files that changed from the base of the PR and between 7131081 and 62ee0ec.

📒 Files selected for processing: 5
  • src/main/orcad/orcad-cli-launcher.integration.test.ts
  • src/main/orcad/orcad-daemon-teardown-fixture.ts
  • src/main/orcad/orcad-daemon-teardown-linux.test.ts
  • src/main/orcad/orcad-serve-parity.integration.test.ts
  • src/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.

Comment on lines +215 to +216
const record = await recordDaemonTree(daemonDir)
recordedProfiles.delete(daemonDir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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)
 }

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.

1 participant