Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Link to Issue or Description of Change
Closes #7648
Related: #7645
Problem:
When an Apigee Chat Completions stream ends with
finish_reason="length", the response handler attempts to parse accumulated tool-call arguments before handling the provider’s finish reason. Truncated JSON can therefore raiseValueError, preventing a terminalMAX_TOKENSresponse from reaching the caller.Additionally, the existing argument-merging fallback can discard an incomplete fragment following a complete JSON object and expose a function call whose arguments were truncated.
Solution:
Validate accumulated tool-call arguments before finalizing responses that terminate with
length.The change:
MAX_TOKENSerror without final executable function calls if any call is incomplete.{}.The implementation is limited to the Apigee response handler and its regression tests.
Testing Plan
Unit Tests:
Regression coverage includes:
{}and valid fragmented JSON.lengthfinish reasons.generate_content_async(stream=True), with termination in the same chunk or a subsequent chunk.Validation matrix
Validation performed on Ubuntu under WSL 2.
xfaileddenotes expected failures, separate from the Failed column.xpasseddenotes tests marked as expected failures that passed.Python 3.14 full-suite validation: 20,852 passed, 1 failed, 94 skipped, 18 xfailed, 2 xpassed.
The sole failure,
test_sequential_tools_add_up, measures elapsed time against a narrow tolerance. It failed in two full-suite runs, including a rerun without other test jobs, and reproduced on the unpatched baseline. The test passed when run individually (1 passed, exit 0).The full Python 3.14 suite therefore did not pass. No patch-specific regression was identified from this failure.
Full suites used:
pre-commit run --all-filesaddlicensehook used its configured skip behaviorManual End-to-End (E2E) Tests:
No live Apigee manual E2E test was performed.
Automated integration tests use
httpx.MockTransportto supply SSE responses throughApigeeLlm.generate_content_async(stream=True). They verify that truncated arguments produce terminalMAX_TOKENSerrors without final executable function calls, while preserving text and metadata and counting token usage once.To reproduce the mocked streaming integration tests:
uv sync --extra test --no-install-package lancedb uv run pytest tests/unittests/models/test_completions_http_client.py \ -k apigee_streaming_truncation_with_mocked_sse -qThe
lancedbinstallation exclusion follows the repository’s CI configuration.Checklist
Additional context
PR #7645 addresses missing-index accumulation in the same handler. Both patches applied cleanly together on upstream main at
fb197fa. Combined focused and Runner validation passed: 1,239 tests. The complete multi-version suite was not rerun on that combined checkout.