feat(build-sdk): a triggers module that lets an app verify, parse and answer platform deliveries

Merged
MA
12d ago
+968-0

Requested by Masen · project thread

Type of change

  • New feature (non-breaking change which adds functionality)

What

reflex_build_sdk.triggers, the app side of the Workflows-in-the-Builder delivery protocol. The platform POSTs batches of events to an app's /_triggers route and reads one result per event from the reply; this module is what that route calls. Standard library only, and importing it pulls in none of the SDK's HTTP extras.

  • sign / verify: Standard Webhooks (HMAC-SHA256 over {id}.{timestamp}.{body}, whsec_ keys, 300 s tolerance either way). Several space-separated signatures are accepted, and REFLEX_TRIGGER_SECRET may hold several space-separated secrets, for rotation. GET /_triggers is verified over an empty body before answering the manifest.
  • parse_delivery(body, headers) -> Delivery: the body is versioned, {"version": 1, "events": [...]}. Each Event carries id, trigger_id, entry_point, payload, type, environment, received_at, and key = "{trigger_id}:{id}" for start(first, key=) (#7925).
  • EntryPoints.add(event=, start=, name=) as a decorator, get, iteration and manifest(). event= takes anything with pydantic's model_validate/model_json_schema, and start is kept as given, so neither pydantic nor reflex-workflow is imported. EntryPoint.build(payload) validates and calls the function (InvalidPayload on a bad payload, None to skip).
  • Result (STARTED, DUPLICATE, SKIPPED, INVALID, ERROR; only ERROR is retried) and reply(results) -> bytes.

Notes for review

  • Changed from the prototype: a signed body that this version can't read now raises InvalidDelivery, the new base class of InvalidSignature, so a route can answer 400 for a format mismatch and keep 401 for a bad secret. Catching InvalidDelivery covers both. The flexgen memory that teaches the route catches only InvalidSignature, so it needs a matching update when flexgen moves onto the release.
  • The wire fixture in test_triggers.py (body bytes and headers) is reproduced byte for byte by flexgen's tests/unit/services/triggers/test_wire.py, so a change on either side fails one of them.
  • The manifest names an entry point's workflow from the qualified name of its step's function, so a step declared on a shared base reports the base. The README says so. Fixing that properly would need reflex-workflow's Step to know its owning class.
  • The README example isn't executed in tests.

Tests

  • uv run pytest tests/units/reflex_build_sdk/test_triggers.py: 26 passed.
  • ruff, ruff format, pyright, pre-commit clean on the touched files.

Linear: ENG-13936


Generated by Claude Code