Journal work before running it, so a crash stops losing messages

Execution was fire-and-forget: an MQTT message or webhook ran a cascade
on a ThreadPoolExecutor built for that one wave, and an engine that died
halfway through simply lost whatever was in flight. Concurrent triggers
each built their own pool, so load meant unbounded threads.

Every external trigger is now journaled to a Redis Streams queue before
anything runs, and acknowledged only once its cascade finishes. A
consumer thread drives cascades on one long-lived pool while node bodies
run on another, so a cascade cannot starve the nodes it is waiting for.
A reaper reclaims what a dead consumer never acknowledged — verified end
to end: work journaled while the engine was stopped runs on restart, and
work abandoned mid-cascade comes back as a second delivery.

At-least-once needs a guard, so nodes that reach outside are marked
non-idempotent and skipped on a redelivery they already completed.
Without Redis the queue degrades to an in-memory one that does not
pretend to be durable, and interactive callers still run inline.

Also fixes two things this turned up: a delay node was sleeping on a
worker thread, where a handful of them could occupy the whole pool, and
webhooks 404'd whenever MCP was enabled because the app mounted at /
answered first for every path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011LF61rxW1FG5YCD2J9YqjY
This commit is contained in:
root
2026-08-16 07:57:07 +02:00
co-authored by Claude Fable 5
parent 2cc25970e3
commit 04329149b3
17 changed files with 1271 additions and 66 deletions
@@ -61,6 +61,21 @@ def test_a_hook_without_a_secret_still_answers_on_its_plain_url():
assert pipeline.values()["house.temp"]["value"] == 21.5
def test_a_hook_is_reachable_past_an_app_mounted_at_the_root():
"""The MCP app is mounted at "/" and answers for every path, so a hook
registered after it would never be reached."""
node = hook_node()
pipeline = Pipeline(nodes=[node])
app = FastAPI()
app.mount("/", FastAPI())
node.register_route(app)
response = TestClient(app).post(HOOK, json={"temp": 21.5})
assert response.status_code == 200
assert pipeline.values()["house.temp"]["value"] == 21.5
@pytest.mark.parametrize(
"path",
[