[PR #2095] [MERGED] Fix inline thinking orphan close parsing #5435

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/issue-2092-thinking-parser


📝 Commits (1)

  • fe0b1a8 Fix inline thinking orphan close parsing

📊 Changes

2 files changed (+80 additions, -0 deletions)

View changed files

➕ src/engine/generation-core/llm/inline-thinking.test.ts (+74 -0)
📝 src/engine/generation-core/llm/inline-thinking.ts (+6 -0)

📄 Description

Linked issue

Closes #2092

Why this change

  • Some providers can emit inline thinking/reasoning close tags followed by visible reply text. If a close tag appears at content position, including an orphan close tag such as </thinking>reply, Marinara should drop only the tag markup and keep the reply as message content instead of exposing or losing the response body.

What changed

  • Treat orphan inline thinking close tags as parser control markup while the stream parser is in content mode.
  • Wait for split orphan close tags across stream chunks before emitting following visible content.
  • Added focused parser regression coverage for <thinking>, <think>, mismatched tag forms, split close tags, orphan close tags, and unrelated tag negative controls.

Refactor impact

Primary owner:

  • Engine generation.

Impact areas reviewed:

  • src/engine/generation/start-generation.ts inline token stream handling.
  • src/engine/generation-core/llm/inline-thinking.ts push/flush parser behavior.

Boundary notes:

  • Engine-only parser change. No React feature imports, shared API adapters, Tauri commands, storage, provider configuration, or remote-runtime boundaries changed.

Pressure points touched:

  • Runtime generation stream parsing only; no shell/mode surfaces, command registration, imports, or storage paths touched.

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

  • Codex ran node --experimental-strip-types scratch\issue-2092-inline-thinking-repro.ts; the focused repro failed before the fix on </thinking>reply and passed after the fix.
  • Codex ran pnpm test -- src\engine\generation-core\llm\inline-thinking.test.ts; 7 parser tests passed.
  • Codex ran pnpm check; line endings, architecture, frontend typecheck, Rust check, docs, discovery, and unused-code checks passed.
  • No browser UI validation was run because this is a parser-only engine generation fix with no visible UI layout or interaction change.
  • Existing PR #2093 also references #2092, but targets staging from another fork and includes broader legacy/package paths. This draft is the focused refactor-targeted fix.

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:

  • Bugfix only; no new discoverable user-facing 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

N/A - parser-only engine generation fix. Proof is the focused stream-parser repro plus Vitest coverage above.


🔄 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/2095 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 6/3/2026 **Status:** ✅ Merged **Merged:** 6/3/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/issue-2092-thinking-parser` --- ### 📝 Commits (1) - [`fe0b1a8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fe0b1a8244d98d8d0a703beefca823f704a6e9c7) Fix inline thinking orphan close parsing ### 📊 Changes **2 files changed** (+80 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `src/engine/generation-core/llm/inline-thinking.test.ts` (+74 -0) 📝 `src/engine/generation-core/llm/inline-thinking.ts` (+6 -0) </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 <!-- Every user-facing PR should reference a feature request or issue report when practical. --> Closes #2092 ## Why this change <!-- What user problem, bug, refactor goal, or maintenance need does this solve? --> - Some providers can emit inline thinking/reasoning close tags followed by visible reply text. If a close tag appears at content position, including an orphan close tag such as `</thinking>reply`, Marinara should drop only the tag markup and keep the reply as message content instead of exposing or losing the response body. ## What changed <!-- List the key changes in this PR. --> - Treat orphan inline thinking close tags as parser control markup while the stream parser is in content mode. - Wait for split orphan close tags across stream chunks before emitting following visible content. - Added focused parser regression coverage for `<thinking>`, `<think>`, mismatched tag forms, split close tags, orphan close tags, and unrelated tag negative controls. ## Refactor impact Primary owner: <!-- Examples: app shell, catalog, chat mode, roleplay mode, game mode, runtime generation, world-state, shared API, engine generation, Rust storage, imports, remote runtime. --> - Engine generation. Impact areas reviewed: - `src/engine/generation/start-generation.ts` inline token stream handling. - `src/engine/generation-core/llm/inline-thinking.ts` push/flush parser behavior. Boundary notes: <!-- Note engine/shared-api/feature/Rust/remote-runtime boundaries. Say "none" only if you checked. --> - Engine-only parser change. No React feature imports, shared API adapters, Tauri commands, storage, provider configuration, or remote-runtime boundaries changed. Pressure points touched: <!-- Mention ModeSurface, GameSurface, shared mode UI, src-tauri/src/lib.rs command registration, or import modules if touched. --> - Runtime generation stream parsing only; no shell/mode surfaces, command registration, imports, or storage paths touched. ## Validation <!-- Check only what you personally ran or manually verified. Treat unchecked items as explicit TODOs. --> <!-- Do not submit *.test.ts or *.test.tsx files as PR proof; cite existing checks, command output, app/browser/Tauri verification, or manual notes instead. --> - [ ] 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 <!-- Describe exact commands and manual steps, including typecheck/build/docs/architecture/Rust/browser/remote-runtime checks when they apply. If an AI agent filled this out, verify it yourself before ticking boxes. --> - Codex ran `node --experimental-strip-types scratch\issue-2092-inline-thinking-repro.ts`; the focused repro failed before the fix on `</thinking>reply` and passed after the fix. - Codex ran `pnpm test -- src\engine\generation-core\llm\inline-thinking.test.ts`; 7 parser tests passed. - Codex ran `pnpm check`; line endings, architecture, frontend typecheck, Rust check, docs, discovery, and unused-code checks passed. - No browser UI validation was run because this is a parser-only engine generation fix with no visible UI layout or interaction change. - Existing PR #2093 also references #2092, but targets `staging` from another fork and includes broader legacy/package paths. This draft is the focused `refactor`-targeted fix. ## 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: - Bugfix only; no new discoverable user-facing 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 <!-- Add before/after screenshots or recordings for visible UI changes. --> N/A - parser-only engine generation fix. Proof is the focused stream-parser repro plus Vitest coverage above. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:16:17 +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#5435
No description provided.