Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "validmind"
version = "2.13.12"
version = "2.13.13"
description = "ValidMind Library"
readme = "README.pypi.md"
requires-python = ">=3.9,<3.15"
Expand Down
2 changes: 1 addition & 1 deletion r/validmind/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: validmind
Type: Package
Title: Interface to the 'ValidMind' Platform
Version: 2.13.12
Version: 2.13.13
Authors@R: c(person("Andres", "Rodriguez", role = c("aut", "cre","cph"),
email = "andres@validmind.ai"))
Maintainer: Andres Rodriguez <andres@validmind.ai>
Expand Down
29 changes: 29 additions & 0 deletions tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,35 @@ async def test_test_result_log_async(
mock_test_result.assert_called_once()
mock_metric.assert_called_once()

@patch("validmind.vm_models.result.result.update_metadata")
@patch("validmind.api_client.alog_test_result")
@patch("validmind.api_client.alog_figure")
async def test_test_result_log_async_pre_serializes_figures(
self, mock_figure, mock_test_result, mock_update_metadata
):
"""Figure PNGs are rendered before any upload request starts"""
mock_test_result.return_value = MockAsyncResponse(200, json={"cuid": "123"})
mock_update_metadata.return_value = None
cached_at_upload = []

async def record(figure):
cached_at_upload.append(figure._cached_png_bytes is not None)
return MockAsyncResponse(200, json={"cuid": "456"})

mock_figure.side_effect = record

fig, ax = plt.subplots()
ax.plot([1, 2], [3, 4])
test_result = TestResult(
result_id="test_1",
figures=[Figure(key="fig_1", figure=fig, ref_id="ref_1")],
)

await test_result.log_async(section_id="section_1", position=0)

self.assertEqual(cached_at_upload, [True])
plt.close(fig)

def test_text_generation_result(self):
"""Test TextGenerationResult initialization and methods"""
text_result = TextGenerationResult(
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion validmind/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.13.12"
__version__ = "2.13.13"
19 changes: 15 additions & 4 deletions validmind/vm_models/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,18 @@ def serialize(self):

return serialized

def _pre_serialize_figures(self):
"""Render figure PNGs before any upload request starts.

Kaleido launches a Chromium per figure and blocks the event loop while it
runs. Rendering while uploads are in flight lets the request timeout
expire on them, and with older kaleido it conflicted with asyncio
outright (ZD-626). log() calls this outside the loop; log_async() calls
it too because the test-suite runner awaits log_async() directly.
"""
for figure in self.figures or []:
figure.pre_serialize()

async def log_async(
self,
section_id: str = None,
Expand All @@ -553,6 +565,8 @@ async def log_async(
if self._is_scorer_result:
return

self._pre_serialize_figures()

tasks = [] # collect tasks to run in parallel (async)

# Default empty dict if None
Expand Down Expand Up @@ -680,10 +694,7 @@ def log( # noqa: C901
if section_id:
self._validate_section_id_for_block(section_id, position)

# Pre-serialize figures before entering async context to avoid conflicts
# between Plotly's kaleido library and asyncio event loops (ZD-626)
for figure in self.figures or []:
figure.pre_serialize()
self._pre_serialize_figures()

run_async(
self.log_async,
Expand Down
Loading