Skip to content

fix(opencode): prevent idle starts and orphaned serve - #1763

Merged
chuks-qua merged 3 commits into
mainfrom
codex/fix-opencode-server-lifecycle
Sep 24, 2026
Merged

chuks-qua merged 3 commits into
mainfrom
codex/fix-opencode-server-lifecycle

Conversation

@chuks-qua

@chuks-qua chuks-qua commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Startup model refresh skips OpenCode even when it is enabled. Its model list loads when a user requests it. Other disabled providers are also skipped.

The OpenCode provider now awaits pool shutdown. On Windows, the pool owns each spawned process tree in a Job Object and verifies that the listener port closes before it forgets the server. Shutdown also waits for starts already in progress.

Why

Startup model refresh previously called every registered provider. OpenCode shutdown returned before its pool finished, and the pool tracked the shell wrapper PID even when opencode.exe survived that wrapper.

Evidence

Before the change, a controlled Mcode process exit left its captured OpenCode listener alive on port 49680. The exact captured listener was stopped after the check.

With this change, awaited pool shutdown removed the captured wrapper and OpenCode listener and closed port 64138. A separate abrupt-exit check removed both captured processes and closed port 54066 through Job Object ownership.

The full worktree Mcode startup check did not reach its health endpoint within agent:ready's wait. Its server stayed in startup after the copied database loaded, so that check does not prove the model warmup path in the full app. The runtime was stopped with agent:down.

Review Notes

The six focused test files passed, with 59 tests total. Server typecheck and targeted oxlint passed. No schema, setting, or migration changed.

@chuks-qua
chuks-qua merged commit e7eb5f7 into main Sep 24, 2026
9 checks passed
@chuks-qua
chuks-qua deleted the codex/fix-opencode-server-lifecycle branch September 24, 2026 15:51
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