Repository navigation
fix(instructor): preserve TypeScript extraction stream lifecycle - #390
Merged
Merged
Conversation
Keep one extraction parent through validation and iterator consumption, restore owned factory patches, and verify floor/current SDKs and documented provider composition over OTLP. Co-Authored-By: Claude Code <noreply@anthropic.com>
Preserve the repaired Instructor contract tests and union lockfile entries without re-resolving unrelated packages. Co-Authored-By: Claude Code <noreply@anthropic.com>
Retain the repaired Instructor importer and union the added SDK lock entries. Co-Authored-By: Claude Code <noreply@anthropic.com>
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.
What does this PR do?
Keep and repair
@traceai/instructor. Preserve the publicInstructorInstrumentationentry point while making extraction spans cover the actual request, validation and stream lifecycle.CHAINextraction parent, not a second model-call span withprovider=instructor. Provider instrumentors retain ownership of model/provider/token/cost accounting and validation-retry child spans.next,returnandthrowunder the extraction context. Preserve errors and cancellation, including closing a never-started stream, without eagerly consuming it._meta; map supplied numeric usage intoinstructor.usage.*rather than duplicating providergen_ai.*totals. Do not estimate usage missing from the SDK.Why?
The final 36-test suite against the original dev implementation failed 26 tests (10 passed). It reproduced premature successful stream completion, missing stream context/errors/output, fake provider attribution, usage loss, passthrough duplication, and non-reversible patching.
Existing PR #385 repairs Python only; it does not overlap this TypeScript package. No dedicated competitor TypeScript Instructor implementation was established, so this repair follows the actual JavaScript SDK rather than importing assumptions from Python integrations. No third-party implementation code was copied.
Pinned upstream contracts:
_meta.usage.How was it tested?
All local tests ran under an OS sandbox denying outbound networking except localhost. No real credentials, vendor/model API, or production backend was used.
@traceai/openai@0.1.14, real OpenAI/Instructor/Zod SDKs, and loopback HTTP transports. The collector receives exactly one CHAIN parent plus one LLM child, with matching trace/parent IDs and no captured synthetic content or credentials.@traceai/fi-core@1.1.0; passed. The README subprocess uses its installed dependency graph.Re-run from
typescript:pnpm --filter @traceai/instructor... install --frozen-lockfile --ignore-scripts pnpm run build:deps pnpm --filter @traceai/instructor run build pnpm --filter @traceai/instructor test --runInBandE2E coverage
Not applicable (no product
e2e/scripts/e2e-coverage.mjsharness). The SDK contract tests and README loopback collector cover this library's end-to-end path; no live backend-ingestion claim is made.Compatibility and rollout
dev, per this repair's instructions (not the generic template'smain). No package version or CHANGELOG version section was hand-edited. Release-please owns the release._meta.usage. Streaming usage remains conditional on what the framework provides; result usage is not a sum of retry costs.enabled: falseand letsregisterInstrumentationsenable it, ensuring privacy configuration is initialized first.Review
Self-reviewed against internal correctness, contracts, failure-mode, performance, security and test-scenario standards, including the whitespace-insensitive diff. No unresolved blocking finding in the final diff. The current package owns no new service, migration or enterprise boundary. Human review remains required.
🤖 Generated with Claude Code