fix: post-loop fallback tests the latest poll, not "ever matched"

Review finding on #97: `statusReached` was sticky, so a guest that reached the
expected status once and then drifted away from it would still be reported as a
success at the deadline, contradicting the fallback's own meaning.

Track the most recent observation instead. A guest that drifts away and never
re-matches now raises PveTaskTimeoutException as it should. A failed poll leaves
the previous observation standing, so an API blip is not read as divergence.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
goodolclint-claude[bot]
2026-09-01 16:47:41 +00:00
committed by GitHub
parent 7e8cda9328
commit 70c147b47d
+5 -5
View File
@@ -131,7 +131,7 @@ namespace PSProxmoxVE.Cmdlets
: $"nodes/{Uri.EscapeDataString(node)}/qemu/{vmid}/status/current";
var deadline = DateTime.UtcNow.AddSeconds(timeoutSeconds);
var statusReached = false;
var lastMatched = false;
using var pollClient = new PveHttpClient(session);
while (DateTime.UtcNow < deadline)
{
@@ -139,11 +139,10 @@ namespace PSProxmoxVE.Cmdlets
{
var json = pollClient.GetAsync(statusResource).GetAwaiter().GetResult();
var snapshot = GuestStatusSnapshot.Evaluate(json, expectedStatus);
lastMatched = snapshot.StatusMatched;
if (snapshot.StatusMatched)
{
statusReached = true;
// PVE reports the target status before the operation releases the
// config lock. A caller that issues its next request inside that
// window gets "can't lock file '/var/lock/qemu-server/lock-<vmid>.conf'
@@ -160,8 +159,9 @@ namespace PSProxmoxVE.Cmdlets
System.Threading.Thread.Sleep(2000);
}
// Status reached and only the lock outlasted the deadline.
if (statusReached)
// The guest still reports the expected status on the final poll and only the
// lock outlasted the deadline.
if (lastMatched)
return task;
throw new PveTaskTimeoutException(