From 7534d8436ce35c26a41b2df95a96f21ae77c9847 Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Tue, 1 Sep 2026 22:19:02 +0100 Subject: [PATCH] fix(multiplayer): recover queue revision conflicts --- Game/scripts/control_plane_client.gd | 8 ++++++++ Game/tests/cases/test_control_plane_client.gd | 8 ++++++++ multiplayer-next.md | 2 ++ 3 files changed, 18 insertions(+) diff --git a/Game/scripts/control_plane_client.gd b/Game/scripts/control_plane_client.gd index 9efc1d56..fd9fa9b1 100644 --- a/Game/scripts/control_plane_client.gd +++ b/Game/scripts/control_plane_client.gd @@ -298,6 +298,10 @@ static func is_retryable_mutation_response(response_code: int) -> bool: return response_code == 0 or response_code == HTTPClient.RESPONSE_REQUEST_TIMEOUT or response_code == HTTPClient.RESPONSE_TOO_MANY_REQUESTS or response_code >= 500 +static func should_recover_queue_after_conflict(operation: String, response_code: int, ticket_id: String) -> bool: + return response_code == HTTPClient.RESPONSE_CONFLICT and operation in ["queue_heartbeat", "queue_cancel"] and not ticket_id.is_empty() + + static func normalize_ticket(payload: Dictionary) -> Dictionary: var result := payload.duplicate(true) if result.has("enqueued_at") and result["enqueued_at"] is String: @@ -373,6 +377,7 @@ func _on_request_completed(result: HTTPRequest.Result, response_code: int, _head _last_mutation_retryable = _last_mutation.get("operation", "") == operation and is_retryable_mutation_response(response_code) var detail := String(parsed.get("error", "request rejected")) var recover_proposal_after_conflict := response_code == HTTPClient.RESPONSE_CONFLICT and (operation == "proposal_accept" or operation == "proposal_decline") and not state.proposal_id.is_empty() + var recover_queue_after_conflict := should_recover_queue_after_conflict(operation, response_code, state.ticket_id) if response_code == HTTPClient.RESPONSE_UNAUTHORIZED: access_token = "" auth_expired = true @@ -396,6 +401,9 @@ func _on_request_completed(result: HTTPRequest.Result, response_code: int, _head if recover_proposal_after_conflict: _pending_resync_resource_id = state.proposal_id call_deferred("_run_pending_resync") + if recover_queue_after_conflict: + _pending_resync_resource_id = state.ticket_id + call_deferred("_run_pending_resync") return var payload: Dictionary = parsed _last_mutation_retryable = false diff --git a/Game/tests/cases/test_control_plane_client.gd b/Game/tests/cases/test_control_plane_client.gd index b527b0d2..665c4d37 100644 --- a/Game/tests/cases/test_control_plane_client.gd +++ b/Game/tests/cases/test_control_plane_client.gd @@ -99,6 +99,14 @@ func test_retryable_mutation_policy_only_retries_safe_failures() -> void: assert_true(not ControlPlaneClient.is_retryable_mutation_response(409), "revision/idempotency conflict is not blindly replayed") +func test_queue_revision_conflicts_schedule_authoritative_recovery() -> void: + assert_true(ControlPlaneClient.should_recover_queue_after_conflict("queue_heartbeat", 409, "ticket-1"), "stale heartbeat recovers the queue ticket") + assert_true(ControlPlaneClient.should_recover_queue_after_conflict("queue_cancel", 409, "ticket-1"), "stale cancellation recovers the queue ticket") + assert_true(not ControlPlaneClient.should_recover_queue_after_conflict("queue_create", 409, "ticket-1"), "create conflict uses its own idempotency path") + assert_true(not ControlPlaneClient.should_recover_queue_after_conflict("queue_heartbeat", 503, "ticket-1"), "transient outage remains retryable instead of being treated as a revision conflict") + assert_true(not ControlPlaneClient.should_recover_queue_after_conflict("queue_cancel", 409, ""), "missing ticket cannot trigger recovery") + + func test_assignment_endpoint_split_never_accepts_url_or_bad_port() -> void: var endpoint := ControlPlaneClient._split_assignment_endpoint("127.0.0.1:31001") assert_eq(endpoint["host"], "127.0.0.1", "assignment host is separated from the port") diff --git a/multiplayer-next.md b/multiplayer-next.md index bb7f2fa4..972ff880 100644 --- a/multiplayer-next.md +++ b/multiplayer-next.md @@ -1558,3 +1558,5 @@ All client resync entry points now apply the open-proposal boundary: a terminal Ticket projections now validate playlist metadata on every update, rejecting unknown values before either phase or playlist state can mutate. An adversarial higher-revision update test covers this boundary. Client sessions now fail closed at the expiry boundary and proactively clear credentials before reconnects or authenticated requests. Boundary and malformed-expiry tests cover the lifecycle guard. + +Queue heartbeat and cancellation revision conflicts now schedule the same authoritative ticket recovery as proposal conflicts, preventing stale client actions from leaving the visible queue state unresolved. Adversarial operation/status/identity coverage is included.