The fold prompt lets memory entries cite previously retained archive IDs,
but covered_archive_ids had to equal the newly supplied set exactly. A
model that also lists retained IDs as covered failed every fold, so the
watermark never moved and the session stayed on degraded raw history.
Accept covered IDs that are the newly supplied ones plus IDs the prior
memory already covered or cited. Still reject omitted, invented or unseen
IDs, and store only the newly folded IDs as covered.
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
The fold loop counted only each exchange's archive text and always folded
the oldest exchange, so one exchange over the plan was sent whole, and
prior learner memory could push a fitting exchange over it.
Fold the longest prefix of whole exchanges whose complete request fits:
prior memory, the system instruction and the exchanges as _summarize()
serializes them, plus a reserve for the length line. If even the oldest
exchange doesn't fit, send no memory call; the watermark stays and the
exchange stays in exact recall.
A failed tutoring-memory call keeps the watermark, so the next turn
retried with the same backlog plus the newest exchange, and the call
grew without limit (#2496). Fold in only the oldest whole exchanges
that fit one history plan, at least one, and leave the rest
unsummarized so the watermark moves only past what was covered.
Related to #2496