refactor(agent): clone the review snapshot once at the spawn chokepoint

Move the structural clone from the four call sites (auto review, codex
runtime, CLI /refine, gateway /refine) into AIAgent._spawn_background_review,
which every review path — immediate, idle-queue deferred, requeued — passes
through. Callers can no longer forget it, and the private helper is no longer
imported across hermes_cli/ and gateway/ package boundaries.

Tests now bind the real chokepoint (capturing at _spawn_background_review_now)
so they still fail if the clone is removed.
This commit is contained in:
kshitijk4poor
2026-09-02 13:22:13 +05:30
committed by kshitij
parent 26f0de23cf
commit 2adb1a4ea6
6 changed files with 43 additions and 43 deletions
+7
View File
@@ -2021,6 +2021,13 @@ class AIAgent:
if not enabled:
return
# Structural clone at the single chokepoint every review path
# (automatic, /refine, idle-queue deferral) goes through. The fork
# sanitizes its transcript in place; a shallow copy would alias the
# nested tool_calls/content containers of the live history (#100795).
from agent.turn_finalizer import _clone_background_review_messages
messages_snapshot = _clone_background_review_messages(messages_snapshot)
kwargs = dict(
messages_snapshot=messages_snapshot,
review_memory=review_memory,