Skip to content

fix: detect interface bugs from #192 and run the tests on stateless_core PRs - #195

Merged
adaamko merged 1 commit into
stateless_corefrom
fix/192-detect-interface-bugs
Nov 16, 2026
Merged

adaamko merged 1 commit into
stateless_corefrom
fix/192-detect-interface-bugs

Conversation

@adaamko

@adaamko adaamko commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes six of the seven bugs listed in #192 on the typed detector interface, one concurrency bug in EncoderDetector, and makes the test workflow run on pull requests against stateless_core.

  • EncoderDetector(model, tokenizer, typer): everything after tokenizer is keyword-only. EncoderDetector(model, tok, EncoderConfig(...)) now raises TypeError instead of taking the config as the typer.
  • Shared tokenizer: detectors built on the same tokenizer share one scoring lock. Each detector had its own lock, so two detectors on one fast tokenizer could fail with RuntimeError: Already borrowed. The contract test test_concurrent_adetect_returns_results_in_call_order builds three such detectors and failed this way for me with transformers 5.1.0.
  • Detection.tokens leaves out zero-width special tokens such as the trailing [SEP]. TokenScore rejects an end that is not after start, as Span does. The deprecated TransformerDetector.predict has its own path and still returns [SEP], so the golden fixtures are unchanged.
  • detect() raises InvalidInputError with the code invalid_request for a request that is not a SourcesInput or a PromptInput, instead of AttributeError.
  • make_cache_key(kind=...) accepts a kind of the caller's own. A kind must be a non-blank string without =, which is reserved for the model_version part of the key. The keys of judge, native and verify are unchanged.
  • predict() on a detector without token scores raises tokens_not_supported with param="output_format" and a message that names output_format="spans". The default stays "tokens".
  • Docs: CONTRIBUTING names tests/test_deprecation_pytest.py, and the EncoderConfig.batch_size docstring says that detect scores one request at a time.
  • CI: python-tests.yml also runs on pull requests against stateless_core. Until now those pull requests only got the rights check.

Not in this pull request: bug 2 of #192 (a TransformerDetector subclass that overrides predict is bypassed by detect()). It needs a decision on which method wins, so it stays open in the issue.

Related issue

Relates to #192. It targets stateless_core, so GitHub will not close the issue; bug 2 keeps it open anyway.

Type of change

  • Bug fix
  • Feature
  • Documentation
  • Tests
  • Refactor or maintenance

Testing

  • ruff format --check lettucedetect/ lettucedetect_api/ tests/
  • ruff check lettucedetect/ lettucedetect_api/ tests/ --extend-exclude lettucedetect/integrations/
  • python -m pytest
  • Other:

Results: 701 passed, 1 failed locally. The failure, test_importing_the_module_has_no_import_cycle_or_warning, starts a subprocess that imported another installed copy of the package on my machine; it fails the same way on stateless_core.

Checklist

  • I kept the PR focused on one change.
  • I added or updated tests/docs when needed.
  • I checked that no secrets, API keys, or credentials are included.

Rights & sign-off (required)

  • I certify that I have the right to submit this code and that it may be
    distributed under the repository's MIT license
    (see CONTRIBUTING).

…ore PRs

- EncoderDetector takes typer, config, model_id and model_version by keyword only, so a config
  passed third is no longer taken as the typer.
- Detectors built on one tokenizer share one scoring lock. A fast tokenizer fails with
  'Already borrowed' when two threads use it at once, also through two detectors.
- Detection.tokens leaves out zero-width special tokens such as the trailing [SEP], and
  TokenScore rejects an end that is not after its start.
- detect() raises InvalidInputError (invalid_request) for a request that is not a SourcesInput
  or a PromptInput.
- make_cache_key accepts a kind of the caller's own.
- predict() on a detector without token scores names output_format="spans" in its error.
- CONTRIBUTING names the right deprecation test file, and the EncoderConfig.batch_size
  docstring says what detect does today.
- The test workflow also runs on pull requests against stateless_core.

Signed-off-by: Kovács Ádám <adaam.ko@gmail.com>
@adaamko
adaamko merged commit 580b2d8 into stateless_core Nov 16, 2026
4 checks passed
@adaamko
adaamko deleted the fix/192-detect-interface-bugs branch November 16, 2026 13:05
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.

1 participant