HDF5 trace metadata loses list types and cannot distinguish JSON-looking strings
Problem
HDF5 trace metadata does not round-trip list values. The exporter JSON-encodes non-scalar metadata, but the loader only decodes strings beginning with {. Lists, including empty and nested lists, are therefore returned as strings.
There is also an encoding ambiguity: a list and a literal JSON-looking string can have identical stored HDF5 attributes, so treating every [-prefixed string as a list would corrupt a valid string value.
Reproduced on main at cb49662150aa794149d477379c605a3bff0c08a2, Python 3.12.13, h5py 3.16.0, NumPy 2.5.4, macOS arm64.
Minimal reproduction
With OpenEvolve and optional h5py installed:
import tempfile
from pathlib import Path
import h5py
from openevolve.utils.trace_export_utils import export_traces, load_traces
metadata = {"labels": ["alpha"], "literal": '["alpha"]'}
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / "trace.h5"
export_traces([{"iteration": 1}], path, format="hdf5", metadata=metadata)
with h5py.File(path, "r") as file:
attrs = file["metadata"].attrs
print(repr(attrs["labels"]), repr(attrs["literal"]))
print(attrs["labels"] == attrs["literal"])
_, loaded = load_traces(path)
print(type(loaded["labels"]).__name__, repr(loaded["labels"]))
print(type(loaded["literal"]).__name__, repr(loaded["literal"]))
Actual output:
'["alpha"]' '["alpha"]'
True
str '["alpha"]'
str '["alpha"]'
Expected: labels remains a list while literal remains a string. I also reproduced the list-to-string conversion for [] and a nested list containing a dictionary. Scalar/object metadata and non-JSON bracket-prefixed strings are unaffected in these checks.
Compatibility question
An encoding tag/version seems necessary to preserve these types without guessing from string contents. What format/compatibility approach would you prefer, especially for existing files whose two values are indistinguishable? I can prepare a focused fix and real-file regression tests once that direction is clear.
Reproduced with AI assistance against the production export/load entry points and real HDF5 persistence; no LLM/provider calls or mocked file operations.