Skip to content

fix: Add automatic citation buffering and preserve point citations - #89

Merged
jiahuei merged 6 commits into
amer-hosted-web-searchfrom
review-fixes-hosted-web-search
Oct 29, 2026
Merged

jiahuei merged 6 commits into
amer-hosted-web-searchfrom
review-fixes-hosted-web-search

Conversation

@jiahuei

@jiahuei jiahuei commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds Molto.messages(..., citation_policy="auto") for conditional citation buffering on translated Responses routes. It buffers text when normalized tools or history signal possible citations; otherwise text streams immediately and unexpected citations are dropped. "buffer" always buffers each text part, "drop" remains the default, and opaque transport extensions do not select automatic buffering. Native Messages and Chat upstream behavior remain unchanged.
  • Preserves point citations without splitting text at zero-length ranges. When no original excerpt exists, the containing block supplies the fallback cited_text. Existing offset validation, blank-text rejection, provider metadata, and SDK-compatible text deltas remain intact.
  • Extends terminal-reason coverage with normal completion and refusal, and adds coverage for automatic buffering, history, transport overrides, point citations, and SDK text iteration.
  • Merges amer-hosted-web-search, retaining its Anthropic continuation metadata, provider-specific missing/empty/placeholder ciphertext rejection, and recorded continuation coverage. No cassette contents differ from that branch.

Removal of output-only missing reasoning-signature checks is tracked independently in PR #90.

Verification

  • .venv/bin/python -m pytest: 2,293 passed in 35.78 seconds on Python 3.12.9 after separating the reasoning-output work. Tests used offline replay only.
  • Focused citation and terminal-reason tests: 154 passed, 267 deselected. Earlier outdated point-citation expectations were corrected before the passing full suite.
  • uv run --extra lint ruff check --output-format github --config pyproject.toml .: passed.
  • uv run --extra lint ruff format --diff --config pyproject.toml .: passed.
  • npx prettier@3.8 --check .: passed.
  • git diff 4235d01 HEAD --exit-code: passed; the final tree exactly matches the verified hosted-search-only merge. Cassettes remain unchanged relative to amer-hosted-web-search.
  • The offline replay workflow targets PRs against main, so PR fix: Add automatic citation buffering and preserve point citations #89 relies on the local suite above while its base remains amer-hosted-web-search.

- Project a reason-less Responses incomplete as unknown instead of inferring pause,
  and keep pause for sources that report it.
- Replace the client-side citation prediction with an explicit citation_policy on
  the Messages adapter, defaulting to drop, and never emit empty or whitespace-only
  text blocks when splitting at citation boundaries.
- Never drop reasoning that Chat cannot represent; fail at the signature boundary.
- Make the hosted search request count a normalized Usage field.
- Treat extra_body and extra_headers as opaque transport extensions.
- Drop unrelated churn and document the new contracts.
- citation_policy=buffer now withholds text parts only when the normalized
  request declares a hosted-search tool or carries search or citation history,
  falling back to the drop outcome otherwise.
- Document that extra_body is opaque while extra_headers is filtered once at the
  credential boundary, and that neither is validated or used for translation.
Anthropic decrypts web_search_result.encrypted_content and
web_search_result_location.encrypted_index on later turns and rejects a request
where either is missing or modified. Translated history cannot supply those
values, so request construction now rejects it with UnsupportedInput instead of
sending an N/A placeholder, and the docs stop recommending replay of translated
Messages responses.
@jiahuei jiahuei changed the title fix: address hosted web search review findings fix: Add automatic citation buffering and preserve point citations Oct 29, 2026
@jiahuei jiahuei changed the title fix: Add automatic citation buffering and preserve point citations fix: Refine citation buffering and accept unsigned reasoning output Oct 29, 2026
@jiahuei jiahuei changed the title fix: Refine citation buffering and accept unsigned reasoning output fix: Add automatic citation buffering and preserve point citations Oct 29, 2026
@jiahuei
jiahuei merged commit c55a6b8 into amer-hosted-web-search Oct 29, 2026
2 checks passed
@jiahuei
jiahuei deleted the review-fixes-hosted-web-search branch October 29, 2026 13:24
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.

1 participant