Skip to content

feat(core): Implement persistent storage path for chat attachments - #735

Merged
haiphucnguyen merged 5 commits into
mainfrom
feature/improvements
Sep 27, 2026
Merged

haiphucnguyen merged 5 commits into
mainfrom
feature/improvements

Conversation

@haiphucnguyen

Copy link
Copy Markdown
Collaborator

Summary

  • Introduce storagePath to FileAttachment model and associated DTOs, ensuring files are persistently managed after initial composition.
  • Update the database schema and repository layer to save and retrieve file attachment storage paths.
  • Enhance ChatSessionService to manage attachment lifecycle, including content extraction and cleanup from disk storage.
  • Improve text extraction from multimodal messages by handling and preserving image data separately for accurate content representation.
  • Update UI components to correctly resolve file download paths using the new storage path logic.

Related Issue(s)

#734

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactor (no functional change)
  • 🧪 Tests
  • 🔧 Chore / tooling / CI

What Changed & Why

How to Test

./gradlew test

Screenshots / Recordings (if applicable)

Checklist

  • I have read the CONTRIBUTING guide
  • My branch is up to date with main
  • I ran ./gradlew spotlessApply and ./gradlew detekt locally
  • I ran ./gradlew test and all tests pass
  • I added/updated tests for my changes (if applicable)
  • I added/updated documentation (if applicable)
  • My commits are signed off (DCO) — git commit -s
  • This PR is focused on a single feature/fix

Additional Notes

- Introduce `storagePath` to `FileAttachment` model and associated DTOs, ensuring files are persistently managed after initial composition.
- Update the database schema and repository layer to save and retrieve file attachment storage paths.
- Enhance `ChatSessionService` to manage attachment lifecycle, including content extraction and cleanup from disk storage.
- Improve text extraction from multimodal messages by handling and preserving image data separately for accurate content representation.
- Update UI components to correctly resolve file download paths using the new storage path logic.

BREAKING CHANGE: File attachment handling now relies on a persistent `storagePath` rather than just temporary file paths, requiring consumers to adapt to the new model structure.
Copilot AI lite review requested due to automatic review settings September 26, 2026 22:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved issues affect attachment persistence, cleanup, path safety, multimodal deduplication, and provider API-key handling.

Review effort: Lite
Findings: 5 High severity · 1 Medium severity

Open (6)
What changed in this PR

Adds persistent filesystem storage for chat attachments, database path tracking, lifecycle handling, multimodal processing updates, and UI download resolution.

Changes:

  • Adds attachment storage paths, migration, persistence, and cleanup.
  • Updates multimodal text extraction and token handling.
  • Adjusts provider configuration and related UI components.
File Description
shared/​src/​main/​kotlin/​io/​askimo/​core/​vision/​VisionExtensions.kt Resolves images from persistent storage.
shared/​src/​main/​kotlin/​io/​askimo/​core/​util/​AskimoHome.kt Adds the attachments directory.
shared/​src/​main/​kotlin/​io/​askimo/​core/​providers/​openaicompatible/​OpenAiCompatibleModelFactory.kt Adjusts API-key gating.
shared/​src/​main/​kotlin/​io/​askimo/​core/​providers/​ChatRequestTransformers.kt Handles multimodal token estimation.
shared/​src/​main/​kotlin/​io/​askimo/​core/​memory/​MemoryMessage.kt Preserves text portions of multimodal messages.
shared/​src/​main/​kotlin/​io/​askimo/​core/​db/​SchemaMigrations.kt Adds the storage-path migration.
shared/​src/​main/​kotlin/​io/​askimo/​core/​chat/​util/​AttachmentStorageManager.kt Manages attachment filesystem persistence.
shared/​src/​main/​kotlin/​io/​askimo/​core/​chat/​service/​ChatSessionService.kt Integrates attachment storage and extraction.
shared/​src/​main/​kotlin/​io/​askimo/​core/​chat/​repository/​ChatMessageRepository.kt Loads stored attachment paths.
shared/​src/​main/​kotlin/​io/​askimo/​core/​chat/​repository/​ChatMessageAttachmentRepository.kt Persists and cleans up attachment metadata.
shared/​src/​main/​kotlin/​io/​askimo/​core/​chat/​mapper/​ChatMessageMapper.kt Maps storage paths between layers.
shared/​src/​main/​kotlin/​io/​askimo/​core/​chat/​dto/​FileAttachmentDTO.kt Adds persistent path fields.
shared/​src/​main/​kotlin/​io/​askimo/​core/​chat/​domain/​FileAttachment.kt Adds the storage path model and schema field.
gradle.properties Bumps the project version.
desktop/​src/​main/​kotlin/​io/​askimo/​desktop/​plan/​PlanEditorView.kt Updates editor text styling.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​common/​theme/​AppTextStyles.kt Removes obsolete code-block styles.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​MessageComponents.kt Uses shared clickable cards.
desktop-shared/​src/​main/​kotlin/​io/​askimo/​ui/​chat/​ChatView.kt Resolves persistent attachment download paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Review effort: Lite
Findings: 3 High severity

Open (3)
Resolved since last review (6)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Use dedicated multi-line code editor text style

desktop/​src/​main/​kotlin/​io/​askimo/​desktop/​plan/​PlanEditorView.kt:240

AppTextStyles.code is documented and implemented as a labelSmall style for short inline snippets, whereas this control is a multi-line YAML editor that previously used the dedicated 13sp/21sp codeBlock style. Replacing it changes the editor's readability and violates the style contract; retain a dedicated multi-line editor style (or add an equivalent replacement) rather than using the inline token.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical path-safety and multiple moderate correctness, migration, lifecycle, and test coverage issues remain unresolved.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (3)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Account for image tokens in context budgeting

shared/​src/​main/​kotlin/​io/​askimo/​core/​providers/​ChatRequestTransformers.kt:221

Filtering out all image content leaves the token budget with no visual-token estimate; an image-only message is counted as the minimum one token even though enforceTokenBudget uses this value to decide how much history to retain. With multiple or high-resolution images this can retain a request beyond the model's actual context and still trigger the context-window failure this change targets. Add a conservative/provider-aware image budget before accepting older message groups.

Low severity Correct DTO documentation for repository-managed fields

shared/​src/​main/​kotlin/​io/​askimo/​core/​chat/​dto/​FileAttachmentDTO.kt:15

This note says messageId and sessionId are provided by this DTO for compatibility, but both fields were removed from the DTO. The documentation now misstates the public shape and may lead callers to look for properties that do not exist; describe them as repository-managed reference-table fields instead.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved attachment cleanup, migration, path resolution, token estimation, and API-key fallback issues remain.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (2)

FileAttachmentsTable.deleteWhere {
FileAttachmentsTable.id eq reference.attachmentId
}
AttachmentStorageManager.deleteAttachmentFile(reference.attachmentId)
Comment on lines +107 to +112
fun saveAttachments(attachments: List<FileAttachmentDTO>): List<FileAttachmentDTO> = attachments.map { attachment ->
// Generate ID FIRST if empty (before saving file) to avoid mismatch
// between storage path (attachments/{id}/{filename}) and database key
val attachmentWithId = if (attachment.id.isEmpty()) {
attachment.copy(id = UUID.randomUUID().toString())
} else {
@haiphucnguyen
haiphucnguyen merged commit 2dc9996 into main Sep 27, 2026
9 of 10 checks passed
@haiphucnguyen
haiphucnguyen deleted the feature/improvements branch September 27, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants