fix(cli): harden managed service replacement - #41946
Open
kitlangton wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Prevent managed-service restart storms when a running TUI outlives an automatic CLI update, and harden lifecycle recovery so clients never terminate a process from registration data alone.
This fixes the incident where a
next-17271TUI remained alive after the installed package becamenext-17272. The old process repeatedly treated each17272service it spawned as incompatible, stopped it, and spawned the same newer binary again. The TUI repeatedly lost transport, migration polling mislabeled the disconnect as a data migration failure, and restart recovery added repeated continuation entries.The lifecycle rules are now explicit:
VersionMismatchError; never stop or spawnservice restartBefore / After
Before
next-17271TUI launched and started an asynchronous update.next-17272, while the TUI process image remained17271.serve --service; the on-disk executable started17272.17272as a mismatch and stopped it.17272executable again, repeating roughly every two seconds.Transport.After
/api/service/stop; it has noSIGTERMorSIGKILLpath.How
packages/cli/src/services/service-config.tspackages/client/src/effect/service.tsandpackages/client/src/promise/service.tsVersionMismatchErrorwhen replacement policy protects the owner;packages/client/src/promise/service.tspackages/cli/src/commands/handlers/service/restart.tspackages/cli/src/services/server-connection.tspackages/tui/src/component/migration-overlay.tsxClientError("Transport")instead of showingData migration failed.Scope
This PR is the incident containment and client-side safety layer. It deliberately does not implement the larger ownership redesign already described in
docs/design/service-lifecycle.md:instanceIDand explicit lifecycle-state protocol fields;The last point is intentionally conservative: a stale registration PID may have been reused by another application, so this PR refuses to signal it.
Testing
cd packages/client && bun run test: 64 passed.cd packages/client && bun typecheck: passed.cd packages/cli && bun run test test/service.test.ts test/server-connection.test.ts --test-name-pattern 'managed version replacement|only newer clients|resolution groups|service options|concurrent service processes': 5 passed.cd packages/cli && bun typecheck: passed.cd packages/tui && bun run test: 661 passed, 5 skipped.cd packages/tui && bun typecheck: passed.The lifecycle battery covers:
Flow
sequenceDiagram participant TUI as Fresh TUI participant Reg as Registration participant Old as Current service participant New as Installed service TUI->>Reg: Read and authenticate owner Reg-->>TUI: version + exact instance alt installed version is newer TUI->>Old: POST /api/service/stop(instanceID) Old-->>TUI: accepted Old-->>Old: graceful shutdown TUI->>New: spawn installed binary New-->>Reg: publish new owner TUI->>New: attach when ready else installed version is older TUI-->>TUI: VersionMismatchError Note over TUI: Explicit service restart is required else reconnect TUI->>Reg: rediscover without version gate TUI->>Old: attach to current owner end