Skip to content

refactor(chat-suggestions): Enhance suggestion matching and manage usage history - #761

Merged
haiphucnguyen merged 3 commits into
mainfrom
feature/improvements
Oct 11, 2026
Merged

haiphucnguyen merged 3 commits into
mainfrom
feature/improvements

Conversation

@haiphucnguyen

Copy link
Copy Markdown
Collaborator

ci(build): Update native image reachability metadata

  • Adjusted internal metadata to ensure proper handling of dependencies for the native image build.

Summary

  • Implements a bounded, FIFO cache for suggestion history to limit memory usage.
  • Centralizes prefix matching logic in PrefixSuggestionMatcher for improved reliability.
  • Updates suggestion services to use the robust prefix matching algorithm for accurate results.

Related Issue(s)

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

…age history

- Implements a bounded, FIFO cache for suggestion history to limit memory usage.
- Centralizes prefix matching logic in `PrefixSuggestionMatcher` for improved reliability.
- Updates suggestion services to use the robust prefix matching algorithm for accurate results.

ci(build): Update native image reachability metadata
- Adjusted internal metadata to ensure proper handling of dependencies for the native image build.
Copilot AI balanced review requested due to automatic review settings October 11, 2026 21:44

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.

🟡 Changes recommended

Cache races can produce inconsistent rankings and double-count newly persisted messages.

3 open findings
What changed in this PR

Refactors chat suggestion matching, adds bounded usage-aware history, and updates native-image metadata.

Changes:

  • Centralizes case-insensitive prefix matching.
  • Deduplicates and ranks eligible history suggestions.
  • Registers the AI-extraction getter for native images.
File Description
PrefixSuggestionMatcher.kt Adds shared prefix-matching logic.
PersistedPhraseSuggestionService.kt Uses the shared matcher.
HistoryBackedSuggestionService.kt Adds bounded, frequency-ranked history caching.
reachability-metadata.json Registers the configuration getter.

🧠 Review effort: Balanced


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

Comment on lines +152 to +156
val seedContent = messageRepository
.getRecentUserMessagesGlobal(limit = HISTORY_SCAN_LIMIT)
.getRecentUserMessagesGlobal(limit = HISTORY_SCAN_LIMIT * SEED_OVERFETCH_FACTOR)
.map { it.content }
.asReversed()
cache.addAll(seedContent)
seedContent.forEach { addOrTouch(it) }

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.

🔵 Needs a closer look

Stored whitespace can make eligible history entries unmatchable, and cache eviction conflicts with the stated FIFO contract.

1 open finding
2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Store normalized message text for consistent deduplication

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​chat/​service/​HistoryBackedSuggestionService.kt:163

Messages are keyed using trimmed text but stored with their original surrounding whitespace. A history entry such as " can you help me" is therefore retained yet can never match trimStart()-normalized input, and if it is the first casing/whitespace variant seen, later repeats keep that unusable content. Store the normalized candidate text used for deduplication/matching.

🧠 Review effort: Balanced

@haiphucnguyen
haiphucnguyen merged commit d32a29a into main Oct 11, 2026
11 of 12 checks passed
@haiphucnguyen
haiphucnguyen deleted the feature/improvements branch October 11, 2026 22:04
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