fix(v2): don't mistake a literal '[' inside a preceding string field for the tasks array start#2426
Open
roli-lpci wants to merge 1 commit into
Open
fix(v2): don't mistake a literal '[' inside a preceding string field for the tasks array start#2426roli-lpci wants to merge 1 commit into
roli-lpci wants to merge 1 commit into
Conversation
…for the tasks array start
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.
Describe your changes
IterableBase.tasks_from_chunks/tasks_from_chunks_async(instructor/v2/dsl/iterable.py), thestreaming path every provider's
Iterable[Model]extraction goes through, detects the start of thestreamed
tasksarray with a naive"[" in chunkcheck on each individual chunk. If a fieldpreceding
tasksin the response JSON contains a literal[inside a string value — for example afree-text
notefield like"check [priority] items first"— that in-string bracket falselytriggers array-start detection. The buffer gets sliced from the wrong offset, and every task
streamed after that point is silently dropped: the function returns an empty list, with no
exception anywhere.
The fix adds
_find_unquoted_char, a small string-aware scanner (tracksin_string/escape state,the same pattern
get_objecta few lines below already uses for brace-matching) and uses it inboth
tasks_from_chunksandtasks_from_chunks_asyncto find the real, unquoted[against thefull accumulated buffer instead of a naive per-chunk substring check. 38 lines changed across both
sync/async entry points plus the new helper; no signature changes.
Tests: added
test_iterable_tasks_from_chunks_ignores_bracket_inside_preceding_stringand itsasync counterpart, mirroring the existing
test_iterable_tasks_from_chunks_handles_braces_inside_stringspattern, using the
note-field repro above. Before fix: 2 failed —assert [] == [Task(name='alpha', priority=1), Task(name='beta', priority=2)](both streamed tasks silently dropped). After fix: all6 tests in
tests/v2/test_iterable_streaming.pypass.ruff checkis clean on both changed files.Issue ticket number and link
No existing issue tracks this bug. Distinct from the already-merged PR #2340 (a consolidation
bundle whose iterable.py portion fixed brace-in-string detection in
get_object) — this fixes adifferent detection bug (array-start bracket, not object-boundary brace) in a different function;
get_objectitself is unchanged.Checklist before requesting a review
detection; no documented behavior changed.)