Repository navigation
feat(plugins): inbound IMAP email trigger - #130230
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Dependency GuardThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
Dependency graph changes notedThis PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin, a member of
Security review is still recommended before merge when the dependency graph change is intentional. |
Post-rebase drift made resolveBoundGatewayContext possibly-undefined; the plugin hook dispatch path invoked it unconditionally. Use the optional-call guard consistent with sibling runtime accessors.
mailparser 3.9.15 pinned [email protected] -> [email protected] (GHSA HIGH, stack exhaustion, <8.0.0). 3.9.16 pins [email protected] -> [email protected], clearing the production audit gate.
|
Codex review: needs real behavior proof before merge. Reviewed August 26, 2026, 3:05 PM ET / 19:05 UTC. ClawSweeper reviewWhat this changesAdds an off-by-default bundled IMAP mailbox watcher and a trusted-plugin Gateway API for dispatching authenticated inbound email into isolated hook-agent sessions. Merge readiness⛔ Blocked until stronger real behavior proof is added - 10 items remain Keep this PR open: its new trusted-plugin hook API lets a retired plugin instance still dispatch an untrusted-email agent run. The existing proof request also remains unmet because the stated live watcher evidence does not show permitted and stale/denied authority through a real Gateway final effect. Priority: P2 Review scores
Verification
How this fits togetherThe IMAP plugin watches configured mailboxes and passes accepted messages through the Gateway hook dispatcher. That dispatcher creates isolated agent runs, wraps external email content, and optionally reports completion through the existing hook delivery path. flowchart LR
A[IMAP mailbox] --> B[IMAP watcher plugin]
B --> C[Sender authentication gate]
C -->|accepted email| D[Trusted plugin hook API]
C -->|rejected email| E[Recorded skip]
D --> F[Gateway hook dispatcher]
F --> G[Isolated agent run]
G --> H[Optional completion notice]
Decision needed
Why: The PR creates a public, compatibility-sensitive plugin runtime capability rather than only repairing existing behavior; the closed earlier IMAP request and this PR’s differing core-seam rationale do not establish current maintainer sponsorship. Before merge
Findings
Agent review detailsSecurityNeeds attention: The new trusted-plugin ingress can outlive plugin lifecycle revocation and trigger a final untrusted-email agent run. PR surfaceSource +1314, Tests +945, Docs +185, Config +24, Other +373. Total +2841 across 41 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Bind hook dispatch to an exact live plugin record and lifecycle epoch, revalidate immediately before agent execution, then prove accepted and revoked paths through the real Gateway without granting the email run unrestricted tools. Do we have a high-confidence way to reproduce the issue? No executed current-head reproduction was possible in this read-only checkout, but source establishes a high-confidence stale-authority path: a retained plugin runtime can dispatch after its active record and lifecycle epoch are revoked. Is this the best way to solve the issue? No. The hook API must carry live plugin-record authority through the queued execution boundary instead of authorizing solely from a retained plugin ID and origin. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 21df0f36a483. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
…s under max-lines The dispatchHookAgentTurn seam pushed server-plugins.ts to 702 effective lines (cap 700). Extract createGatewayHooksRuntime into the sibling runtime-helpers module, mirroring createGatewayNodesRuntime/createGatewaySubagentRuntime; no suppression added.
|
Merged via squash.
|
The bundled imap plugin landed in #130230 without regenerating the plugin inventory docs, so pnpm plugins:inventory:check failed on main and the plugin was absent from the reference index. Regenerate, and register its operator guide in PLUGIN_DOC_ALIASES so the generated reference page links to /automation/imap (same mechanism codex and firecrawl use).
* feat(plugin-sdk): add in-process hook agent dispatch seam * feat(plugins): add imap inbound email trigger plugin * fix(imap): coalesce sweep wakeups and drop test-only gate exports * docs(imap): fix agents bindings command invocation * fix(gateway): guard optional bound context in plugin hook dispatch Post-rebase drift made resolveBoundGatewayContext possibly-undefined; the plugin hook dispatch path invoked it unconditionally. Use the optional-call guard consistent with sibling runtime accessors. * fix(imap): bump mailparser to 3.9.16 off vulnerable deepmerge-ts mailparser 3.9.15 pinned [email protected] -> [email protected] (GHSA HIGH, stack exhaustion, <8.0.0). 3.9.16 pins [email protected] -> [email protected], clearing the production audit gate. * refactor(gateway): extract plugin hooks runtime to keep server-plugins under max-lines The dispatchHookAgentTurn seam pushed server-plugins.ts to 702 effective lines (cap 700). Extract createGatewayHooksRuntime into the sibling runtime-helpers module, mirroring createGatewayNodesRuntime/createGatewaySubagentRuntime; no suppression added. * docs(secrets): register imap plugin password in secretref credential matrix The bundled imap plugin declares a secretInput (accounts.*.password); regenerate the user-supplied credentials matrix and surface list so the target-registry docs sync test stays green.
…130363) The bundled imap plugin landed in openclaw#130230 without regenerating the plugin inventory docs, so pnpm plugins:inventory:check failed on main and the plugin was absent from the reference index. Regenerate, and register its operator guide in PLUGIN_DOC_ALIASES so the generated reference page links to /automation/imap (same mechanism codex and firecrawl use).
What Problem This Solves
OpenClaw's inbound-email trigger story was Gmail-only: Google Pub/Sub → the external
gogbinary → the generic/hooksendpoint → an isolated hook agent session. A non-Gmail mailbox (Outlook, Fastmail, iCloud, any generic IMAP) could not trigger OpenClaw at all — the bundled himalaya skill only lets an agent act on IMAP when explicitly asked; nothing watches.This adds an inbound IMAP trigger that feeds the same isolated, tool-clamped hook-session model the Gmail flow documents, with no Google Cloud, no Tailscale Funnel, and no public HTTP endpoint.
This revisits #33199 (previously closed not-planned, routed to community plugins). That close asserted "no OpenClaw core API change is required," but a source audit found otherwise: the seams it cited (
runEmbeddedAgent,subagent.run, system events) all bypass the external-content wrapping, suspicious-pattern detection, and hook-admission containment that make the Gmail flow safe. A pure-SDK plugin would therefore ship untrusted email without Gmail-grade containment, or reimplement core security policy in a plugin. This PR closes that gap with one small shared core seam and ships the trigger as a bundled, off-by-default plugin — the distribution/ownership decision called for in #99084.Why This Change Was Made
Automation, not a channel: an email trigger has no pairing, threading grammar, or outbound message adapter (the channel boundary), so like Gmail it is one-way ingestion of untrusted external content into isolated agent runs.
docs/automation/hooks.mdforbids a long-lived watcher living in a hook handler, so the watcher is a gateway-lifecycle plugin service.Two pieces:
Core seam (
feat(plugin-sdk): add in-process hook agent dispatch seam): extracts the post-HTTP core of the Gmail hook dispatcher into one lifecycle-ownedcreateGatewayHookDispatcher, shared by the HTTP endpoint and a new trusted-plugins-onlyapi.runtime.hooks.dispatchHookAgentTurn. Isolation and email-class external-content wrapping are hard-coded (noallowUnsafeExternalContenton the seam); the plugin identity is host-bound into a newgateway.hooks.pluginingress boundary; it requires nohooks.enabled.Plugin (
extensions/imap): a twin-driver watcher (IMAP IDLE with polling fallback, wakeup-≠-fetch cursor sweeps), a layered sender gate (mandatory allowlist → client-side DKIM/DMARC verification viamailauth→ trusted-Authentication-Resultsfallback opt-in → per-sender plus-address tokens), and durable cursor/dedupe state in plugin keyed stores (shared state DB; no new tables, no schema bump, no files).User Impact
imap, disabled by default. Operators opt in underplugins.entries.imap.configwith a clampedmail_readerreader agent (minimal tool profile, session-scoped sandbox,workspaceAccess: none), documented indocs/automation/imap.md.senderAuth.min: "verified"requires an aligned DKIM/DMARC pass verified client-side; SPF-only, untrustedAuthentication-Results, and no-auth senders are rejected with recorded skips unless the operator explicitly relaxes the threshold or configures a sender-bound token.Evidence
gpt-5.6-sol, high).pnpm buildgreen; bundled plugin present atdist/extensions/imap/index.js. Only pre-existing Control UIINEFFECTIVE_DYNAMIC_IMPORTwarnings (verified present at base).pnpm check:changedgreen (typecheck, lint, architecture, coercion/import-cycle guards,plugin-sdk:surface:check);pnpm docs:check-config-examplesgreen including the IMAP page's config fence.N:*ghost filter; a scripted in-process IMAP server driving the real connection manager through connect→IDLE→sweep→dispatch with fault injection (mid-IDLE disconnect, no-IDLE fallback, auth-failure escalation, UIDVALIDITY rotation). The sweep-coalesce regression test fails on pre-fix code.imapflow, with the realmailauthgate verifying DKIM/DMARC against live public DNS. A genuine DKIM-alignedgithub.commessage →verified→ dispatched; a body-tampered copy → rejected; a forged-From no-signature message →dmarc-failrejected; an allowlisted sender + valid address token → dispatched. Confirmed live: the gate omitstrustReceivedand disables ARC, so a post-delivery message whose DKIM was mangled in transit correctly fails to reachverifiedrather than riding a spurious SPF/ARC pass.Production LOC: +1,124 net (core +210, mostly code motion from the extracted dispatcher; plugin +914). Tests +1,018, docs +176, manifest/package +130, lockfile +373.
Known follow-ups (named, not blockers): XOAUTH2 for Microsoft 365; ARC-override for forwarded mail; adopting the RFC 51 sender-auth-strength primitive (#124218) once its SDK contract lands; a live-gateway zero-tool-escape acceptance run and keyed-store persistence across a real restart.