feat(inference): relocate InferenceMetric to ManifoldInference + wire FoundationBackend metrics#1883
Merged
Merged
Conversation
… FoundationBackend metrics Move InferenceMetric/InferenceMetricSink/InMemoryMetricSink and GenerationMetricTracker/SSEGenerationMetrics from ManifoldCloudCore to ManifoldInference so that ManifoldFoundation (which depends on ManifoldInference but not ManifoldCloudCore) can emit metrics without a cross-family import. ManifoldCloudCore re-exports ManifoldInference via @_exported import in MetricTypeAliases.swift to preserve source compat for all existing import ManifoldCloudCore consumers. SSEGenerationTaskRunner is updated to compute cost using InferenceCostEstimator (which stays in CloudCore) and pass the resolved values to the now-parameter-explicit SSEGenerationMetrics.record. FoundationBackend gains a public metricSink property (defaulting to InMemoryMetricSink.shared) and emits one InferenceMetric per generation via GenerationMetricTracker in both the text-only and tool-aware streaming paths. FoundationBackendMetricEmissionTests covers the sink wiring and live-inference paths (guarded by XCTSkip when Apple Intelligence is absent). Co-Authored-By: Claude Sonnet 4.6 <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.
Summary
InferenceMetric,InferenceMetricSink,InMemoryMetricSinkandGenerationMetricTracker/SSEGenerationMetricsfromManifoldCloudCoretoManifoldInference/Metrics/so the Foundation backend (which depends onManifoldInferencebut notManifoldCloudCore) can emit metrics@_exported import ManifoldInferencetoManifoldCloudCore/MetricTypeAliases.swiftfor source compat — existingimport ManifoldCloudCoreconsumers see the types unchangedSSEGenerationMetrics.recordto accept cost fields as explicit params (computed fromInferenceCostEstimatorin the CloudCore callsite) rather than calling the estimator itself, removing the cross-layer deppublic var metricSink: (any InferenceMetricSink)?toFoundationBackend(defaults toInMemoryMetricSink.shared) and wiresGenerationMetricTrackerinto bothrunTextOnlyStreamandrunToolAwareStreamFoundationBackendMetricEmissionTestsinManifoldBackendsTestscovering sink wiring and live-inference paths (guarded byXCTSkipwhen Apple Intelligence is unavailable)Backend checklist
FoundationBackend— wired in this PRSSECloudBackend(Anthropic, OpenAI, Ollama) — already wired, unmodifiedMLXBackend/LlamaBackend— live in companion packages, tracked separatelyTest plan
swift build --build-tests— cleanscripts/test.sh --profile spike --spike-module ManifoldBackendsTests --skip-update— 129/129 Swift Testing passedscripts/test.sh --profile spike --spike-module ManifoldInferenceTests --skip-update— 2647/2647 XCTest passedFoundationBackendMetricEmissionTestscovers: default sink is non-nil, sink can be nilled, metric emitted on success, error path populateserrorClass, nil sink emits nothing🤖 Generated with Claude Code