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): retry managed service binds after temporary conflicts by kitlangton · Pull Request #50782 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Sep 23, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Why

A managed-service startup can lose a race for its port even when that port becomes free immediately afterward. Today the process catches the bind failure and spends up to 15 seconds looking for an existing OpenCode service, but never tries to bind again. It eventually reports that the port is occupied even though another startup can now use it.

The important distinction is a failed bind at one instant versus a port that remains unavailable.

What Changes

Within the existing recovery window, a managed startup retries the actual bind when no compatible authenticated service has appeared.

Only EADDRINUSE permits another attempt. The deadline bounds bind recovery and incumbent checks; once binding succeeds, it does not impose a new deadline on application boot.

What happens after the first bind conflict? Before After
Previous listener releases the port Original startup still fails; a fresh process is needed Original startup binds and becomes ready
Another OpenCode process registers Recognize that owner and exit cleanly Same
Unrelated process keeps the port Bounded wait, then actionable conflict Same
A different startup error occurs Fail with that error Same

Waiting for an owner is not retrying a bind

sequenceDiagram
    participant P as Managed startup
    participant L as Previous listener
    participant R as Service registration
    P->>L: Try to bind its port
    L-->>P: EADDRINUSE
    L->>L: Release the port
    alt Before
        loop Until recovery window ends
            P->>R: Has another service registered?
            R-->>P: No
        end
        Note over P: Reports conflict although the port is free
    else After
        P->>R: Has another service registered?
        R-->>P: No
        P->>P: Retry binding the same port
        P->>R: Register this process
        Note over P: Original startup becomes ready
    end
Loading

Before / After Proof

The regression uses a real unrelated listener and the real CLI process. A stale fixture registration permits incumbent probes. The second probe can only happen after the initial bind has failed; that probe is the release barrier. The test frees the port at that boundary, then requires the original child PID to register and become healthy.

This distinguishes a recovered attempt from merely launching another process. The listener, registration, database, and home/config directories all belong to the test.

Same positive regression Observed result
Base 43f1dad8e1 + the new test Fails: original child exits with the occupied-port diagnostic after release; no registration for its PID (17.01s test)
Fixed implementation + the same test Passes: the original child registers and serves authenticated health on that port (4.35s runner)

The test also stops the recovered service and checks that its registration and listener are released. Existing tests cover persistent/unresponsive occupancy, concurrent starts, a late incumbent, and reuse of an already-failed registered service.

Scope

This PR owns temporary bind-conflict recovery. #50784 independently preserves failures across client startup attempts. Free-port fallback admission has a separate ownership problem and proof.

Verification

cd packages/cli
bun run test test/service.test.ts -t 'the original managed service contender'
bun run test test/service.test.ts
bun typecheck

cd ../..
bun run check
bunx prettier --check packages/cli/src/server-process.ts packages/cli/test/service.test.ts
git diff --check
  • The new positive regression was run before and after the production change, with the results above.
  • The complete service suite ran three times: 21 passed, 0 failed each run (96.02s / 88.17s / 78.13s).
  • CLI typecheck, formatting, and root lint/typecheck passed: 35/35 tasks.
  • Process-test commands ran inside an allowlisted temporary HOME/XDG environment with a local empty model catalog and updates disabled. Test listeners use random ports. No installed service was used.
  • Supplemental isolated probes confirmed that 100 failed bind acquisitions retained no child scopes, and a non-bind EISDIR registration failure during retry propagated immediately with its original diagnostic. These probes supplement the committed regression; they are not Windows/WSL coverage.

Sorry, something went wrong.

Uh oh!

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

All reactions
@github-actions github-actions Bot added the contributor label Sep 23, 2026
This was referenced Sep 23, 2026
fix(client): preserve background service startup failures #50784
Merged
fix(client): wait for service shutdown before restart #50042
Merged
fix(server): preserve historical service health probes #50824
Closed
@kitlangton
kitlangton force-pushed the service-bind-retry branch from 5ffecc1 to 9f70a9e Compare September 25, 2026 21:25
@Hona Hona mentioned this pull request Sep 30, 2026
fix(cli): give each WSL distro its own service port and skip reserved host ports #49909
Closed
@kitlangton
kitlangton force-pushed the service-bind-retry branch from 9f70a9e to 48aa7cb Compare October 4, 2026 04:59
@kitlangton
fix(cli): retry managed service binds after temporary conflicts
c3a48b6
@kitlangton
kitlangton force-pushed the service-bind-retry branch from 48aa7cb to c3a48b6 Compare October 5, 2026 04:02
@kitlangton
refactor(cli): reuse the incumbent probe during bind recovery
bf46b8e
@kitlangton
kitlangton merged commit 515b302 into v2 Oct 5, 2026
9 checks passed

Uh oh!

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

@kitlangton
kitlangton deleted the service-bind-retry branch October 5, 2026 04:33
@yang0228 yang0228 mentioned this pull request Oct 5, 2026
fix(cli): load saved environment when starting managed services #50907
Merged
3 of 6 tasks
Ichinose-Kazuki pushed a commit to Ichinose-Kazuki/opencode that referenced this pull request Oct 7, 2026
@kitlangton
fix(cli): retry managed service binds after temporary conflicts (anom…
85bb844
…alyco#50782)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

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.

Uh oh!

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

1 participant

@kitlangton
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.