feat(api): experimental quote_history flag on reply - #789
Open
jiashuoz wants to merge 3 commits into
Open
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…und, docs Contract scenario now uses future send_at so seed mode never submits real mail and cleanup cannot race a submission lease; extractBodyParts gains the same depth bound mailparse has (newly hot via reply quoting); the composed-ceiling interaction is documented; the new CLI test passes in isolation. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
Author
|
Adversarial review round completed before handing off (findings + fixes in eaef777):
Cleared during review (verified, no change needed): CRLF/header injection via parent headers (net/mail unfolds; QP encoding canonicalizes), HTML injection (same contract as forward's blockquote), idempotency (dedup hashes raw request bytes, so key reuse with a different flag value correctly 422s), scenario determinism (6× green). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an experimental opt-in
quote_historyboolean toPOST /v1/agents/{email}/messages/{id}/reply. Whentrue, the server composes the referenced message beneath the caller's body as mail-client-style quoted history — anOn <date>, <sender> wrote:attribution line, the original text>-prefixed, and (when anhtmlbody is supplied) the original HTML in a blockquote. Defaultfalse: bodies remain byte-verbatim, today's behavior.Why: API-sent replies currently look terse to human correspondents and give newly added thread participants no context. No peer email API offers this (Graph, Nylas, AgentMail all require hand-rolled quoting — it's a documented pain point for Graph), so it's cheap differentiation for the agent-as-correspondent use case. The composition generalizes the existing forward quote path (
internal/outbound/forward.go) intointernal/outbound/quote.go; both shareForwardContextextraction.Design notes:
mailparse.stripQuotedReplies) recognizes the emittedOn … wrote:marker, so agent-to-agent mail with the flag on adds zero noise to the receiving agent's model-facingparsed.text(verified live against a local instance + Mailpit across a 9-scenario matrix: human recipient, deep-thread nesting>→>>, text-only, HTML-only parent, reply-to-own-outbound, HITL hold/approve, idempotent retry, control).<pre>text fallback). Parent with no extractable body degrades to a verbatim reply.Experimentalin the OpenAPI doc (house precedent:send_at,unsubscribebeta markers); additive only, oasdiff-clean.Client surface checklist
internal/httpapi/outbound_reply_quote_test.go,internal/outbound/quote_test.go)make generateis clean)ReplyInputflows the generatedquoteHistoryfield per thesendAtprecedent (no hand-written mapping layer exists for reply fields), unit + type tests addedquote_historykwarg onreply(sync mirror is automatic), 3 tests added, mypy clean--quote-historyone2a reply, wired intocheckFlagsallowlist + help (marked experimental), tests addedquote_historyinput onreply_to_message(plain optional, no default — no MCP field has one), mapping + schema-description tests addedreply_quote_historyintests/contract/scenarios.yaml— proven through the Go runner; TS/Python runners skip it by established rule (usesinject_messagestore setup, same asscheduled_reply_fields)web/, so no dashboard change appliesOperational risk
Low. Opt-in flag, default off; no schema change; no new external calls. The composed body passes through the existing outbound size ceilings (
413on overflow, unchanged). Held replies show reviewers the final composed content — behavior reviewers should be told about, not a risk per se. Rollback = revert; no data migration to unwind.Known caveats (why it's marked experimental):
parsed.textfor outbound rows too, so the contract scenario asserts the attribution-line projection; exact wire bytes are pinned by unit tests.Test plan
make test-unitclean;make spec-check+make openapi-compat-checkclean (additive, no breaking changes)TestScenarios/reply_quote_historyPASS (Postgres-backed)🤖 Generated with Claude Code