Skip to content

feat(platform): triage the Inbox and draft replies in the mail packs - #4036

Merged
larryro merged 6 commits into
mainfrom
feat/inbox-triage-drafts
Oct 1, 2026
Merged

larryro merged 6 commits into
mainfrom
feat/inbox-triage-drafts

Conversation

@larryro

@larryro larryro commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Why

The three Triage the … inbox packs read the raw mailbox and wrote a digest into the run's JSON: Gmail ids nobody could open, no cursor (the same 25 newest mails re-judged every six hours), nothing drafted, nobody told. After #4034 the rows were at least populated; the pack was still a demo.

What

They now work on the Inbox the sync packs fill — one document for Gmail, Outlook and IMAP, connector substituted (packs.test.ts trio rule holds).

  • conversation.list_untriaged (new native, backend/domains/conversations/triage.ts): the open threads of one mail connector whose newest message — by arrival (seq) — is the customer's and newer than the thread's triage stamp. Each row: subject, contact, the message as text (the ingest's plain part, else HTML stripped, 4000-char cap), unread count, assigned, the Inbox link. Newest first, ≤100.
  • triage (llm, skipped when nothing waits): one verdict per thread — action: reply | no_reply, priority, one-sentence reason — plus a summary.
  • conversation.record_triage (new native): stamps metadata.triage {at, seq, action, priority, reason, runId} and sets priority only where none is set (a person's choice is never overwritten). The stamp's seq is the cursor: a thread is listed again only when a message lands after it — however old that message's own Date header is (a sync pass ingests mail minutes after it was sent; a wall-clock cursor stepped over it for good, which the integration lane caught in its first run).
  • due (transform): the reply verdicts joined back onto the listing, so a verdict naming an id the pack never read is dropped.
  • draft (llm, forEach) → propose (conversation.draft_reply, forEach, onError: continue): one drafted reply per thread that needs one, left as the pending message a person sends (CONV-F13's lane; a thread already holding a pending draft keeps it, created: false).
  • Output: read, summary, recorded, needsReply[] (with Inbox links), drafted[].

Also: connector contract + mocks (conversation/connector.yml), native wiring + tests, docs builtin.md EN/DE/FR, manifests' descriptions in three languages, manual box CONV-F37, coverage row, and a checkInboxTriageLane in backend:integration.

Not in scope: a bell notification for the digest (dropped by request), an Inbox badge for the triage verdict, a REST twin.

Proof

  • packs.test.ts (each pack's own tests walk list → judge → record → draft → draft_reply against the mocks), natives/index.test.ts, registry.test.ts, triage.test.ts, the integration-scope guard: green. Platform typecheck, oxlint, lint:manual, lint:links, @tale/docs test (locale parity): green.
  • ITEST_LANES=checkInboxTriageLane backend:integration on a throwaway tale-db + MinIO: 20/20 — listing (waiting + person-prioritized threads in, team-answered-last and closed out, HTML stripped, link shape), stamp (verdict, runId, priority set on one and kept urgent on the other, unknown id reported), and the seq cursor (nothing after the stamp; a customer message dated an hour earlier but ingested after it surfaces the thread again).
  • Live run on the dev stack: pending — needs a backend restart and the new document saved as a new version in an existing org (an org created before this change keeps its deployed versions).

The three inbox triage packs read the raw mailbox and wrote a digest
into the run's JSON: ids nobody could open, no cursor, nothing drafted,
nobody told. They now work on the Inbox the sync packs fill.

conversation.list_untriaged hands a pack the open threads of one mail
connector whose newest message — by arrival, seq — is the customer's
and newer than the thread's triage stamp: subject, contact, the message
as text (the ingest's plain part, else the HTML stripped, 4000 chars)
and the Inbox link. The model judges each one (reply / no_reply,
priority, one reason); conversation.record_triage stamps the verdict on
metadata.triage and sets the priority where no person has, so the
thread is listed again only when the customer writes again, however old
that message's Date header is. For every thread that needs an answer a
second model call drafts one and conversation.draft_reply leaves it in
the thread as the pending message a person sends. The three packs stay
one document with the connector substituted; their own tests walk the
whole lane against the mocks.

Docs EN/DE/FR, the manifests' descriptions in three languages, the
manual box CONV-F37, and a backend:integration lane on the real schema
— listing, stamp, kept priority, and the seq cursor surfacing a
late-ingested older message.

An organization created before this change keeps its deployed digest
versions; the new document lands as a new version through the editor or
in a new organization.
@larryro

larryro commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Live proof (dev stack, test org, Gmail)

Backend restarted on the branch; the new document saved as a new version of gmail-triage-inbox (the org keeps its earlier versions) and deployed. The org serves no anthropic/claude-haiku-4-5, so the first live run failed at the triage node with the engine's model refusal (the inbox native had already answered) — the pack's documented "pick a served model before a live run" case; the proof versions name the org's own model.

  • Run 1, limit: 3 → success: read 3, all three no_reply (a payment provider's policy notice, a property listing, a developer newsletter), recorded {recorded: 3, prioritized: 3}, drafted []. Each thread now carries metadata.triage {action, priority, reason, seq, at, runId} and priority: low where none was set.
  • Run 2, limit: 3 → success: read the next 3 (the first three were not re-read — the seq cursor), two no_reply, one reply / high with a one-sentence reason and the thread's Inbox link; drafted [{created: true, approvalId}] — the thread holds a pending approval (source: automation, confidence: 0.5) whose emailBody is a short, on-topic reply in the customer's language, ending in "Best regards". Nothing was sent.

Read back from app.conversations / app.approvals on the dev database. Outlook and IMAP are the same document (connector substituted) over the same natives; their lane is the mock tests plus checkInboxTriageLane, which is connector-agnostic.

The reading pane keys a drafted reply on pendingApproval._id — the 0.4
approval shape the frontend contract declares — and suppresses the seed
when that id equals the draft it just replaced. loadPendingApprovals
handed the panel the raw {id, metadata} row, so _id was undefined, the
comparison held against an absent replacedApprovalId, and no drafted
reply ever rendered: the first live Inbox triage run left a pending
draft the thread did not show.

The newest pending approval now rides onto the item as an ApprovalItem
(_id, _creationTime, status, resource, priority, metadata, the optional
fields only when set), and the list projection test pins that shape.
@larryro

larryro commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up fix in this PR — the first live draft did not show in the thread. Root cause: loadPendingApprovals handed the Inbox item the raw {id, metadata} approval row while the reading pane (and the frontend contract) key the pending draft on pendingApproval._id; with _id undefined the panel's "suppress the replaced seed" comparison held against an absent replacedApprovalId and hid every drafted reply (pre-existing on main; CONV-F13 is a manual box and the panel's unit test seeds the _id shape). The projection now emits the ApprovalItem wire shape, pinned by service.list.test.ts.

The reading pane wrote a drafted reply straight into the composer, so a
person could not tell what they had typed from what a model proposed —
and the editor persisted the proposal as their own local draft.

The pending approval now renders as a Suggested reply card above the
composer: a labelled region with the proposal and two decisions. Put in
editor hands the text to the composer through the one-time seed the
undo lane already uses and leaves a status line; Discard rejects the
approval through the approvals door and refreshes the thread, so the
triage pack does not propose on it again until the customer writes
again. The composer is never seeded on the person's behalf.

Catalogs EN/DE/FR, the built-in automations guide in three locales,
CONV-F13 and the coverage register updated; component tests for the
card and the panel's two decisions.
@larryro

larryro commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Suggested-reply card (in this PR, by request) — an automation's drafted reply used to be written straight into the composer, indistinguishable from what the person typed (and persisted as their local draft). It now renders above the composer as a labelled Suggested reply region with Put in editor / Discard; the composer is never seeded on the person's behalf. Put in editor goes through the one-time seed the undo lane already uses and leaves a status line; Discard rejects the approval through the existing /approvals/:id/decide door and refreshes the thread, so the triage pack does not propose on that thread again until the customer writes again. EN/DE/FR catalogs, the guide in three locales, CONV-F13, component tests for the card and the panel's two decisions. Verified in the running app (the accessibility tree reads region › heading "Suggested reply" › buttons Discard / Put in editor › the proposal).

Also in this PR: the drafting prompt now keeps greeting, body and sign-off in the customer's language (it used to demand an English "Best regards").

@larryro
larryro merged commit 13af54d into main Oct 1, 2026
71 checks passed
@larryro
larryro deleted the feat/inbox-triage-drafts branch October 1, 2026 09:40
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