You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/pi please analyze geewallet bug 320 (nblockchain/geewallet#320), and then analyze geewallet source code (cloning it from https://github.com/nblockchain/geewallet/ , preferably the stable branch because this is where the bugfix will land). Don't code yet a fix for the bug, just tell me possible ways to fix it. Elaborate different approaches for me to choose the best one.
After analyzing the issue geewallet #320 and the geewallet source code, I have identified the cause of the bug and several potential ways to fix it.
Analysis of the Bug
The bug occurs when FaultTolerantParallelClient is used with the OneServerConsistentWithCertainValueOrTwoServers consistency mode, typically during balance checks.
FaultTolerantParallelClient Logic:
The WhenSomeInternal function collects results from parallel jobs.
When a new result is obtained, it calls MeasureConsistency to count occurrences of each result.
If OneServerConsistentWithCertainValueOrTwoServers is used, it returns a ConsistentResult if:
a) The new result matches a "certain value" (e.g., cached balance).
b) There are at least two consistent results (even if they don't match the cached value).
If no consistent result is found yet, and there are still tasks running or jobs to launch, it continues waiting.
If all jobs have finished and no consistency was reached, it returns InconsistentOrNotEnoughResults.
Inconsistency Handling:
In QueryInternalImplementation, if the result is InconsistentOrNotEnoughResults, it checks how many successful results were obtained.
If some results were obtained, it attempts to wrap the settings to throw a ResultInconsistencyException or NotEnoughAvailableException.
It currently uses a "HACK" (line 618 of FaultTolerantParallelClient.fs) that converts OneServerConsistentWithCertainValueOrTwoServers into SpecificNumberOfConsistentResponsesRequired 2u for the purpose of generating the exception.
The Crash:
The crash reported in the issue (System.ArgumentException: number of funcs must be equal or higher than numberOfConsistentResponsesRequired) happens because when it retries due to inconsistency, it uses the wrapped settings (SpecificNumberOfConsistentResponsesRequired 2u) but might have fewer than 2 servers available to query (e.g., if some servers were discarded or if the total number of servers for that currency is 1).
Proposed Approaches for Fix
Here are three ways to fix this, ranging from surgical to more architectural:
Approach 1: Fix the Hack in QueryInternalImplementation
Modify the retry logic in QueryInternalImplementation to be aware of the OneServerConsistentWithCertainValueOrTwoServers mode instead of blindly wrapping it to 2u. If the total number of available servers is less than 2, it should either:
Downgrade the requirement to 1 (risky for consistency).
Correctly throw a NotEnoughAvailableException instead of letting the ArgumentException trigger during the retry call.
In QueryInternalImplementation, before calling QueryInternalImplementation recursively for a retry, check if the number of available funcs is at least as many as numberOfConsistentResponsesRequired. If not, throw NotEnoughAvailableException immediately.
Pros: Prevents the ArgumentException by providing a more meaningful domain exception. Cons: Still relies on the 2u wrapping which might not be strictly correct for all modes.
Approach 3: Implement Proper Exception Handling for the New Mode
Instead of the HACK that converts the mode to SpecificNumberOfConsistentResponsesRequired 2u, add explicit support for OneServerConsistentWithCertainValueOrTwoServers in the exception generation logic. This would involve:
Removing the HACK at line 618.
Adding a match arm for OneServerConsistentWithCertainValueOrTwoServers in the exception handling section (around line 628).
Ensuring that if a retry is triggered, it uses the original consistency settings rather than the wrapped ones.
Pros: Cleanest architecture, removes technical debt ("HACK" comment). Cons: Slightly more complex as it requires touching multiple match statements.
Approach 4: Relax Preconditions for Retries
Modify the ArgumentException check at the beginning of QueryInternalImplementation to allow numberOfConsistentResponsesRequired to be greater than the number of functions only if it's a retry and we are in a specific recovery state. (Not recommended as it might mask other bugs).
Recommendation
I recommend Approach 3. It addresses the root cause (the inaccurate wrapping of consistency settings) and removes the technical debt acknowledged in the source code. This will allow the system to correctly identify that it doesn't have enough servers to satisfy the "2-server consistency" rule and throw a proper NotEnoughAvailableException instead of crashing with an ArgumentException.
Activity
knocte commentedon Sep 27, 2026
/pi please analyze geewallet bug 320 (nblockchain/geewallet#320), and then analyze geewallet source code (cloning it from https://github.com/nblockchain/geewallet/ , preferably the stable branch because this is where the bugfix will land). Don't code yet a fix for the bug, just tell me possible ways to fix it. Elaborate different approaches for me to choose the best one.
nodefect commentedon Sep 27, 2026
After analyzing the issue geewallet #320 and the geewallet source code, I have identified the cause of the bug and several potential ways to fix it.
Analysis of the Bug
The bug occurs when
FaultTolerantParallelClientis used with theOneServerConsistentWithCertainValueOrTwoServersconsistency mode, typically during balance checks.FaultTolerantParallelClient Logic:
WhenSomeInternalfunction collects results from parallel jobs.MeasureConsistencyto count occurrences of each result.OneServerConsistentWithCertainValueOrTwoServersis used, it returns aConsistentResultif:a) The new result matches a "certain value" (e.g., cached balance).
b) There are at least two consistent results (even if they don't match the cached value).
InconsistentOrNotEnoughResults.Inconsistency Handling:
QueryInternalImplementation, if the result isInconsistentOrNotEnoughResults, it checks how many successful results were obtained.ResultInconsistencyExceptionorNotEnoughAvailableException.FaultTolerantParallelClient.fs) that convertsOneServerConsistentWithCertainValueOrTwoServersintoSpecificNumberOfConsistentResponsesRequired 2ufor the purpose of generating the exception.The Crash:
System.ArgumentException: number of funcs must be equal or higher than numberOfConsistentResponsesRequired) happens because when it retries due to inconsistency, it uses the wrapped settings (SpecificNumberOfConsistentResponsesRequired 2u) but might have fewer than 2 servers available to query (e.g., if some servers were discarded or if the total number of servers for that currency is 1).Proposed Approaches for Fix
Here are three ways to fix this, ranging from surgical to more architectural:
Approach 1: Fix the Hack in
QueryInternalImplementationModify the retry logic in
QueryInternalImplementationto be aware of theOneServerConsistentWithCertainValueOrTwoServersmode instead of blindly wrapping it to2u. If the total number of available servers is less than 2, it should either:NotEnoughAvailableExceptioninstead of letting theArgumentExceptiontrigger during the retry call.Pros: Low risk, localized change.
Cons: Keeps the "hacky" wrapping logic.
Approach 2: Validate Server Count before Wrapping
In
QueryInternalImplementation, before callingQueryInternalImplementationrecursively for a retry, check if the number of availablefuncsis at least as many asnumberOfConsistentResponsesRequired. If not, throwNotEnoughAvailableExceptionimmediately.Pros: Prevents the
ArgumentExceptionby providing a more meaningful domain exception.Cons: Still relies on the
2uwrapping which might not be strictly correct for all modes.Approach 3: Implement Proper Exception Handling for the New Mode
Instead of the HACK that converts the mode to
SpecificNumberOfConsistentResponsesRequired 2u, add explicit support forOneServerConsistentWithCertainValueOrTwoServersin the exception generation logic. This would involve:OneServerConsistentWithCertainValueOrTwoServersin the exception handling section (around line 628).Pros: Cleanest architecture, removes technical debt ("HACK" comment).
Cons: Slightly more complex as it requires touching multiple match statements.
Approach 4: Relax Preconditions for Retries
Modify the
ArgumentExceptioncheck at the beginning ofQueryInternalImplementationto allownumberOfConsistentResponsesRequiredto be greater than the number of functions only if it's a retry and we are in a specific recovery state. (Not recommended as it might mask other bugs).Recommendation
I recommend Approach 3. It addresses the root cause (the inaccurate wrapping of consistency settings) and removes the technical debt acknowledged in the source code. This will allow the system to correctly identify that it doesn't have enough servers to satisfy the "2-server consistency" rule and throw a proper
NotEnoughAvailableExceptioninstead of crashing with anArgumentException.View action run | Model: ppq/auto | Time: 46s | Tokens: 205.8K | Cost: $0.06 | Pi SDK v0.85.1 | Action v2.28.0-unknown (unknown @ unknown)