Repository navigation
fix(link): settle a gaining link from its pidfile when a reload restarts it, and let every pidfile removal fail softly - #8626
Merged
lidge-jun merged 4 commits intoNov 13, 2026
Conversation
…every pidfile removal fail softly A reload that both changed a one-route link's record (a new listener port, say) and gave it routes skipped the gained-routes pidfile check, so an unflagged link with no child could start a candidate while an earlier ssh held the port. Such a link now settles from its pidfile, observe-only, with the flagged changed links. The conditional removal after a tunnel's exit or stop and the one-route startup removal now go through the same warning helper as the orphan removals, so a failed removal no longer aborts a tick, an exit's classification, a stop, a reload or the start. Readable and removable pidfiles are handled exactly as before. Refs #8609
…ops its unproven child A one-route link whose pidfile write failed keeps its child registered and the older pidfile in place, which may name an earlier live ssh. When a reload gave such a link routes, with or without a record change, it stopped the child and started rounds without reading that pidfile. Every link that goes from one route to several through a restart now settles from its pidfile, observe-only, after the stop. A test also covers the tick that stops an unrecorded child when the removal of its pidfile fails. Refs #8609
Contributor
|
Caution Review failedThe pull request is closed.
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. |
Contributor
|
✅ Deterministic PR hygiene checks passed. |
lidge-jun
marked this pull request as ready for review
November 13, 2026 03:36
lidge-jun
deleted the
fix/link-orphan-reload-instance-and-pidfile-removal
branch
November 13, 2026 03:36
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Nov 13, 2026
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.
Summary
The last follow-up to #8621 (issue #8609), from the final review of that PR. A Remote Link with several routes must never start a route candidate while an earlier ssh tunnel of it may still run. The Home supervisor flags such links
orphan-unverifiedand watches the process named in the link's pidfile.A link that gained routes during a restart skipped its pidfile. #8621 made a one-route link that gains routes settle from its pidfile even without a flag. A reload sends some links through its restart path instead of the gained-routes check, and those links were never checked:
createdAt, tunnel port and the store-wide listener port, so this includes a link that one reload gave both a new listener port and routes.After such a reload the link's rounds started without the pidfile being read. That matters most when a one-route spawn's pidfile write failed: the child is registered before the write, so the older pidfile stays in place and may name an earlier live ssh. Every link that goes from one route to several through a restart now settles from its pidfile, observe-only (no signal, no removal: the rule for a replaced record), after the reload has stopped its child. Only a child in the connected state, which the link adopts as its tunnel, skips the check. That behaviour is unchanged, and
structure/remote-link.mdnotes that for a one-route tunnel the connected state is the grace or catalog heuristic, so it does not prove the forward is held.Every pidfile removal now fails softly. #8621 made the orphan removals warn instead of throw. The removals of this Home's own pidfiles still threw on anything other than ENOENT (a read-only directory, an immutable flag, a Windows sharing lock):
start().conditionalRemovePidfileand the one-route startup removal now go through the samedropStalePidfilehelper, which logs[link] stale pidfile could not be removed link=<id>and goes on. The read and the condition (the pidfile names this link and this child) are unchanged, so a readable, removable pidfile is handled exactly as before; a test pins that.Comments and docs. The helper's comment no longer calls a leftover pidfile harmless without qualification. On Linux with a start time the next start sees its process gone; without a start time, a pid reused by another process blocks a multi-route link at the next start until that process exits.
structure/remote-link.mdnow says a process with a proven identity is signalled at startup, when a reload adds the link or gives it routes, or on a later tick once an unreadable pidfile becomes readable. It also covers the new removal sites and the restart-path check. The guide has no sentence about signalling, so it is unchanged.What keeps this inert. Behaviour changes only when a pidfile removal fails, or when a reload gives a one-route link routes through its restart path; the latter costs one pidfile read, and a link without a pidfile is unaffected. One-route links still spawn, clear their flag and overwrite their pidfile as before, which is the documented one-route exception. No configuration or default changes.
Verification
Tests written first in
tests/clients/link-route-supervisor.test.ts. The harness's pidfile-write option now receives the path and the pidfile, so a test can read back what the supervisor wrote. Withsrc/link/supervisor.tsput back todev(ad3eb91), the final test file gives 66 pass and 8 fail:a reload that changes an unflagged one-route link's record and gives it routes still checks its pidfile: ondevthe link is not flagged.a one-route link whose pidfile write failed and that gains routes while it changes its record in the same reload / keeps its record settles from the older pidfile once its tunnel is stopped: started without a tick. Ondevthe link is not flagged.a one-route startup that stops an earlier ssh whose pidfile cannot be removed still starts the link: ondev, EACCES escapesstart().a one-route / multi-route tunnel exit whose pidfile cannot be removed is still classified: ondevthe removal error escapes and the exit is not classified.a reload that stops a one-route link whose pidfile cannot be removed still completes: ondevthe reload rejects.a one-route tunnel stopped by the tick after its pidfile write failed survives a pidfile that cannot be removed: ondevthe removal error escapes the tick.a one-route exit removes exactly its own pidfile once: pins existing behaviour, so it passes ondevand on this branch.The tick branch that stops a failed link's running child can be reached: after a one-route pidfile write fails, the link is failed with a running child. The last test above covers that branch.
Commands (exit codes):
TMPDIR=/tmp bun scripts/test.ts --parallel=2 tests/clients/link-route-supervisor.test.ts tests/clients/link-supervisor.test.ts tests/clients/link-boundary.test.ts tests/ci-workflows/structure-ssot.test.ts tests/ci-workflows/ci-structure-gate.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts: 205 pass, 0 fail (exit 0).bun run typecheck: exit 0.bun run privacy:scan: exit 0.bun run structure:check: exit 0.structure/remote-link.md:TMPDIR=/tmp bun scripts/test.ts --parallel=2 tests/clients tests/server/link-management-routes.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/structure-ssot.test.ts tests/ci-workflows/ci-structure-gate.test.ts tests/ci-workflows/file-size-ratchet.test.ts(206 files): 3558 pass, 67 skip, 3 fail (exit 1). The 3 failures are the Rust ocx-child tests (tests/clients/link-ocx-child-e2e.test.ts, two cases, and the Rust case oftests/clients/link-ocx-child-conformance.test.ts). They stop before any test code runs, becausecargoon the build machine has no default rustup toolchain. This branch touches no Rust code.NOT RUN: the full
bun run testsuite (the build machine allows focused files only; CI covers the rest); the three Rust ocx-child tests above (no toolchain); Windows and macOS. A Windows sharing lock is the case the removal fix covers, exercised here through an injected EACCES.Review: four read-only rounds by one independent reviewer (gpt-6.1-terra, xhigh effort), continued across rounds.
The reviewer also confirmed that the observe-only re-check never signals, and that readable, removable pidfiles are handled as before.
Checklist