Skip to content

[SC-11676] Improve API timeout support to prevent timeouts with large datasets#411

Merged
juanmleng merged 2 commits intomainfrom
juan/sc-11676/improve-api-timeout-support-to-prevent-timeouts-with-large-datasets
Aug 8, 2025
Merged

[SC-11676] Improve API timeout support to prevent timeouts with large datasets#411
juanmleng merged 2 commits intomainfrom
juan/sc-11676/improve-api-timeout-support-to-prevent-timeouts-with-large-datasets

Conversation

@juanmleng
Copy link
Contributor

@juanmleng juanmleng commented Aug 7, 2025

Pull Request Description

What and why?

What

  • Added configurable batching for figure uploads via VM_FIGURE_MAX_BATCH_SIZE environment variable (defaults to 20 figures per batch)
  • Made API request timeout configurable via VM_API_TIMEOUT environment variable (defaults to 30 seconds)

Why

  • Test results with many figures (e.g., 20+ plots) could cause depending on the network environment timeouts issues when uploaded simultaneously. Batching prevents overwhelming the API.
  • Sequential batch processing with concurrent uploads within each batch provides a balance between speed and stability, reducing failed uploads due to resource constraints.
  • Configurable timeout and batch size allow users to adjust based on their network conditions without code changes.

How to test

  • Add the following code before importing validmind:
import os
os.environ["LOG_LEVEL"] = "DEBUG"
  • To reproduce a timeout error, set VM_API_TIMEOUT=5 in your .env and run the application_scorecard_full_suite.ipynb notebook.
  • To check the effect of batch processing, set VM_API_TIMEOUT=5 and VM_FIGURE_MAX_BATCH_SIZE=2 to avoid timeout errors.

What needs special review?

Dependencies, breaking changes, and deployment notes

Release notes

Checklist

  • What and why
  • Screenshots or videos (Frontend)
  • How to test
  • What needs special review
  • Dependencies, breaking changes, and deployment notes
  • Labels applied
  • PR linked to Shortcut
  • Unit tests added (Backend)
  • Tested locally
  • Documentation updated (if required)
  • Environment variable additions/changes documented (if required)

@juanmleng juanmleng self-assigned this Aug 7, 2025
@juanmleng juanmleng added the bug Something isn't working label Aug 7, 2025
Copy link
Contributor

@cachafla cachafla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2025

PR Summary

This PR introduces several functional improvements related to API logging and figure upload processing in the project. The key changes include:

  1. In the API client, the HTTP client timeout is now configurable via an environment variable (VM_API_TIMEOUT) instead of being hardcoded to 30 seconds. This allows dynamic adjustment of API call timeouts without code changes.

  2. A new decorator, log_api_operation, has been implemented in the logging module. This decorator enables function-level logging for API operations. It logs the operation (using a provided operation name or the function name) and supports the extraction of a key from the function arguments for more informative logs. The decorator activates only if the logging level is set to DEBUG (unless forced), aiming to reduce unnecessary logging in production.

  3. In the result module, the processing of figure uploads has been enhanced by breaking the figures into configurable batches. The batch size is determined by the environment variable (VM_FIGURE_MAX_BATCH_SIZE) with a default of 20, which allows better control over resource usage during the upload process. Each batch upload is wrapped with the new log_api_operation decorator to track the operation.

Overall, the changes aim to provide more flexibility and transparency in API operations and improve the handling of batch uploads for figures.

Test Suggestions

  • Verify that the API client session timeout correctly reads the value from the VM_API_TIMEOUT environment variable and falls back to 30 when not set.
  • Test the log_api_operation decorator to ensure it logs the operation name and extracted key correctly, particularly when the logger is in DEBUG mode.
  • Create tests for the alog_figure function to ensure that it is properly wrapped by log_api_operation and logs as expected.
  • Simulate different sizes of the figures list to confirm that batching works correctly with the batch size determined by VM_FIGURE_MAX_BATCH_SIZE.
  • Run tests with different log levels to ensure that the logging behavior changes appropriately when not in DEBUG mode.

Copy link
Contributor

@AnilSorathiya AnilSorathiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm 👍

@juanmleng juanmleng merged commit 60fdeaf into main Aug 8, 2025
7 of 8 checks passed
@juanmleng juanmleng deleted the juan/sc-11676/improve-api-timeout-support-to-prevent-timeouts-with-large-datasets branch August 8, 2025 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants