From c3bcd208995f78aee6f5296f2a2ed0f9b9bfe7b5 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 3 Sep 2026 04:44:06 +0530 Subject: [PATCH] test(state): make the quarantine-guard test exercise the guard The seed put the retry deadline 900s in the future, so on unguarded code the method short-circuited on the backoff check and the protection assertions passed anyway; only the field-reset assertions failed. Seed the deadline in the past so a rebuild is due, and condense the guard comment. --- hermes_state_schema.py | 24 ++++++----------------- tests/state/test_fts_rebuild_admission.py | 9 ++++++--- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/hermes_state_schema.py b/hermes_state_schema.py index 58daf0ea95..f25e04afd8 100644 --- a/hermes_state_schema.py +++ b/hermes_state_schema.py @@ -682,24 +682,12 @@ class SessionSchemaMixin: if not getattr(self, "_fts_stale", False): return False if getattr(self, "_db_corrupt", False): - # Quarantined: structural corruption was already observed on - # this handle, so the only safe policy is to stop touching the - # file (mirrors hermes_state.py's _try_wal_checkpoint). A full - # FTS rebuild is real DDL/DML against the same damaged image — - # exactly what quarantine exists to prevent — and this method - # is called unconditionally every housekeeping tick for the - # life of a long-running gateway process, so a stale-FTS flag - # left set on a now-corrupt handle would otherwise retry the - # rebuild forever. - # - # Reset the backoff bookkeeping too (mirrors the success path's - # own reset a few lines down): no code path today clears - # _db_corrupt on a live handle, so this is inert in practice, - # but leaving a doubled _fts_stale_retry_interval sitting behind - # a flag nothing currently clears is a footgun for whoever adds - # an un-quarantine/recovery path later — the next real retry - # should start from the default backoff, not wherever this - # handle's interval happened to be when it was quarantined. + # Quarantined: never run FTS DDL/DML against a damaged image + # (mirrors _try_wal_checkpoint / close). This runs every + # housekeeping tick for the life of a gateway process, so a stale + # flag on a corrupt handle would otherwise retry the rebuild + # forever. Reset the backoff so any future un-quarantine path + # starts from the default interval, not a doubled stale one. self._fts_stale_retry_after = 0.0 self._fts_stale_retry_interval = 0.0 return False diff --git a/tests/state/test_fts_rebuild_admission.py b/tests/state/test_fts_rebuild_admission.py index 7af9330d6e..cac3ef1690 100644 --- a/tests/state/test_fts_rebuild_admission.py +++ b/tests/state/test_fts_rebuild_admission.py @@ -648,9 +648,12 @@ class TestDeferredFtsRetryInProcess: assert gw._fts_stale is True gw._db_corrupt = True gw._db_corrupt_reason = "database disk image is malformed" - # Simulate a handle that had already been backing off for a - # while before it tripped quarantine. - gw._fts_stale_retry_after = time.monotonic() + 900.0 + # A retry that is DUE (backoff already elapsed) on a handle that + # had been backing off before it tripped quarantine. Seeding the + # deadline in the past matters: a future deadline would make the + # unguarded code short-circuit on the backoff check and this test + # would pass without the quarantine guard ever being exercised. + gw._fts_stale_retry_after = time.monotonic() - 1.0 gw._fts_stale_retry_interval = 900.0 assert gw.retry_deferred_fts_recovery() is False # Untouched: still marked stale, triggers still absent — no