test(core): add a temporary workaround for UI tests flakiness on THP
What changed, and why it matters
This commit adds a short 0.1-second delay in a UI test helper when using a newer protocol version (THP/V2). It is a temporary test-only workaround to reduce flaky test failures caused by occasional lost screen-recording packets after an event loop restart. It does not change production firmware, wallet logic, or any security-critical code path.
No security action required. Treat as a routine test-stability patch.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is confined to tests/ui_tests/init.py. It imports time and ProtocolVersion, then before starting a DebugLinkRecordScreen session it sleeps 0.1 s if client.protocol_version is ProtocolVersion.V2. The comment explains the delay mitigates lost first packets following a THP event loop restart, which manifest as ‘FirmwareError: Invalid magic’ during test setup. The commit is marked [no changelog] and explicitly framed as a temporary workaround pending refactoring.
Changed components
tests/ui_tests/__init__.pyInspect captured patch +11 / −0
diff --git a/tests/ui_tests/__init__.py b/tests/ui_tests/__init__.py
index d684710a8..bd5f6fa03 100644
--- a/tests/ui_tests/__init__.py
+++ b/tests/ui_tests/__init__.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import logging
import shutil
+import time
import typing as t
from contextlib import contextmanager
@@ -10,6 +11,7 @@ from _pytest.nodes import Node
from _pytest.outcomes import Failed
from noise.exceptions import NoiseInvalidMessage
+from trezorlib.client import ProtocolVersion
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import ThpError
from trezorlib.transport import Timeout
@@ -59,6 +61,15 @@ def screen_recording(
shutil.rmtree(testcase.actual_dir, ignore_errors=True)
testcase.actual_dir.mkdir()
+ if client.protocol_version is ProtocolVersion.V2:
+ # In case of an event loop restart, it's possible that the first
+ # packet(s) of `DebugLinkRecordScreen` will be lost, resulting in
+ # `TrezorFailure: FirmwareError: Invalid magic` error responses
+ # during test setup.
+ # This issue will be resolved as part of THP event loop restart refactoring,
+ # but till then let's wait a bit here, to reduce the packet loss probability.
+ # TODO: remove after THP event loop restart refactoring
+ time.sleep(0.1)
try:
client.debug.start_recording(str(testcase.actual_dir))
yield
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.