Skip to content

fix(link): keep the orphan checks working when a stale pidfile cannot be removed, and check a gained link's pidfile even without a flag - #8621

Merged
lidge-jun merged 2 commits into
devfrom
fix/link-orphan-pidfile-removal-and-gained-routes
Nov 13, 2026
Merged

lidge-jun merged 2 commits into
devfrom
fix/link-orphan-pidfile-removal-and-gained-routes

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

Last follow-up to #8616 (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-unverified, watches the process named in the link's pidfile, and since #8616 reads an unreadable pidfile again on every tick.

A pidfile that could not be removed stopped the tick. Once a watched process is gone, the supervisor removes its pidfile. That happens at two places: when a watch ends, and in the orphan reaper's gone-process branch, which the per-tick re-read, startup, gained routes and the reload of an added link all reach. A removal that failed with anything other than ENOENT (a read-only directory, an immutable flag, a Windows sharing lock) threw out of the tick, or out of start() or reload(). The rest of that tick's work was skipped for every link, and the link was left flagged with no watch and no re-read entry, so it stayed blocked until a restart. Both sites now call dropStalePidfile, which logs [link] stale pidfile could not be removed link=<id> and goes on. A pidfile whose process is gone is harmless: the next start finds the process gone again.

A link that gained routes without a flag skipped its pidfile. When a one-route link gains routes, the supervisor checked the pidfile only if the link was flagged. Since #8616 removing a link clears its flag. So a one-route link that was removed, added again, and failed to spawn (ssh missing, say) gained routes without any check, and its rounds could start while an earlier Home's ssh still held the port. The cost was refused forwards and 60 s rests until that ssh exited. Every gained link with no running child and no watch now settles from its pidfile, flagged or not. A link without a pidfile is unaffected (ENOENT), and a running child, including one adopted when the link gains routes, is never checked.

Docs. structure/remote-link.md now says that a process with a proven identity can be signalled at startup or on a later tick, once an unreadable pidfile becomes readable. It also describes the gained-routes check and the removal warning. The Remote Link guide's stale-tunnel bullet now says a link whose pidfile was deleted starts within a second "or when its retry is due", because the round starts at once only for an idle link. The guide's seven translated copies (fr, ja, ko, ru, tr, zh-cn, zh-tw) do not have this section yet, so only the English guide changes.

What keeps this inert. Only links with several routes are affected, and only when a pidfile removal fails or a link without a flag or running child gains routes. One-route links, the pidfile reader, configuration and defaults are unchanged.

Verification

Tests written first in tests/clients/link-route-supervisor.test.ts. The harness gained an option that makes pidfile removal throw EACCES. With src/link/supervisor.ts put back to dev (f7c2131), the final test file gives 62 pass and 3 fail; the three failures are the new tests below that are marked as failing on dev.

  • a stale pidfile that cannot be removed once its watched process is gone does not stop the tick: on dev, EACCES escapes the tick at the end of the watch.
  • a re-read pidfile naming a gone process that cannot be removed lifts the block and starts the round: on dev, EACCES escapes the tick from the orphan reaper.
  • a link that gains routes without a flag or a running child still has its pidfile checked (flagged at start, removed, re-added with ssh missing, given routes): on dev the link is not flagged.
  • a pidfile that becomes readable on a later tick is signalled there when its identity is proven, SIGKILL after the grace: pins existing behaviour that the doc now describes, so it passes on dev and on this branch.

Commands on the head (exit codes):

  • TMPDIR=/tmp bun test tests/clients/link-route-supervisor.test.ts tests/clients/link-supervisor.test.ts: 101 pass, 0 fail (exit 0).
  • bun run typecheck: exit 0.
  • bun run privacy:scan: exit 0.
  • bun run structure:check: exit 0.
  • 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, including tests/clients/link-boundary.test.ts): 3549 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 of tests/clients/link-ocx-child-conformance.test.ts). They stop before any test code runs, because cargo on the build machine has no default rustup toolchain. This branch touches no Rust code.

NOT RUN: the full bun run test suite (the build machine allows focused files only; CI covers the rest); the three Rust ocx-child tests above (no toolchain); the docs-site build (one sentence changed in the English guide); Windows and macOS (a Windows sharing lock is the case the removal fix covers, exercised here through an injected EACCES).

Review: two read-only rounds by one independent reviewer (gpt-6.1-terra, xhigh effort). Round 1 found two P2s, both in an optional 64 KiB cap on the pidfile read that this branch first added: one read call can return a short read, and the capped reader also fed the one-route startup path, where an oversized file would have read as no pidfile. The cap was removed in the second commit, and the pidfile reader is identical to dev. Round 2 found no P0–P3 on the head and ran the two supervisor test files there (101 pass).

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

…ink's pidfile even unflagged, and cap the pidfile read

A pidfile removal that failed (a read-only directory, a sharing lock) threw out of
the supervisor tick, skipped every other link's work that tick, and left the link
flagged with nothing to lift it. A stale pidfile whose process is gone is harmless,
so the failure is now warned and the tick goes on. A link that gains routes with no
running child now settles from its pidfile even without a flag, since removing a
link drops its flag. The strict pidfile read is capped at 64 KiB. Docs: signalling
a proven process can also happen on a later tick, and a link whose pidfile was
deleted starts within a second or when its retry is due.

Refs #8609
The cap was optional. One read call can return a short read, and the capped reader
also feeds the one-route startup path, where an oversized file would read as no
pidfile. The strict reader is back to reading the whole file, as on dev.

Refs #8609
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions github-actions Bot added the bug Something isn't working label Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun
lidge-jun marked this pull request as ready for review November 13, 2026 02:23
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 02:23
@lidge-jun
lidge-jun merged commit ad3eb91 into dev Nov 13, 2026
28 checks passed
@lidge-jun
lidge-jun deleted the fix/link-orphan-pidfile-removal-and-gained-routes branch November 13, 2026 02:23
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T02:25:56.364888Z 8d396b8 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant