[PR #1723] [MERGED] Fix terminal LLM stream cleanup #5235

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1723
Author: @Promansis
Created: 5/31/2026
Status: ✅ Merged
Merged: 6/1/2026
Merged by: @Promansis

Base: refactor ← Head: fix/issue-1716-llm-stream-channel


📝 Commits (5)

  • 2137405 auto cancel streams when streams finished.
  • f952e35 Fix LLM stream semantic completion cleanup
  • ba30678 Fix terminal LLM stream cleanup
  • c30ce81 Harden LLM stream cancellation pruning
  • e2c920a Suppress LLM stream done events

📊 Changes

4 files changed (+436 additions, -72 deletions)

View changed files

📝 src-tauri/crates/llm/src/lib.rs (+233 -50)
📝 src-tauri/src/state.rs (+82 -11)
📝 src/shared/api/llm-api.test.ts (+74 -2)
📝 src/shared/api/llm-api.ts (+47 -9)

📄 Description

Linked issue

Closes #1716

Why this change

  • Local LLM streaming could finish at the provider level while the native streaming command remained unsettled, leaving the frontend waiting on native cleanup instead of completing the generator.
  • Some provider terminal chunks were not treated as terminal unless the stream also sent a separate [DONE]-style marker.

What changed

  • Treat OpenAI-compatible chat finish_reason chunks as terminal while preserving emitted token content.
  • Treat Gemini finishReason chunks as terminal even when the terminal metadata block does not include content parts.
  • Add a short Tauri cleanup grace period after a terminal stream event, then cancel native cleanup if the command remains unsettled.
  • Update targeted TS and Rust tests for the terminal-event cleanup path.

Refactor impact

Primary owner:

shared API, Rust LLM provider transport

Impact areas reviewed:

  • Tauri LLM stream channel cleanup and cancellation.
  • OpenAI-compatible chat stream SSE parsing.
  • Google/Gemini stream SSE parsing.
  • Remote runtime stream path for boundary impact.

Boundary notes:

  • Frontend behavior stays in src/shared/api/llm-api.ts.
  • Provider SSE parsing stays in src-tauri/crates/llm.
  • No feature code or engine mode ownership changed.

Pressure points touched:

  • llm_stream_channel cleanup behavior through the shared API wrapper.
  • Rust LLM stream parser terminal handling.

Validation

  • pnpm check passes locally
  • pnpm typecheck passes locally
  • pnpm build passes locally
  • pnpm check:architecture passes locally
  • pnpm check:docs passes locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace passes locally
  • Rust clippy/tests were run for Rust behavior changes
  • Browser or Tauri app manual verification completed
  • Playwright, screenshot, or recording evidence added for UI changes
  • Remote runtime smoke checked when relevant

Manual verification notes

  • pnpm exec vitest run src/shared/api/llm-api.test.ts
  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-llm openai_chat_stream_finish_reason_is_terminal
  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-llm google_stream_finish_reason_is_terminal_without_parts
  • pnpm typecheck
  • cargo check --manifest-path src-tauri/Cargo.toml
  • pnpm check:architecture
  • Live provider, browser/Tauri, and remote runtime smoke checks were not run.

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.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced LLM streaming: improved detection of stream completion across all providers (OpenAI, Anthropic, Google)
    • Improved cancellation handling: better cleanup and timeout management for stopping streams

🔄 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/1723 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 5/31/2026 **Status:** ✅ Merged **Merged:** 6/1/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `refactor` ← **Head:** `fix/issue-1716-llm-stream-channel` --- ### 📝 Commits (5) - [`2137405`](https://github.com/Pasta-Devs/Marinara-Engine/commit/21374051bf5ce77660c7fbf1d762ed3e325ea209) auto cancel streams when streams finished. - [`f952e35`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f952e35fec4850297d827bb63f3f82f9abc838b6) Fix LLM stream semantic completion cleanup - [`ba30678`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ba3067896bf1b5595544d818eb7fd7de28f4227d) Fix terminal LLM stream cleanup - [`c30ce81`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c30ce81f933cb5aaf81d4d8c7552a901e7714d29) Harden LLM stream cancellation pruning - [`e2c920a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e2c920a98c1c682dbf432374623811a95d38c24f) Suppress LLM stream done events ### 📊 Changes **4 files changed** (+436 additions, -72 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/crates/llm/src/lib.rs` (+233 -50) 📝 `src-tauri/src/state.rs` (+82 -11) 📝 `src/shared/api/llm-api.test.ts` (+74 -2) 📝 `src/shared/api/llm-api.ts` (+47 -9) </details> ### 📄 Description <!-- Target branch: `refactor`. Change the base to `refactor` before submitting unless a maintainer explicitly asked for another base. --> <!-- Keep all checkboxes unchecked until a human has actually verified them. --> ## Linked issue Closes #1716 ## Why this change - Local LLM streaming could finish at the provider level while the native streaming command remained unsettled, leaving the frontend waiting on native cleanup instead of completing the generator. - Some provider terminal chunks were not treated as terminal unless the stream also sent a separate `[DONE]`-style marker. ## What changed - Treat OpenAI-compatible chat `finish_reason` chunks as terminal while preserving emitted token content. - Treat Gemini `finishReason` chunks as terminal even when the terminal metadata block does not include content parts. - Add a short Tauri cleanup grace period after a terminal stream event, then cancel native cleanup if the command remains unsettled. - Update targeted TS and Rust tests for the terminal-event cleanup path. ## Refactor impact Primary owner: shared API, Rust LLM provider transport Impact areas reviewed: - Tauri LLM stream channel cleanup and cancellation. - OpenAI-compatible chat stream SSE parsing. - Google/Gemini stream SSE parsing. - Remote runtime stream path for boundary impact. Boundary notes: - Frontend behavior stays in `src/shared/api/llm-api.ts`. - Provider SSE parsing stays in `src-tauri/crates/llm`. - No feature code or engine mode ownership changed. Pressure points touched: - `llm_stream_channel` cleanup behavior through the shared API wrapper. - Rust LLM stream parser terminal handling. ## Validation <!-- Check only what you personally ran or manually verified. Treat unchecked items as explicit TODOs. --> - [x] `pnpm check` passes locally - [x] `pnpm typecheck` passes locally - [x] `pnpm build` passes locally - [x] `pnpm check:architecture` passes locally - [x] `pnpm check:docs` passes locally - [x] `cargo check --manifest-path src-tauri/Cargo.toml --workspace` passes locally - [x] Rust clippy/tests were run for Rust behavior changes - [ ] Browser or Tauri app manual verification completed - [ ] Playwright, screenshot, or recording evidence added for UI changes - [ ] Remote runtime smoke checked when relevant ### Manual verification notes - `pnpm exec vitest run src/shared/api/llm-api.test.ts` - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-llm openai_chat_stream_finish_reason_is_terminal` - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-llm google_stream_finish_reason_is_terminal_without_parts` - `pnpm typecheck` - `cargo check --manifest-path src-tauri/Cargo.toml` - `pnpm check:architecture` - Live provider, browser/Tauri, and remote runtime smoke checks were not run. ## 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. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced LLM streaming: improved detection of stream completion across all providers (OpenAI, Anthropic, Google) * Improved cancellation handling: better cleanup and timeout management for stopping streams <!-- 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:14:28 +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#5235
No description provided.