fix: preserve cached agent prefill context

This commit is contained in:
Frank Song
2026-05-25 08:46:48 +08:00
parent 4132085e0c
commit 535c238285
3 changed files with 17 additions and 2 deletions
+4 -1
View File
@@ -3,6 +3,10 @@
## [Unreleased]
### Fixed
- Cached WebUI agents no longer overwrite `prefill_messages` with an empty list when a later request does not include explicit prefill context.
## [v0.51.132] — 2026-05-24 — Release DD (stage-batch14 — 4-PR replayed-context + interrupted-response + shutdown affordance + passkey opt-in)
### Added
@@ -27,7 +31,6 @@
- CHANGELOG entries added for PR #2685 and PR #2824 (both originally missing despite functional code changes)
- Deferred to follow-up: per-turn cumulative live-tool-prompt token cap (#2685 only added per-call cap; aggregate across many tool calls is a separate refactor).
- **i18n parity**: 7 new shutdown-affordance keys added across all 11 non-en locales (it, ja, ru, es, de, zh, zh-Hant, pt, ko, fr, tr) so locale parity tests pass on first run.
## [v0.51.131] — 2026-05-24 — Release DC (stage-batch13 — 6-PR notes-drawer + context-parity + PWA-swipe + locale polish)
### Added
+1 -1
View File
@@ -4374,7 +4374,7 @@ def _run_agent_streaming(
agent.reasoning_callback = _agent_kwargs.get('reasoning_callback')
if hasattr(agent, 'clarify_callback'):
agent.clarify_callback = _agent_kwargs.get('clarify_callback')
if hasattr(agent, 'prefill_messages'):
if 'prefill_messages' in _agent_kwargs and hasattr(agent, 'prefill_messages'):
agent.prefill_messages = list(_agent_kwargs.get('prefill_messages') or [])
if _session_db is not None:
# Close any previously held SessionDB connection before
+12
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import json
from pathlib import Path
def test_prefill_json_file_keeps_valid_roles_and_drops_invalid_items(tmp_path):
@@ -78,3 +79,14 @@ def test_prefill_status_redactor_handles_secret_shaped_text():
assert "redaction-test-placeholder" not in redacted
assert "[REDACTED]" in redacted
def test_cached_agent_prefill_refresh_requires_explicit_kwargs():
"""Cached agents should not get an empty prefill list when kwargs omitted it."""
src = Path("api/streaming.py").read_text(encoding="utf-8")
callback_refresh = src.index("# Refresh per-turn callbacks")
session_db_refresh = src.index("if _session_db is not None:", callback_refresh)
body = src[callback_refresh:session_db_refresh]
assert "'prefill_messages' in _agent_kwargs" in body
assert "hasattr(agent, 'prefill_messages')" in body