Skip to content
Closed
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions src/agents/tracing/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ def _truncate_json_value_for_limit(self, value: Any, max_bytes: int) -> Any:
return self._truncate_string_for_json_limit(value, max_bytes)

if isinstance(value, dict):
# Avoid re-truncating our own truncated preview dicts, which
# would cause infinite recursion (the preview dict contains bool
# values that get wrapped into new preview dicts, and so on).
if value.get("truncated") is True and "original_type" in value and "preview" in value:
return value
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Narrow truncated-preview detection to SDK-generated shape

The early return in _truncate_json_value_for_limit now treats any dict with truncated=True, original_type, and preview as an internal preview object and skips truncation. If user-provided span data legitimately uses those keys and also contains large additional fields, root-level truncation returns the oversized dict unchanged, which can exceed _OPENAI_TRACING_MAX_FIELD_BYTES and cause export rejection or dropped tracing data. This check should only bypass truncation for SDK-created preview dicts (for example by requiring the exact key set or using a dedicated sentinel).

Useful? React with 👍 / 👎.

Comment on lines +302 to +303
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict preview bypass to SDK-owned objects

Fresh evidence: although this guard now also checks original_type and preview, it still short-circuits on any user-supplied dict that includes "__truncated_preview__": true and those keys. If that dict also contains large extra fields and exceeds _OPENAI_TRACING_MAX_FIELD_BYTES, _truncate_json_value_for_limit returns it unchanged instead of delegating to _truncate_mapping_for_json_limit, so sanitization can still emit oversized span fields that get rejected or dropped by trace ingestion.

Useful? React with 👍 / 👎.

return self._truncate_mapping_for_json_limit(value, max_bytes)

if isinstance(value, list):
Expand Down