Skip to content

pairing: Add retry logic to get_pairing_data to fix flaky test#664

Merged
cdecker merged 1 commit intomainfrom
2026w06-flaky-test_pairing_session
Feb 14, 2026
Merged

pairing: Add retry logic to get_pairing_data to fix flaky test#664
cdecker merged 1 commit intomainfrom
2026w06-flaky-test_pairing_session

Conversation

@cdecker
Copy link
Collaborator

@cdecker cdecker commented Feb 12, 2026

Summary

The test_pairing_session test was flaky due to a race condition in the pairing protocol.

Problem

The NewDeviceClient generates the device_id locally and sends it via the QR code channel before the PairDevice gRPC request reaches the server. When the AttestationDeviceClient immediately calls GetPairingData with that device_id, the session might not exist on the server yet, causing a KeyError.

The race happens because:

  1. The Rust client creates the gRPC request future but doesn't await it immediately
  2. It sends the QR data (containing device_id) to the channel first
  3. Only then does it await the actual gRPC call

Solution

Add retry logic to get_pairing_data in the AttestationDeviceClient that retries for up to 10 seconds with 100ms intervals. This handles the inherent race condition in the pairing protocol where the attestation device may receive the QR code before the new device's PairDevice request has been processed by the server.

Testing

Verified with flaky test plugin - passed 10 out of 10 runs:

pytest tests/test_pairing.py::test_pairing_session --force-flaky --max-runs=10 --min-passes=10

The test_pairing_session test was flaky due to a race condition in the
pairing protocol. The NewDeviceClient generates the device_id locally
and sends it via the QR code channel before the PairDevice gRPC request
reaches the server. When the AttestationDeviceClient immediately calls
GetPairingData with that device_id, the session might not exist yet.

This adds retry logic to get_pairing_data that retries for up to 10
seconds with 100ms intervals, handling the inherent race condition
in the pairing protocol.
@cdecker cdecker force-pushed the 2026w06-flaky-test_pairing_session branch from 2a35ca6 to e28f79d Compare February 13, 2026 16:57
@cdecker cdecker merged commit 3d69d9a into main Feb 14, 2026
12 checks passed
@cdecker cdecker deleted the 2026w06-flaky-test_pairing_session branch February 14, 2026 13:58
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