Preserve partial cross-client identity fixes before canonical-ID continuation
This commit is contained in:
@@ -465,41 +465,14 @@ func (h *chatHub) snapshot(sessionID string) []protocol.ChatMessage {
|
||||
return messages
|
||||
}
|
||||
|
||||
// reconcileHistory annotates an authoritative page with operation identities
|
||||
// from the retained live user turns. Pairing is by the backend's message order,
|
||||
// never by text, timestamps, or a connection/request id. It is deliberately
|
||||
// conservative: a partial page cannot establish a safe one-to-one mapping.
|
||||
// reconcileHistory intentionally does not infer identity. OpenCode history
|
||||
// exposes only its native message id and does not echo the prompt operation id,
|
||||
// so there is no reliable mapping from a retained cross-client user event to a
|
||||
// history record. In particular, position, text, timestamps and page boundaries
|
||||
// are not identity keys; annotating with any of them corrupts partial, reordered,
|
||||
// older or overlapping pages. The live event already carries the operation id.
|
||||
func (h *chatHub) reconcileHistory(sessionID string, messages []protocol.ChatMessage) []protocol.ChatMessage {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
turn := h.turns[sessionID]
|
||||
if turn == nil {
|
||||
return messages
|
||||
}
|
||||
var live []*chatMessage
|
||||
for _, id := range turn.order {
|
||||
message := turn.messages[id]
|
||||
if message != nil && message.role == protocol.ChatRoleUser && message.operationID != "" {
|
||||
live = append(live, message)
|
||||
}
|
||||
}
|
||||
var users []int
|
||||
for i := range messages {
|
||||
if messages[i].Role == protocol.ChatRoleUser {
|
||||
users = append(users, i)
|
||||
}
|
||||
}
|
||||
if len(users) == 0 || len(users) != len(live) {
|
||||
return messages
|
||||
}
|
||||
out := append([]protocol.ChatMessage(nil), messages...)
|
||||
for i, index := range users {
|
||||
out[index].OperationID = live[i].operationID
|
||||
if out[index].Client == "" {
|
||||
out[index].Client = live[i].client
|
||||
}
|
||||
}
|
||||
return out
|
||||
return messages
|
||||
}
|
||||
|
||||
// shellSnapshot returns the session's still-running shells, in the order they
|
||||
|
||||
Reference in New Issue
Block a user