From 57b4818b8b720d25a17b409e78c8ef8f95185d9e Mon Sep 17 00:00:00 2001 From: harshajv7981 <87539405+harshajv7981@users.noreply.github.com> Date: Fri, 23 Oct 2026 10:36:10 +0530 Subject: [PATCH] fix(database): decode small bytes artifacts in get_artifacts store_artifacts encodes bytes as {"__bytes__": } but get_artifacts decoded with plain json.loads, so small bytes artifacts came back as dicts. Use the existing _artifact_deserializer as the object_hook. Fixes #536 --- openevolve/database.py | 4 +++- tests/test_artifacts.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/openevolve/database.py b/openevolve/database.py index f06786cf48..bcaad6b603 100644 --- a/openevolve/database.py +++ b/openevolve/database.py @@ -2660,7 +2660,9 @@ def get_artifacts(self, program_id: str) -> Dict[str, Union[str, bytes]]: # Load small artifacts from JSON if program.artifacts_json: try: - small_artifacts = json.loads(program.artifacts_json) + small_artifacts = json.loads( + program.artifacts_json, object_hook=self._artifact_deserializer + ) artifacts.update(small_artifacts) except json.JSONDecodeError as e: logger.warning(f"Failed to decode artifacts JSON for program {program_id}: {e}") diff --git a/tests/test_artifacts.py b/tests/test_artifacts.py index 5ccbce55f9..0095f2a718 100644 --- a/tests/test_artifacts.py +++ b/tests/test_artifacts.py @@ -90,6 +90,15 @@ def test_store_small_artifacts(self): program = self.database.get(self.program.id) self.assertIsNotNone(program.artifacts_json) + def test_store_small_bytes_artifacts(self): + """Test that small bytes artifacts round-trip as bytes""" + artifacts = {"blob": b"\x00\x01binary"} + + self.database.store_artifacts(self.program.id, artifacts) + + retrieved = self.database.get_artifacts(self.program.id) + self.assertEqual(retrieved, artifacts) + def test_store_large_artifacts(self): """Test storing large artifacts to disk""" large_content = "x" * (50 * 1024) # 50KB