Fix synapse variable shadowing in dendrite_with_retries#83
Open
sniper-noob wants to merge 1 commit into
Open
Conversation
The loop `for i, synapse in enumerate(responses)` shadows the function parameter `synapse` (the original query TextSynapse). On retry attempts, the original query is lost and replaced with the last response from the previous iteration, sending corrupted data on retries.
Fix: Rename loop variable from `synapse` to `resp` to preserve the original parameter.
Example:
dendrite_with_retries(synapse=TextSynapse(texts=["hello"]), cnt_attempts=3)
Before (BUG):
Attempt 1: sends correct synapse -> responses come back
for i, synapse in enumerate(responses): # synapse param overwritten!
Attempt 2: sends responses[-1] instead of original query -> wrong data
After (FIX):
Attempt 1: sends correct synapse -> responses come back
for i, resp in enumerate(responses): # synapse param preserved
Attempt 2: sends original synapse again -> correct retry behavior
295d4a0 to
69c7464
Compare
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.
The loop variable synapse shadows the function parameter synapse. On retry attempts, the original query is lost and replaced with the last response from the previous iteration.
Fix: Rename loop variable from synapse to resp.
Example:
Before: synapse param gets overwritten by loop
for i, synapse in enumerate(responses): # overwrites param!
2nd retry: synapse is now responses[-1], not original query
After: param preserved
for i, resp in enumerate(responses): # param intact
2nd retry: synapse is still the original query