Skip to content

fix(pm-stack): harden pm-dispatch/pm-tunnel startup + tunnel watchdog, add outside dispatch probe (#6992) - #8391

Merged
dezren39 merged 2 commits into
mainfrom
queue/11451-6992-dispatch-hardening
Nov 11, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/11451-6992-dispatch-hardening

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Issue #6992 / task 11451 (lane code-j): harden pm-dispatch/pm-tunnel startup against network-not-ready, restart the tunnel when its edge connections stay down, and add the outside health probe.

Root cause (triage task 11437, re-verified live 2026-11-11): the dispatch app never emits 502 — the Cloudflare edge answers 502 while the tunnel has no live connector. The connector can be process-alive with zero live edge connections, so Restart=on-failure never fires and the outage is only noticed by the next scheduled consumer, a day later.

Changes (nixos/services/pm-stack/default.nix)

  • pm-dispatch: ExecStartPre waits (up to 180s, then starts anyway) for tailscale0 to carry an IPv4 address before the server binds DISPATCH_HOSTS — no more EADDRNOTAVAIL crash-loop at boot; ordered after tailscaled.service as well; TimeoutStartSec=300 to hold the wait.
  • pm-tunnel: ExecStartPre waits until the Cloudflare edge hostname resolves (local stub-resolver readiness at boot); cloudflared now runs with --metrics 127.0.0.1:20242 so its /ready endpoint is available locally.
  • pm-tunnel-watchdog (new service + 2-minute timer): reads the connector's own /ready; three consecutive failures restart pm-tunnel. Any success resets the counter.
  • Pre-NixOS unit files under pm-stack/systemd/ are historical (kept per the module header) and unchanged.

Outside probe (.github/workflows/dispatch-health-probe.yml)

Every 30 minutes from GitHub's network: GET https://dispatch.security.cab/health must be 200 and an unauthenticated POST /v1/sessions must get the app's own 401 (an edge 502/000 fails), 3 attempts over ~2 minutes. Failure opens or updates one meta/dispatch-probe alert issue; the next green run comments the recovery and closes it. Detection target: under an hour, per the packet.

Verification


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 01:31
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ac99bb28-e7f7-4379-8b4e-74be8efad3c6
Commits

Reviewing files that changed from the base of the PR and between d8c37d2 and dba5e00.

Files selected for processing: 3

  • .github/workflows/dispatch-health-probe.yml
  • doc/fleet-schedule-registry.md
  • nixos/services/pm-stack/default.nix
  • 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T02:43:50.922735Z dba5e00 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37d1fbe2d8

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +74 to +77
gh issue create \
--title "dispatch probe: dispatch.security.cab public path DOWN" \
--label meta/dispatch-probe \
--body "$body"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enqueue new probe alerts or document their queue exemption

When an outage occurs without an existing open alert, this branch files an issue but neither enqueues its triage packet nor explains why it is deliberately excluded from the queue. A persistent public-path outage therefore produces no worker task to investigate it; the standing queue reconciliation defaults to observe-only rather than guaranteeing repair. Enqueue the alert in the same pass, or record the deliberate exemption in its filing text, as required by the filing rule in AGENTS.md.

AGENTS.md reference: AGENTS.md:L62-L66

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in dba5e00 (shepherd commit by lane code-y, task 11451): the alert body the workflow files now records the deliberate exemption in the filing text itself, per the AGENTS.md filing rule — a GitHub Actions workflow has no path to the fleet queue backend, so the alert is not enqueued at filing time; the standing coverage reconciliation (scripts/fleet/queue-reconcile/) enqueues every open issue into repo-health-code-pilot, and the alert issue is the tracked item until it closes. Enqueueing from the workflow is not possible (the queue broker lives on the fleet laptop/Turso backend, unreachable from GitHub Actions), so the documented-exemption branch of the rule is the applicable one.

Comment on lines +593 to +595
OnBootSec = "2min";
OnUnitActiveSec = "2min";
Unit = "pm-tunnel-watchdog.service";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Register the new tunnel-watchdog timer

Enabling pm-stack now installs a recurring laptop systemd timer, but this change does not register it in doc/fleet-schedule-registry.md. Searching the registry for the timer name and tunnel aliases found no corresponding entry, so the new recurring work is invisible to the fleet placement inventory. Add its cadence and service pointer in the same change, as required by the Fleet schedules rule in AGENTS.md.

AGENTS.md reference: AGENTS.md:L53-L58

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in dba5e00: pm-tunnel-watchdog.timer is now registered in doc/fleet-schedule-registry.md Surface 2b (cadence OnUnitActiveSec=2min,OnBootSec=2min, activates pm-tunnel-watchdog.service, marked Nix-configured / not yet loaded, header counts updated). Same defect class in the same PR also fixed: the new dispatch-health-probe GitHub Actions workflow is registered in Surface 4.

Comment thread nixos/services/pm-stack/default.nix Outdated
# hostname resolves. On timeout start anyway (cloudflared keeps
# retrying internally; the watchdog below covers the rest).
for i in $(seq 1 90); do
if ${pkgs.glibc}/bin/getent hosts region1.v2.argotunnel.com >/dev/null 2>&1; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reference the getent output in the DNS readiness check

Every pm-tunnel start now waits the full 180 seconds even when DNS is healthy: ${pkgs.glibc} resolves to the library output, but the pinned glibc derivation moves bin/getent into a separate getent output, so this command always fails with its error suppressed. Besides never checking resolver readiness, this adds three minutes of downtime to every watchdog-triggered restart. Reference ${pkgs.glibc.getent}/bin/getent instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in dba5e00: waitForDns now calls ${pkgs.glibc.getent}/bin/getent. Verified against the pinned nixpkgs on the laptop: glibc has a getent output ((import <nixpkgs> {}).glibc.getent.name → "glibc-2.44-57"), and the module still parses (nix-instantiate --parse clean). The readiness check now actually probes DNS instead of always burning the 180s timeout.

repo-worker-code (lane code-j) added 2 commits November 10, 2026 20:40
…chedule registry, probe queue note (#6992)

P2: waitForDns used ${pkgs.glibc}/bin/getent, which never exists (getent is a separate glibc output) — every pm-tunnel start burned the full 180s wait. Use ${pkgs.glibc.getent}/bin/getent (verified: glibc has a getent output in the pinned nixpkgs).

P1: register pm-tunnel-watchdog.timer in doc/fleet-schedule-registry.md Surface 2b, and the dispatch-health-probe workflow in Surface 4 (same defect class, same rule).

P1: the probe alert issue now records why it is deliberately not enqueued at filing time (AGENTS.md filing rule): a GitHub Actions workflow has no path to the fleet queue backend; the standing coverage reconciliation enqueues every open issue.
@dezren39
dezren39 force-pushed the queue/11451-6992-dispatch-hardening branch from 37d1fbe to dba5e00 Compare November 11, 2026 02:41
@dezren39
dezren39 merged commit 6d03b82 into main Nov 11, 2026
3 of 9 checks passed
@dezren39
dezren39 deleted the queue/11451-6992-dispatch-hardening branch November 11, 2026 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant