mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-09-11 02:32:20 +02:00
fix(chat): preserve URL prefetch failures in context (#5954)
* fix(chat): preserve URL fetch failures in context * fix(chat): avoid duplicating signed URLs in fetch failures --------- Co-authored-by: Alexandre Teixeira <alexandremagteixeira@gmail.com>
This commit is contained in:
co-authored by
Alexandre Teixeira
parent
0af6a99e81
commit
ee252e7cd9
+26
-1
@@ -462,7 +462,14 @@ class ChatProcessor:
|
||||
skip_url_fetch = len(message) > 2000 or len(non_yt_urls) > 3
|
||||
if not skip_url_fetch:
|
||||
for url in non_yt_urls:
|
||||
result = fetch_webpage_content(url)
|
||||
try:
|
||||
result = fetch_webpage_content(url)
|
||||
except Exception:
|
||||
# The URL and exception can both contain signed-query
|
||||
# credentials or response-controlled text. Keep the log
|
||||
# diagnostic stable as well as the model-facing context.
|
||||
logger.warning("Automatic URL fetch failed while building context")
|
||||
result = {"success": False, "error": ""}
|
||||
if result.get('success'):
|
||||
content = result.get('content', '')[:10000]
|
||||
preface.append(untrusted_context_message(
|
||||
@@ -470,6 +477,24 @@ class ChatProcessor:
|
||||
f"Content from {url}:\n\n{content}",
|
||||
provenance_origin="external",
|
||||
))
|
||||
else:
|
||||
# A failed automatic URL fetch is context too. Never pass
|
||||
# exception text or response-controlled diagnostics back to
|
||||
# the model: reduce the result to a small transport-owned
|
||||
# status and explicitly state that the page was not read.
|
||||
error = str(result.get("error") or "")
|
||||
status = "the page was unavailable"
|
||||
status_match = re.match(r"^HTTP\s+(\d{3})\b", error)
|
||||
if status_match:
|
||||
status = f"the server returned HTTP {status_match.group(1)}"
|
||||
elif error.startswith("TooLarge:"):
|
||||
status = "the response exceeded the fetch size limit"
|
||||
elif error.startswith("Rate limit"):
|
||||
status = "the request was rate limited"
|
||||
preface.append(untrusted_context_message(
|
||||
"web page fetch failure",
|
||||
f"A linked page was not read: {status}.",
|
||||
))
|
||||
|
||||
# Skills index — progressive disclosure. Only injected when the
|
||||
# model has the `manage_skills` tool available (agent_mode), and
|
||||
|
||||
Reference in New Issue
Block a user