Skip to content

feat(hosting): ask the registered owner of an address for its state, as the CLI does (#847) - #904

Merged
Blind-Striker merged 4 commits into
masterfrom
feat/847-find-incumbent
Nov 15, 2026
Merged

Blind-Striker merged 4 commits into
masterfrom
feat/847-find-incumbent

Conversation

@Blind-Striker

@Blind-Striker Blind-Striker commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #847

What

OpenCodeServer.FindIncumbentAsync(Uri url, OpenCodeServerDiscoverOptions? options = null, CancellationToken cancellationToken = default) is upstream's incumbent(url) (packages/client/src/effect/service.ts:33-43). It asks the registered background service that answers at a given address for its state, and returns an OpenCodeServerIncumbent { Server, State } with OpenCodeServerState { Ready, Waiting, Failed }, or null. The names are the maintainer's (2026-11-15).

In upstream's order:

  • the registration is read first; with none, the answer is null before the URL is evaluated (service.ts:37-38);
  • a URL that cannot serve as a WHATWG base (relative, or opaque such as mailto:) throws ArgumentException, as upstream's new URL("/api/info", url) throws outside its catch (service-probe.ts:55-60); the base check (ServiceRegistrationReader.CanBeBase) follows the WHATWG rules: C0 and space trimmed at the ends, tab/LF/CR removed anywhere, the scheme grammar, the six special schemes, and a / after the colon otherwise;
  • any other absolute URL that is not HTTP or HTTPS answers no service, as fetch rejects it and upstream's catch makes it no service;
  • otherwise the registration is addressed at the caller's URL (the unspecified address connected as loopback, the URL string kept as the handle's Endpoint) and probed once with the registration's credential;
  • a compatible service is returned in any state; a set ExpectedVersion filters on the version the probe reports (a null value accepts any version).

The door guards only a null URL; a base check at the door would change upstream's observable order. It reuses SystemDiscoveryProbe(), so it adds no clock site and no pragma. The caller's URL receives the registration's credential, as upstream's does; the guide says so. A URL carrying userinfo is probed (as the CLI's Bun runtime does), but the handle's CreateClient refuses it, as the client refuses userinfo.

Also: OpenCodeServer.Endpoint and OpenCodeServerDiscoverOptions.ExpectedVersion XML now describe the caller-addressed handle; canon (client-runtime.md), the connection-modes and errors guides, and the CHANGELOG Added line are updated. No GLOSSARY edit: "Incumbent" already landed with the GLOSSARY rewrite (#894).

Recorded divergence: host parsing

WHATWG's host parser refuses some hosts .NET's Uri accepts (for example http://example.42/, whose numeric last label WHATWG reads as a failed IPv4 address). Upstream throws there; the SDK, which does not reimplement that parser, probes and answers null. The maintainer decided this stands as a recorded divergence (2026-11-15). docs/architecture/client-runtime.md records it with its reason (parity would reimplement WHATWG's host, IPv4 and IDNA rules for hosts no loopback service uses) and its reversal trigger (a consumer needs the throw).

Tests

OpenCodeServerFindIncumbentTests (on MockFileSystem with substitute probes): every state with the caller's endpoint, pid, password and non-ownership; one probe at the caller's address with the caller's token; unspecified addresses as loopback; null without a probe when no registration reads (including for a non-base URL); null for no compatible answer; the version filter in all three states and for a versionless registration; a passwordless registration; non-HTTP and special-scheme rows (ws://, x-opencode://, http:\\, https:\\, wss:\\, ftp:\\, file:c:/x, tab/LF/CR, outer spaces, userinfo); validation before cancellation and before any file access; probe, registration-read and migration cancellation propagated as the same instance; the caller's token at the registration read and the channel migration; the null-URL guard. A live test over the pinned managed service reports Ready at a different spelling of the service's address and asserts the probe used it. A cancellation-identity row runs the public door end to end.

Mutants, each run against one authorized member with the full analyzer build, all failing at an assertion on net10.0 and net11.0: 29 in the implementation round (2 more were analyzer-unreachable, IDE0060) and 3 in the two review rounds (the special-scheme list, LF/CR stripping, and https/wss/ftp). The net472 replay of these mutants is pending on the Windows gate host (this macOS host builds net472 but does not run its tests); the PR is enqueued only after it.

Version impact (ADR-0034)

Additive: one new public method and two new public types. No existing signature changes.

Local evidence (macOS arm64, head 9f883c76 on 03238e37)

The full local check passed on the head:

  • slopwatch (0 issues), dotnet build --configuration Release -p:IncludeNet472Tests=true, dotnet build --configuration Release, both format passes and verify-clones;
  • OpenCode.Sdk.Tools.Tests [Category!=NativeAot]: 2823 of 2823 (including the file-size gate);
  • OpenCode.Sdk.Tests [(Category!=ServiceElection)&(Category!=NativeAot)]: 8828 of 8828 on net10.0 and net11.0;
  • OpenCode.Sdk.Tests [Category=ServiceElection] with --max-parallel-test-modules 1: 18 of 18;
  • opencode-tool --help and generate --verify: current.

The run used the pinned ripgrep 15.1.0 on PATH.

The third commit moves the background-service cancellation doors (AtStopPreCancelledAsync, AtServiceRequestAsync, InvokeServiceAsync, WriteServiceRegistrationAsync and their constants) out of CancellationIdentityTests.cs into a sealed, constructor-composed tests/OpenCode.Sdk.Tests/Support/ServiceCancellationDoors.cs. #902 grew that file to 793 lines, and this change's rows would have taken it to 801, over the 800-line test-file cap; after the move it is 655. Every assertion, row and variant is unchanged; the cancellation class runs the same 63 tests per framework before and after.

One unrelated flake was seen once in a worker's run: OpenCodeServerDescriptorTests.StartAsync_Should_Give_Each_Concurrent_Server_Only_Its_Own_Pipes saw six descriptors instead of 0, 1, 2 on net11; three reruns of that class passed 20 of 20, and this change touches no launcher code. It is recorded as a finding for the launcher's owner.

Reviews

  • A fresh Opus reader on the implementation found no defects (order, CanBeBase against WHATWG and .NET Uri, DiscoverAsync unchanged); its test gaps and nits were fixed by a fix-up worker.
  • A fresh Opus reader on that fix-up found no production defect; its gaps (a doc sentence that became false for userinfo URLs, unpinned schemes, the live probe address) were fixed in a second round.

@Blind-Striker Blind-Striker added this to the Next milestone Nov 15, 2026
@Blind-Striker
Blind-Striker marked this pull request as ready for review November 15, 2026 18:29
@Blind-Striker

Copy link
Copy Markdown
Collaborator Author

net472 mutation proof (Windows), at fe493ac2

  • Host: Windows 10.0.28000, .NET SDK 11.0.100, full analyzer Release build, external/opencode at the pin a6b15d33.
  • Baseline on net472: OpenCodeServerFindIncumbentTests 46/46, live FindIncumbentAsync_Should_Probe_The_Caller_Address 1/1.
  • All 32 mutants (M01–M32) built analyzer-clean and were killed on net472; none needed re-spelling, none survived. Both IDE0060-safe extras (X1, X2) were killed too.
  • Every mutant was restored with a clean git diff; the final run on the restored tree was green again (46/46, 1/1).
  • No sleep or standby event on the host during the run window.

@Blind-Striker
Blind-Striker added this pull request to the merge queue Nov 15, 2026
Merged via the queue into master with commit eaf9d64 Nov 15, 2026
17 checks passed
@Blind-Striker
Blind-Striker deleted the feat/847-find-incumbent branch November 15, 2026 21:00
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.

Background service: expose a registered owner's waiting, failed or ready state (upstream's incumbent probe)

1 participant