Skip to content

fix: harden MLX generation path with staged errors and terminal stream events - #34

Merged
corasan merged 8 commits into
mainfrom
fix/reliability-posthog-review
Aug 6, 2026
Merged

fix: harden MLX generation path with staged errors and terminal stream events#34
corasan merged 8 commits into
mainfrom
fix/reliability-posthog-review

Conversation

@corasan

@corasan corasan commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

PostHog data for July 7 to August 6, 2026 showed that all recorded MLX replies failed. Failed replies gave no error detail, no failure stage, and no elapsed time. This PR hardens the common generation path in the module.

Changes

  • Add a concurrency guard. A second generation call now fails fast with LLMError.alreadyGenerating. Overlapping generations on one MLX container can no longer occur.
  • Make LLMError descriptive. It now conforms to LocalizedError and carries a failure stage: prepare, generate, tool, or history. JS receives a real error message.
  • Add a generation_error terminal stream event. On failure, streamWithEvents emits the error message, the stage, and partial stats with the real elapsed time. The promise still rejects.
  • Make interrupts deterministic. stop() or a new load() ends the stream with a terminal generation_end event and partial stats.
  • Regenerate the Nitro bridge for the new event kind and the stage envelope field.

Tests

  • TS: two new mapStreamEventEnvelope tests. All 12 pass.
  • Swift: new standalone LLMErrorTests binary (bun test:ios-llm-error). Passes.
  • Build: the MLXReactNative pod compiles for iOS in the example workspace.

Notes

  • On-device behavior needs a physical device. Verify with the cora app after release.
  • Every streamWithEvents call now ends with exactly one terminal event. Analytics can record real failure time and stage.

https://claude.ai/code/session_01DgCfBw3xKnd12KjNkGLcuV

@corasan
corasan merged commit e14d78b into main Aug 6, 2026
1 of 3 checks passed
@corasan
corasan deleted the fix/reliability-posthog-review branch August 6, 2026 17:15
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