Repository navigation
fix(restart): retire drained parent ownership and preserve bind scope #7874
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
lidge-jun
merged 10 commits into
lidge-jun:dev
from
luvs01:codex/7871-restart-bind-followup-20261028
Oct 28, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
889dc0f
fix(restart): retire drained parent ownership and preserve bind scope
luvs01 0fe66b2
fix(liveness): preserve default loopback bind across discovery
luvs01 5fed0d4
test(server): preserve restart handoff diagnostics and descendant cle…
lidge-jun 96a4ee3
test(server): resolve restart fixture graph once before process handoff
lidge-jun d5a8945
test(server): drain restart capture before fixture removal
lidge-jun 105a5bf
test(server): confine restart fixture cleanup to owned processes
lidge-jun ed650a2
Merge remote-tracking branch 'origin/dev' into fix/7874-review-followup
lidge-jun 87b39d5
fix(grok): separate recovery probe destinations from bind policy
lidge-jun 10db36d
test(restart): exercise stale identities and refused endpoints
lidge-jun 3f1af0b
test(grok): assert ensure carries the observed bind scope and probe a…
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
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,49 @@ | ||
| import { lstatSync } from "node:fs"; | ||
| import { | ||
| getPidPath, getRuntimePortPath, readPidFileValue, readRuntimePort, removePid, removeRuntimePort, | ||
| } from "../config/process-state"; | ||
| import { acquireOwnershipMutationLease } from "../service/ownership-mutation-lease.mjs"; | ||
| import { serviceStatePaths } from "../service/state"; | ||
|
|
||
| function refusal(): Error { | ||
| return Object.assign(new Error("Restart parent ownership could not be retired safely"), { | ||
| code: "RESTART_PARENT_OWNERSHIP_UNVERIFIED", | ||
| }); | ||
| } | ||
|
|
||
| /** Only ENOENT proves absence; an unreadable, malformed or linked record is not ours to retire. */ | ||
| function recordExists(path: string): boolean { | ||
| try { | ||
| if (!lstatSync(path).isFile()) throw refusal(); | ||
| return true; | ||
| } catch (error) { | ||
| if ((error as NodeJS.ErrnoException).code === "ENOENT") return false; | ||
| throw refusal(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Called only after completed drain and successful listener stop, before waiting for child health. | ||
| * The parent is still alive, but no longer owns a listener or startup recovery. Retire only this | ||
| * process's records under the same lease that serializes child recovery and publication. Ordinary | ||
| * live/unknown owners retain the startup fence; no child marker grants an exemption from it. | ||
| */ | ||
| export function retireRestartParentOwnership(port?: number): void { | ||
| const lease = acquireOwnershipMutationLease(serviceStatePaths()); | ||
| try { | ||
| const pidPath = getPidPath(), runtimePath = getRuntimePortPath(); | ||
| const hasPid = recordExists(pidPath), hasRuntime = recordExists(runtimePath); | ||
| const runtime = readRuntimePort(); | ||
| if ((hasPid && readPidFileValue() !== process.pid) | ||
| || (hasRuntime && (!runtime || runtime.pid !== process.pid | ||
| || (port !== undefined && runtime.port !== port)))) throw refusal(); | ||
| // Keep the alive-PID fence if runtime retirement fails. The helpers also recheck the PID | ||
| // immediately before unlink, so a successor's record is never unconditional cleanup. | ||
| if (hasRuntime) removeRuntimePort(process.pid); | ||
| if (recordExists(runtimePath)) throw refusal(); | ||
| if (hasPid) removePid(process.pid); | ||
| if (recordExists(pidPath)) throw refusal(); | ||
| } finally { | ||
| lease.release(); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.