Skip to content

Avoid consuming one-shot helper iterables - #1838

Open
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/helper-telemetry-generator-exhaustion
Open

Avoid consuming one-shot helper iterables#1838
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/helper-telemetry-generator-exhaustion

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Prevent SDK helper telemetry from consuming one-shot Iterable request parameters before they are serialized.

The Messages APIs accept Iterable values for messages and tools. stainless_helper_header() currently iterates both collections to discover helper tags before request-body transformation runs. When a caller supplies a generator, telemetry exhausts it first, so the actual request can lose its messages or tools entirely.

Fix

Restrict helper-tag collection to safely replayable Sequence inputs. Lists, tuples, and other replayable sequences continue to contribute helper telemetry. Arbitrary iterables such as generators are left untouched so request serialization remains the first consumer.

Regression coverage

Adds tests verifying that generator-backed messages and tools survive into the actual JSON request body, while normal list-backed helper telemetry continues to work.

The production change is confined to Anthropic's hand-maintained _stainless_helpers.py path.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 16, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant