[PR #2210] [MERGED] Fix managed message attachment handling #5471

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/managed-message-attachments


📝 Commits (8)

  • bebfde9 Fix managed message attachment handling
  • ce0c3b6 Address managed attachment review feedback
  • 290f72b Clean up streaming attachment rollback
  • ad93fd5 Harden managed attachment rollback
  • 5ec7bae Restore chat draft after send failure
  • 755e963 Guard chat send retry restoration
  • bccc172 Address managed attachment review findings
  • 5db9adf Deduplicate URL blob conversion

📊 Changes

20 files changed (+1075 additions, -213 deletions)

View changed files

📝 src/engine/capabilities/storage.ts (+12 -0)
📝 src/engine/contracts/schemas/chat.schema.ts (+8 -3)
📝 src/engine/contracts/types/chat.ts (+2 -0)
📝 src/engine/generation/generate-route-utils.ts (+3 -14)
📝 src/engine/generation/start-generation.ts (+70 -26)
➕ src/engine/shared/attachments/image-attachments.ts (+203 -0)
➕ src/features/catalog/gallery/cache.ts (+26 -0)
📝 src/features/catalog/gallery/index.ts (+1 -0)
📝 src/features/modes/conversation/components/ConversationInput.tsx (+208 -42)
📝 src/features/modes/conversation/components/ConversationMessage.tsx (+27 -42)
📝 src/features/modes/game/components/GameInput.tsx (+11 -5)
📝 src/features/modes/game/components/GameSurface.tsx (+80 -26)
📝 src/features/modes/shared/chat-ui/components/ChatInput.tsx (+95 -9)
📝 src/features/modes/shared/chat-ui/components/ChatMessage.tsx (+21 -40)
➕ src/features/modes/shared/chat-ui/components/MessageAttachmentImagePreview.tsx (+133 -0)
📝 src/features/modes/shared/chat-ui/index.ts (+1 -0)
📝 src/features/modes/shared/chat-ui/lib/message-attachments.ts (+15 -3)
📝 src/features/runtime/generation/hooks/use-generate.ts (+5 -2)
➕ src/shared/api/message-attachment-api.ts (+20 -0)
📝 src/shared/api/storage-api.ts (+134 -1)

📄 Description

Linked issue

N/A

Why this change

  • Image attachments on user messages need to be stored as managed gallery assets instead of keeping inline data in message extras.
  • Attachment preparation failures should not silently clear the user's draft or pending files.
  • Gallery drawers should refresh when message attachments create new gallery rows.

What changed

  • Added managed image attachment preparation and provider data-url resolution through the storage gateway.
  • Saved attachment-only user messages and preserved managed attachment references on generated/manual message paths.
  • Updated conversation, shared chat, and game input flows so failed attachment preparation leaves drafts and files in place.
  • Invalidated gallery image queries after managed attachment rows are created.
  • Expanded the generation attachment schema to accept managed reference fields such as url, filePath, and galleryId.

Refactor impact

Primary owner:

Engine generation, shared API storage, and mode input surfaces.

Impact areas reviewed:

  • Conversation and shared chat input send/post-only paths.
  • Game turn input and GameSurface send path.
  • Gallery image query cache invalidation.
  • Message attachment rendering and generation attachment contract.

Boundary notes:

  • Engine code uses the StorageGateway port for storage-backed attachment behavior.
  • Shared API owns managed gallery URL/data resolution through existing storage, local-file, and URL-binary wrappers.
  • Feature UI calls typed shared API/runtime helpers and does not add raw Tauri or remote-runtime calls.
  • Rust command boundaries are unchanged; existing generic gallery storage create continues to persist inline data URLs as managed files.

Pressure points touched:

  • GameSurface send orchestration.
  • Shared mode ChatInput.

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

Commands run locally:

  • git diff --check
  • git diff --cached --check
  • pnpm typecheck
  • pnpm check:architecture
  • pnpm check

Manual native Tauri image-send QA was not run. The remaining manual check is sending an image attachment in conversation/roleplay and game, then confirming the message renders, provider image input still works, and the gallery updates.

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:

N/A proposed: this is a bugfix/internal storage and send-flow correction, not a new discoverable feature. Left unchecked for human confirmation.

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

Docs/release notes: no docs changes were needed for this bugfix. No root changelog/release note file is present in this checkout.

UI evidence

No screenshots or recordings captured. Native/manual UI QA remains the main proof gap.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced image attachment support with improved handling of URLs, file paths, and gallery-backed references.
    • Added automatic data URL resolution for image attachments across conversations and games.
  • Bug Fixes

    • Improved attachment validation and caching behavior for image attachments.

🔄 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/2210 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 6/4/2026 **Status:** ✅ Merged **Merged:** 6/5/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/managed-message-attachments` --- ### 📝 Commits (8) - [`bebfde9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bebfde9780d2780b57beee2d8e34b45eba2ab92f) Fix managed message attachment handling - [`ce0c3b6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ce0c3b6692ea57804b2b4ed4b2b64706b2ac197d) Address managed attachment review feedback - [`290f72b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/290f72bc15f11ca807b69eec358d6e015ba1e42c) Clean up streaming attachment rollback - [`ad93fd5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ad93fd57966576b47a4ea9ba057292eff6c0137a) Harden managed attachment rollback - [`5ec7bae`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5ec7bae05dd024947d3339c127d5c33a08d473c9) Restore chat draft after send failure - [`755e963`](https://github.com/Pasta-Devs/Marinara-Engine/commit/755e96349a6ec0b5360b12d8e21810551f6e446d) Guard chat send retry restoration - [`bccc172`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bccc1725979600eb61005574d40c2fe0a7dff03a) Address managed attachment review findings - [`5db9adf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5db9adf493b7a47facffcf637dd41e4e7395cbfb) Deduplicate URL blob conversion ### 📊 Changes **20 files changed** (+1075 additions, -213 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/capabilities/storage.ts` (+12 -0) 📝 `src/engine/contracts/schemas/chat.schema.ts` (+8 -3) 📝 `src/engine/contracts/types/chat.ts` (+2 -0) 📝 `src/engine/generation/generate-route-utils.ts` (+3 -14) 📝 `src/engine/generation/start-generation.ts` (+70 -26) ➕ `src/engine/shared/attachments/image-attachments.ts` (+203 -0) ➕ `src/features/catalog/gallery/cache.ts` (+26 -0) 📝 `src/features/catalog/gallery/index.ts` (+1 -0) 📝 `src/features/modes/conversation/components/ConversationInput.tsx` (+208 -42) 📝 `src/features/modes/conversation/components/ConversationMessage.tsx` (+27 -42) 📝 `src/features/modes/game/components/GameInput.tsx` (+11 -5) 📝 `src/features/modes/game/components/GameSurface.tsx` (+80 -26) 📝 `src/features/modes/shared/chat-ui/components/ChatInput.tsx` (+95 -9) 📝 `src/features/modes/shared/chat-ui/components/ChatMessage.tsx` (+21 -40) ➕ `src/features/modes/shared/chat-ui/components/MessageAttachmentImagePreview.tsx` (+133 -0) 📝 `src/features/modes/shared/chat-ui/index.ts` (+1 -0) 📝 `src/features/modes/shared/chat-ui/lib/message-attachments.ts` (+15 -3) 📝 `src/features/runtime/generation/hooks/use-generate.ts` (+5 -2) ➕ `src/shared/api/message-attachment-api.ts` (+20 -0) 📝 `src/shared/api/storage-api.ts` (+134 -1) </details> ### 📄 Description ## Linked issue N/A ## Why this change - Image attachments on user messages need to be stored as managed gallery assets instead of keeping inline data in message extras. - Attachment preparation failures should not silently clear the user's draft or pending files. - Gallery drawers should refresh when message attachments create new gallery rows. ## What changed - Added managed image attachment preparation and provider data-url resolution through the storage gateway. - Saved attachment-only user messages and preserved managed attachment references on generated/manual message paths. - Updated conversation, shared chat, and game input flows so failed attachment preparation leaves drafts and files in place. - Invalidated gallery image queries after managed attachment rows are created. - Expanded the generation attachment schema to accept managed reference fields such as `url`, `filePath`, and `galleryId`. ## Refactor impact Primary owner: Engine generation, shared API storage, and mode input surfaces. Impact areas reviewed: - Conversation and shared chat input send/post-only paths. - Game turn input and GameSurface send path. - Gallery image query cache invalidation. - Message attachment rendering and generation attachment contract. Boundary notes: - Engine code uses the `StorageGateway` port for storage-backed attachment behavior. - Shared API owns managed gallery URL/data resolution through existing storage, local-file, and URL-binary wrappers. - Feature UI calls typed shared API/runtime helpers and does not add raw Tauri or remote-runtime calls. - Rust command boundaries are unchanged; existing generic gallery storage create continues to persist inline data URLs as managed files. Pressure points touched: - `GameSurface` send orchestration. - Shared mode `ChatInput`. ## 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 Commands run locally: - `git diff --check` - `git diff --cached --check` - `pnpm typecheck` - `pnpm check:architecture` - `pnpm check` Manual native Tauri image-send QA was not run. The remaining manual check is sending an image attachment in conversation/roleplay and game, then confirming the message renders, provider image input still works, and the gallery updates. ## 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: N/A proposed: this is a bugfix/internal storage and send-flow correction, not a new discoverable feature. Left unchecked for human confirmation. ## 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 Docs/release notes: no docs changes were needed for this bugfix. No root changelog/release note file is present in this checkout. ## UI evidence No screenshots or recordings captured. Native/manual UI QA remains the main proof gap. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Enhanced image attachment support with improved handling of URLs, file paths, and gallery-backed references. * Added automatic data URL resolution for image attachments across conversations and games. * **Bug Fixes** * Improved attachment validation and caching behavior for image attachments. <!-- 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:16:37 +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#5471
No description provided.