Repository navigation
Expose Apple Intelligence token usage through M.E.AI - #404
Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
Expert Code Review — PR #404Methodology: 2 independent reviewers (1 failed to complete — reduced coverage, no tiebreaker) with adversarial consensus. Findings: 2 posted as inline comments (both 🟡 moderate). Both reached full 2/2 consensus.
Discarded (flagged by only 1 of 2 reviewers, no tiebreaker):
Test coverage: Good — the PR adds Backward compatibility: CI status: PR
|
There was a problem hiding this comment.
Expert Code Review: 2 findings posted inline. See the lean summary comment for full details.
Generated by Expert Code Review (auto) for #404 · 324.1 AIC · ⌖ 18.9 AIC · ⊞ 12.3K
433f9e2 to
c6b4a19
Compare
c6b4a19 to
74946b4
Compare
74946b4 to
4aa189c
Compare
d8515bd to
0301fa3
Compare
0301fa3 to
1dc0960
Compare
Map Xcode 27 Foundation Models usage into standard Microsoft.Extensions.AI responses and streaming updates. Add reusable provider usage tests for Apple and OpenAI compatibility. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9dd6eab1-b5fd-4250-9d0c-49b901de09ca
Validate positive usage counts without assuming every provider defines total tokens as exactly input plus output. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9dd6eab1-b5fd-4250-9d0c-49b901de09ca
Assert actual provider/model spans, cached-input tags, input/output token histograms, operation duration and streaming timings for both live providers. Preserve sensitive-data exclusions and document the pinned M.E.AI telemetry mapping. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: fb5d1926-9f89-4115-9a96-65cd7ee59e9c
1dc0960 to
7e6aa42
Compare
Expose Apple Foundation Models' native OS 27 token usage through the standard
Microsoft.Extensions.AIresponse surface.Dependencies and native stack
This PR targets #623's
mattleibow-apple-foundation-models-image-inputbranch, currentlyde5e19ba6c8e5f7cf0e920f6b19432f36f7b5808. It includes image input and its OS 26 rejection coverage, #630's trace-grouped diagnostics, and merged #629's model/streaming fixes and Xcode 27 build configuration.Existing native stack 636 is preserved, including its merged lower member:
#629 → #630 → #623 → #404 → #631.
The broken session was recovered into a clean isolated worktree. This PR is published at
d8515bdcedeca25615318cb17bc8dba9dba0caf7: both original usage commits are unchanged by range-diff, with one additional telemetry regression/documentation commit above the latest image-input tip. The dependent #631 branch is published at287ee658fff7fdd6a1f520eb6c22c93231d6595c, exactly six unchanged Hybrid commits above this PR; all six range-diff entries are=. Both pushes used explicit compare-and-swap leases. Original stale worktrees were preserved, and no stack membership, PR bases, or draft states were changed.Changes
ChatResponse.Usage, including input, output, total, cached-input, and reasoning token counts.UsageContentupdate before streaming completion so standard response aggregation and built-in telemetry consume native usage normally, including the provider model ID.null; no reconstructed or estimated counts are added.ChatClientUsageTestsBase<T>tests to capture realActivityandMeteroutput for Apple and the configured Azure OpenAI Responses client, in both single and streaming modes. Assert provider/request/response model tags, input/output and cached-input span counts, exact token histogram values, request duration, streaming timing measurements, and sensitive-data exclusions. Record observed measurements in test output and bound requests with cancellation.UsageDetails.Addaccumulation and the exact pinned M.E.AI 10.4.1 telemetry mapping.No provider-specific public usage API is introduced. The inherited diagnostics pipeline already consumes both
ChatResponse.Usageand streamingUsageContent.Live telemetry comparison on macOS 27
The earlier model-readiness blocker is cleared. A fresh native
SystemLanguageModel.default.availabilityprobe reportsavailable, and both Apple usage requests successfully generated responses. These are real provider counts, not estimates or fake-client results.The final 62-case device-test run captured:
The same synthetic one-word prompt was used. Counts are not expected to match across providers/tokenizers; the assertion is that each provider's response usage exactly matches its emitted standard telemetry.
Both providers emit
gen_ai.operation.name, provider/request/response model tags, input/output usage tags, cached-input usage tags,gen_ai.client.token.usagehistograms, andgen_ai.client.operation.duration. Fully consumed streams additionally emit time-to-first-chunk and time-per-output-chunk histograms. Sensitive prompt/response telemetry remains explicitly disabled.Parity is not provider-specific identity: Apple does not invent Azure-only endpoint tags, response IDs, or finish reasons. Pinned M.E.AI 10.4.1 exposes total/reasoning counts on
UsageDetailsbut does not emit separate built-in total/reasoning span tags or metrics.Validation on the upgraded Mac
Default toolchain: macOS 27.0.1, Xcode 27.0 / Swift 6.4, .NET SDK and workloads 10.0.401.
net10.0-ios27.0,net10.0-maccatalyst27.0, andnet10.0-macos27.0, with zero warnings/errors.NLEmbeddingGeneratorgeneration/similarity/metadata coverage.The PR remains draft; no merge or ready-for-review action was requested.