fix conv file mongo doc id and add time#1300
Conversation
Review Summary by QodoAdd timestamps and fix MongoDB document ID handling in ConversationFile
WalkthroughsDescription• Add timestamp tracking with CreatedTime and UpdatedTime properties • Add JSON property name mappings for MongoDB document serialization • Fix MongoDB upsert logic to properly handle document ID and timestamps • Refactor bulk write operations to use update model instead of replace Diagramflowchart LR
A["ConversationFile Model"] -->|"Add timestamps & JSON mappings"| B["Updated Model"]
C["ConversationFileDocument"] -->|"Add timestamp fields"| D["Enhanced Document"]
E["SaveConversationFiles"] -->|"Use UpdateOneModel with SetOnInsert"| F["Fixed Upsert Logic"]
B --> F
D --> F
File Changes1. src/Infrastructure/BotSharp.Abstraction/Conversations/Models/ConversationFile.cs
|
Code Review by Qodo
1. File conv_files.json break
|
| [JsonPropertyName("conversation_id")] | ||
| public string ConversationId { get; set; } |
There was a problem hiding this comment.
1. File conv_files.json break 🐞 Bug ✓ Correctness
Adding JsonPropertyName("conversation_id") makes ConversationId no longer deserialize from existing
file-based conv_files.json that likely used "conversationId" (camelCase), causing thumbnails to not
load (ConversationId becomes null/unmatched). This will silently affect any deployment with existing
stored thumbnails in the FileRepository backend.
Agent Prompt
## Issue description
`ConversationFile.ConversationId` is now bound to JSON key `conversation_id`. Existing `conv_files.json` written by the file repository (camelCase `conversationId`) will no longer populate `ConversationId`, so thumbnails won’t match conversations.
## Issue Context
FileRepository reads `conv_files.json` via `JsonSerializer.Deserialize<ConversationFile>(..., _options)` and `_options` uses camelCase naming.
## Fix Focus Areas
- src/Infrastructure/BotSharp.Abstraction/Conversations/Models/ConversationFile.cs[3-16]
- src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs[892-942]
- src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs[75-82]
## Suggested fix
- Implement backward-compatible parsing in `FileRepository.GetConversationFiles`:
- Parse JSON into `JsonDocument`.
- Read `conversation_id` **or** `conversationId`.
- Read `created_time`/`createdTime` and `updated_time`/`updatedTime` if present.
- Construct `ConversationFile` manually.
- Optionally, after successful legacy read, rewrite the file in the new format to migrate data.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| [JsonPropertyName("created_time")] | ||
| public DateTime CreatedTime { get; set; } = DateTime.UtcNow; | ||
|
|
||
| [JsonPropertyName("updated_time")] | ||
| public DateTime UpdatedTime { get; set; } = DateTime.UtcNow; |
There was a problem hiding this comment.
2. File timestamps reset 🐞 Bug ✓ Correctness
FileRepository.SaveConversationFiles writes whatever timestamps are on the provided ConversationFile; since controller constructs a new ConversationFile per update, CreatedTime/UpdatedTime default to UtcNow and CreatedTime will reset on every thumbnail update (UpdatedTime isn’t explicitly bumped). This makes the new time fields unreliable in file-backed deployments.
Agent Prompt
## Issue description
File-backed `conv_files.json` timestamps are not managed: updates overwrite `CreatedTime` because the controller creates a fresh `ConversationFile` and `FileRepository.SaveConversationFiles` writes it directly.
## Issue Context
Mongo backend uses `SetOnInsert` for `CreatedTime` and `Set` for `UpdatedTime`, but FileRepository has no equivalent logic.
## Fix Focus Areas
- src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs[944-980]
- src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.File.cs[119-138]
## Suggested fix
- In `FileRepository.SaveConversationFiles`:
- If `conv_files.json` exists, load the existing `ConversationFile` (using backward-compatible parsing if needed).
- Set `file.CreatedTime = existing.CreatedTime` when existing has a non-default value.
- Set `file.UpdatedTime = DateTime.UtcNow` on every save.
- If file is new/legacy without times: set `CreatedTime` once and `UpdatedTime` to now.
- Consider also setting timestamps in the controller, but repository-side is safer/centralized.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
No description provided.