feat(build-sdk): a triggers module that lets an app verify, parse and answer platform deliveries
Merged
MA
12d ago+968+968+012345678901234567890123456789-0-0-0123456789
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, andREFLEX_TRIGGER_SECRETmay hold several space-separated secrets, for rotation.GET /_triggersis verified over an empty body before answering the manifest.parse_delivery(body, headers) -> Delivery: the body is versioned,{"version": 1, "events": [...]}. EachEventcarriesid,trigger_id,entry_point,payload,type,environment,received_at, andkey="{trigger_id}:{id}"forstart(first, key=)(#7925).EntryPoints.add(event=, start=, name=)as a decorator,get, iteration andmanifest().event=takes anything with pydantic'smodel_validate/model_json_schema, andstartis kept as given, so neither pydantic nor reflex-workflow is imported.EntryPoint.build(payload)validates and calls the function (InvalidPayloadon a bad payload,Noneto skip).Result(STARTED,DUPLICATE,SKIPPED,INVALID,ERROR; onlyERRORis retried) andreply(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 ofInvalidSignature, so a route can answer 400 for a format mismatch and keep 401 for a bad secret. CatchingInvalidDeliverycovers both. The flexgen memory that teaches the route catches onlyInvalidSignature, 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'stests/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
Stepto 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