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.
This commit is contained in:
kshitijk4poor
2026-09-03 04:44:06 +05:30
committed by kshitij
parent c79df9c4d9
commit c3bcd20899
2 changed files with 12 additions and 21 deletions
+6 -18
View File
@@ -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
+6 -3
View File
@@ -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