Skip to content

fix(experiments): reject nonpositive concurrency limits - #1980

Draft
linjiaye929 wants to merge 1 commit into
langfuse:mainfrom
linjiaye929:codex/reject-zero-experiment-concurrency
Draft

linjiaye929 wants to merge 1 commit into
langfuse:mainfrom
linjiaye929:codex/reject-zero-experiment-concurrency

Conversation

@linjiaye929

Copy link
Copy Markdown

What does this PR do?

Reject nonpositive max_concurrency values before scheduling an experiment.

With nonempty data, max_concurrency=0 creates a zero-permit semaphore and every item waits indefinitely. No task can enter the semaphore and release a permit. Negative values already raise ValueError from asyncio.Semaphore; they retain that exception type with a more actionable message.

The validation runs before experiment IDs, item tasks, or observations are created. The client and dataset docstrings explicitly require a value greater than zero, including for empty datasets. Positive limits and empty datasets with positive limits retain their behavior.

Type of change

  • Bug fix

Verification

Python 3.12.14; dependencies installed from the frozen lockfile. socksio==1.0.0 was added only to the local test environment so httpx could initialize with the execution environment's SOCKS proxy; dependency files are unchanged. Proxy settings were preserved for the final verification. Test commands use OTEL_TRACES_SAMPLER=always_on because the execution environment otherwise samples only 1% of spans; this only affects the test process and its in-memory exporter.

  • OTEL_TRACES_SAMPLER=always_on .venv/bin/pytest tests/unit/test_experiment.py::TestExperimentConcurrency -q: 10 passed. Uses local asyncio scheduling and the repository's in-memory Langfuse fixture, with dummy credentials and no real provider or Langfuse requests.
  • Before the fix, the same 10 cases produced 6 failures and 4 passes. The public zero-concurrency call hit the 5-second pytest timeout; the internal nonempty zero-concurrency call hit a 1-second asyncio.wait_for timeout and was cancelled. Empty data with zero concurrency did not raise, and negative inputs raised the old semaphore ValueError message.
  • OTEL_TRACES_SAMPLER=always_on .venv/bin/pytest tests/unit/test_experiment.py -q: 30 passed. The pristine base at bf11ec121479145923ff27b32ec2ad1d06fd2d51 passes its 20 existing experiment tests with the same test-only sampler setting. Initial runs had four missing-span failures on both base and fixed source because of the inherited 1% sampler; those failures disappear with deterministic test sampling. This is not a full-suite or CI pass.
  • .venv/bin/ruff check .: passed.
  • .venv/bin/ruff format --check langfuse/_client/client.py langfuse/_client/datasets.py tests/unit/test_experiment.py: passed.
  • .venv/bin/mypy langfuse --no-error-summary: passed.
  • git diff --check: passed.

The full unit suite, E2E suite, and live-provider tests were not run.

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added tests for the behavior change.
  • I updated the affected parameter documentation.
  • I did not hand-edit generated files.
  • I did not commit secrets or credentials.

AI assistance: OpenAI Codex inspected the source, implemented the change, and ran the local checks described above.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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.

2 participants