Skip to content

Fix lifecycle validation teardown leaks - #366

Merged
TraderSamwise merged 3 commits into
masterfrom
chore/next-after-pr-365
Jul 18, 2026
Merged

Fix lifecycle validation teardown leaks#366
TraderSamwise merged 3 commits into
masterfrom
chore/next-after-pr-365

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • make daemon shutdown await project actor teardown before process exit
  • clean validation-only orphan daemons/processes and tmux sessions during aimux restart/repair
  • emit repair diagnostics and restart summary counts when validation orphans are cleaned

Validation

  • yarn vitest run src/lifecycle-orphans.test.ts src/runtime-restart.test.ts src/daemon.test.ts
  • yarn typecheck
  • yarn lint
  • git diff --check
  • yarn build
  • isolated live smoke: created a lifecycle-labeled Node process and tmux session, ran built cleanup, verified both were gone
  • pre-push full gate: yarn typecheck && yarn lint && yarn test (174 files, 2518 tests)

Summary by CodeRabbit

  • New Features
    • Added cleanup for abandoned lifecycle-validation processes and tmux sessions during daemon restarts.
    • Restart results now report cleaned orphan processes/sessions and any cleanup failures.
    • Added repair diagnostics for validation-orphan cleanup.
  • Bug Fixes
    • Improved daemon shutdown reliability with coordinated, idempotent stopping (now blocks further startups during shutdown) and proper actor/server teardown.
    • Signal-based exits now return appropriate status codes for interruption and termination.
    • New HTTP requests return 503 while shutdown is in progress.
  • Tests
    • Expanded coverage for lifecycle orphan detection/cleanup and shutdown/restart behavior.

@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Jul 18, 2026 4:46pm

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a14c66f0-ca9e-4cba-9e5e-5bc2930185fe

📥 Commits

Reviewing files that changed from the base of the PR and between 1fa72b8 and 648b8aa.

📒 Files selected for processing (6)
  • src/daemon.test.ts
  • src/daemon.ts
  • src/lifecycle-orphans.test.ts
  • src/lifecycle-orphans.ts
  • src/runtime-restart.test.ts
  • src/runtime-restart.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/runtime-restart.test.ts
  • src/lifecycle-orphans.ts
  • src/daemon.ts
  • src/runtime-restart.ts

📝 Walkthrough

Walkthrough

The PR makes daemon shutdown await actor and server teardown, adds lifecycle-validation orphan detection and cleanup, and integrates cleanup results into restart summaries, rendered diagnostics, and repair events. Signal handlers now await shutdown and use signal-specific exit codes.

Changes

Lifecycle runtime management

Layer / File(s) Summary
Coordinated daemon shutdown
src/daemon.ts, src/main.ts, src/daemon.test.ts
Daemon shutdown is promise-based, idempotent, awaits project actors and server closure, rejects new project startup during shutdown, and uses signal-specific exit codes.
Lifecycle-validation orphan cleanup
src/lifecycle-orphans.ts, src/lifecycle-orphans.test.ts
Validation-owned processes and tmux sessions are detected, terminated with escalation, and tested with injected process and tmux dependencies.
Restart cleanup integration and reporting
src/runtime-restart.ts, src/runtime-restart.test.ts, src/repair-events.ts
Restart performs orphan cleanup before planning, reports cleanup counts and failures, renders the results, and emits the new repair action.

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

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant Restart
  participant OrphanCleanup
  participant Runtime
  participant Diagnostics
  Restart->>OrphanCleanup: await lifecycle orphan cleanup
  Restart->>Runtime: build restart plan
  Restart->>Diagnostics: report counts and repair event
  Diagnostics-->>Restart: rendered restart result
Loading

Suggested reviewers: bhanuprasad14

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing lifecycle validation teardown leaks across daemon shutdown and restart cleanup.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/next-after-pr-365

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/daemon.ts (1)

447-476: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Stop accepting project work before snapshotting actors.

The server remains active while Line 459 snapshots actors. A concurrent route can create an actor afterward; Line 468 then clears it without calling stop(), leaking its project service during shutdown. Close admission and drain in-flight ensures before the snapshot, or keep draining actors until none remain.

As per coding guidelines, changes under src/*.ts require yarn build, and CLI runtime verification must use a local release asset.

🤖 Prompt for 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.

In `@src/daemon.ts` around lines 447 - 476, Update stopUnlocked() to close
project-work admission and await/drain in-flight requests before snapshotting
this.projectActors. Ensure no route can create an actor after the actors array
is captured; then stop all captured actors before clearing the map and
completing shutdown. Validate the change with yarn build and CLI runtime
verification using a local release asset.

Source: Coding guidelines

🤖 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 `@src/lifecycle-orphans.ts`:
- Around line 97-117: Separate attempted, confirmed-cleaned, and failed orphan
targets in src/lifecycle-orphans.ts lines 97-117, counting a PID as cleaned only
after confirmed exit and preserving errors for unsuccessful cleanup. In
src/runtime-restart.ts lines 894-904, derive cleaned counts from confirmed
successes and append cleanup errors to summary.failures. In
src/runtime-restart.ts lines 932-945, emit the cleanup event whenever errors
exist, including when no target was successfully removed.

---

Outside diff comments:
In `@src/daemon.ts`:
- Around line 447-476: Update stopUnlocked() to close project-work admission and
await/drain in-flight requests before snapshotting this.projectActors. Ensure no
route can create an actor after the actors array is captured; then stop all
captured actors before clearing the map and completing shutdown. Validate the
change with yarn build and CLI runtime verification using a local release asset.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 292017b5-a876-4fec-a35d-47274a5f8dd9

📥 Commits

Reviewing files that changed from the base of the PR and between ecc8baf and 1fa72b8.

📒 Files selected for processing (8)
  • src/daemon.test.ts
  • src/daemon.ts
  • src/lifecycle-orphans.test.ts
  • src/lifecycle-orphans.ts
  • src/main.ts
  • src/repair-events.ts
  • src/runtime-restart.test.ts
  • src/runtime-restart.ts

Comment thread src/lifecycle-orphans.ts Outdated
@TraderSamwise

Copy link
Copy Markdown
Owner Author

Review loop follow-up: CodeRabbit is green on 648b8aa, and the independent sub-agent review found no correctness issues. Local validation for this phase passed: yarn typecheck, yarn lint, yarn build, full yarn test (174 files / 2523 tests), plus an isolated live orphan-cleanup smoke that removed a fake lifecycle validation node daemon and tmux session without touching wrapper processes.

@TraderSamwise
TraderSamwise merged commit a91f765 into master Jul 18, 2026
3 checks passed
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