Skip to content

feat(api): item 15(a) MLX OOM 自动恢复 gc+重试 (CC 2.1.234, closes #128) - #129

Merged
dahai80 merged 1 commit into
mainfrom
feat/item15-mlx-oom-gc-retry
Aug 22, 2026
Merged

dahai80 merged 1 commit into
mainfrom
feat/item15-mlx-oom-gc-retry

Conversation

@dahai80

@dahai80 dahai80 commented Aug 22, 2026

Copy link
Copy Markdown
Owner

背景

enhance-0819.md item 15: MLX OOM 自动恢复。

memory_guard 撞顶 (memory limit exceeded / Reduce context size) 原为确定性失败 — 同上下文重试必再 OOM → 标 x-should-retry:false 立即放弃。但若先 gc 释放显存, 同上下文可能装下。

改动 (surgical)

src/services/api/fusion-mlx-adapter.ts (1 文件):

  • const mlxResponse → let (:1636) — gc-retry 成功时重赋值转 OK 路径
  • OOM 检测块 (:1649-1734): OOM → requestMlxGC() (:604) → 若 gc 成功, mlxFetchWithRetry (:372) 重发同 mlxBody 一次。成功转既有 OK 路径 (流式/非流式分支原样复用); gc 失败 / 重发仍失败 / 重发异常 → fallback 既有 x-should-retry:false 错误 (防空转重试)

mirror 既有 truncate-retry 模式 (非流式 max_tokens 升级 :1710)。仅 OOM case 触发, 不碰更高层 truncate/compact/熔断 路径。重试一次不循环。requestMlxGC / mlxFetchWithRetry 同文件已有。

测试

tests/services/api/fusion-mlx-adapter.test.ts (+195, 5 新测):

  1. OOM → gc 成功 + 重发成功 → 返回 200 正常响应
  2. OOM → gc 失败 → fallback x-should-retry:false, 不重发
  3. OOM → gc 成功但重发仍 OOM → fallback x-should-retry:false
  4. OOM 重发抛异常 → fallback x-should-retry:false (异常被 catch 不传播)
  5. 非 OOM 错误 → 不调 gc, 既有行为不变 (无 x-should-retry)

门禁

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 407 pass / 0 fail
  • bun test tests/services/api/fusion-mlx-adapter.test.ts — 36 pass (5 新)
  • bunx biome lint src/services/api/fusion-mlx-adapter.ts — 0 error (2 warn 4 info, 既有)
  • bun run build:dev — pass

范围说明

item 15(b) gateway reconnect+stream-resume 为 L-size 跨 3 文件框架 (MLX SSE 无 resume cursor, 现无 stream-resume infra), 独立 defer — 见 issue #128。

关联

Co-Authored-By: Claude Fable 5 [email protected]

memory_guard 撞顶 (memory limit exceeded / Reduce context size) 原为确定性
失败: 同上下文重试必再 OOM → 标 x-should-retry:false 立即放弃。但若先 gc
释放显存, 同上下文可能装下。

本 PR: OOM 检测 → requestMlxGC() (POST /api/v1/gc, 同文件 :604) → 若 gc 成功,
mlxFetchWithRetry (同文件 :372) 重发同 mlxBody 一次。成功则转既有 OK 路径
(流式/非流式分支原样复用); gc 失败/重发仍失败/重发异常 → fallback 既有
x-should-retry:false 错误 (防空转重试)。

mirror 既有 truncate-retry 模式 (非流式 max_tokens 升级 :1710), 同为 adapter
层透传恢复。仅 OOM case 触发, 不碰更高层 truncate/compact/熔断 路径。
重试一次不循环。infra (requestMlxGC/mlxFetchWithRetry) 同文件已有。

item 15(b) gateway reconnect+stream-resume 为 L-size 跨 3 文件框架, MLX SSE
无 resume cursor, 现无 stream-resume infra — 独立 defer (见 issue #128)。

测试: 5 新测覆盖 gc-retry 全分支 (成功/失败/重发仍 OOM/重发异常/非 OOM 不触发)。
门禁: typecheck 0 / 407 测 pass / lint 0 err / build:dev pass。

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit bdfb8a8 into main Aug 22, 2026
1 check passed
@dahai80
dahai80 deleted the feat/item15-mlx-oom-gc-retry branch August 22, 2026 14:02
dahai80 added a commit that referenced this pull request Aug 22, 2026
Patch release bundling 17 commits since v0.4.23:
- item 15(a) MLX OOM auto-recovery gc+retry (#129)
- #7 one-click diagnostic fixAction framework (#131)
- 维度5 background-default spawn FUSION_SUBAGENT_DEFAULT_BACKGROUND (#127)
- #4 proactive MLX OOM detection via /v1/health (#125)
- item 17 fullscreen pre-compact history + :598 synthetic decouple (#123)
- item 25B workflow stagger fan-out (#122)
- item 21 auto-mode local rule classifier test coverage (#120)
- item 23 archive plugin source + SHA-256 lock (#118)
- item 24 marketplace command source (#116)
- item 6 transcript disk trimming + crash-safe checkpoint (#114)
- item 5 normalizeMessages secondary normalize cache (#112)
- item 19 screen-reader plaintext render (#110)
- item 16 compact retry countdown + stall hint (#108)
- item 25A workflow execution runtime docs (#106)
- item 25A minimal workflow execution runtime (#105)
- item 12 subagent auto-background threshold (#103)
- item 20 vimInsertModeRemaps dual-key INSERT sequence (#101)

Co-Authored-By: Claude Fable 5 <[email protected]>
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.

item 15(a): MLX OOM 自动恢复 — gc + 重试 (surgical sub-feature)

1 participant