Repository navigation
test: add background service lifecycle tests - #53406
Merged
Merged
Conversation
kitlangton
force-pushed
the
service-lifecycle-tests
branch
from
October 5, 2026 20:46
6a702f3 to
8db2e0f
Compare
|
run |
Nowaker
added a commit
to Nowaker/opencode
that referenced
this pull request
Nov 19, 2026
"reports a failed registered service" (Promise and Effect) failed on a loaded host with "Missing service command": the tests run ensure with accelerated timing, a 100 ms probe deadline and a 200 ms contender grace. When the failed-owner fixture's HTTP 500 health answer took longer than 100 ms, the probe aborted, ensure saw the registration as unanswered, and once the grace elapsed it recruited a contender, which fails on the test's empty command. The tests then measured probe latency, not the classification they are about. These two tests now use awaitAnswer timing: the probe deadline equals ensure's own budget and the contender grace is twice that, so only an answered probe can decide, and a stall past the whole budget fails with ensure's own timeout error rather than by spawning. The registration is published only after the fixture's server listens, so the first probe is never refused. Production timing and ensure are unchanged. The tests date from anomalyco#53406 (cdd63fa). Not proven by a test: the race has no deterministic red, because under the old timing the tests fail only when the answer takes longer than 100 ms. The fix is argued from the code; one diagnostic run at load 54.8 passed both files (45/0). AI-Tool: opencode 1.19.5-vt-432-006d837c50 AI-Model: anthropic/claude-opus-5-5 AI-Variant: high AI-Platform: linux AI-Harness: Vibeterm 5c268353754 AI-Session-ID: ses_e3832b1b0ffe6q98OeUzhgqhjQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Every CLI, TUI, and desktop client shares one managed background service (
opencode serve --service). Its lifecycle bugs show up as a client stuck on "Starting background server…" or a healthy server killed out from under a client. The client tests cover the lifecycle decisions with fixture servers, but nothing runs real servers through restarts, upgrades, crashes, and races and then checks where the system ends up.What Changes
Real servers:
packages/cli/test/service-lifecycle.test.tsadds 7 cases. They cover only behavior that needs real processes, driven through the realopencode service start|restartcommands and the Effect client'sService.ensure. Each case gets an isolated home directory and its own port.ensurecalls at once, from coldservice restartcalls during concurrent starts/api/infoservice.json, an immediate start, then a crash (SIGKILL)Every case ends by requiring the service to settle:
serve --serviceprocess for that homeservice.jsonnames it, and/api/infoanswers 200 with that PID and the expected version on the configured portThe restart race and the crash case also require that the same server is still registered after its 5 s registration self-check.
Client fixture tests: two cases in both the Effect and Promise client suites, 0.1–0.3 s each:
ensurestart a replacementservice.jsonnaming a dead process is replacedKeeping It Cheap
XDG_CACHE_HOME, which otherwise makes every spawned server transpile the CLI from scratch. Sharing one Bun transpiler cache cuts time to registration from about 1.3 s to 0.9 s.The unrelated-port case takes about 24 s, because each startup attempt waits out the server's fixed 15 s bind-recovery window before the error surfaces.
Scope
Tests only, and everything passes on current
v2. Cases for gaps these tests surfaced land with their fixes.Verification
--rerun-each 3, plus two more runs under heavy machine load (load average around 35). The slowest case took 48 s under load, so each case has a 120 s timeout.v2from before fix(client): preserve service on protocol-only reconnect mismatch #50825 and fix(client): preserve background service startup failures #50784, the old-protocol case fails becauseservice startreplaced the 404 server, and the unrelated-port case times out instead of reporting the conflict.