Repository navigation
fix(cli): refuse to compete with a Desktop-supervised runtime in service, update, start and stop #6809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix(cli): refuse to compete with a Desktop-supervised runtime in service, update, start and stop #6809
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f8bdbc1
fix(service): refuse service activation while OpenCodex Desktop runs …
lidge-jun 39c742c
fix(update): leave a Desktop-supervised runtime and its package alone
lidge-jun 8a23b32
fix(cli): explain Desktop supervision on start, stop and restart
lidge-jun 4a5fba1
docs: describe the Desktop supervision command guards
lidge-jun f8fa8c5
test: follow the guarded service calls in source-oracle tests
lidge-jun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { createSupervisionLatch, inspectDesktopSupervision } from "../service/desktop-supervision.mjs"; | ||
| import type { DesktopSupervision, SupervisionInspector } from "../service/desktop-command-guard"; | ||
| import { UpdateRestartRequired } from "./update-restart-candidate"; | ||
| import { runProxyRestart, type ProxyRestartIo } from "./tray-proxy"; | ||
|
|
||
| function evidenceForTarget(evidence: DesktopSupervision, pid: number | null | undefined): DesktopSupervision { | ||
| // Injected inspectors must obey the same target binding as the production inspector. | ||
| return evidence.kind === "desktop" && pid != null && evidence.runtimePid !== pid | ||
| ? { kind: "unknown", reason: "unrelated-target", desktopSeen: false } : evidence; | ||
| } | ||
|
|
||
| export function duplicateRuntimeMessage( | ||
| pid: number | null | undefined, | ||
| port: number, | ||
| inspect: SupervisionInspector = inspectDesktopSupervision, | ||
| ): string { | ||
| const latch = createSupervisionLatch(); | ||
| const evidence = evidenceForTarget(inspect({ targetPid: pid ?? undefined }), pid); | ||
| if (pid != null && latch.observe(evidence)) { | ||
| const supervisor = evidence.kind === "desktop" ? `, ${evidence.app}` : ""; | ||
| return `OpenCodex Desktop supervises the running proxy (pid ${pid}${supervisor}, port ${port}). ` | ||
| + "Use the running proxy, or quit OpenCodex before starting it from this CLI."; | ||
| } | ||
| return `⚠️ Proxy already running (PID ${pid ?? "unknown"}, port ${port}). Use 'ocx stop' first.`; | ||
| } | ||
|
|
||
| export function desktopStopNotice(evidence: DesktopSupervision): string | null { | ||
| const latch = createSupervisionLatch(); | ||
| return latch.observe(evidence) | ||
| ? "OpenCodex Desktop may start this proxy again after a short backoff. Use Stop Proxy or Quit in the OpenCodex menu to keep it stopped." | ||
| : null; | ||
| } | ||
|
|
||
| export function runDesktopAwareProxyRestart( | ||
| io: ProxyRestartIo, | ||
| inspect: SupervisionInspector = inspectDesktopSupervision, | ||
| info: (line: string) => void = console.log, | ||
| ) { | ||
| const latch = createSupervisionLatch(); | ||
| let targetPid: number | undefined; | ||
| let supervisedRequest = false; | ||
| return runProxyRestart({ | ||
| ...io, | ||
| requestInPlaceRestart: async previous => { | ||
| targetPid = previous.pid ?? undefined; | ||
| const evidence = evidenceForTarget(inspect({ targetPid }), targetPid); | ||
| supervisedRequest = latch.observe(evidence); | ||
| const result = await io.requestInPlaceRestart(previous); | ||
| if (evidence.kind === "desktop" && result.accepted) { | ||
| info("Restart requested; OpenCodex Desktop starts the replacement."); | ||
| } | ||
| if (supervisedRequest && !result.accepted && !result.uncertain && result.error instanceof UpdateRestartRequired) { | ||
| info("OpenCodex Desktop supervises this proxy. Use the app's updater (tray → Check for Updates), or quit OpenCodex before updating and restarting from this CLI."); | ||
| return { accepted: false as const, uncertain: false, error: new Error("restart_desktop_update_required") }; | ||
| } | ||
| return result; | ||
| }, | ||
| startWhenStopped: async recovering => { | ||
| const blocked = latch.observe(evidenceForTarget(inspect({ targetPid }), targetPid)); | ||
| // An accepted supervised handoff keeps its replacement intent through temporary absence. | ||
| if (supervisedRequest || blocked) return { status: "skipped" as const }; | ||
| return io.startWhenStopped(recovering); | ||
| }, | ||
| }); | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: lidge-jun/opencodex
Length of output: 6335
🏁 Script executed:
Repository: lidge-jun/opencodex
Length of output: 12553
🏁 Script executed:
Repository: lidge-jun/opencodex
Length of output: 19218
Use the planner notice for Desktop-supervised updates.
A successful update can reach this branch after Desktop takes over between the last pre-replacement check and the final post-install check. In that case, the generic warning explains what was skipped but omits the documented instruction to use the app updater.
Proposed change
📝 Committable suggestion
🤖 Prompt for AI Agents