Bug: Bandaid null validation result. #898
Merged
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.
Not a real fix as far as I'm concerned, but perhaps the only one we can get.
Before:
After:
Way Too Much Information:
When running concurrently with multiple threads in guardrails-api, there seems to be a concurrent modification of history across two threads. Evidence: Some of the validation_outputs are becoming None between steps of the stack trace. This scales linearly with the number of threads. The same behavior for the same code does not appear if num-threads is set to 1 and the number of workers is increased. (
gunicorn --bind 0.0.0.0:8000 --timeout=30 --workers=2 --threads=1 'guardrails_api.app:create_app("sample.env", "sample_config.py")')A Better Option:
Since we want Guards to be able to be used seamlessly across threads, we should make it possible to modify history and use it in a way that's thread-safe. We could do this by protecting the history object with a mutex or some other kind of thread-safe structure. Unfortunately, the base class is autogenerated and while it's possible that the modification to the subclass will remain compatible, if another type of Guard decides to inherit the interface guard instead of our base guard then we might end up in a place with really troublesome and subtle errors. (Also, we don't want to have to worry about the ordering of the parent classes, though it does potentially make our lives easier: https://docs.python.org/3/tutorial/classes.html#multiple-inheritance)