Repository navigation
feat(hosting): discover the background service and shut its persistent terminals down in one call (#848) - #898
Conversation
|
net472 mutation proof: pending, on a Windows run. The mutants in this PR's body were proven on net10.0 and net11.0 on macOS, where the net472 test target builds but does not run; the lead replays them on a Windows host and posts the results here. |
|
net472 mutation proof for this PR, replayed on the head
Test names omit the prefix
On this unit seam, the full analyzer build rejects mutant 2 ("never call the shutdown") as an unused parameter. That behaviour is pinned by the live test's counting wrapper, whose "skip the shutdown" mutant was proven on net10.0 and net11.0, as the description records. |
Closes #848
What
OpenCodeServer.ShutdownPersistentPtyAsyncis upstream'sshutdownPersistentPty(packages/cli/src/services/server-connection.ts:80-87), which the CLI's uninstall runs before it stops the service. It discovers the background service exactly asDiscoverAsyncdoes, with the same options. When discovery answers no service, it sends nothing and completes. Otherwise it sends onePOST /api/experimental/persistent-pty/shutdownto the registered endpoint with the registration's credential, no location and no request bound of its own, as upstream's call has none, so the client's default per-read network window applies. The service's persistent-terminal daemon then stops with every terminal it owns; a daemon that is not running answers 204. Failures propagate asOpenCodeApiExceptionorOpenCodeTransportException, and nothing is retried. The call stops no service and touches no handoff sidecar. It carriesOPENCODE002, because it calls an experimental route.The maintainer's decisions (2026-11-15): the name
ShutdownPersistentPtyAsync, upstream's spelling;OpenCodeServerDiscoverOptions?as the options (O1);Taskas the result (R1).OpenCodeServer.BackgroundService.cs: the public door; an internal test hook,ShutdownPersistentPtyWithSeamsAsync, that takes the discovery and the shutdown; and one privateSystemDiscoveryProbe()factory thatDiscoverAsyncand the new door share. Discover's existingTimeProvider.Systemchoice and itsRS0030pragma moved into that factory unchanged; the file still has exactly threeRS0030pairs, andDiscoverAsync's behaviour is unchanged.ReservedNamePolicy,GeneratedSourceCompilerand the suppression ledger are unchanged.Divergence (O1, recorded in the canon)
Upstream's
shutdownPersistentPtyremoves the version requirement before it discovers (server-connection.ts:83). The SDK takes discovery's own options, whoseExpectedVersionis null by default, which is the same any-version discovery; a caller who sets it reaches only a service at that version. It is a superset that reuses discovery's options type instead of a near-copy without the member.client-runtime.md's list "Where the SDK deliberately differs" records it with its reason and reversal trigger.Tests
OpenCodeServerPersistentPtyShutdownTests(seven tests onMockFileSystem, substitute probe and shutdown): a missing registration sends nothing; a waiting, failed or incompatible service sends nothing; a ready service gets exactly one shutdown with its registration, and the caller's token reaches both the probe and the shutdown; a shutdownOpenCodeApiExceptionpropagates as the same instance;ExpectedVersionnarrows the discovery; contradictory options throw before any call; a cancellation thrown during discovery propagates unchanged with no shutdown.OpenCodeServerDiscoveryLiveTests: one live test over the pinned managed service, through the patient discovery path (never the two-second probe bound). Both arms first assert a ready, compatible, untimed discovery verdict and exactly one shutdown call. Daemon arm: the created terminal is listed before the call and gone after it. Daemon-absent arm: create answers 503 namingopencode-pty, the shutdown answers 204, and the list is empty.CancellationIdentityTests: ashutdown-persistent-ptyrow runs the public door end to end and asserts the caller's token, the request order, the Basic header, nox-opencode-directoryheader, the registration kept, and no sidecar.Mutants, each run once against the committed code and failing at an assertion on net10.0 and net11.0: a door that throws on no service; discovery's readiness check removed; no shutdown;
Noneto the shutdown;Noneto discovery; a swallowed shutdown failure;ExpectedVersioncleared;ExpectedVersionrefused; a swallowedArgumentException; a swallowed discovery cancellation; and, for the live test, a door that skips the shutdown (daemon arm: "Expected to be 1 but found 0").Live evidence (macOS arm64, daemon arm):
Version impact (ADR-0034)
Additive: one new public static method. No existing signature changes.
Local evidence (macOS arm64, head
47a831d7onc734f4b6)The full local check passed on the rebased head:
dotnet build --configuration Release -p:IncludeNet472Tests=true,dotnet build --configuration Release, both format passes andverify-clones;OpenCode.Sdk.Tools.Tests[Category!=NativeAot]: 2819 of 2819;OpenCode.Sdk.Tests[(Category!=ServiceElection)&(Category!=NativeAot)]: 8496 of 8496 on net10.0 and net11.0;OpenCode.Sdk.Tests[Category=ServiceElection]with--max-parallel-test-modules 1: 18 of 18.The run used the pinned ripgrep 15.1.0 on
PATH. The branch was rebased onto #897 (the stop option'sPtyrename) without conflicts; this change names neither renamed type.Reviews
DiscoverAsyncrefactor is behaviour-identical, and the daemon-absent oracle matches what the pinned server answers. Its test gaps and nits were fixed by a fix-up worker in the second commit. One gap stays open as Live tests leave the persistent-terminal daemon running when an assertion fails #896: a live test that fails between the create and the shutdown leaves the detached terminal daemon running;PersistentPtyLiveTestshas the same exposure, and one fix will cover both.PersistentPtyLiveTests.DaemonServiceandCreateRequest()became internal so the new live test reuses them; moving them intoSupport/waits for the persistent-PTY family rename.