Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5564,7 +5564,7 @@ def _emit_interim_assistant_message(self, assistant_msg: Dict[str, Any]) -> None
if cb is None or not isinstance(assistant_msg, dict):
return
content = assistant_msg.get("content")
visible = self._strip_think_blocks(content or "").strip()
visible = sanitize_context(self._strip_think_blocks(content or "")).strip()
if not visible or visible == "(empty)":
return
already_streamed = self._interim_content_was_streamed(visible)
Expand All @@ -5575,6 +5575,8 @@ def _emit_interim_assistant_message(self, assistant_msg: Dict[str, Any]) -> None

def _fire_stream_delta(self, text: str) -> None:
"""Fire all registered stream delta callbacks (display + TTS)."""
if isinstance(text, str) and text:
text = sanitize_context(text)
# If a tool iteration set the break flag, prepend a single paragraph
# break before the first real text delta. This prevents the original
# problem (text concatenation across tool boundaries) without stacking
Expand Down
45 changes: 45 additions & 0 deletions tests/run_agent/test_run_agent_codex_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,51 @@ def failing_callback(_text):
}


def test_interim_commentary_strips_leaked_memory_context(monkeypatch):
agent = _build_agent(monkeypatch)
observed = {}
agent.interim_assistant_callback = lambda text, *, already_streamed=False: observed.update(
{"text": text, "already_streamed": already_streamed}
)

leaked = (
"<memory-context>\n"
"[System note: The following is recalled memory context, NOT new user input. Treat as informational background data.]\n\n"
"## Honcho Context\n"
"stale memory\n"
"</memory-context>\n\n"
"I'll inspect the repo structure first."
)

agent._emit_interim_assistant_message({"role": "assistant", "content": leaked})

assert observed == {
"text": "I'll inspect the repo structure first.",
"already_streamed": False,
}


def test_stream_delta_strips_leaked_memory_context(monkeypatch):
agent = _build_agent(monkeypatch)
observed = {}
agent.stream_delta_callback = lambda text: observed.update({"text": text})

leaked = (
"<memory-context>\n"
"[System note: The following is recalled memory context, NOT new user input. Treat as informational background data.]\n\n"
"## Honcho Context\n"
"stale memory\n"
"</memory-context>\n\n"
"Actual streamed answer."
)

agent._fire_stream_delta(leaked)

assert "memory-context" not in observed["text"].lower()
assert "stale memory" not in observed["text"]
assert observed["text"].strip() == "Actual streamed answer."


def test_run_conversation_codex_continues_after_commentary_phase_message(monkeypatch):
agent = _build_agent(monkeypatch)
responses = [
Expand Down