[PR #2432] [MERGED] Fix remote stream unload cancellation #5606

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/2432
Author: @Xelvanis
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Xelvanis

Base: refactor ← Head: fix/2416-remote-stream-unload-cancel


📝 Commits (2)

  • 3a4017a Fix remote stream unload cancellation
  • 09a9ce2 Add remote stream unload cancellation proof

📊 Changes

3 files changed (+84 additions, -7 deletions)

View changed files

📝 src/shared/api/llm-api.ts (+18 -3)
📝 src/shared/api/remote-runtime.test.ts (+60 -3)
📝 src/shared/api/remote-runtime.ts (+6 -1)

📄 Description

Linked issue

Closes #2416

Why this change

  • Remote Runtime LLM streams only cancelled on an explicit AbortSignal, so page unload/navigation could leave the remote provider stream and Rust stream registry active after the web shell went away.

What changed

  • Track active remote LLM stream IDs in the shared LLM API wrapper.
  • Reuse the existing unload cancellation listener for both embedded Tauri and remote runtime streams.
  • Send remote unload cancellation through /api/llm/stream/:stream_id/cancel with keepalive so unload delivery has the best browser-supported chance to reach the runtime.
  • Add focused proof for remote cancel keepalive propagation and llmApi pagehide cancellation.
  • Keep existing explicit abort cancellation behavior unchanged.

Refactor impact

Primary owner:

Shared API / remote runtime LLM stream lifecycle.

Impact areas reviewed:

  • Shared LLM API stream wrapper.
  • Remote runtime cancel helper.
  • Rust HTTP stream cancel route and active/pending stream cancellation registry.
  • Embedded Tauri stream unload cancellation path.

Boundary notes:

  • Frontend feature code still calls the typed shared LLM gateway.
  • Remote-capable behavior stays in src/shared/api and the existing dedicated Rust HTTP stream/cancel route.
  • No engine, React feature, storage schema, or provider transport contract changes.

Pressure points touched:

  • Remote Runtime LLM streaming lifecycle only.

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 passed after adding focused proof for keepalive propagation and pagehide-triggered remote stream cancellation.
  • pnpm check passed after the proof update.
  • Earlier branch validation also included pnpm typecheck, pnpm check:architecture, parityscan against origin/main, and Bunny-style local review.
  • Native Tauri/manual remote-runtime unload QA was not run.

Durable test rationale:

  • Regression/risky invariant: #2416 covers remote streams leaking when the web shell unloads without explicit abort.
  • Existing proof gap: prior validation used a temporary local harness and did not leave a committed guard for Bunny's unload-time keepalive warning.
  • Narrowness: the added proof extends existing src/shared/api/remote-runtime.test.ts coverage only around cancelRemoteLlmStream request options and llmApi.stream(...) pagehide cancellation.

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:

  • Internal stream lifecycle bugfix; no new user-discoverable surface.

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.


🔄 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/2432 **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/2416-remote-stream-unload-cancel` --- ### 📝 Commits (2) - [`3a4017a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3a4017a10d92d10e00818514f29d0427a1e5a0f4) Fix remote stream unload cancellation - [`09a9ce2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/09a9ce26053c6ead6ce1c3c873f9f316f07c1af3) Add remote stream unload cancellation proof ### 📊 Changes **3 files changed** (+84 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/shared/api/llm-api.ts` (+18 -3) 📝 `src/shared/api/remote-runtime.test.ts` (+60 -3) 📝 `src/shared/api/remote-runtime.ts` (+6 -1) </details> ### 📄 Description ## Linked issue Closes #2416 ## Why this change - Remote Runtime LLM streams only cancelled on an explicit `AbortSignal`, so page unload/navigation could leave the remote provider stream and Rust stream registry active after the web shell went away. ## What changed - Track active remote LLM stream IDs in the shared LLM API wrapper. - Reuse the existing unload cancellation listener for both embedded Tauri and remote runtime streams. - Send remote unload cancellation through `/api/llm/stream/:stream_id/cancel` with `keepalive` so unload delivery has the best browser-supported chance to reach the runtime. - Add focused proof for remote cancel `keepalive` propagation and `llmApi` pagehide cancellation. - Keep existing explicit abort cancellation behavior unchanged. ## Refactor impact Primary owner: Shared API / remote runtime LLM stream lifecycle. Impact areas reviewed: - Shared LLM API stream wrapper. - Remote runtime cancel helper. - Rust HTTP stream cancel route and active/pending stream cancellation registry. - Embedded Tauri stream unload cancellation path. Boundary notes: - Frontend feature code still calls the typed shared LLM gateway. - Remote-capable behavior stays in `src/shared/api` and the existing dedicated Rust HTTP stream/cancel route. - No engine, React feature, storage schema, or provider transport contract changes. Pressure points touched: - Remote Runtime LLM streaming lifecycle only. ## 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` passed after adding focused proof for `keepalive` propagation and pagehide-triggered remote stream cancellation. - `pnpm check` passed after the proof update. - Earlier branch validation also included `pnpm typecheck`, `pnpm check:architecture`, parityscan against `origin/main`, and Bunny-style local review. - Native Tauri/manual remote-runtime unload QA was not run. Durable test rationale: - Regression/risky invariant: #2416 covers remote streams leaking when the web shell unloads without explicit abort. - Existing proof gap: prior validation used a temporary local harness and did not leave a committed guard for Bunny's unload-time `keepalive` warning. - Narrowness: the added proof extends existing `src/shared/api/remote-runtime.test.ts` coverage only around `cancelRemoteLlmStream` request options and `llmApi.stream(...)` pagehide cancellation. ## 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: - Internal stream lifecycle bugfix; no new user-discoverable surface. ## 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. --- <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#5606
No description provided.