[PR #2436] [MERGED] Fix LLM stream error event parity #5607

Closed
opened 2026-10-22 04:17:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2436
Author: @Xelvanis
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Xelvanis

Base: refactor ← Head: fix/stream-error-contract-2415


📝 Commits (2)

  • 690db61 Fix LLM stream error event parity
  • 98b077f Address stream error review feedback

📊 Changes

8 files changed (+376 additions, -39 deletions)

View changed files

📝 src/engine/generation/agent-runner.test.ts (+40 -0)
📝 src/engine/generation/agent-runner.ts (+19 -3)
📝 src/engine/generation/makers.ts (+18 -2)
📝 src/engine/generation/start-generation.test.ts (+24 -2)
📝 src/engine/generation/start-generation.ts (+11 -2)
📝 src/shared/api/llm-api.ts (+81 -5)
📝 src/shared/api/remote-runtime.test.ts (+166 -1)
📝 src/shared/api/remote-runtime.ts (+17 -24)

📄 Description

Linked issue

Closes #2415

Why this change

  • Embedded Tauri LLM streaming could reject the native command on provider/Rust failures instead of yielding the documented error stream chunk.
  • Remote runtime already emitted stream error events, but the shared remote adapter converted them back into thrown API errors.
  • This made 11-PROV-RUNTIME-stream-event-contract drift between embedded and remote runtime paths.

What changed

  • Convert embedded llm_stream_channel command rejections into terminal type: "error" chunks while preserving thrown AbortError cancellation behavior.
  • Preserve remote /api/llm/stream SSE error chunks as yielded terminal stream events.
  • Normalize provider error text from text, string data, top-level message/error, and data.message/data.error.
  • Make generation, agent, and maker stream consumers fail normally when they receive a stream error chunk.
  • Add focused shared API tests for remote SSE error events, embedded native command rejection, and embedded cancellation.

Refactor impact

Primary owner:

Shared API / runtime generation / engine generation.

Impact areas reviewed:

  • Shared API LLM wrapper and remote runtime SSE reader.
  • Embedded Tauri LLM stream command rejection path.
  • Main generation, agent runner, and maker stream consumers.
  • Legacy origin/main SSE stream error behavior for parity.

Boundary notes:

  • Runtime adapter behavior stays in src/shared/api.
  • Product generation behavior stays in src/engine.
  • Rust command and HTTP route behavior already emitted or returned the needed error shape; no Rust changes were needed.
  • Remote stream cancellation remains routed through the existing focused shared API wrapper.

Pressure points touched:

  • src/shared/api/llm-api.ts
  • src/shared/api/remote-runtime.ts
  • src/engine/generation/start-generation.ts
  • src/engine/generation/agent-runner.ts
  • src/engine/generation/makers.ts

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • pnpm exec vitest run src/shared/api/remote-runtime.test.ts src/engine/generation/agent-runner.test.ts src/engine/generation/start-generation.test.ts passed: 3 test files, 30 tests.
  • pnpm typecheck passed.
  • pnpm check:architecture passed.
  • pnpm check passed.
  • Static comparison against refreshed origin/main confirmed legacy generation SSE sends terminal type: "error" events and legacy client handling treats error events as terminal.
  • Manual live Tauri/provider and live remote-runtime streaming QA were not run.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Stream error contract bugfix only; no new user-discoverable feature or workflow.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

No visible UI changes. No screenshots or recordings attached.

Summary by CodeRabbit

  • Bug Fixes

    • Improved LLM stream error handling with consistent message extraction across different provider response formats.
    • Enhanced error recovery in generation workflows when LLM providers report failures.
    • Standardized error handling for both remote and native streaming modes.
  • Tests

    • Added test coverage for LLM streaming error scenarios and edge cases.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/2436 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/stream-error-contract-2415` --- ### 📝 Commits (2) - [`690db61`](https://github.com/Pasta-Devs/Marinara-Engine/commit/690db61e0d3435d42b47651dd796a2c14b74a5d2) Fix LLM stream error event parity - [`98b077f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/98b077f9ce49e815928722d669c1f92cc5177612) Address stream error review feedback ### 📊 Changes **8 files changed** (+376 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/generation/agent-runner.test.ts` (+40 -0) 📝 `src/engine/generation/agent-runner.ts` (+19 -3) 📝 `src/engine/generation/makers.ts` (+18 -2) 📝 `src/engine/generation/start-generation.test.ts` (+24 -2) 📝 `src/engine/generation/start-generation.ts` (+11 -2) 📝 `src/shared/api/llm-api.ts` (+81 -5) 📝 `src/shared/api/remote-runtime.test.ts` (+166 -1) 📝 `src/shared/api/remote-runtime.ts` (+17 -24) </details> ### 📄 Description ## Linked issue Closes #2415 ## Why this change - Embedded Tauri LLM streaming could reject the native command on provider/Rust failures instead of yielding the documented `error` stream chunk. - Remote runtime already emitted stream error events, but the shared remote adapter converted them back into thrown API errors. - This made `11-PROV-RUNTIME-stream-event-contract` drift between embedded and remote runtime paths. ## What changed - Convert embedded `llm_stream_channel` command rejections into terminal `type: "error"` chunks while preserving thrown `AbortError` cancellation behavior. - Preserve remote `/api/llm/stream` SSE `error` chunks as yielded terminal stream events. - Normalize provider error text from `text`, string `data`, top-level `message`/`error`, and `data.message`/`data.error`. - Make generation, agent, and maker stream consumers fail normally when they receive a stream `error` chunk. - Add focused shared API tests for remote SSE error events, embedded native command rejection, and embedded cancellation. ## Refactor impact Primary owner: Shared API / runtime generation / engine generation. Impact areas reviewed: - Shared API LLM wrapper and remote runtime SSE reader. - Embedded Tauri LLM stream command rejection path. - Main generation, agent runner, and maker stream consumers. - Legacy `origin/main` SSE stream error behavior for parity. Boundary notes: - Runtime adapter behavior stays in `src/shared/api`. - Product generation behavior stays in `src/engine`. - Rust command and HTTP route behavior already emitted or returned the needed error shape; no Rust changes were needed. - Remote stream cancellation remains routed through the existing focused shared API wrapper. Pressure points touched: - `src/shared/api/llm-api.ts` - `src/shared/api/remote-runtime.ts` - `src/engine/generation/start-generation.ts` - `src/engine/generation/agent-runner.ts` - `src/engine/generation/makers.ts` ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `pnpm exec vitest run src/shared/api/remote-runtime.test.ts src/engine/generation/agent-runner.test.ts src/engine/generation/start-generation.test.ts` passed: 3 test files, 30 tests. - `pnpm typecheck` passed. - `pnpm check:architecture` passed. - `pnpm check` passed. - Static comparison against refreshed `origin/main` confirmed legacy generation SSE sends terminal `type: "error"` events and legacy client handling treats error events as terminal. - Manual live Tauri/provider and live remote-runtime streaming QA were not run. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Stream error contract bugfix only; no new user-discoverable feature or workflow. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence No visible UI changes. No screenshots or recordings attached. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved LLM stream error handling with consistent message extraction across different provider response formats. * Enhanced error recovery in generation workflows when LLM providers report failures. * Standardized error handling for both remote and native streaming modes. * **Tests** * Added test coverage for LLM streaming error scenarios and edge cases. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:46 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5607
No description provided.