Skip to content

fix(inference): fix concurrent request Rust borrow checker panic - #5733

Merged
mattf merged 7 commits into
ogx-ai:mainfrom
zy1o:zy1o_parallelism_fixes
May 14, 2026
Merged

fix(inference): fix concurrent request Rust borrow checker panic#5733
mattf merged 7 commits into
ogx-ai:mainfrom
zy1o:zy1o_parallelism_fixes

Conversation

@zy1o

@zy1o zy1o commented May 6, 2026

Copy link
Copy Markdown
Contributor

also added an integration test exposing the issue

What does this PR do?

Wrap inline reranker call in a threading.Lock preventing threads from changing a mutable Rust object at the same time resulting with borrow checker panic.

Closes #5729

Test Plan

Added an integration test exposing this problem which seems to be invoking the bug every time on my local dev machine, so executing the tests should suffice.

With the lock applied, the test passes reliably.

Re-using the test_rerank_text logic (just above) just sending all the sequential requests at the same time(-ish) to trigger this race condition. Using ThreadPoolExecutor because the existing fixture client_with_models exposes the sync client.

also added an integration test exposing the issue
@franciscojavierarceo
franciscojavierarceo added this pull request to the merge queue May 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 6, 2026
@leseb
leseb added this pull request to the merge queue May 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks May 6, 2026
@leseb
leseb enabled auto-merge May 7, 2026 14:08
@zy1o
zy1o marked this pull request as draft May 7, 2026 14:14
auto-merge was automatically disabled May 7, 2026 14:14

Pull request was converted to draft

@zy1o

zy1o commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Hey @leseb, I think that these tests passed this time because I was just lucky.

I have a fix for the Issue #5752 (which will periodically strike with this test using threads to make requests in parallel), though the fix is limited to the OGXAsLibraryClient class. Unsure how to proceed with that now. Should I just push that commit onto this branch? Or open another PR?

Without it, I'm afraid that the test sending the requests in parallel will be flaky. Asking because I also just saw your PR #5760 raising deprecation warnings.

@mattf mattf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zy1o this isn't your fault but we should delete this rerank code instead of making it thread safe. though fixing it would be nice. issue off the top of my head -

  • (small) redundant checks on request.items / request.max_num_results
  • (big) qwen specific prompts
  • (big) use of casual lm on a cross encoder model
  • (medium) liberal use of Any

@franciscojavierarceo i wonder if this impacts your rag benchmarks. this code is going to produce nonsense w/o a qwen model and maybe even with, since it treats a cross encoder model as a casual.

@zy1o

zy1o commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@mattf I am new to this code base, but less code is a win in my book. I was looking at parallelizing test execution when i stumbled over these concurrency issues.

Feel free to discard this PR. 🍻

@mattf

mattf commented May 7, 2026

Copy link
Copy Markdown
Collaborator

@mattf I am new to this code base, but less code is a win in my book. I was looking at parallelizing test execution when i stumbled over these concurrency issues.

Feel free to discard this PR. 🍻

welcome and thank you for looking into these things.

given we have a sentence_transformer inference provider as well, which lacks a rerank impl, we should delete this and add a rerank impl to SentenceTransformersInferenceImpl.

@zy1o

zy1o commented May 10, 2026

Copy link
Copy Markdown
Contributor Author

given we have a sentence_transformer inference provider as well, which lacks a rerank impl, we should delete this and add a rerank impl to SentenceTransformersInferenceImpl.

@mattf would you want me to take care of the move? It feels like this change will have a bigger blast radius.

It feels that the Issue #5732 should also be addressed. I have a feeling that it will surface at a random point in time and cause confusion.

My proposal is to continue as follows:

  1. Review and merge the PR fix(core): make OGXAsLibraryClient thread-safe #5773.
  2. Merge this PR in, so that the rerank logic doesn't result with Rust borrow checker error.
  3. Implement the move. I can take it up.

@mattf

mattf commented May 11, 2026

Copy link
Copy Markdown
Collaborator

given we have a sentence_transformer inference provider as well, which lacks a rerank impl, we should delete this and add a rerank impl to SentenceTransformersInferenceImpl.

@mattf would you want me to take care of the move? It feels like this change will have a bigger blast radius.

It feels that the Issue #5732 should also be addressed. I have a feeling that it will surface at a random point in time and cause confusion.

i'm not too concerned about that, because it'd be a circular import and explode pretty early, but welcome improvements.

My proposal is to continue as follows:

1. Review and merge the PR [fix(core): make OGXAsLibraryClient thread-safe #5773](https://github.com/ogx-ai/ogx/pull/5773).

2. Merge this PR in, so that the rerank logic doesn't result with Rust borrow checker error.

3. Implement the move. I can take it up.

brilliant!

@zy1o
zy1o marked this pull request as ready for review May 12, 2026 03:51
@zy1o

zy1o commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Hey @mattf, @leseb, @franciscojavierarceo

Now that #5773 was merged in, the path to Step 2 (merging this and clearing the borrow checker panic) is clear. All checks are green!

@mattf
mattf added this pull request to the merge queue May 14, 2026
Merged via the queue into ogx-ai:main with commit 911ba9d May 14, 2026
25 checks passed
franciscojavierarceo added a commit that referenced this pull request Jun 25, 2026
# What does this PR do?
* Moves `rerank` implementation from `transformers` to
`sentence_transformers` - following up on @mattf's
[comment](#5733 (comment)).
* Removes `transformers` module from inline providers, as it was simply
empty after the move.
* Updates benchmarking k8s scripts.
* Updates distrubutions.
* Updates unit tests and integration tests accordingly. Also search &
replace pre-recorded responses to match `sentence-transformers`
provider. Simply updated:
```
                provider_id="transformers",
                model_id="Qwen/Qwen3-Reranker-0.6B",
```
to
```
                provider_id="sentence-transformers",
                model_id="Qwen/Qwen3-Reranker-0.6B",
```
across all files.

Closes #5732.

**Notes**
* This PR does not address other issues raised by @mattf in this
[comment](#5733 (review)),
I can pick them up, once small step at a time.
* I noticed that the `integration-tests.sh` has the models hardcoded:
  ```
  # Run Python tests unless typescript-only mode
  if [[ "$TYPESCRIPT_ONLY" == "false" ]]; then
      pytest -s -v $PYTEST_TARGET \
          $STACK_CONFIG_ARG \
          --inference-mode="$INFERENCE_MODE" \
          -k "$PYTEST_PATTERN" \
          $EXTRA_PARAMS \
          --color=yes \
--embedding-model=sentence-transformers/nomic-ai/nomic-embed-text-v1.5 \
--rerank-model=sentence-transformers/Qwen/Qwen3-Reranker-0.6B \
          --capture=tee-sys
      exit_code=$?
  else
      echo "Skipping Python tests (--typescript-only mode)"
      exit_code=0
  fi
   ```
  and I think that is should be:
  ```

--embedding-model="${OGX_TEST_EMBEDDING_MODEL:-sentence-transformers/nomic-ai/nomic-embed-text-v1.5}"
\

--rerank-model="${OGX_TEST_RERANK_MODEL:-sentence-transformers/Qwen/Qwen3-Reranker-0.6B}"
\
   ```

## Test Plan
```
./scripts/integration-tests.sh --stack-config server:ci-tests \
  --inference-mode replay --setup vllm --suite base-vllm-subset
```

---------

Signed-off-by: Charlie Doern <cdoern@redhat.com>
Co-authored-by: Derek Higgins <derekh@redhat.com>
Co-authored-by: Francisco Javier Arceo <arceofrancisco@gmail.com>
Co-authored-by: Charlie Doern <cdoern@redhat.com>
Co-authored-by: Matthew Farrellee <matt@cs.wisc.edu>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Concurrent requests result with errors (including RuntimeError: Already borrowed)

4 participants