Skip to content

fix(edge): load gateway env for caddy validate and reload on retry - #30

Merged
zyx1121 merged 2 commits into
mainfrom
fix/edge-caddy-env
Oct 12, 2026
Merged

zyx1121 merged 2 commits into
mainfrom
fix/edge-caddy-env

Conversation

@zyx1121

@zyx1121 zyx1121 commented Oct 12, 2026

Copy link
Copy Markdown
Member

Problem

domain_add sysmon.bensonho.winlab.tw (operation f628a636328fa94b07f9363bd631fe38) first failed with backend_unavailable, then reported ready on retry. HTTPS still failed with TLS alert 80 for more than 20 minutes.

The edge adapter (scripts/edge-agent.py) has 2 bugs:

  1. It runs caddy validate on CT 200 without the Caddy service's EnvironmentFile. The Cloudflare token is empty, so validation fails after carrel.Caddyfile and the certificates are already pushed.
  2. On retry, the files already match, so the adapter skips the reload and returns ok. Caddy never loads the new site.

The same failure hit Book on 2026-10-04 (operation 3784e4e2ba0b008b6ead56aa8cfab800).

Fix

  • Validate through systemd-run -p EnvironmentFile=/home/user/gateway/.env, the same environment as the service.
  • Keep a frontend.unloaded marker in /var/lib/carrel-edge until the reload succeeds. A retry reloads while the marker exists.

Verification

  • uv run pytest -q: 204 passed; ruff check and format pass.
  • The 2 new tests fail on main and pass with this change.
  • The new validate command on the live CT 200 prints Valid configuration, exit 0.

🤖 Generated with Claude Code

zyx1121 and others added 2 commits October 12, 2026 15:54
The edge adapter ran `caddy validate` on CT 200 without the Caddy
service's EnvironmentFile, so validation failed (empty Cloudflare token)
after carrel.Caddyfile and certificates were already pushed. A retry then
saw matching files, skipped the reload and reported the domain ready,
while Caddy never loaded the new site (TLS alert 80).

- Validate through systemd-run with the service EnvironmentFile.
- Keep a frontend.unloaded marker until reload succeeds, so a retry
  reloads even when the files already match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Touch the marker before pushing certificates and re-push while it
exists, so a half-pushed bundle or a renewal is reloaded on retry.
Apply the same marker to the CT 207 proxy reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zyx1121
zyx1121 merged commit eaa3f5c into main Oct 12, 2026
2 checks passed
@zyx1121
zyx1121 deleted the fix/edge-caddy-env branch October 12, 2026 07:59
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