Skip to content

feat(hosting): set and unset the background service's config, stopping it first as the CLI does (#213, S-c) - #930

Merged
Blind-Striker merged 1 commit into
masterfrom
feat/213-service-config-set
Nov 16, 2026
Merged

Blind-Striker merged 1 commit into
masterfrom
feat/213-service-config-set

Conversation

@Blind-Striker

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

Copy link
Copy Markdown
Collaborator

📝 Description

What does this PR do?

The third slice of #213: every set and unset of the background service's config, as opencode's own CLI does them (packages/cli/src/services/service-config.ts, commands/handlers/service/set.ts and unset.ts at the 2.3.0 pin). The read and the write path (S-a + S-b, #926) are already on master; remote access on, and the canon, guides and CHANGELOG, follow in later PRs for #213.

  • Nine operations on OpenCodeServiceConfiguration: SetDisabledAsync, SetHostnameAsync, SetPortAsync, SetPasswordAsync, SetCorsOriginsAsync, SetEnvironmentVariableAsync, DisableRemoteAsync, UnsetAsync(OpenCodeServiceSetting) and UnsetEnvironmentVariableAsync, with the new OpenCodeServiceSetting enum (Disabled, Hostname, Port, Password, CorsOrigins).
  • Each one runs the CLI's sequence: read (a document upstream can read but the SDK's strict reader cannot is refused with OpenCodeServerException before anything stops), stop the running service, re-read, merge, write. Only enabling the service (SetDisabledAsync(false), UnsetAsync(Disabled)) does not stop it, as upstream. A stop that fails propagates as itself and leaves the change unmade.
  • The written document keeps upstream's member order: an existing member stays in place, a new one is added last; removing the last environment entry drops env; DisableRemoteAsync marks remoteAccepted only when a route was present; an empty password is stored as given; the port must be 1 to 65535.
  • CORS origins are validated as upstream validates them; the policy accepts an origin only when it equals the origin .NET's own parse rebuilds, so it cannot be looser than upstream. All 81 verdicts of the oracle corpus (produced by upstream's own code) match.
  • The stop reuses OpenCodeServer.StopAsync's composition through a new internal OpenCodeServer.SystemStopper, with the caller's token, channel and installed version; StopAsync keeps its clock choice.
  • ServiceConfigDocument's settings are now private-set properties set through its one internal constructor and changed only through named operations; the reader passes them as constructor arguments. Read semantics are unchanged (connection resolution in Hosting: a connection-mode resolver with reconnect and restart (upstream's ServerConnection.resolve) #850 reads through the same store).
  • The new config cancellation door sits in ServiceCancellationDoors.cs with its row in the cancellation table, under the session-isolation guard, which already covers every path the stop resolves.

Related Issue(s):

🔄 Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

🎯 Protocol & API Surface

  • Public API changed deliberately, and tests/OpenCode.Sdk.Tests/Snapshots/PublicApi.verified.txt is updated in this PR (nine OpenCodeServiceConfiguration methods and OpenCodeServiceSetting)
  • dotnet run --file tools/opencode-tool.cs -- generate --verify passes
  • The pinned snapshot (spec/) is untouched
  • Nothing under external/ was hand-edited

🧪 Testing

How has this been tested?

Local check on 9244c65f (macOS arm64, on master 81c1c057, after #921 merged), all green: the oracle bun tools/oracles/service-config.ts run twice with no diff (100 config scenarios and 81 CORS verdicts from upstream's own code), slopwatch (0 issues), dotnet build -c Release and with -p:IncludeNet472Tests=true (0 warnings), both format passes, verify-clones (0 new clones), Tools tests (2861), SDK tests excluding ServiceElection and NativeAot (9616, net10.0 and net11.0), ServiceElection (22), --help, generate --verify.

Rebased onto #921 (#850): its parameterless OpenCodeServer.SystemStopper() (used by StopAsync and StopLocatedAsync) keeps its clock choice and pragma pair and now delegates to this PR's internal SystemStopper(environment, fileSystem, time); both sides' cancellation doors and compiler rows are kept. S-c reads the config only through ReadForWriteAsync, which #850 builds on its non-throwing ServiceConfigStore.ReadAsync. A fresh read of the rebase found nothing blocking.

Tests: the oracle parity rows for every operation (member order, legacy repair under a write, env order, remoteAccepted, empty password), the stop table (which operations stop, the read-stop-read-write order, the stop's options and token), stop failure and refusal before stopping, argument guards before any collaborator, the CORS corpus, cancellation through every await and the new table row, and a live test that sets an environment variable on the pinned managed service and asserts it really stopped (process exited, registration gone) while the config kept its members and values.

Mutation proof, one mutant at a time under the full analyzer build, each killed at its assertion on net10.0 and net11.0: 19 mutants (which operations stop, the stop's position and options, the re-read, remoteAccepted, env order and removal, the empty password, a swallowed stop failure, the port guards, the CORS trim set, default ports and case). Not counted: three analyzer rejections (S1144 for a plain Trim(), re-spelled as a killed variant; S8949 twice for a token replaced by default). The net472 replay is pending on the Windows gate host; this PR is enqueued only after it.

Review: a fresh cross-family read found nothing blocking under the review convergence rule.

📚 Documentation

Known follow-ups

Non-blocking items from the read, left for a later change:

  • CORS origin policy: oracle rows for empty labels, DNS length limits and WHATWG-only host characters #929: CORS oracle rows for empty labels, DNS length limits and WHATWG-only host characters, where .NET's parse may refuse an origin upstream accepts; confirm on the net472 leg too.
  • The three analyzer-rejected mutants (S1144, S8949 twice) are killed by their oracles by reading, not by a run.
  • The two SystemStopper overloads differ only in their parameters; the parameterless one only chooses the clock, and a distinct name would read clearer.
  • S-c stops through the full StopAsync (locate, then stop); Hosting: a connection-mode resolver with reconnect and restart (upstream's ServerConnection.resolve) #850 now offers StopLocatedAsync, which a later slice may weigh against the CLI's behaviour.
  • Small tidy-ups: CreateStore(random, out _) shares the stop through an out parameter and ReadAsync builds a stop it discards; AssignRemoteAccepted(bool) is only called with true; RepairRemote(null) doubles as "disable remote"; RemoveEnvironment() wraps AssignEnvironment(null); ["bad", null] reports the first item's ArgumentException before the null; the editor tests named ServiceConfigEditor_Should_Refuse_* test the public door guards; the stop table indexes rows by number; the new cancellation Map arm matches by name only; XML on the internal editor methods is uneven.

@Blind-Striker Blind-Striker added this to the Next milestone Nov 16, 2026
@Blind-Striker
Blind-Striker force-pushed the feat/213-service-config-set branch from 8bf98e3 to 9244c65 Compare November 16, 2026 17:46
@Blind-Striker

Copy link
Copy Markdown
Collaborator Author

net472 mutation replay on Windows at 9244c65:

  • Baseline: the isolation guard (1), ServiceConfigEditorTests (22), OpenCodeServiceConfigurationTests (42), CorsOriginPolicyTests (1), the cancellation table (71) and the live stop test (1) all passed.
  • Mutants: 19 of 19 were killed. Each failure matched the expected test and row. No analyzer rejected a mutant, and none survived.
  • Restored tree: the same six runs all passed.

@Blind-Striker
Blind-Striker added this pull request to the merge queue Nov 16, 2026
Merged via the queue into master with commit cc86ec3 Nov 16, 2026
17 checks passed
@Blind-Striker
Blind-Striker deleted the feat/213-service-config-set branch November 16, 2026 19:10
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