From 9da3f1bfadddf55dfede5bf99f5b7d95f8390226 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sun, 18 Oct 2026 09:23:10 +0000 Subject: [PATCH] fix(automations): a run's trace marks an action that waits as waiting, not done An action that asks first or waits for its time passed nothing on, and the workflow engine called its node done. finish() now marks it waiting or scheduled, and the canvas shows those as would ask you first / would wait for its time. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01AjJqXgjj1cNdKGRQbX5frb --- docs/automations.md | 3 ++- fastapi_backend/app/domain/automation_nodes.py | 6 +++++- .../tests/domain/test_automation_nodes.py | 2 +- .../tests/domain/test_automation_runs.py | 1 + .../components/canvas/flow-canvas.tsx | 16 +++++++++++++--- .../components/workflows/node-settings.tsx | 11 ++++++++++- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/docs/automations.md b/docs/automations.md index a67ccc0cd..6bb0e7524 100644 --- a/docs/automations.md +++ b/docs/automations.md @@ -1208,7 +1208,8 @@ when it completes. It gives the run's id, or none when nothing ran. A run goes: Routine actions are done; ones that ask first wait for the person's pick and ones with a time wait for it (until approvals and timers are built, they stay waiting). 6. **It finishes** `done`, `partly` (some actions failed), `failed` or `waiting` (actions wait), with its cost and - tokens, what each node did (`trace`), its log (at most 500 lines) and an `automation.` row in the activity + tokens, what each node did (`trace`: `done`, `skipped`, `failed`, or `waiting` and `scheduled` for an action that + asks first or waits for its time), its log (at most 500 lines) and an `automation.` row in the activity ledger; and it appears in the stream as `automation.ran`. When a waiting action is decided or its time comes, its status changes (`automations.update_intent`) and the run's follows. diff --git a/fastapi_backend/app/domain/automation_nodes.py b/fastapi_backend/app/domain/automation_nodes.py index 69999937a..dce2123b2 100644 --- a/fastapi_backend/app/domain/automation_nodes.py +++ b/fastapi_backend/app/domain/automation_nodes.py @@ -368,7 +368,11 @@ def _action(r, f, node): def finish(trace, box): - """The trace with each action that failed marked failed, with why (flow.py saw it pass nothing on).""" + """The trace with each action that failed marked failed, with why, and each that waits for a pick or a time marked + waiting or scheduled (flow.py saw them pass nothing on, and called them done).""" + for i in box.items: + if i["status"] in ("waiting", "scheduled") and i["path"] in trace: + trace[i["path"]] = {**trace[i["path"]], "status": i["status"]} for path, why in box.failed.items(): if path in trace: trace[path] = {**trace[path], "status": "failed", "error": why} diff --git a/fastapi_backend/tests/domain/test_automation_nodes.py b/fastapi_backend/tests/domain/test_automation_nodes.py index b31fdd177..2f6801774 100644 --- a/fastapi_backend/tests/domain/test_automation_nodes.py +++ b/fastapi_backend/tests/domain/test_automation_nodes.py @@ -232,7 +232,7 @@ def test_an_intent_that_asks_first_or_fails_passes_nothing_on(db, cfg, made): # a change to another asset asks first: the node passes nothing on and what comes after it is skipped g = graph(node("a", "action", action="tag", params={"object": "lens:recording/99"}), after, edges=[edge("in", "a"), edge("a", "l")]) out = _try(db, cfg, g) - assert out["trace"]["a"]["status"] == "done" and out["trace"]["a"]["ports"] == [] and out["trace"]["l"]["status"] == "skipped" + assert out["trace"]["a"]["status"] == "waiting" and out["trace"]["a"]["ports"] == [] and out["trace"]["l"]["status"] == "skipped" assert [(i["node"], i["status"], i["risk"]) for i in out["intents"]] == [("a", "waiting", "ask")] assert "stopped at a: waiting for your pick" in out["log"] and made == [] # an out action asks first too (nothing can come after it) diff --git a/fastapi_backend/tests/domain/test_automation_runs.py b/fastapi_backend/tests/domain/test_automation_runs.py index 2da0e100e..820e6f0a6 100644 --- a/fastapi_backend/tests/domain/test_automation_runs.py +++ b/fastapi_backend/tests/domain/test_automation_runs.py @@ -282,6 +282,7 @@ def test_intents_wait_for_a_pick_or_a_time_and_settle_later(db, cfg, env, monkey run = automations.get_run(db, run_id) assert run["status"] == "waiting" and run["counts"] == {"done": 0, "waiting": 1, "scheduled": 1, "failed": 0} assert run["trace"]["s"]["status"] == "skipped" and any("waiting for your pick" in line for line in run["log"]) + assert run["trace"]["t"]["status"] == "waiting" and run["trace"]["w"]["status"] == "scheduled" # not done yet by = {i["node"]: i for i in run["intents"]} assert by["t"]["status"] == "waiting" and by["t"]["result"] == {"approval": 77} and asked[0][0]["key"] == by["t"]["key"] assert asked[0][1]["id"] == SAMPLE["id"] # the approval says which activity it's about diff --git a/nextjs-frontend/components/canvas/flow-canvas.tsx b/nextjs-frontend/components/canvas/flow-canvas.tsx index 8964d41f0..43972aa4d 100644 --- a/nextjs-frontend/components/canvas/flow-canvas.tsx +++ b/nextjs-frontend/components/canvas/flow-canvas.tsx @@ -43,7 +43,7 @@ export type CanvasNode = { outputs: string[]; tone?: "blue" | "green" | "gold" | "red" | "purple" | "neutral"; /** What the last try did: ran, was skipped or failed, and a peek at what it passed on. */ - status?: "done" | "skipped" | "failed"; + status?: "done" | "skipped" | "failed" | "waiting" | "scheduled"; peek?: string; /** It has a body of nodes, opened by double-clicking. */ opens?: boolean; @@ -111,11 +111,21 @@ function CardNode({ data, selected }: NodeProps>) { ? "Ran in the last try" : data.status === "skipped" ? "Skipped in the last try" - : "Failed in the last try" + : data.status === "waiting" + ? "Would ask you first in the last try" + : data.status === "scheduled" + ? "Would wait for its time in the last try" + : "Failed in the last try" } className={cn( "absolute -right-1.5 -top-1.5 size-3 rounded-full border-2 border-background", - data.status === "done" ? "bg-green" : data.status === "failed" ? "bg-red" : "bg-fg-muted", + data.status === "done" + ? "bg-green" + : data.status === "failed" + ? "bg-red" + : data.status === "waiting" || data.status === "scheduled" + ? "bg-gold" + : "bg-fg-muted", )} /> )} diff --git a/nextjs-frontend/components/workflows/node-settings.tsx b/nextjs-frontend/components/workflows/node-settings.tsx index 65a185edf..b6c4a7d9b 100644 --- a/nextjs-frontend/components/workflows/node-settings.tsx +++ b/nextjs-frontend/components/workflows/node-settings.tsx @@ -160,7 +160,16 @@ export function NodeSettings({ {peek && (
- Last try: {peek.status === "done" ? "ran" : peek.status === "failed" ? "failed" : "skipped"} + Last try:{" "} + {peek.status === "done" + ? "ran" + : peek.status === "failed" + ? "failed" + : peek.status === "waiting" + ? "would ask you first" + : peek.status === "scheduled" + ? "would wait for its time" + : "skipped"} {peek.error &&

{peek.error}

} {peek.value && (