Skip to content

fix(windows): contain desktop smoke process trees - #41

Merged
slashdevcorpse merged 14 commits into
mainfrom
fix/windows-smoke-job-containment
Jul 20, 2026
Merged

fix(windows): contain desktop smoke process trees#41
slashdevcorpse merged 14 commits into
mainfrom
fix/windows-smoke-job-containment

Conversation

@slashdevcorpse

@slashdevcorpse slashdevcorpse commented Jul 20, 2026

Copy link
Copy Markdown
Owner

What Changed

  • launch the Windows desktop smoke under a checked-in PowerShell 5.1 Job Object helper
  • contain Electron and every descendant atomically with KILL_ON_JOB_CLOSE
  • use an authenticated READY/shutdown protocol with bounded failure-only taskkill cleanup
  • add native Windows process-tree/TCP/argv coverage to the permanent windows_x64 CI gate

Why

The previous Windows smoke cleanup could report success while late Electron descendants were still settling, and PID-tree discovery left a spawn-to-assignment race. Assigning the wrapper to a kill-on-close Job before Electron starts makes containment deterministic and fail-closed.

Verification

  • exact Windows lifecycle CI slice: 80/80
  • native lifecycle pair: 33/33
  • four native integration repetitions
  • five isolated Electron smokes across the source and clean transplant; every run returned with zero new Electron PIDs and zero listeners
  • frozen install, desktop build, Node syntax, Windows PowerShell 5.1 parser, and diff checks passed

Checklist

  • This PR is focused on one Windows lifecycle defect
  • I explained what changed and why
  • No UI changes

Summary by cubic

Contain Windows desktop smoke process trees with a checked-in PowerShell 5.1 Job Object wrapper, and run the built desktop smoke directly in CI for deterministic, fail-closed teardown.

  • Bug Fixes

    • Atomic containment: assign KILL_ON_JOB_CLOSE before launch; start observation only after SYNARA_SMOKE_JOB_READY <id>; send SYNARA_SMOKE_JOB_TERMINATE <id>\n then EOF; enforce 30s startup, 13s teardown, 2s settlement. Treat SYNARA_SMOKE_JOB_ERROR, invalid/missing run id, and unexpected/duplicate READY as fatal; never send shutdown more than once; guard late helper errors; hold output through settlement.
    • Failure-only cleanup: resolve SystemRoot\System32\taskkill.exe via SystemRoot/WINDIR (case-insensitive), pass the Windows env, add a close‑proof margin, abandon fallback if the window expires, and finish with direct SIGKILL.
    • Harden launch: validate absolute/UNC Windows paths for executable/helper/cwd; per‑run UUID via SYNARA_SMOKE_JOB_RUN_ID; resolve powershell.exe via SystemRoot/WINDIR; keep POSIX direct spawn unchanged.
  • New Features

    • Added createDesktopSmokeSpawnSpec to choose the Windows wrapper vs POSIX and pass a clean env/run id/working directory; apps/desktop/scripts/smoke-test.mjs now uses it with a generated run id.
    • Added Windows‑native integration tests (process tree + TCP, argv with -- and quoting, stdin‑EOF shutdown, startup failure, protocol errors, bounded startup/settlement).
    • CI: run the built desktop smoke via bun run --cwd apps/desktop smoke-test after the build; enforce workflow contracts for this exact post‑build command, unconditional fail‑closed behavior, correct ordering, and reject the Turbo wrapper token by exact test:desktop-smoke matching—including quoted or redirected variants; windows_x64 also runs scripts/smoke-test.test.mjs and scripts/smoke-test-windows-job.windows.integration.test.mjs.

Written for commit 5f0c85e. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows desktop smoke-test containment supervision using Job Object–based handling, marker-gated startup, reliable shutdown token control, and more resilient teardown/fallback when isolation doesn’t close cleanly.
  • Tests
    • Added Windows-only integration coverage for argv preservation, controlled shutdown on stdin EOF, READY/timeout edge cases, and multiple Windows teardown failure scenarios.
  • Chores
    • Updated CI to run the Windows desktop smoke containment regressions and adjusted workflow validation to require an unconditional, fail-closed post-build smoke step in the x64 pipeline.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Windows desktop smoke tests now launch through a PowerShell Job Object wrapper with run-specific tokens, platform-specific supervision, bounded teardown, and expanded unit/integration regression coverage. Non-Windows launch behavior remains direct.

Changes

Windows smoke lifecycle

Layer / File(s) Summary
Launch contracts and platform dispatch
apps/desktop/scripts/smoke-test-lifecycle.mjs, apps/desktop/scripts/smoke-test.mjs
Adds Windows spawn-spec construction, path validation, run IDs, and routing to Windows or POSIX supervision.
Process teardown and supervision state machines
apps/desktop/scripts/smoke-test-lifecycle.mjs
Adds marker-driven Windows Job supervision, bounded cleanup and settlement handling, and revised POSIX/taskkill teardown logic.
PowerShell Job Object wrapper
apps/desktop/scripts/smoke-test-windows-job.ps1
Validates arguments, creates the Job Object, starts the child, relays output, processes shutdown tokens, and reports failures.
Windows lifecycle regression coverage
apps/desktop/scripts/smoke-test.test.mjs, apps/desktop/scripts/smoke-test-windows-job.windows.integration.test.mjs, .github/workflows/ci.yml, scripts/lib/workflow-contracts.ts, scripts/lib/workflow-contracts.test.ts
Adds unit, integration, and workflow-contract coverage for quoting, readiness markers, process-tree cleanup, deadlines, wrapper failures, and CI execution.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related issues

  • slashdevcorpse/synara#7 — Covers Windows process-tree ownership and cleanup through Job Object-based supervision.

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant SmokeTest as smoke-test.mjs
  participant Lifecycle as superviseDesktopSmokeProcess
  participant Wrapper as smoke-test-windows-job.ps1
  participant Electron as Electron process
  SmokeTest->>Lifecycle: Start process with windowsJobRunId
  Lifecycle->>Wrapper: Launch PowerShell Job wrapper
  Wrapper->>Electron: Start target inside Job Object
  Wrapper-->>Lifecycle: Emit READY marker and relay output
  Lifecycle->>Wrapper: Write shutdown token
  Wrapper->>Electron: Terminate Job Object
  Lifecycle-->>SmokeTest: Return supervision result
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly summarizes the main change: containing Windows desktop smoke process trees.
Description check ✅ Passed The description covers What Changed, Why, Verification, and Checklist, with UI changes effectively marked as not applicable.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/desktop/scripts/smoke-test-windows-job.ps1`:
- Around line 5-9: Rename the unapproved Fail-SmokeJob function to
Stop-SmokeJob, preserving its parameters and behavior, and update all four call
sites to use the new approved function name.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: eecb787f-8751-4966-9bec-810b6610e6cf

📥 Commits

Reviewing files that changed from the base of the PR and between 336e3f5 and 39e4cc4.

📒 Files selected for processing (6)
  • .github/workflows/ci.yml
  • apps/desktop/scripts/smoke-test-lifecycle.mjs
  • apps/desktop/scripts/smoke-test-windows-job.ps1
  • apps/desktop/scripts/smoke-test-windows-job.windows.integration.test.mjs
  • apps/desktop/scripts/smoke-test.mjs
  • apps/desktop/scripts/smoke-test.test.mjs

Comment thread apps/desktop/scripts/smoke-test-windows-job.ps1 Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread .github/workflows/ci.yml
Comment thread apps/desktop/scripts/smoke-test-lifecycle.mjs Outdated
Comment thread apps/desktop/scripts/smoke-test-windows-job.ps1 Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/desktop/scripts/smoke-test-windows-job.ps1`:
- Around line 5-8: Rename Stop-SmokeJob to the non-state-changing
Write-SmokeJobError and update all four call sites to use the new name,
preserving its existing error output and process-exit behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 192ad9c7-07e2-4cc9-af89-ae3099eb0aad

📥 Commits

Reviewing files that changed from the base of the PR and between da54d09 and 130ff22.

📒 Files selected for processing (5)
  • apps/desktop/scripts/smoke-test-lifecycle.mjs
  • apps/desktop/scripts/smoke-test-windows-job.ps1
  • apps/desktop/scripts/smoke-test-windows-job.windows.integration.test.mjs
  • apps/desktop/scripts/smoke-test.mjs
  • apps/desktop/scripts/smoke-test.test.mjs
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/desktop/scripts/smoke-test.mjs
  • apps/desktop/scripts/smoke-test-windows-job.windows.integration.test.mjs
  • apps/desktop/scripts/smoke-test.test.mjs
  • apps/desktop/scripts/smoke-test-lifecycle.mjs

Comment thread apps/desktop/scripts/smoke-test-windows-job.ps1 Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/lib/workflow-contracts.ts`:
- Around line 179-184: Update the validation around the desktop smoke check in
workflow-contracts.ts to detect tokenized test:desktop-smoke invocations within
rawCommand, including arguments and shell composition, rather than matching only
the exact command; preserve the existing no-wrapper error behavior. In
scripts/lib/workflow-contracts.test.ts, add an argument-bearing wrapper mutation
within the existing test coverage and assert that validation fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d3abb641-264a-4ffa-b06f-87054de4a479

📥 Commits

Reviewing files that changed from the base of the PR and between 130ff22 and 752ef55.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml
  • scripts/lib/workflow-contracts.test.ts
  • scripts/lib/workflow-contracts.ts

Comment thread scripts/lib/workflow-contracts.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread scripts/lib/workflow-contracts.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread scripts/lib/workflow-contracts.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread scripts/lib/workflow-contracts.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread scripts/lib/workflow-contracts.ts Outdated
@slashdevcorpse
slashdevcorpse merged commit b6dbb03 into main Jul 20, 2026
10 of 11 checks passed
@slashdevcorpse
slashdevcorpse deleted the fix/windows-smoke-job-containment branch July 20, 2026 21:18
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