Skip to content

#561 fix: fetch-and-render answers 422 target_unreachable for an unreachable target, not 500 - #562

Merged
gregoryfoster merged 4 commits into
mainfrom
561-fetch-and-render-unreachable
Nov 28, 2026
Merged

gregoryfoster merged 4 commits into
mainfrom
561-fetch-and-render-unreachable

Conversation

@gregoryfoster

Copy link
Copy Markdown
Member

Closes #561 (epic #503, Tier 1).

Change

POST /api/v1/tools/fetch-and-render answered 500 kind="server" when the fetch failed. It now answers 422 kind="domain", with target_unreachable at /url, as preview-extraction and propose-selectors already do (#473). That covers DNS, a refused connection, a timeout, and a TLS error that persists after retries.

  • fetch_target (src/core/tools/target_fetch.py) is the transport leg. It catches httpx.HTTPError and raises TargetUnreachableError(str(e) or type(e).__name__).
    • fetch_2xx is now fetch_target plus the 2xx gate. fetch_and_render calls fetch_target.
    • The route catches the error and calls _raise_fetch_refusal.
  • Transport errors only. A non-2xx is still a 200 with status_code, and the route gets no target_http_error. render=True is still a 501, before any fetch.
  • Versions: service v4.49.2. archiver-client stays 5.19.0: the regenerated client and the hand-written wrappers move docstrings only, per Preview extraction ignores the HTTP status: a 403 bot challenge reads as "selector matched nothing" #473's precedent. There's no sdk_tag push.
  • Tests: the raw-TLS fetch fake moves from test_tools_preview_extraction.py to tests/api/conftest.py. New tests:
    • route: DNS, connect-timeout, empty ReadTimeout, ReadError, persistent and one-off raw ssl.SSLError, non-2xx → 200, render=True → 501 before a fetch;
    • fetch_target unit tests;
    • a new tests/core/tools/test_fetch_and_render.py.
  • Docs: the route description, _raise_fetch_refusal's docstring, target_fetch's module docstring, docs/API.md's row and the CHANGELOG. preview-extraction's description no longer says it composes fetch_and_render.

Verification

  • scripts/pre-ship.sh: 6195 passed, 6 skipped, vitest 142. client-drift OK.
  • Wire check on 8001: https://nonexistent.invalid/ → 422 target_unreachable ("[Errno -2] Name or service not known"); a URL returning 404 → 200 with status_code: 404; render: true → 501.
  • CR: 4 findings. 1 and 2 are fixed (490d9736, 470dc726); 3 and 4 are stet.

Known limits and post-merge host steps: #561 (comment)

🤖 Generated with Claude Code

gregoryfoster and others added 4 commits November 27, 2026 23:31
…y, for fetch-and-render's tests too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…port error, not 500

fetch_2xx's transport leg becomes fetch_target, shared with fetch_and_render;
a non-2xx stays a 200 with status_code, render=True stays 501. v4.49.2; SDK
unchanged (5.19.0), docstrings only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s context budget

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… error

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POST /tools/fetch-and-render answers 500 for an unreachable target; preview and propose answer 422 target_unreachable

1 participant