Repository navigation
fix(rpc): live-owner scan past dead wrappers (rework of #302, reduced scope) #559
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3885,13 +3885,39 @@ export async function startRpcSession( | |
| // omp >= 18.5 lets only one process own a session file; a second `--resume` | ||
| // child would fork into a new nested session on its first write. Reuse the | ||
| // live wrapper that already reports this file (e.g. after it moved files). | ||
| if (sessionFile && !existing) { | ||
| // A dead keyed wrapper must not skip this scan: it owns nothing anymore, | ||
| // and a live wrapper under another key may already own this file. | ||
| if (sessionFile && (!existing || !existing.isAlive())) { | ||
| for (const candidate of new Set(registry.values())) { | ||
| if (candidate.isAlive() && candidate.sessionFile && samePath(candidate.sessionFile, sessionFile)) { | ||
| registry.set(sessionId, candidate); | ||
| notifyRunningChange({ refreshSessionList: true }); | ||
| return { session: candidate, realSessionId: candidate.sessionId }; | ||
| if (!candidate.isAlive() || !candidate.sessionFile || !samePath(candidate.sessionFile, sessionFile)) continue; | ||
| // The scan must not silently reuse a live owner whose spawn-time | ||
| // --advisor flag the caller just toggled: apply the same gate as the | ||
| // keyed path above (unknown legacy flag, no opinion, busy child, or an | ||
| // unreplaceable host-owned child all reuse; an idle mismatch replaces). | ||
| const candidateEffectiveAdvisor = advisor === true || candidate.launchAdvisor === true; | ||
| const reuseCandidate = advisor === undefined | ||
| || (candidate.adopted && !candidate.hostOwnedLifecycle) | ||
| || candidate.advisorSpawned === candidateEffectiveAdvisor | ||
| || candidate.isRunning() | ||
| || candidate.isEditingHistory() | ||
| || (candidate.hostOwnedLifecycle && !candidate.canReplaceAdvisor()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply the replacement-readiness check to local owners too. After terminal Reuse any candidate for which
|
||
| if (!reuseCandidate) { | ||
| if (candidate.hostOwnedLifecycle) { | ||
| replacement = await candidate.replaceAdvisorIfIdle(launch, preparingCommand) ?? undefined; | ||
| if (replacement) break; | ||
| // The daemon could not replace it: keep the live owner, as the | ||
| // keyed path does when its replacement comes back null. | ||
| } else { | ||
| // Replace the mismatched owner instead of spawning beside it: a | ||
| // second --resume child would fork into a nested session. | ||
| await candidate.destroyAndWait("advisor", true); | ||
| if (candidate.destroyPromise) await untilHostDown(candidate.host, candidate.destroyPromise); | ||
|
Comment on lines
+3913
to
+3914
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make a start wait for a disposing owner before it spawns. The live-owner scan awaits A start must wait for any disposing candidate on the same session file before it reaches the spawn, so only one child can write that file.
|
||
| continue; | ||
| } | ||
| } | ||
| registry.set(sessionId, candidate); | ||
| notifyRunningChange({ refreshSessionList: true }); | ||
| return { session: candidate, realSessionId: candidate.sessionId }; | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Restrict candidate selection to the requested host.
If hosts A and B have the same absolute
sessionFilepath, this filter accepts A's owner for a request on B. On an advisor mismatch, Line 3906 replaces A's child. Startup then constructs the replacement wrapper with host B at Line 3945.Require
candidate.host.id === host.idbefore reusing or replacing a candidate. Path equality does not establish file identity across machines.