Repository navigation
fix(orcad): refuse new terminals while an update stops the server (R32) - #29834
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ecb1d3c8-4454-4207-9ebb-4e2a75fa4b87
📒 Files selected for processing: 19
src/main/ipc/pty/host-env/spawn-cwd-update-fence.test.tssrc/main/ipc/pty/host-env/spawn-cwd.tssrc/main/ipc/pty/ipc/spawn-run.tssrc/main/ipc/pty/runtime/spawn.tssrc/main/runtime/rpc/methods/orcad-terminal-census.test.tssrc/main/runtime/rpc/methods/orcad-terminal-census.tssrc/main/runtime/terminal-admission-fence.tssrc/main/ssh/orcad-installed-activation.tssrc/main/ssh/orcad-remote-deploy.test.tssrc/main/ssh/orcad-remote-deploy.tssrc/main/ssh/orcad-runtime-maintenance.tssrc/main/ssh/orcad-terminal-census-client.tssrc/main/ssh/orcad-update-admission-fence.test.tssrc/main/ssh/orcad-update-admission-fence.tssrc/main/wsl/wsl-orcad-deploy.tssrc/main/wsl/wsl-orcad-incumbent.test.tssrc/main/wsl/wsl-orcad-incumbent.tssrc/shared/orcad-runtime-capabilities.tssrc/shared/orcad-terminal-census.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.
| it('answers unverifiable, still fenced, when an admitted spawn never settles', async () => { | ||
| vi.useFakeTimers() | ||
| const stuck = runAdmittedTerminalSpawn( | ||
| () => {}, | ||
| () => new Promise<void>(() => {}) | ||
| ) | ||
| void stuck | ||
| const census = call({ closeAdmissionForMs: 60_000 }, 0).result | ||
| await vi.advanceTimersByTimeAsync(10_001) | ||
| await expect(census).resolves.toMatchObject({ | ||
| liveSessions: null, | ||
| admissionClosedUntil: expect.any(Number) | ||
| }) | ||
| expect(collect).not.toHaveBeenCalled() | ||
| }) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,125p' src/main/runtime/rpc/methods/orcad-terminal-census.test.ts
sed -n '20,75p' src/main/runtime/terminal-admission-fence.tsRepository: stablyai/orca
Length of output: 6157
Reset the stuck admitted spawn in this test so later fenced census tests are not affected.
The stuck spawn never settles, so spawnsInFlight stays at 1 for the rest of the module. A later census test that requests the admission fence would wait the full 10 s drain timeout. The current test order does not hit this, but a future fenced test can fail or time out. Hold the spawn's resolver, release it, and await the spawn in a finally block.
Proposed fix
--- "a/src/main/runtime/rpc/methods/orcad-terminal-census.test.ts"
+++ "b/src/main/runtime/rpc/methods/orcad-terminal-census.test.ts"
@@ -87,21 +87,26 @@
await expect(census).resolves.toMatchObject({ liveSessions: 1 })
})
it('answers unverifiable, still fenced, when an admitted spawn never settles', async () => {
vi.useFakeTimers()
+ let release: () => void = () => {}
const stuck = runAdmittedTerminalSpawn(
() => {},
- () => new Promise<void>(() => {})
+ () => new Promise<void>((resolve) => (release = resolve))
)
- void stuck
- const census = call({ closeAdmissionForMs: 60_000 }, 0).result
- await vi.advanceTimersByTimeAsync(10_001)
- await expect(census).resolves.toMatchObject({
- liveSessions: null,
- admissionClosedUntil: expect.any(Number)
- })
- expect(collect).not.toHaveBeenCalled()
+ try {
+ const census = call({ closeAdmissionForMs: 60_000 }, 0).result
+ await vi.advanceTimersByTimeAsync(10_001)
+ await expect(census).resolves.toMatchObject({
+ liveSessions: null,
+ admissionClosedUntil: expect.any(Number)
+ })
+ expect(collect).not.toHaveBeenCalled()
+ } finally {
+ release()
+ await stuck
+ }
})
it('still counts terminals it may not close, and closes nothing for a plain census', async () => {
collect.mockResolvedValue({ ...idle, liveSessions: 2 })📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('answers unverifiable, still fenced, when an admitted spawn never settles', async () => { | |
| vi.useFakeTimers() | |
| const stuck = runAdmittedTerminalSpawn( | |
| () => {}, | |
| () => new Promise<void>(() => {}) | |
| ) | |
| void stuck | |
| const census = call({ closeAdmissionForMs: 60_000 }, 0).result | |
| await vi.advanceTimersByTimeAsync(10_001) | |
| await expect(census).resolves.toMatchObject({ | |
| liveSessions: null, | |
| admissionClosedUntil: expect.any(Number) | |
| }) | |
| expect(collect).not.toHaveBeenCalled() | |
| }) | |
| it('answers unverifiable, still fenced, when an admitted spawn never settles', async () => { | |
| vi.useFakeTimers() | |
| let release: () => void = () => {} | |
| const stuck = runAdmittedTerminalSpawn( | |
| () => {}, | |
| () => new Promise<void>((resolve) => (release = resolve)) | |
| ) | |
| try { | |
| const census = call({ closeAdmissionForMs: 60_000 }, 0).result | |
| await vi.advanceTimersByTimeAsync(10_001) | |
| await expect(census).resolves.toMatchObject({ | |
| liveSessions: null, | |
| admissionClosedUntil: expect.any(Number) | |
| }) | |
| expect(collect).not.toHaveBeenCalled() | |
| } finally { | |
| release() | |
| await stuck | |
| } | |
| }) |
|
|
||
| const unstopped = incumbent ? await stopTransactionIncumbent(options, incumbent, lock) : null | ||
| if (unstopped) { | ||
| await reopenIncumbentAdmission(options) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Reopen admission when a pre-stop step fails.
After a fenced recount permits activation, writeOrcadActivationTransaction can throw before the incumbent stop begins. The incumbent then remains running, but neither release branch runs. New terminal spawns remain refused until the fence expires. Cover the pre-stop error path with best-effort admission release before propagating the error.
| return recount.liveSessions === null && recount.admissionClosedUntil === undefined | ||
| ? preUploadCensus | ||
| : recount |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Keep the pre-upload census when the server does not confirm a fence.
If an older server ignores closeAdmissionForMs, it can return a non-null liveSessions count without admissionClosedUntil. This condition accepts that unfenced recount. An SSH update can then defer on a count that the stated fallback says to ignore. Fall back whenever the marker is absent, and update the successful-recount test to include a fence marker.
…y code into src/main/managed-server/install/ (#30335) orcad-remote-*, remote-install-*, remote-node-runtime-store-*, remote-versioned-install and remote-deploy-timing leave src/main/ssh. git mv plus import and path-literal rewrites; one e2e route regex learns the new folder. orcad-remote-deploy and orcad-remote-node-runtime-report stay for now because open PRs #29834 and #29829 edit them.
…c/main/managed-server/lifecycle/ (#30343) orcad-managed-*, orcad-runtime-*, orcad-stdio-bridge-*, orcad-decommission-* and orcad-rollback-* leave src/main/ssh. git mv plus import and path-literal rewrites; two e2e route regexes learn the new folder. orcad-runtime-maintenance stays for now because open #29834 edits it.
ea99104 to
6b9d4e0
Compare
…the stop The last census before an SSH or WSL update stops the server now closes the server's terminal admission first. Every spawn lease (acquireWorktreeTerminalSpawn, which both spawn paths hold across the provider spawn) passes the fence, the census waits for leases taken before the close, and an update that leaves the incumbent serving reopens it. A reattach to a session the daemon still runs is still admitted.
…on when no stop was sent
6b9d4e0 to
57a8f95
Compare
Main's #29834 terminal-admission fence and this PR's restart reservation are kept side by side (three-model panel, unanimous): a capable host ends itself through reserve/commit with no fenced recount; an explicit Force of a host older than restart admission recounts with the fence, reopens it after every abandoned attempt and when no stop was sent, and keeps main's 45s stop deadline.
ELI5
To update a remote Orca server, the desktop counts the terminals running on it, then stops it. A terminal opened in the gap between that last count and the stop died with the stop, and nobody had counted it. Now the last count also tells the server to stop accepting new terminals until the stop happens, so nothing can start in that gap.
What Changed
Before: an SSH or WSL server update recounted terminals right before the stop (#30874), but nothing stopped a new terminal from starting after that recount. That terminal was killed by the update without warning.
After:
Mechanism:
orcad.terminalCensustakes a new optionalcloseAdmissionForMs(0 reopens) and returnsadmissionClosedUntilwhen asked.TerminalUpdateAdmission(src/main/runtime/terminal/stop/terminal-update-admission.ts). It is enforced in the existing spawn lease,acquireWorktreeTerminalSpawn. Both spawn paths (renderer IPC and runtime RPC) already hold that lease across the provider spawn, so no separate spawn hook was added. Every lease counts as in flight until it is released, and the census waits up to 10 s for those leases. If they don't finish, the census answersunverifiable, the update defers, and admission reopens.orcad-runtime-maintenance.ts) and WSL (wsl-orcad-incumbent.ts) build their counts with one shared helper,updateTerminalCounts. Only the last count is fenced; the first one comes before the upload, which can take minutes.OrcadDeployOptions.releaseIncumbentAdmissionis now required next torecountCensus, so every deploy caller has to say how its fence reopens.Why
Wire compatibility.
Supersedes: this rewrites the earlier version of this PR onto current main, keeping the same goal. It drops the unused capability string and reuses the existing spawn lease instead of a parallel mechanism. Its review findings are covered: the stuck test spawn, release on pre-stop failure, and release when no stop was sent.
Linked Issue
Risk R32 (SSH hardening list). No GitHub issue.
Visual Proof
N/A. The only visible change is a spawn error message during a few seconds of an update.
Testing
terminal-update-admission-census.test.tsdrives the real runtime and the census RPC with the params the SSH and WSL updates send. Against origin/main, the spawn after the final census is admitted and the test fails. With this change it is refused.terminal-update-admission.test.ts: the fence lapses; a reattach is admitted attach-only; a failed lease is released; a spawn that never settles is reported.orcad-update-admission-fence.test.ts, on the fake-host harness:orcad-remote-deploy.test.ts);SIGNAL_FAILEDreopens it,STILL_RUNNINGkeeps it closed.src/main/ssh/orcad-*,src/main/wsl/wsl-orcad*,src/main/managed-server,src/main/runtime/terminal/stop, spawn-lease runtime tests, pty launch parity).pnpm tcpasses.Design check
This needed more than three review rounds, so the design was compared with how other remote-server products handle restarting while sessions are active. They follow the same pattern: the host that executes the work counts active consumers and refuses new ones while it shuts down. They don't kill sessions blindly or rely on a client-side count. Orca's version is one gate held from the final recount through the stop, and it sits in the existing spawn lease rather than a new hook. The approach is unchanged; the round-3 fix only bounds how long the desktop may rely on the gate.
Notes
Residuals:
still-running/unconfirmed), admission stays closed until it lapses, at most 60 s.