Skip to content

feat(inference): relocate InferenceMetric to ManifoldInference + wire FoundationBackend metrics#1883

Merged
roryford merged 1 commit into
mainfrom
feat/obs-metric-parity
Jun 15, 2026
Merged

feat(inference): relocate InferenceMetric to ManifoldInference + wire FoundationBackend metrics#1883
roryford merged 1 commit into
mainfrom
feat/obs-metric-parity

Conversation

@roryford

Copy link
Copy Markdown
Owner

Summary

  • Moves InferenceMetric, InferenceMetricSink, InMemoryMetricSink and GenerationMetricTracker/SSEGenerationMetrics from ManifoldCloudCore to ManifoldInference/Metrics/ so the Foundation backend (which depends on ManifoldInference but not ManifoldCloudCore) can emit metrics
  • Adds @_exported import ManifoldInference to ManifoldCloudCore/MetricTypeAliases.swift for source compat — existing import ManifoldCloudCore consumers see the types unchanged
  • Refactors SSEGenerationMetrics.record to accept cost fields as explicit params (computed from InferenceCostEstimator in the CloudCore callsite) rather than calling the estimator itself, removing the cross-layer dep
  • Adds public var metricSink: (any InferenceMetricSink)? to FoundationBackend (defaults to InMemoryMetricSink.shared) and wires GenerationMetricTracker into both runTextOnlyStream and runToolAwareStream
  • Adds FoundationBackendMetricEmissionTests in ManifoldBackendsTests covering sink wiring and live-inference paths (guarded by XCTSkip when Apple Intelligence is unavailable)

Backend checklist

  • FoundationBackend — wired in this PR
  • SSECloudBackend (Anthropic, OpenAI, Ollama) — already wired, unmodified
  • MLXBackend / LlamaBackend — live in companion packages, tracked separately

Test plan

  • swift build --build-tests — clean
  • scripts/test.sh --profile spike --spike-module ManifoldBackendsTests --skip-update — 129/129 Swift Testing passed
  • scripts/test.sh --profile spike --spike-module ManifoldInferenceTests --skip-update — 2647/2647 XCTest passed
  • New FoundationBackendMetricEmissionTests covers: default sink is non-nil, sink can be nilled, metric emitted on success, error path populates errorClass, nil sink emits nothing

🤖 Generated with Claude Code

… 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>
@roryford roryford merged commit 072c5dc into main Jun 15, 2026
12 checks passed
@roryford roryford deleted the feat/obs-metric-parity branch June 15, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant