Skip to content

feat(hosting): turn the background service's remote access on through the installed CLI (#213, S-d) - #936

Merged
Blind-Striker merged 2 commits into
masterfrom
feat/213-service-config-remote-on
Nov 17, 2026
Merged

Blind-Striker merged 2 commits into
masterfrom
feat/213-service-config-remote-on

Conversation

@Blind-Striker

Copy link
Copy Markdown
Collaborator

📝 Description

What does this PR do?

The fourth slice of #213: turning the background service's remote access on, the way opencode's own CLI does it (opencode service set remote true, packages/cli/src/services/service-config.ts and commands/handlers/service/set.ts at the 2.3.0 pin). The read, the write path and every other set/unset are already on master (#926, #930); the canon, guides and CHANGELOG follow in the last #213 PR.

  • OpenCodeServiceConfiguration.EnableRemoteAsync(options, cancellationToken) returns the route. Upstream's remote-on builds the tunnel itself, so the SDK runs the installed CLI rather than reimplementing it (the maintainer's decision): it resolves the command the way StartAsync resolves its command, runs <command...> service set remote true with the given environment overlay, and only after the CLI reports success reads the route back. The SDK does no read, stop or write of its own before the run; the CLI owns the stop and the write.
  • The route is read back through the config store's one shared, non-throwing read (the same read connection resolution uses since Hosting: a connection-mode resolver with reconnect and restart (upstream's ServerConnection.resolve) #850, with its migration and in-place legacy repair). A config without a readable route (absent, refused, no remote) throws OpenCodeServerException naming the config file; the message never carries the route or a password.
  • New options on OpenCodeServiceConfigOptions: CliCommand (default ["opencode"], the CLI's executable and any leading arguments, the counterpart of upstream's selfCommand()) and Environment (entries layered over the process's environment for the CLI). The XML says only EnableRemoteAsync reads them, and that CliCommand, Channel and Environment must name the same config the other operations read.
  • The options are snapshotted and validated at entry (command and environment entries non-blank and free of NUL, as EnsureAsync validates its own), before any resolution or I/O.
  • The CLI child is launched through the launcher's own child strategies: no password injected (ServerChildStart.Password is now optional, and a null password neither injects nor removes OPENCODE_PASSWORD), stdout drained, stderr captured into a bounded tail (the 40-line / 8,192-character limits now live in one owner, BoundedLineBuffer.ForStderrTail, which the launcher uses unchanged) even when the host sets OPENCODE_PRINT_LOGS=1. Only an ordinary exit 0 succeeds; any other end names the executable, the exit and the stderr tail. Cancellation ends the child and propagates as the caller's cancellation; the child is released on every path.

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 (OpenCodeServiceConfigOptions.CliCommand, .Environment, OpenCodeServiceConfiguration.EnableRemoteAsync)
  • 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 2b61e55c (macOS arm64, on master cc86ec33), all green: the oracle bun tools/oracles/service-config.ts run twice with no diff, 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 (9714, net10.0 and net11.0), ServiceElection (22), --help, generate --verify.

Tests: the remote-on sequence (CLI first, then the route read; exact executable, arguments, environment and token), entry validation with one invalid input per row, the shared-read outcomes for every config shape, the runner against scripted and real children (exit evaluation, stderr tail limits, stdout drain, cancellation ending the child), both platform strategies' optional credential and forced stderr, the cancellation table row (pre-cancelled, bun --version, never a real opencode) under the extended session-isolation guard (proven red), and a live test that runs the pinned source CLI through a shim inside the managed fixture's run root (service set env, no tunnel, no installed CLI) and asserts the config change and the service's stop.

Mutation proof, one mutant at a time under the full analyzer build, each killed on net10.0 and net11.0: 39 mutants across the entry validation, the run order and arguments, the route read, the runner's exit, tail, cancellation and release, the credential composition and both platforms' stderr routing, and the live row. Two test rows were tightened while proving (each invalid-input row now makes exactly one input invalid; the pre-cancelled runner test scripts the child's exit so a launch fails fast instead of hanging). The net472 replay is pending on the Windows gate host; this PR is enqueued only after it.

Review: a fresh cross-family read found one blocking issue (the runner's live tests cleaned up in DisposeAsync, where TUnit only logs failures); it was fixed (cleanup in each test body, proven to fail a test when a step fails) together with a collapsed boolean assertion the repository gate rejected.

📚 Documentation

Known follow-ups

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

  • ServiceRemoteRequest.Snapshot repeats the acceptance rules of EnsureRequest instead of sharing them; its single combined CliCommand message differs from Ensure's three, and a malformed environment dictionary with duplicate keys throws without ParamName = options.
  • ServiceCliRunner builds its own "Recent stderr" text instead of the launcher's DescribeStderr, and appends the label even when the tail is empty.
  • For an unresolvable CliCommand the resolver's message points at OpenCodeServerOptions.Command, the launcher's option.
  • WindowsServerChildTests covers only the no-credential, forced-stderr case; the host and caller password cases run through the POSIX strategy only (the composer is shared).
  • The EnableRemoteAsync XML covers cancellation after the CLI's success but not cancellation mid-run, where upstream may already have stopped the service or left an issuance half done (upstream resumes it on the next run).
  • Small tidy-ups: ReadRouteAsync resolves the paths a second time for its message; the store's message names remote-on options; ServiceRemoteRequest properties lack XML; a missing blank line in ChildEnvironmentComposer.Compose; a Task[] indirection in the runner tests; the remote-on store composition discards the stop (CreateStore(random, seams, out _)).

@Blind-Striker

Copy link
Copy Markdown
Collaborator Author

net472 mutation replay on Windows at 2b61e55:

  • Baseline: the isolation guard (1), ServiceRemoteAccessTests (29), ServiceCliRunnerTests (7), the Posix server-child tests (10), WindowsServerChildTests (4), the service runner tests (14), ServiceCliRunnerLiveTests (7), the live stop tests (2) and the cancellation table (72) all passed. Every live class ran on Windows for the first time.
  • Mutants: 39 of 39 were killed. Each failure matched its expected test and row. M18, M30 and M33 fail deterministically through the mutated behaviour (the SDK's own mismatch exception, and the missing password entry). No analyzer rejected a mutant, and none survived.
  • Restored tree: every baseline run passed again, and no child process was left behind.

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