fix(engine): sweep stray engines machine-wide, not per-port (#1592) - #1593
Merged
jeonghun-jj-lee merged 1 commit intoSep 28, 2026
Merged
Conversation
adopt-or-spawn (#1145) and its orphan-reclaim (#1178) only probe the CONFIGURED port. An engine on any OTHER port — a stale install, a workspace whose window died — is invisible to them and squats forever with its MCP child tree, and the two engines' MCP trees churn against each other (flickering connected/failed status tiles). Add sweepStrayEngines: after adopt-or-spawn resolves, enumerate every opencode serve on the machine and reap the ones that are neither the engine we kept (handshake PID) nor still serving a live client. Pure decision logic over injected seams (listOpencodeEngines / hasLiveClient / killEngine), production seams reap by PID regardless of port. Wired into activation on both the adopted and cold-spawn ready paths. Never reaps: the adopted engine, an engine with a live client (a real second workspace), or a foreign process.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
jeonghun-jj-lee
merged commit Sep 28, 2026
19b49c3
into
feature/free-tier-fleet
11 of 12 checks passed
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.
Closes #1592.
What
Adds a machine-wide stray-engine sweep so the "one
opencode serveper machine" invariant survives installs/workspaces that resolve to different ports.Why
adoptOrSpawn(#1145) + orphan-reclaim (#1178) only ever probe the configured port. When a second install's window dies, its engine is orphaned on its own port, invisible to the guard — it squats with a full MCP child tree, and the two engines' MCP trees churn against each other (the flickeringconnected/failedMCP status tiles observed live onjjs-macbook-pro: installed-ext PID 48240 on 4094 alongside the hub PID 79829 on 4093).How
sweepStrayEngines(deps)— pure decision logic over injected seams. Reaps every engine that is neitherkeepPid(the handshake/adopted engine) nor still serving a live client.listOpencodeEngines(enumerate allopencode serve+ ports via lsof/ps, confirmed by the existingisOpencodeServersignature),hasLiveClient(ESTABLISHED conn from a non-engine PID),reclaimEnginePid(SIGTERM→SIGKILL by PID, any port).adoptOrSpawnon both the adopted path and the cold-spawnonReadypath, keyed off the handshake PID. Non-fatal — a sweep failure never blocks activation.Invariants (unit-tested, 6 new cases)
Verification
server_lifecycle.test.ts: 37/37 green (6 new).typecheck: clean.fleet_peer_e2e.test.ts(CI-gated real-SSH,describe.skipIf) — proven pre-existing: identical 2 failures on the untouched base commit3da4bc56.Do not merge until CI is green.