Skip to content

refactor(cli): extract the serve supervisor's after-exit decision into a pure policy - #27446

Merged
OrcaWin merged 2 commits into
mainfrom
np/d1-supervisor-policy
Oct 11, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
np/d1-supervisor-policy

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​90 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​90
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​97 $\color{#cf222e}{\Huge{\mathbf{−}}}$​29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​68

ELI5

When orca serve runs under a service manager, a small CLI process watches the real server process and decides what to do when it exits: exit too, explain a crash, or wait for an update and start the new version. That decision was mixed into the code that spawns processes and reads files. This PR moves the decision into its own small, pure function so the upcoming restart rules (backoff, crash-loop brake) can be tested on their own. Nothing changes for users.

What Changed

  • New src/cli/runtime/serve-supervisor-policy.ts: decideAfterServeChildExit({ exit, expectedHandoff, handoff, hasHandoffPath }) returns exit, fail-replacement, signal-exit or await-install.
  • superviseForegroundServe keeps only the I/O. It waits for the child, reads the handoff file (only in the cases that read it before), records failures, waits for the bundle, and respawns. It then acts on the decision.
  • No behavior change. The decision table is the same, line for line, and the handoff file is read on exactly the same paths.

Why

This is step B2 of the headless-serve design, and it comes before any behavior change. The owner's decision Q5 adds a --supervise mode with jittered backoff and a durable crash-loop brake. Doing that inside an I/O loop would make the rules hard to test exhaustively. A pure policy allows model tests over random exit sequences. The orcad launch path already reuses this loop, so it inherits the same contract.

Linked Issue

Refs #10493 and #14541 (groundwork for the supervised mode; no behavior change)

Visual Proof

N/A: refactor with no behavior change.

Testing

  • Automated tests added/updated
  • New serve-supervisor-policy.test.ts: covers the following.
    • A normal exit code passes through.
    • A forwarded signal exits 0.
    • An unforwarded signal gets explained.
    • It waits for the new bundle only when this very child requested the install (pid match and a handoff path).
    • A replacement that exits before serving the target version fails the update.
    • A failed readiness check exits 1.
  • The existing src/cli/runtime suites pass unchanged (206 tests), including the macOS supervisor/update-handoff tests in launch.test.ts.
  • pnpm tc, pnpm lint and pnpm run check:code-quality:changed pass.

Review

Agent skill upstream boundary

  • Not applicable

Notes

  • No wire, platform or SSH impact. The supervisor's behavior is identical on macOS, Linux and Windows.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered
  • pnpm lint, pnpm typecheck, and focused tests pass locally; CI covers the rest

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 14ea910e-aa95-404f-a67e-826234757d4a

📥 Commits

Reviewing files that changed from the base of the PR and between 873d8f9 and 6a6e440.


📒 Files selected for processing (1)
  • src/cli/runtime/serve-supervisor-policy.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c61c83e6-f916-49d4-8b12-a3d11431655e


📥 Commits

Reviewing files that changed from the base of the PR and between 398cb84 and 873d8f9.



📒 Files selected for processing (3)
  • src/cli/runtime/serve-supervisor-policy.test.ts
  • src/cli/runtime/serve-supervisor-policy.ts
  • src/cli/runtime/serve-update-supervisor.ts


Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.




📝 Walkthrough
📝 Walkthrough

Walkthrough

The change adds decideAfterServeChildExit to evaluate serve-child exit details, readiness, and handoff state. The foreground serve supervisor delegates exit handling to this policy and acts on the returned decision. Tests cover exit codes, forwarded and unforwarded signals, handoff matching, and readiness outcomes.



Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 873d8

This refactor moves the serve supervisor's exit decision into a separate tested policy function. No behavior change or merge-blocking risk was identified.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: extracting the serve supervisor's after-exit decision into a pure policy.
Description check Passed The description is detailed and covers the change, rationale, testing, visual proof, review notes, and checklist. It identifies linked issues with Refs #10493 and #14541, although the template reque…
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 💡 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.

@OrcaWin
OrcaWin merged commit 616e9c3 into main Oct 11, 2026
43 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