4c349e85f8
Gateway Session Hygiene auto-compression destroyed the original transcript when the throwaway hygiene agent couldn't rotate the session (#21301, P1). The _hyg_agent is built WITHOUT a session_db, so _compress_context cannot end-and-fork the session (its rotate block is gated on agent._session_db). The session_id stays unchanged, and the rewrite_transcript() call ran UNCONDITIONALLY — replacing the full original transcript with just the head+summary list. Permanent data loss on every hygiene compaction. Guard the rewrite behind 'rotated OR in-place' exactly like the /compress path already does (#44794/#39704): only overwrite when a new session id was minted or in-place compaction succeeded; otherwise preserve the original transcript and log a warning. The token/count bookkeeping that followed the rewrite is moved inside the guard, with no-change values in the preserve branch. Co-authored-by: SandroHub013 <sandrohub013@gmail.com> Co-authored-by: WuTianyi123 <wtyopenclaw@gmail.com> Co-authored-by: kyssta-exe <kyssta-exe@users.noreply.github.com>