Merge pull request #1 from 866-lgtm/codex/check-for-bugs-and-optimizatio#7
Merge pull request #1 from 866-lgtm/codex/check-for-bugs-and-optimizatio#7866-lgtm wants to merge 2 commits intoHO-git:mainfrom
Conversation
…tion Fix notification safety and optimize chunk save path
Greptile SummaryThis PR applies a bug-check and optimization pass to Key changes:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant saveChunkToQdrant
participant ensureCollection
participant chunkExistsInCollection
participant QdrantAPI
Caller->>saveChunkToQdrant: chunk, participants[]
saveChunkToQdrant->>saveChunkToQdrant: generateEmbedding(chunk.text)
loop For each participant (duplicate-check + readyParticipants build)
saveChunkToQdrant->>ensureCollection: characterName, embedding.length
alt collection NOT ready
ensureCollection-->>saveChunkToQdrant: false → continue (skip participant)
else collection ready
ensureCollection-->>saveChunkToQdrant: true
saveChunkToQdrant->>saveChunkToQdrant: readyParticipants.push(characterName)
saveChunkToQdrant->>chunkExistsInCollection: collectionName, embedding, text, threshold
alt duplicate found
chunkExistsInCollection-->>saveChunkToQdrant: true → alreadyExists=true, break
else no duplicate
chunkExistsInCollection-->>saveChunkToQdrant: false → continue loop
end
end
end
alt alreadyExists == true
saveChunkToQdrant->>Caller: showNotification("info", ...) → return false
else no duplicate
loop For each in readyParticipants (save phase — ensureCollection NOT called again)
saveChunkToQdrant->>QdrantAPI: PUT /collections/{name}/points
QdrantAPI-->>saveChunkToQdrant: 200 OK / error
end
saveChunkToQdrant->>Caller: return successCount > 0
end
Last reviewed commit: fc430e5 |
| function showNotification(level, message, title = "Qdrant Memory", options = {}) { | ||
| const toastr = window.toastr | ||
| if (toastr && typeof toastr[level] === "function") { | ||
| toastr[level](message, title, options) | ||
| return | ||
| } | ||
|
|
||
| if (settings.debugMode) { | ||
| console.log(`[Qdrant Memory] ${level.toUpperCase()}: ${message}`) | ||
| } | ||
| } |
There was a problem hiding this comment.
Silent notification drop in non-debug mode
When window.toastr is not available and settings.debugMode is false, all notification calls are silently swallowed — the user receives no feedback at all. The original code would have thrown a runtime error (which is worse), but the current fallback could also leave the user confused with no visible response to their actions.
Consider always emitting a console.warn (outside the debugMode guard) so that at minimum a developer inspecting the console can diagnose missing notifications:
| function showNotification(level, message, title = "Qdrant Memory", options = {}) { | |
| const toastr = window.toastr | |
| if (toastr && typeof toastr[level] === "function") { | |
| toastr[level](message, title, options) | |
| return | |
| } | |
| if (settings.debugMode) { | |
| console.log(`[Qdrant Memory] ${level.toUpperCase()}: ${message}`) | |
| } | |
| } | |
| function showNotification(level, message, title = "Qdrant Memory", options = {}) { | |
| const toastr = window.toastr | |
| if (toastr && typeof toastr[level] === "function") { | |
| toastr[level](message, title, options) | |
| return | |
| } | |
| console.warn(`[Qdrant Memory] toastr unavailable — ${level.toUpperCase()}: ${message}`) | |
| } |
This removes the debugMode gate from the fallback so the notification is never silently discarded.
| if (alreadyExists) { | ||
| if (settings.showMemoryNotifications) { | ||
| const toastr = window.toastr | ||
| toastr.info("Similar conversation already saved", "Qdrant Memory", { timeOut: 1500 }) | ||
| showNotification("info", "Similar conversation already saved", "Qdrant Memory", { timeOut: 1500 }) | ||
| } | ||
| return false | ||
| } |
There was a problem hiding this comment.
readyParticipants is incomplete when loop breaks early
When a duplicate is detected in participant i, the loop breaks immediately. Participants at positions i+1 and beyond have not had ensureCollection called and are therefore absent from readyParticipants. Because the function returns false immediately in this branch, the incomplete list is harmless today.
However, if this block is ever refactored (e.g., to save the checked participants even when a duplicate is found), the subtle incompleteness of readyParticipants could introduce a silent data-loss bug. Adding a short comment here would make the invariant explicit:
| if (alreadyExists) { | |
| if (settings.showMemoryNotifications) { | |
| const toastr = window.toastr | |
| toastr.info("Similar conversation already saved", "Qdrant Memory", { timeOut: 1500 }) | |
| showNotification("info", "Similar conversation already saved", "Qdrant Memory", { timeOut: 1500 }) | |
| } | |
| return false | |
| } | |
| if (alreadyExists) { | |
| // readyParticipants may be a partial list here (loop broke early); only used | |
| // in the save path below, which is skipped on this return branch. | |
| if (settings.showMemoryNotifications) { | |
| showNotification("info", "Similar conversation already saved", "Qdrant Memory", { timeOut: 1500 }) | |
| } | |
| return false | |
| } |
check-for-bugs-and-optimization run