agent: Save threads before closing them (#51744)

Closes #46078

When we unloaded sessions, we weren't necesarily making sure we had
saved the current state. Now we save it whenever we remove it from the
session map.

Release Notes:

- Agent: Fix cases where thread state wasn't saved before closing the
thread.
8a25373fb9Ben Brandt committed on 3/17/2026, 10:26:06 AM· committed by GitHubparent4bc324c
1 file changedLine totals unavailable