fix(engine): store wg_pubkey right after addPeer so failed peers are cleanable

Keeps the wg_peer resource gated on a verified handshake (idempotency) while
ensuring PurgeHost can always remove the hub peer, even on terminal failure.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat/portal-design
nexxo 2026-07-25 11:07:41 +02:00
parent 9e664654a2
commit 294c9aef2f
1 changed files with 5 additions and 4 deletions

View File

@ -63,14 +63,15 @@ class ConfigureWireguard extends HostStep
$this->hub->addPeer($publicKey, $wgIp);
// Verify the tunnel BEFORE recording the peer as provisioned. If the
// handshake isn't up we retry and re-run the full setup next time (no
// wg_peer resource yet), instead of skipping a broken configuration.
// Store the pubkey now (so removal can always clean up the hub peer), but
// record the wg_peer resource only AFTER the handshake verifies — the
// idempotent short-circuit must not skip an un-verified configuration.
$host->update(['wg_pubkey' => $publicKey]);
if ($this->verifyHandshake()->type !== StepResult::ADVANCE) {
return StepResult::retry(15, 'WireGuard handshake not up yet');
}
$host->update(['wg_pubkey' => $publicKey]);
$this->recordResource($run, $host, 'wg_peer', $publicKey);
return StepResult::advance();