AutoGPT icon indicating copy to clipboard operation
AutoGPT copied to clipboard

fix: truncate large data in logging and switch info logs to debug

Open seer-by-sentry[bot] opened this issue 8 months ago β€’ 11 comments

πŸ‘‹ Hi there! This PR was automatically generated by Autofix πŸ€–

This fix was triggered by Nicholas Tindle.

Fixes AUTOGPT-SERVER-353. The issue was that: Oversized FillTextTemplateBlock output, included in untruncated JSON log fields, exceeded Google Cloud Logging's 256KB limit, causing an InvalidArgument.

  • Added a _truncate_large_data method to the LogMetadata class to truncate large data structures (dicts, lists, strings) before logging to prevent exceeding log limits.
  • Implemented truncation for info, warning, error, debug, and exception logging methods.
  • Changed log_metadata.info calls to log_metadata.debug in execute_node to reduce verbosity of logs.

If you have any questions or feedback for the Sentry team about this fix, please email [email protected] with the Run ID: 21640.

seer-by-sentry[bot] avatar Apr 09 '25 14:04 seer-by-sentry[bot]

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 09 '25 14:04 CLAassistant

This PR targets the master branch but does not come from dev or a hotfix/* branch.

Automatically setting the base branch to dev.

github-actions[bot] avatar Apr 09 '25 14:04 github-actions[bot]

Deploy Preview for auto-gpt-docs canceled.

Name Link
Latest commit 81c1fcbd689ceea0478eabc4e42ed6f5420d3f19
Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/680c8c3389074a000839ce5d

netlify[bot] avatar Apr 09 '25 14:04 netlify[bot]

Here's the code health analysis summary for commits 9715ea5..81c1fcb. View details on DeepSourceΒ β†—.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScriptβœ…Β SuccessView CheckΒ β†—
DeepSource Python LogoPythonβœ…Β Success
❗ 1 occurence introduced
🎯 1 occurence resolved
View CheckΒ β†—

πŸ’‘ If you’re a repository administrator, you can configure the quality gates from the settings.

deepsource-io[bot] avatar Apr 09 '25 14:04 deepsource-io[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 09 '25 14:04 github-actions[bot]

Conflicts have been resolved! πŸŽ‰ A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 10 '25 02:04 github-actions[bot]

Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
Latest commit 81c1fcbd689ceea0478eabc4e42ed6f5420d3f19
Latest deploy log https://app.netlify.com/sites/auto-gpt-docs-dev/deploys/680c8c33dd07720008f9977c

netlify[bot] avatar Apr 10 '25 02:04 netlify[bot]

This or something like it is very much needed! I keep running into this issue, whenever you use a files worth of data in an agent it's too big to be logging the entire thing.

Torantulino avatar Apr 16 '25 18:04 Torantulino

Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

PR Reviewer Guide πŸ”

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 πŸ”΅πŸ”΅βšͺβšͺβšͺ
πŸ§ͺΒ No relevant tests
πŸ”’Β No security concerns identified
⚑ Recommended focus areas for review

Truncation Limit

The truncation limit for lists is hardcoded to 100 items but doesn't consider the total size of those items. Large lists with small items might be fine, while small lists with large items could still exceed limits.

    return [self._truncate_large_data(v, max_size) for v in data[:100]]
elif isinstance(data, str) and len(data) > max_size:
Recursive Depth

The _truncate_large_data method is recursive without a depth limit, which could potentially cause stack overflow for deeply nested structures.

def _truncate_large_data(self, data, max_size=10000):
    if isinstance(data, dict):
        return {k: self._truncate_large_data(v, max_size) for k, v in data.items()}
    elif isinstance(data, list):
        return [self._truncate_large_data(v, max_size) for v in data[:100]]
    elif isinstance(data, str) and len(data) > max_size:
        return data[:max_size] + "... [truncated]"
    return data

qodo-code-review[bot] avatar Apr 16 '25 18:04 qodo-code-review[bot]

Reopening this as the fix is still relevant for other levels of errors. It's come up a few times.

Torantulino avatar Apr 16 '25 22:04 Torantulino

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar May 14 '25 19:05 github-actions[bot]