fix: extract multi-digit state indices in extract_state_value_from_output#2081
Open
Osamaali313 wants to merge 1 commit into
Open
fix: extract multi-digit state indices in extract_state_value_from_output#2081Osamaali313 wants to merge 1 commit into
Osamaali313 wants to merge 1 commit into
Conversation
…tput The regex matched a single digit and the matches were passed through set(), so a state index >= 10 (e.g. "10") was split into separate digits and an arbitrary one was returned, with the result order depending on set hashing (nondeterministic across runs). Role._think then read the wrong state and silently transitioned incorrectly, or looped, for any role with 10+ states. Match the first (optionally negative, multi-digit) integer and drop the set() dedup so the whole number is returned deterministically. Single-digit and "-1" outputs are unchanged. Adds a regression test.
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.
Problem
extract_state_value_from_outputis used byRole._thinkto read the next state index from an LLM's reply (role.py):Two issues:
>= 10is split into separate digits. Forcontent == "10"the result is"1"or"0"— never"10".list(set(matches))makes the choice order-dependent on set hashing, which varies withPYTHONHASHSEEDacross processes, so the returned digit is nondeterministic.Because the caller only validates
int(next_state) in range(-1, len(self.states)), a wrong-but-in-range digit passes silently, so any role with 10+ states can transition to the wrong state (or loop) without error.Fix
Match the first optionally-negative, multi-digit integer and drop the
set()dedup:Single-digit outputs and the
"-1"no-op state are unchanged; multi-digit indices are now returned whole and deterministically.Test
Adds
test_extract_state_value_from_outputcovering"0"," 3\n","-1","10", and"The next state is 12.". Without the fix the"10"and"12"cases fail (return a single digit).