| 1 | package agent |
| 2 | |
| 3 | import "reasonix/internal/provider" |
| 4 | |
| 5 | // NormalizeSession runs the persisted-history-safe repairs on a loaded |
| 6 | // conversation and is the agent-side entry point for making old, partially |
| 7 | // saved, or interrupted sessions replayable. It is a thin wrapper over |
| 8 | // provider.NormalizeSessionMessages, which shares assistant-turn repairs with |
| 9 | // the provider send path without applying wire-only cleanup such as dropping |
| 10 | // standalone tool messages. |
| 11 | // |
| 12 | // LoadSession calls this right after decoding so a session that was written by |
| 13 | // an older code version, or that was cut short mid-turn, is corrected in memory |
| 14 | // before anything reads it. The corrected messages are persisted lazily: the |
| 15 | // next Session.Save (naturally triggered by the following turn) rewrites the |
| 16 | // whole file with the repairs baked in, so the same stale-data bug is not |
| 17 | // re-repaired on every turn forever. A session that is only ever read (never |
| 18 | // appended to) stays unmodified on disk and is simply re-normalized on the next |
| 19 | // load — cheap, because the fast path returns the input slice unchanged. |
| 20 | // |
| 21 | // Well-formed histories are returned without allocating (see |
| 22 | // provider.NormalizeSessionMessages), so this is a no-op in both time and memory |
| 23 | // for the common case and cannot perturb a provider's prefix-cache key. |
| 24 | func NormalizeSession(msgs []provider.Message) []provider.Message { |
| 25 | return provider.NormalizeSessionMessages(msgs) |
| 26 | } |
| 27 |