Skip to content

desktop (S12): land Apple Foundation Models behind the local-inference port, dark - #14395

Merged
Git-on-my-level merged 4 commits into
mainfrom
feat/desktop-afm-local-inference-engine
Sep 17, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
feat/desktop-afm-local-inference-engine

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Lands the Apple Foundation Models engine behind the existing local-inference port. Dark: the default engine is still .localServer and OMI_FORCE_LOCAL_INFERENCE_ENGINE=afm is the only way to select AFM.

The free tier replaces cloud conversation summarization with an on-device summary. That pipeline (S10/S11) already shipped dark and complete: ConversationChunkSummarizer → LocalInferenceRuntime (fail-closed ladder: selected engine → one retry → DeterministicConversationMinimum, never cloud) → LocalProjectionFinalization → the backend client_processing projection. The only registered engine was LocalServerInferenceAdapter, an OpenAI-compatible loopback client defaulting to 127.0.0.1:11434 — Ollama. Ordinary users do not run Ollama, so in practice a free-tier conversation never got a summary at all. LocalInferenceEngineID.afm already existed with the comment "S12 lands the adapter"; this is that.

What it does

AFMLocalInferenceAdapter conforms to LocalInferenceService. AFMJSONSchemaBridge walks the port's JSON Schema into DynamicGenerationSchema / GenerationSchema — there is no jsonSchema: initializer on this SDK, so the walk is the bridge. Unsupported keywords throw capabilityUnavailable rather than being silently dropped, and nesting deeper than 8 is rejected instead of exhausting the stack.

Availability is fail-closed: anything other than .available from SystemLanguageModel.default.availability — Apple Intelligence off, model not downloaded, ineligible device, OS below 26 — becomes engineUnavailable(.afm), so the runtime degrades to the deterministic minimum. runToolLoop throws capabilityUnavailable. The package target is macOS 14.0 and all Foundation Models use sits behind canImport plus macOS 26 availability guards.

Context window is read at runtime. SystemLanguageModel.contextSize is a runtime getter, not a constant; on macOS 27 with Apple Intelligence available it reports 8192. An earlier revision of this branch hardcoded 4096, which would have doubled the summarizer's map passes since ConversationChunkSummarizer is window-agnostic and trusts this number. Values outside 256…131072 fall back to a clearly-labelled constant, because a zero or negative window yields a nominal 64-token budget and Int.min would trap during the chunker's subtraction, bypassing the fail-closed ladder entirely.

Required draft fields. LocalSummaryDraft's schema previously required only title, so guided generation legitimately omitted every optional field and produced title-only drafts. It now requires the fields the map/reduce prompts actually ask for. This schema is shared by every engine; the downstream contract tolerates absence either way (ProjectedStructure/ClientProcessing have defaults and ClientProcessingContract.assemble always emits overview and arrays), so the change is safe for the local-server path. That path also now wraps decode failures as .invalidResponse so undecodable output is treated as deterministic and not retried.

Known limitation: macOS 27 error classification under the Xcode 26.6 pin

On macOS 27 the framework throws LanguageModelError, which is @available(macOS 27.0, *) and therefore cannot be named under the pinned ship toolchain (desktop/macos/ci/xcode-pin.json → Xcode 26.6). So the adapter maps LanguageModelSession.GenerationError and falls back at runtime behind if #available(macOS 27.0, *).

Consequence, stated plainly: a 26.6-built binary running on macOS 27 classifies LanguageModelError.refusal as a retryable session_failed, so the runtime retries once even though refusal is documented non-retryable.

This is not hidden behind a compiler gate. An earlier revision used #if compiler(>=6.4), which desktop/macos/scripts/check-desktop-compiler-gates.py correctly rejected — that is the #12867/#13548 class, where a compiler gate compiles Apple SDK APIs out of the pinned toolchain so CI stays green while the shipped app silently builds the fallback. The checker now reports desktop compiler gates: none found. Closing this properly needs an Xcode pin bump, which is a separate decision. AFM ships dark, so nothing in production is exposed today.

This engine alone does not deliver a free-tier summary

Found while reviewing this branch, verified independently, and out of scope here: the desktop client never renders the projection it uploads. ServerConversation.init (APIClient+ConversationModels.swift:222-230) builds its visible structured value from wire.structured alone and drops wire.clientProcessing, while the backend bind endpoint deliberately "updates only client_processing. Never touches structured". ConversationProcessingState's docstring makes rendering the projection a client contract. So a free-tier user still sees the deterministic minimum until a client change lands. That is pre-existing, separate work, and tracked.

Failure-Class: FC-advertised-capability-acknowledges-and-drops

Evidence

xcrun swift test --package-path Desktop on macOS 27 (this Mac's toolchain is Xcode 27 / Swift 6.4, newer than the 26.6 CI pin, so run-swift-ci.sh was not used):

AFMLocalInferenceAdapterTests                 21 tests, 0 failures (2 skipped)
LocalServerInferenceAdapterTests              passed
ConversationChunkSummarizerTests              passed
ConversationFinalizationLocalProjectionTests  passed
LocalInferenceRuntimeFailClosedTests          passed
LocalSummaryBenchmarkTests                    passed
Omi ComputerTests.xctest                      60 tests, 0 failures (4 skipped)

The two skips are the GenerationError classification tests: that type is obsoleted: 27.0, so they cannot run on this Mac and will execute on CI's 26.6 runner, which is the toolchain they describe.

python3 desktop/macos/scripts/check-desktop-compiler-gates.py → desktop compiler gates: none found.

Live, against the real on-device model (OMI_AFM_LIVE=1, gated so CI never needs Apple Intelligence):

AFM_LIVE_WINDOW: selected=8192 systemLanguageModel.contextSize=8192
AFM_LIVE_DRAFT: title=On-Device Summarizer Launch overview_len=81 sections=2 action_items=1
AFM_LIVE_PROJECTION: runtime=local model=afm sections=2 action_items=1

That is a real StoredClientProjection out of ConversationChunkSummarizer, not the deterministic minimum.

Layer measured: unit tests plus a live on-device run on this Mac. Not measured: a macOS 14.0 launch proving dyld weak-linking of FoundationModels, and a build under the pinned Xcode 26.6 (not installed here).

🤖 Generated with Claude Code

Review in cubic

Git-on-my-level and others added 4 commits September 18, 2026 01:48
Register AFMLocalInferenceAdapter so forceLocalInferenceEngine=afm can
select on-device guided generation. Default remains local-server.

Co-authored-by: Cursor <[email protected]>
… prompts ask for

Hardcoding 4096 was half this Mac's live window and is not what contextSize returns. Report SystemLanguageModel.default.contextSize when the model is available; 4096 is only the unavailable/old-OS fallback. Guided generation was omitting overview/sections because only title was required. Gate the live suite on OMI_AFM_LIVE=1.

Co-authored-by: Cursor <[email protected]>
LanguageModelError.refusal was falling through to a retryable session_failed. Map the current framework errors, keep GenerationError only on the Xcode 26.6 path, reject out-of-range windows, and wrap local-server DecodingError as invalidResponse so undecodable output is not retried.

Co-authored-by: Cursor <[email protected]>
…26.6 pin

LanguageModelError and related replacements are macOS 27 SDK types, not 26.4. Naming them behind #if compiler compiled the mapping out of the ship toolchain. Map GenerationError only, with a runtime macOS 27 fallback that documents the retryable-refusal gap until the Xcode pin moves.

Co-authored-by: Cursor <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 53cbdb0 into main Sep 17, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the feat/desktop-afm-local-inference-engine branch September 17, 2026 21:53
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