fix(tests): eliminate CI-only embedding batch race by waiting for terminal status - #1025
fix(tests): eliminate CI-only embedding batch race by waiting for terminal status#1025seonghobae wants to merge 5 commits into
Conversation
…minal status complete_embeddings_batch() against a provider (ThreadPoolExecutor-backed, asynchronous) embedding agent returns as soon as the job is submitted unless a wait_timeout is passed. Two tests in test_provider_embedding_batch_backend.py asserted on the returned document's total_tokens immediately, without wait_timeout, racing the background executor thread. Reproduced deterministically by adding an artificial delay to job execution: the assertion failed with KeyError: 'total_tokens' (the non-terminal document shape) exactly as seen on CI, and passed once wait_timeout=1 was added -- matching the pattern already used by sibling tests in the same file for this exact shape. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BV96rXhqoR3tYZ9AeAVur4
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Preserve the exact provider embedding batch wait-timeout regression fix while adopting current protected main non-destructively. Record the change in the current CHANGELOG.d fragment convention instead of carrying the stale monolithic CHANGELOG.md edit.
|
Protected-base reconciliation completed non-destructively.
Semantic preservation was checked before the ref move: intervening main changes did not touch Fresh base→head diff is exactly two files: the changelog fragment and the provider embedding batch regression test ( |
Adopt main@212ff437 without rewriting history; the main admin-console delta is disjoint from the provider embedding batch test repair.
Bring in main's already-landed fix for the pre-existing tests/test_admin_contract.py::test_model_group_mutations_refresh_audit_events NameError (missing 'import json', commit 39a4348 / #1035) that PR #1025 was still behind on. PR #1025's own diff (CHANGELOG.d fragment + tests/test_provider_embedding_batch_backend.py) is untouched by this merge. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BV96rXhqoR3tYZ9AeAVur4
Triage: "Full unit and contract suite" failure on run 33649256377 (head
|
|
Adjudication evidence (host 1 session, 2026-09-06 KST; full report with commands in #1080). Nothing here closes, flips, or retargets anything — the decision is the opener's. Near-duplicate of #1044 — not verified as superseded, so not closable on this evidence. Both make the same |
Summary
tests/test_provider_embedding_batch_backend.py:test_unknown_tokenizer_uses_authoritative_provider_usageandtest_unknown_tokenizer_byte_bound_never_becomes_recorded_usagecalledCostRoutingCoordinator.complete_embeddings_batch()against a provider (async,ThreadPoolExecutor-backed) embedding agent withoutwait_timeout, then asserted on the returned document'stotal_tokensimmediately.ProviderEmbeddingBatchBackend.submit()hands the job to a backgroundThreadPoolExecutorand returns immediately; withoutwait_timeout,complete_embeddings_batch()polls the job document right away. Under light/isolated load the background thread usually wins the race, but under CI's heavier concurrent load (full suite, thousands of tests) it sometimes hadn't finished, so the poll returned a non-terminal document shape that omitstotal_tokensentirely, producingKeyError: 'total_tokens'.test_runtime_added_remote_embedding_member_uses_provider_backend,test_provider_embedding_requests_are_sharded_by_the_existing_token_limitboth passwait_timeout=1for the same provider-backend-plus-immediate-check shape).Root cause and diagnosis
main(single-file run, single-test run), matching a race rather than a deterministic logic bug.ProviderEmbeddingBatchBackend._run_job(job execution): both tests failed with the exact sameKeyError: 'total_tokens'seen on CI (RED), and passed oncewait_timeout=1was added to thecomplete_embeddings_batch()calls (GREEN), with the artificial delay still in place. The delay was reverted before committing — the only committed change is the twowait_timeout=1additions plus a CHANGELOG entry.CHANGELOG.md,README.md,docs/product-technical-gap-baseline.md), so the failure could not be its own defect. Once merged, the fix will be ported into feat(discovery): add bounded OpenRouter free canary #985 (and any other PR hitting the same flake) by mergingmainin.Verification
pytest tests/test_provider_embedding_batch_backend.py -q -k "test_unknown_tokenizer_uses_authoritative_provider_usage or test_unknown_tokenizer_byte_bound_never_becomes_recorded_usage"— RED with the artificial delay before the fix, GREEN after.pytest tests/test_provider_embedding_batch_backend.py tests/test_batch_routing.py tests/test_cost_router.py -q— 72 passed (no artificial delay).🤖 Generated with Claude Code
https://claude.ai/code/session_01BV96rXhqoR3tYZ9AeAVur4
Generated by Claude Code