GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(cli): refuse to overwrite an invalid service.json by kitlangton · Pull Request #66687 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Nov 26, 2026 •
edited by opencodejr Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

A typo or syntax error in service.json now stops with a clear error instead of wiping your saved background server settings.
service.json stores your local background server's port, hostname, password, CORS origins, remote route, and environment variables. First-run startup with no service.json and automatic upgrades of older boolean remote settings are unaffected.

🔍 Origin: Fixes #52412

❌ Before

  1. You edit service.json by hand and make a mistake (for example "port": "4096" as a string, or a truncated JSON file).
  2. ❌ Reading service.json swallows the error and pretends the file is empty ({}).
  3. ❌ Starting the background server or running opencode service set overwrites service.json — wiping your hostname, port, CORS list, environment variables, and remote route, and locking out connected clients with 401.

✅ After

  1. You edit service.json by hand and make a mistake.
  2. Reading service.json fails with ServiceConfig.InvalidError naming the file path and every invalid field or JSON error, while a missing file still returns {}.
  3. Starting the server or running opencode service set / unset stops before changing service.json, while opencode service status, opencode service stop, and opencode debug heap-dump can still inspect or stop an already-running server.
- read service.json -> missing, unreadable, or invalid -> return {} -> next write replaces file
+ read service.json -> missing (NotFound) -> return {}
+                   -> unreadable -> fail with PlatformError (file untouched)
+                   -> invalid JSON or schema -> fail with ServiceConfig.InvalidError (file untouched)

📊 Proof

Case Before After
Missing service.json on first run ✅ Starts and creates password ✅ Starts and creates password
Legacy boolean remote in service.json ✅ Repaired in place ✅ Repaired in place
Typo or syntax error in service.json on serve --service or service set / unset ❌ Overwrites service.json and rotates password ✅ Fails with path + issue; file untouched
Unreadable service.json on service set / unset ❌ Overwrites service.json ✅ Fails with PlatformError; file untouched
service status / service stop while service.json is invalid ✅ Works ✅ Still works via registrationFile

The new regression tests in packages/cli/test/service-config.test.ts fail without this change (the server overwrites service.json with only a new password and exits 0 instead of reporting InvalidError); 452 pass, 9 skip, 0 fail across packages/cli.

👀 Read: packages/cli/src/services/service-config.ts, where read distinguishes NotFound from unreadable or invalid files and registrationFile splits state-file lookup from reading service.json. The rest is routine.

Checks run
  • bun test --timeout 30000 test/service-config.test.ts --rerun-each 10 --randomize (in packages/cli): 30 pass, 0 fail
  • bun run test (in packages/cli): 452 pass, 9 skip, 0 fail
  • bun run check: 36/36 tasks pass
  • bun run typecheck:tsc: 34/34 tasks pass

Added by the opencode bot (AI-generated).

Fixes #52412

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kitlangton
fix(cli): refuse to overwrite an invalid service.json
1ed257f
@github-actions github-actions Bot added the contributor label Nov 26, 2026
opencodejr[bot]
opencodejr Bot reviewed Nov 26, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works. I reproduced the data loss on the base branch (an invalid service.json is wiped by service set and by serve --service, which also rotates the password). With this PR, both commands stop with ServiceConfig.InvalidError naming the file and the bad field, and the file is left untouched. opencode run now shows the same clear error, and service status still works. The reproduction script from #52412 behaves the same way. The new tests pass here and fail 3 of 5 on the base, and tsc -b passes for packages/cli.

Public API: the file format and CLI commands are unchanged. An invalid service.json now causes an error instead of being treated as empty.

One request: the new test file is quite large for what it checks (see inline comment).

Fixes #52412

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/cli/test/service-config.test.ts Outdated
}
}

yield* Effect.forEach(

@opencodejr opencodejr Bot Nov 26, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs 24 operations against each of 3 sample files, which makes the test long and harder to read than the fix needs. One read() check that the error names the path, plus one or two commands that write (e.g. set("port", …) and password()) showing the file is untouched, would cover the fix. The unreadable-file test and the serve --service subprocess test could also be shortened to their key assertions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kitlangton
test(cli): tighten service-config regression tests
0585b94
opencodejr[bot]
opencodejr Bot reviewed Nov 26, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file is now much smaller: one read() check, a few commands that write showing the file stays untouched, the unreadable-file case, and one command-line test covering serve --service and service status/stop. That covers my earlier comment. The tests pass and tsc -b passes in packages/cli. The fix itself is unchanged from what I verified before, and the public API is unchanged. No new concerns.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot mentioned this pull request Nov 27, 2026
📊 AI CLI 工具社区动态日报 2026-11-27 litang9/big_model_radar#766
Open
@rekram1-node
rekram1-node merged commit e702df9 into dev Nov 27, 2026
14 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node
rekram1-node deleted the fix-service-config-corrupt branch November 27, 2026 06:26
@Edo771977 Edo771977 mentioned this pull request Nov 27, 2026
chore: merge upstream/dev into the fork Edo771977/opencode#104
Merged
@simonklee simonklee mentioned this pull request Nov 27, 2026
fix(cli-rs): port provider order and the service.json refusal, and fix CI-only test races #66776
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

service set/unset silently erases the stored config when service.json cannot be decoded

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@kitlangton @rekram1-node
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.