docs: fix three statements the per-model image strip left stale
The image-rejection recovery no longer switches the session to text-only or strips history; it records the (provider, model) and build_api_request strips images from that model's requests only. Three places still described the old behaviour: - recover_before_classification docstring and the adjacent comment said "switch session to text-only" / "mark session vision-unsupported". - TestStripImagesDropsStaleApiContent's rationale claimed the strip runs on persistent history and that leaving api_content would replay rejected images every turn because the recovery gates on _image_rejecting_models — false on both counts: current callers pass per-call clones. Reworded as the generic helper contract (a rewritten persisted row must drop its sidecar) with the no-op note. - _strip_images_from_messages docstring, same fix. Comments and docstrings only; no code change.
This commit is contained in:
@@ -337,7 +337,9 @@ def _strip_images_from_messages(messages: list) -> bool:
|
||||
|
||||
``tool`` / ``tool_calls`` messages left empty get a placeholder, NOT deleted (deleting
|
||||
orphans the paired ``tool_call_id`` → HTTP 400); other now-empty messages are dropped.
|
||||
Rewritten messages lose their ``api_content`` sidecar (it carries the removed images).
|
||||
Rewritten messages lose their ``api_content`` sidecar (it carries the removed images):
|
||||
a caller rewriting a persisted row must not leave bytes that replay them next turn. The
|
||||
current callers pass per-call clones, where this is a no-op.
|
||||
"""
|
||||
from agent.context_compressor import _DB_PERSISTED_MARKER
|
||||
from agent.turn_context import drop_stale_api_content
|
||||
|
||||
@@ -236,9 +236,10 @@ def recover_before_classification(
|
||||
api_kwargs: Any, active_system_prompt: Any,
|
||||
) -> Tuple[bool, Any]:
|
||||
"""Recovery branches that run BEFORE ``classify_api_error``: UnicodeEncodeError
|
||||
sanitization, provider image-content rejection (switch session to text-only), and the
|
||||
Bedrock AnthropicBedrock SDK streaming fallback. Returns ``(retry_now,
|
||||
active_system_prompt)``; the prompt may be ASCII-sanitized in place."""
|
||||
sanitization, provider image-content rejection (record the (provider, model);
|
||||
build_api_request strips images from that model's requests only), and the Bedrock
|
||||
AnthropicBedrock SDK streaming fallback. Returns ``(retry_now, active_system_prompt)``;
|
||||
the prompt may be ASCII-sanitized in place."""
|
||||
if isinstance(api_error, UnicodeEncodeError) and getattr(agent, '_unicode_sanitization_passes', 0) < 2:
|
||||
_recovered, active_system_prompt = _recover_unicode_encode_error(
|
||||
agent, api_error, messages, api_messages, api_kwargs, active_system_prompt
|
||||
@@ -246,8 +247,9 @@ def recover_before_classification(
|
||||
if _recovered:
|
||||
return True, active_system_prompt
|
||||
|
||||
# Some providers 4xx on image_url content: strip images, mark session
|
||||
# vision-unsupported, retry text-only. English phrase match; extend it.
|
||||
# Some providers 4xx on image_url content: record the (provider, model) and retry;
|
||||
# build_api_request strips images from that model's requests only. English phrase
|
||||
# match; extend it.
|
||||
_err_body = ""
|
||||
try:
|
||||
_err_body = str(getattr(api_error, "body", None) or getattr(api_error, "message", None) or str(api_error))
|
||||
|
||||
@@ -226,14 +226,14 @@ class TestImageRejectionPhraseIsolation:
|
||||
|
||||
|
||||
class TestStripImagesDropsStaleApiContent:
|
||||
"""The strip runs on the persistent history, not just the per-call copy.
|
||||
"""Generic helper contract: a rewritten row drops its ``api_content`` sidecar.
|
||||
|
||||
``api_content`` is the byte-stability sidecar: it holds the exact bytes
|
||||
previously sent for a message, and the next turn substitutes it back into
|
||||
``content``. Leaving it in place on a message this function rewrote would
|
||||
replay the images the strip just removed — and the recovery cannot re-fire,
|
||||
because it records the model in ``_image_rejecting_models`` and gates itself
|
||||
on that. The session would then send rejected images on every subsequent turn.
|
||||
``content``. When a caller rewrites a PERSISTED row, the sidecar must go with
|
||||
it or the next turn replays the images the strip just removed. The current
|
||||
callers only pass per-call clones (``api_messages``), where dropping the
|
||||
sidecar is a no-op — the contract is kept for any caller that does not.
|
||||
|
||||
Same contract the other content-rewrite paths follow (stale-confirmation
|
||||
redaction in ``replay_cleanup``, compression rewrites, merge-into-tail):
|
||||
|
||||
Reference in New Issue
Block a user