fix(k1): refresh stale endpoint before start

This commit is contained in:
DCCONSTRUCTIONS
2026-08-14 16:27:03 +03:00
parent 9ef115d3b4
commit 9e6b5b403a
2 changed files with 129 additions and 0 deletions
@@ -3188,6 +3188,60 @@ class XgridsK1CompatibilityService:
"маршрут K1 изменился во время контрольной проверки"
)
supervisor = self._connection_supervisor.snapshot()
if (
path.available
and path.route_class == "direct"
and observed_epoch == binding.host_path_epoch
and supervisor.host_path.epoch == binding.host_path_epoch
and supervisor.endpoint.target == target
and supervisor.endpoint.intent_id == binding.intent_id
and supervisor.endpoint.host_path_epoch == binding.host_path_epoch
and supervisor.endpoint.reason_code == "endpoint-observation-stale"
):
# Project preparation can legitimately outlive the supervisor's
# TCP silence lease while the exact MQTT control proof remains
# fresh. Refresh only that expired read-only endpoint fact before
# the physical START admission. This is not a command retry: no
# operation or physical ledger row exists yet. A second route
# sample binds the TCP result to the same host/association epoch;
# any changed path or unreachable broker still fails closed.
endpoint = _probe_control_endpoint_socket(binding.target_ipv4)
final_path = self._sample_host_path(
binding.target_ipv4,
association_timeout_seconds=COMMAND_BOUND_ASSOCIATION_TIMEOUT_SECONDS,
)
final_epoch = self._connection_supervisor.observe_host_path_if_current(
expected_intent_id=binding.intent_id,
expected_target=target,
expected_host_path_epoch=binding.host_path_epoch,
result=final_path,
)
path_unchanged = bool(
final_epoch == binding.host_path_epoch
and final_path.available
and final_path.route_class == "direct"
and final_path.fingerprint == path.fingerprint
and final_path.interface == path.interface
and final_path.source_ipv4 == path.source_ipv4
and final_path.kernel_route_fingerprint == path.kernel_route_fingerprint
)
if final_epoch == binding.host_path_epoch:
self._connection_supervisor.observe_endpoint_if_current(
target=target,
intent_id=binding.intent_id,
host_path_epoch=binding.host_path_epoch,
reachable=endpoint.reachable and path_unchanged,
reason_code=(
None
if endpoint.reachable and path_unchanged
else endpoint.reason_code
if not endpoint.reachable
else "host-path-changed-during-tcp-probe"
),
)
path = final_path
observed_epoch = final_epoch
supervisor = self._connection_supervisor.snapshot()
path_is_current = bool(
not supervisor.closed
and path.available