fix(persistence): preserve subclass dump hooks

This commit is contained in:
jinli.yl 2026-08-26 16:29:49 +08:00
parent 65f3bc3ef2
commit d4cc454c78
2 changed files with 34 additions and 2 deletions

View file

@ -103,8 +103,12 @@ class LocalFileStore(BaseFileStore):
# Dependencies are closed separately by Application (reverse
# topological order) or BaseComponent (owned standalone dependencies).
# Persist only this store's local state here so each component writes
# exactly once during shutdown.
await self._dump_owned_state()
# exactly once during shutdown. Preserve the historical dump() hook for
# third-party subclasses that override it to write additional state.
if type(self).dump is LocalFileStore.dump:
await self._dump_owned_state()
else:
await self.dump()
self.file_chunks.clear()
await super()._close()

View file

@ -319,6 +319,34 @@ def test_close_persists_each_component_once(monkeypatch):
run(go())
def test_close_preserves_subclass_dump_override():
"""Third-party stores using the historical dump hook still persist sidecars."""
class SidecarFileStore(LocalFileStore):
"""Local store extension that persists an additional sidecar."""
def __init__(self):
super().__init__(name="t_sidecar_dump", embedding_store="")
self.dump_calls = 0
self.sidecar_path = self.component_metadata_path / "sidecar.txt"
async def dump(self) -> None:
self.dump_calls += 1
await super().dump()
self.sidecar_path.write_text("persisted", encoding="utf-8")
async def go():
with tempfile.TemporaryDirectory() as tmp, temp_chdir(tmp):
store = SidecarFileStore()
await store.start()
await store.close()
assert store.dump_calls == 1
assert store.sidecar_path.read_text(encoding="utf-8") == "persisted"
run(go())
def test_start_does_not_health_check_embedding_without_backfill():
"""Hot startup keeps local vector retrieval independent of provider health."""