Harden paged chat history loading
Close the per-thread history loading gate before launching requests, make live/history part reconciliation linear, and reject duplicate history envelope fields. Complete task-owned history paging work remains preserved in the preceding recovery commit. Checked packaged templates and packaged authoring skill references: neither needs an update; docs/notes/large-chat-history.md records the stale shared documentation.
This commit is contained in:
@@ -84,26 +84,29 @@ func readHistoryPage(ctx context.Context, sessionID string, r io.Reader) ([]prot
|
||||
} else if descending {
|
||||
p.take(nil, '{')
|
||||
found := false
|
||||
fields := make(map[string]struct{})
|
||||
for err == nil {
|
||||
key := &historyBuffer{limit: 256}
|
||||
if err = p.str(key, nil); err != nil {
|
||||
break
|
||||
}
|
||||
var name string
|
||||
if !key.overflow {
|
||||
_ = json.Unmarshal(key.Bytes(), &name)
|
||||
if key.overflow || json.Unmarshal(key.Bytes(), &name) != nil {
|
||||
err = fmt.Errorf("invalid history envelope field")
|
||||
break
|
||||
}
|
||||
if _, duplicate := fields[name]; duplicate {
|
||||
err = fmt.Errorf("duplicate history envelope field %q", name)
|
||||
break
|
||||
}
|
||||
fields[name] = struct{}{}
|
||||
if err = p.take(nil, ':'); err != nil {
|
||||
break
|
||||
}
|
||||
switch name {
|
||||
case "data":
|
||||
if found {
|
||||
err = fmt.Errorf("duplicate history data")
|
||||
} else {
|
||||
found = true
|
||||
err = readMessages()
|
||||
}
|
||||
found = true
|
||||
err = readMessages()
|
||||
case "cursor":
|
||||
cursor := &historyBuffer{limit: 64 << 10}
|
||||
err = p.value(cursor, 1, false)
|
||||
|
||||
Reference in New Issue
Block a user