[mirror] fix: persist per-turn model on chats and queued messages#4
[mirror] fix: persist per-turn model on chats and queued messages#4yashwant86 wants to merge 19 commits intomm-base-24688from
Conversation
Addresses johnstcn review threads: - PRRT_kwDOGkVX1s59XAf8 - PRRT_kwDOGkVX1s59XCa9 - PRRT_kwDOGkVX1s59XDUB
…ted_at Codex finding: coder#24688 (comment)
⚡ Risk Assessment —
|
| Files | Summary |
|---|---|
Database Schema & Queryingcoderd/database/dump.sqlcoderd/database/migrations/000477_chat_queued_message_model_config.up.sqlcoderd/database/migrations/000477_chat_queued_message_model_config.down.sqlcoderd/database/queries/chats.sqlcoderd/database/queries.sql.gocoderd/database/models.go |
Add model_config_id column to chat_queued_messages table with migration that backfills from chat.last_model_config_id. Update all related query functions and models to include the new field. |
Chat Daemon Model Resolutioncoderd/x/chatd/chatd.go |
Implement model config resolution logic with three-tier fallback: explicit override → queued message config → chat's last model config → default. Validate requested model configs exist and reject invalid IDs with ErrInvalidModelConfigID. |
Chat Daemon Testscoderd/x/chatd/chatd_test.go |
Add comprehensive tests for model config persistence: queued message model capture, promotion with stored configs, fallback for legacy/invalid configs, and auto-promotion order preservation across multiple queued messages. |
API Layer & SDKcoderd/exp_chats.gocodersdk/chats.gosite/src/api/typesGenerated.ts |
Add model_config_id field to ChatQueuedMessage SDK type and API response. Validate model config IDs in CreateChatMessage endpoint and return ErrInvalidModelConfigID for invalid overrides. |
Integration Testscoderd/exp_chats_test.go |
Add end-to-end tests verifying model override persistence: direct sends, queued messages, enqueue-time capture, subsequent sends reusing persisted model, and watch event propagation of updated model config. |
Frontend Cache Merge Logicsite/src/api/queries/chats.tssite/src/api/queries/chats.test.tssite/src/pages/AgentsPage/AgentsPage.tsx |
Extract event-scoped cache merge logic into mergeWatchedChatSummary and mergeWatchedChatIntoCaches helpers. Implement precise timestamp comparison to prevent stale watch payloads from clobbering fresher cached metadata. Update AgentsPage to use new merge functions. |
Database SDK Conversioncoderd/database/db2sdk/db2sdk.go |
Update ChatQueuedMessage conversion to include model_config_id field mapping from database to SDK type. |
Sequence Diagram
sequenceDiagram
participant Client
participant API
participant ChatDaemon
participant Database
Client->>API: CreateChatMessage(modelConfigID?)
API->>ChatDaemon: SendMessage(modelConfigID?)
ChatDaemon->>Database: GetChatModelConfigByID(requested)
alt Explicit Override
Database-->>ChatDaemon: config found
ChatDaemon->>ChatDaemon: use requested config
else No Override
ChatDaemon->>ChatDaemon: use chat.LastModelConfigID
end
alt Chat Not Busy
ChatDaemon->>Database: InsertChatMessage(modelConfigID)
Database-->>ChatDaemon: message
ChatDaemon-->>API: direct send result
else Chat Busy
ChatDaemon->>Database: InsertChatQueuedMessage(modelConfigID)
Database-->>ChatDaemon: queued message
ChatDaemon-->>API: queued result
end
API-->>Client: response with model config
alt Queued Message Promotion
Client->>API: PromoteQueuedMessage(queuedMessageID)
API->>ChatDaemon: PromoteQueued(queuedMessageID)
ChatDaemon->>Database: GetChatQueuedMessage(queuedMessageID)
Database-->>ChatDaemon: queued message with stored modelConfigID
ChatDaemon->>ChatDaemon: resolveQueuedMessageModelConfigID
ChatDaemon->>Database: InsertChatMessage(resolvedModelConfigID)
ChatDaemon->>Database: UpdateChatLastModelConfig(resolvedModelConfigID)
ChatDaemon->>Database: PublishChatWatchEvent(statusChange)
Database-->>ChatDaemon: event published
ChatDaemon-->>API: promoted result
API-->>Client: response
Client->>Client: mergeWatchedChatIntoCaches(eventKind)
end
Dig Deeper With Commands
/review <file-path> <function-optional>/chat <file-path> "<question>"/roast <file-path>
Runs only when explicitly triggered.
Mirror of upstream coder#24688 for benchmark. Do not merge.
Summary by MergeMonkey