-
Notifications
You must be signed in to change notification settings - Fork 2k
Register broker ownership and safely reclaim abandoned helper trees #563
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
Open
ccheng555
wants to merge
30
commits into
openai:main
Choose a base branch
from
ccheng555:cc-5219-idle-app-server-child
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
be5edea
[CC-5219] release idle Codex app-server children
ccheng555 eb6b3a6
[CC-5219] terminate idle app-server helper groups
ccheng555 289f39d
[CC-5219] clean detached app-server descendants
ccheng555 41fe9c7
[CC-5219] make helper cleanup identity safe
ccheng555 0f235a0
[CC-5219] isolate runtime broker fixtures
ccheng555 6240ce1
Merge branch 'main' into cc-5219-idle-app-server-child
ccheng555 38529f4
[CC-5219] address review findings: unwedge disconnected-stream state,…
ccheng555 16547a0
[CC-5219] address Codex review: await async teardown at all call site…
ccheng555 58d84b1
[CC-5219] address Codex review round 2: exclude root from descendant …
ccheng555 59a40a3
[CC-5219] track every observed member of a signaled process group
ccheng555 386411c
[CC-5219] terminate the spawned app-server when initialization fails
ccheng555 c663c57
Never report cleanup as verified without evidence
ccheng555 ce3a15e
Never signal a process whose ownership cannot be established
ccheng555 5f27c1a
Give every persisted ownership record exactly one writer
ccheng555 03eac6e
Let a cancel tombstone outlive the pass that wrote it, and let absent…
ccheng555 3f95424
Refuse a process group whose leader identity no longer matches
ccheng555 19ac644
Tie stream ownership to the turn rather than to its client socket
ccheng555 6e8659b
[CC-5571] Make detached test helpers self-expire
ccheng555 9d0b378
[CC-5576] Close crash cleanup and spawn failure gaps
ccheng555 8cec19f
[CC-5219] register broker ownership for safe cleanup
ccheng555 8fbd958
[CC-5219] fix registered reaper review findings
ccheng555 7f3094a
[CC-5219] close terminal ownership gaps
ccheng555 58c1ea3
[CC-5589] make automatic broker launch transactional
ccheng555 328bdd5
[CC-5589] close broker ownership activation races
ccheng555 4e8884b
[CC-5589] close helper ownership and registry retirement gaps
ccheng555 ec40de8
[CC-5589] fail closed on observation contention
ccheng555 4f6a87f
[CC-5589] constrain observed cleanup authority
ccheng555 d179455
[CC-5589] Bind broker locks and owner publication to process identity
ccheng555 d735a66
[CC-5589] Close late orphan lifecycle races
ccheng555 00015e3
[CC-5589] Bound detached test broker lifetime
ccheng555 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,87 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import fs from "node:fs"; | ||
| import process from "node:process"; | ||
| import { spawn } from "node:child_process"; | ||
|
|
||
| const activation = fs.createReadStream(null, { fd: 3, autoClose: true }); | ||
| let activated = false; | ||
| let activationBuffer = ""; | ||
| let child = null; | ||
|
|
||
| function exitWithoutChild(code = 1) { | ||
| if (child || process.exitCode != null) { | ||
| return; | ||
| } | ||
| process.exitCode = code; | ||
| process.stdin.resume(); | ||
| } | ||
|
|
||
| function startAppServer() { | ||
| if (activated || child) { | ||
| return; | ||
| } | ||
| activated = true; | ||
| child = spawn("codex", ["app-server"], { | ||
| cwd: process.cwd(), | ||
| env: process.env, | ||
| detached: false, | ||
| stdio: ["pipe", "pipe", "pipe"], | ||
| shell: process.platform === "win32" ? (process.env.SHELL || true) : false, | ||
| windowsHide: true | ||
| }); | ||
| child.stdout.pipe(process.stdout); | ||
| child.stderr.pipe(process.stderr); | ||
| process.stdin.pipe(child.stdin); | ||
| child.on("error", (error) => { | ||
| process.stderr.write(`Unable to start codex app-server: ${error.message}\n`); | ||
| process.exit(1); | ||
| }); | ||
| // `close` follows both process exit and stdio closure, so the wrapper does | ||
| // not truncate the JSONL stream while forwarding the child's final bytes. | ||
| child.on("close", (code, signal) => { | ||
| process.exit(Number.isInteger(code) ? code : signal ? 1 : 0); | ||
| }); | ||
| } | ||
|
|
||
| activation.setEncoding("utf8"); | ||
| activation.on("data", (chunk) => { | ||
| if (activated) { | ||
| return; | ||
| } | ||
| activationBuffer += chunk; | ||
| const newlineIndex = activationBuffer.indexOf("\n"); | ||
| if (newlineIndex === -1) { | ||
| return; | ||
| } | ||
| if (activationBuffer.slice(0, newlineIndex).trim() !== "activate") { | ||
| exitWithoutChild(1); | ||
| return; | ||
| } | ||
| startAppServer(); | ||
| }); | ||
| activation.on("end", () => { | ||
| if (!activated) { | ||
| exitWithoutChild(1); | ||
| } | ||
| }); | ||
| activation.on("error", () => { | ||
| if (!activated) { | ||
| exitWithoutChild(1); | ||
| } | ||
| }); | ||
|
|
||
| process.stdin.on("end", () => { | ||
| if (!activated) { | ||
| exitWithoutChild(1); | ||
| return; | ||
| } | ||
| child?.stdin.end(); | ||
| }); | ||
| process.stdin.on("error", () => { | ||
| child?.stdin.destroy(); | ||
| }); | ||
| // Keep protocol bytes buffered until activation has created the real app | ||
| // server and its stdin pipe. Flowing stdin here can discard an initialize | ||
| // request that races the activation-control pipe. | ||
| process.stdin.pause(); |
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.
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.
When a background worker falls back to a direct app-server and is killed abruptly after that detached app-server or a helper starts, this persists only the worker's identity. Cancel and SessionEnd later invoke
terminateProcessTreewith no ownership snapshot; once the worker PID is absent, cleanup reports verified without any way to rediscover its reparented direct child, allowing the app-server/helper to survive while the job record is removed. Persist worker-observed direct-child ownership or keep the direct child attached so an abnormal worker exit can be recovered.Useful? React with 👍 / 👎.