fix(feishu): tolerate malformed dedup timestamps

Salvages @Es1la's PR #13632 — a non-numeric timestamp in the persisted
feishu dedup state crashed adapter startup with ValueError/TypeError
from the unguarded float() call. Wrap the float() conversion in
try/except; skip the bad key and keep loading the rest.

The original PR also restructured existing TestDedupTTL tests to use
tempfile.TemporaryDirectory + HERMES_HOME patching — that was
test-hygiene scope creep unrelated to the bug. Kept only the
malformed-timestamp fix and added a focused regression test.
This commit is contained in:
Es1la 2026-05-05 08:47:46 -07:00 committed by Teknium
parent 77a102b7de
commit a877c3f6d9
2 changed files with 39 additions and 1 deletions

View file

@ -3197,6 +3197,37 @@ class TestDedupTTL(unittest.TestCase):
with patch.object(adapter, "_persist_seen_message_ids"):
self.assertFalse(adapter._is_duplicate("om_old"))
@patch.dict(os.environ, {}, clear=True)
def test_load_tolerates_malformed_timestamp_values(self):
"""Regression #13632 — a non-numeric timestamp in the persisted
dedup state must not crash adapter startup. The bad key is
skipped; the rest of the state loads.
"""
import tempfile
from gateway.config import PlatformConfig
from gateway.platforms.feishu import FeishuAdapter
with tempfile.TemporaryDirectory() as temp_home:
with patch.dict(os.environ, {"HERMES_HOME": temp_home}, clear=True):
adapter = FeishuAdapter(PlatformConfig())
adapter._dedup_state_path.parent.mkdir(parents=True, exist_ok=True)
adapter._dedup_state_path.write_text(
json.dumps(
{
"message_ids": {
"om_good": time.time(),
"om_bad_str": "not-a-timestamp",
"om_bad_null": None,
}
}
),
encoding="utf-8",
)
adapter._load_seen_message_ids()
assert "om_good" in adapter._seen_message_ids
assert "om_bad_str" not in adapter._seen_message_ids
assert "om_bad_null" not in adapter._seen_message_ids
@patch.dict(os.environ, {}, clear=True)
def test_persist_saves_timestamps_as_dict(self):
from gateway.config import PlatformConfig