Repository navigation
Conversation
…dels ai 6 wraps v2 models in a Proxy whose get trap returns a fresh closure forwarding to the target on every read, with no set trap. Capturing that closure and assigning a wrapper landed the wrapper on the target while the closure still forwarded to it, recursing until the stack overflowed. The wrapper now calls the model's stored method instead, and the model passed to the operation — the proxy's target — is patched at the operation start, so the model-call span is still emitted.
Collaborator
|
Thanks for picking this up and for the clear write-up of the cause, @PCTEJA. We went with a different fix in #26941: the resolveLanguageModel hook returns a Proxy around the model instead of assigning onto it. That avoids writing to objects we don't own, so it doesn't need the descriptor walk or the extra guards, and it keeps the v4-only operation-start patch as it was. Closing this in favor of #26941. Appreciate the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes the
Maximum call stack size exceededcrash on everygenerateTextcall with ai 6 and a spec-v2 provider: the model-call patch now calls the model's storeddoGenerate/doStreaminstead of the forwarding closure ai 6'sasLanguageModelV3proxy returns, so patching through the proxy no longer recurses. The model-call span is still emitted, including for models reached only viaprepareStepor a string model id.Why
ai 6 wraps v2 models in a Proxy whose get trap returns a fresh closure forwarding to the target on every read, with no set trap — capturing that closure and assigning a wrapper landed the wrapper on the target while the closure still forwarded to it. The stored method is the real one (v2 providers define these as prototype methods), and the SDK still invokes the closure, which forwards to the wrapper.
Closes: #26905