Skip to content

feat(hosting): read and write the background service's config the CLI's way (#213, S-a + S-b) - #926

Merged
Blind-Striker merged 9 commits into
masterfrom
feat/213-service-config
Nov 16, 2026
Merged

Blind-Striker merged 9 commits into
masterfrom
feat/213-service-config

Conversation

@Blind-Striker

Copy link
Copy Markdown
Collaborator

📝 Description

What does this PR do?

The first two slices of #213: typed read of the background service's config, and its write path, as opencode's own CLI reads and writes it (packages/cli/src/services/service-config.ts, commands/handlers/service/get.ts at the 2.3.0 pin). Every set/unset, remote access, and the canon, guides and CHANGELOG follow in later PRs for #213.

  • OpenCodeServiceConfiguration.ReadAsync(options, cancellationToken) returns OpenCodeServiceConfig, the safe view upstream's service get prints: disabled, remote enabled/accepted, hostname, port, CORS origins in order, environment entries. The password and the route are never exposed. OpenCodeServiceConfigOptions selects the channel and installed version, as the CLI resolves them.
  • ReadAsync reads the CLI's way: when the config file is missing it copies a current-shape legacy donor (migrateConfig), and it repairs a legacy boolean remote in place. It stops nothing, as get stops nothing.
  • OpenCodeServiceConfiguration.GetOrCreatePasswordAsync(options, cancellationToken) returns the stored password, creating and storing one when none exists. The config is written as the CLI writes it: its JSON form, an owner-only file, its directory created, and a rename retried on a transient failure.
  • A document upstream can read but the SDK's strict reader cannot is refused with OpenCodeServerException naming the file, before any copy or write; a document neither can read is replaced as upstream replaces it. This covers the config file and the legacy donor.
  • A donor is judged and copied on the same decoded text, through one step shared by the config store and ServiceMigration, for both the config and the registration donor; invalid UTF-8 inside a string is copied as upstream's decode writes it.
  • The launcher's password generator moves into RandomCredential, unchanged in output, so the launcher and the config share it.
  • The config cancellation doors live in ServiceCancellationDoors.cs with their rows in the cancellation table, beside the other background-service doors, and a guard asserts every config door resolves under the test session's isolated roots, so no test reaches the developer's real OpenCode files.
  • Canon (client-runtime.md): the smallest correction that OpenCodeServiceConfiguration's operations read and repair the config the CLI's way and write it; Discovery, Ensure and Stop still read the document as it is. The full canon, guides and CHANGELOG entry come with the last Background-service configuration administration: keep or drop #213 slice.

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 (OpenCodeServiceConfiguration with ReadAsync and GetOrCreatePasswordAsync, OpenCodeServiceConfig, OpenCodeServiceConfigOptions)
  • 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 09cff076 (macOS arm64, rebased onto master 837ae9a2), all green: the oracle bun tools/oracles/service-config.ts run twice with no diff (it runs upstream's own service-config.ts over the corpus and writes the expected fixtures), slopwatch (0 issues), dotnet build -c Release and with -p:IncludeNet472Tests=true (0 warnings), both format passes, verify-clones, Tools tests (2841), SDK tests excluding ServiceElection and NativeAot (9250, net10.0 and net11.0), ServiceElection (18), --help, generate --verify.

Tests: the oracle corpus (read, repair, donor copy, write shapes, CORS), the store, writer, editor, retry, cancellation and write tests, the door tests through OpenCodeServiceConfiguration's seams, ServiceConfigReader and ServiceMigration additions, RandomCredential, the file-system and environment seams, a live test that reads the pinned managed service's password through the password door without writing, and the cancellation table rows.

Mutation proof, one mutant at a time under the full analyzer build, each killed at its assertion on net10.0 and net11.0: more than sixty mutants across the implementation and its five fix-up rounds (the read, the repair, the donor rule, the refusal, the writer, the password door, the shared decode step, the duplicate-member refusal and the doors' seams); the net472 replay re-targets the ones still meaningful at this head as 59 rows. Not counted: four analyzer controls (three S8949, one IDE0060). Token-dropping mutants on the config doors ran only after the isolation guard was in, and wrote only under the session roots. The net472 replay is pending on the Windows gate host; this PR is enqueued only after it.

Reviews: fresh cross-family reads of S-a, its fix-up, S-b and each of its five fix-up rounds; every blocking finding was fixed and re-proven. The isolation guard is proven red on both of its path checks (the registration path with XDG_STATE_HOME withheld, the config path with OPENCODE_CONFIG_DIR and XDG_CONFIG_HOME withheld; the guard alone ran under those mutants), and the method that runs the config doors depends on it, so a failed guard skips the doors.

📚 Documentation

  • XML documentation comments added for the new public API
  • CHANGELOG.md, the consumer guide and the full canon section: deliberately left to the last Background-service configuration administration: keep or drop #213 slice, which documents the whole configuration surface at once; this PR corrects only the canon sentence S-b made untrue

Known follow-ups

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

  • [DependsOn] sits on the cancellation table's public-door method, so a failed isolation guard also skips that method's non-config rows (HTTP, events, PTY); only the two config rows need it.
  • A filtered run of one public-door row now also runs the isolation guard, so filtered counts include it.
  • ServiceConfigWriteData.CollidingDonorNames is now the config-only colliding donor beside CollidingRegistrationNames; its name could say so.

…n, and the existence contract says what it returns (#213)
…or is judged by the text it would copy, and the config cancellation doors join the shared table (#213)
…the config cancellation doors stay in isolated roots, and the runtime canon says the config operations write (#213)
…oded text as the config store, and the config cancellation doors rely on the session's isolated roots (#213)
…, the migration's refusal of colliding names is pinned, and the isolation guard is proven on its path checks (#213)
… the duplicate refusal alone, and the config doors run after their isolation guard (#213)
@Blind-Striker Blind-Striker added this to the Next milestone Nov 16, 2026
@Blind-Striker

Copy link
Copy Markdown
Collaborator Author

net472 mutation replay on Windows: 59 of 59 killed at head 09cff076 (upstream pin a6b15d33), on .NET SDK 11.0.100, Windows build 26300, Bun 1.4.4.

  • Baseline (net472), every filter green at its expected total:
    • the isolation guard 1/1;
    • ServiceConfigReaderTests 69, OpenCodeServiceConfigurationTests 26, OpenCodeServiceConfigTests 1;
    • the store tests: 14, 5, 3 and 7;
    • ServiceConfigJsonWriterTests 4, ServiceConfigEditorTests 4, ServiceMigrationTests 33;
    • ServiceFileSystemTests 32, ServiceEnvironmentTests 6, RandomCredentialTests 2;
    • the cancellation table 63;
    • the live configuration test 1/1, over the pinned managed service.
  • Mutants F01 to F59: every mutant built clean, with no analyzer rejection and no re-spelling. Every expected-red test named for a mutant failed under that mutant, and every restore was clean. For F58, the token-dropping row, the isolation guard ran green on the mutant build before its tests.
  • Final restored tree (net472): every filter green again, at the same totals.
  • Hygiene:
    • each test command ran with --framework net472 and kept its TRX evidence;
    • no build-weakening switch was used;
    • the operator endpoint and password variables were removed from the runner's environment.

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