fix(ai): 回滚 LLMSession 的错误 stub-out,正确施加 GPU.synchronize cancel guard

前一个 fix commit (1ee512d) 的 implementer subagent 错误地把 MLX import
全部注释掉,把 actor LLMSession 整体包进 #if false,并新增了一组假的
ModelContainer / ModelConfiguration / LLMModelFactory stub 类型。这是
对 spec 的严重偏离——MLX SPM 依赖已经存在(Task 1 用户手动配置 + 多
次 BUILD SUCCEEDED 已验证)。

本 commit 恢复 ad1b045 的真实 MLX 实现,并保留原本只有 2 行的 P0
修复(GPU.synchronize 仅在 !Task.isCancelled 路径执行)。

防再犯:后续 fix subagent prompt 加入"不要修改与 P0 无关的代码"
显式红线。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
link2026
2026-05-25 16:07:54 +08:00
parent 1ee512dce1
commit f5f78e36a6

View File

@@ -1,12 +1,7 @@
import Foundation import Foundation
import MLX
// TODO: MLX import MLXLLM
// import MLX import MLXLMCommon
// import MLXLLM
// import MLXLMCommon
// MLX
#if false
/// MLX ,actor 线访 /// MLX ,actor 线访
/// mlx-swift-examples 2.29.1(commit 9bff95ca) API /// mlx-swift-examples 2.29.1(commit 9bff95ca) API
@@ -70,6 +65,7 @@ actor LLMSession {
break break
} }
} }
// , GPU
if !Task.isCancelled { if !Task.isCancelled {
MLX.GPU.synchronize() MLX.GPU.synchronize()
} }
@@ -83,23 +79,3 @@ actor LLMSession {
} }
} }
} }
#endif
//
class ModelContainer: @unchecked Sendable {
init() {}
}
struct ModelConfiguration {
let directory: URL
init(directory: URL) { self.directory = directory }
}
class LLMModelFactory: @unchecked Sendable {
static let shared = LLMModelFactory()
func loadContainer(configuration: ModelConfiguration) async throws -> ModelContainer {
throw NSError(domain: "MLXNotAvailable", code: -1, userInfo: [NSLocalizedDescriptionKey: "MLX framework not available"])
}
}