8000 fix(automations): a run's trace marks an action that waits as waiting, not done by adeelahmad · Pull Request #586 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/automations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<status>` 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.<status>` 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.

Expand Down
6 changes: 5 additions & 1 deletion fastapi_backend/app/domain/automation_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion fastapi_backend/tests/domain/test_automation_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions fastapi_backend/tests/domain/test_automation_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions nextjs-frontend/components/canvas/flow-canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,11 +111,21 @@ function CardNode({ data, selected }: NodeProps<Node<Data>>) {
? "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",
)}
/>
)}
Expand Down
11 changes: 10 additions & 1 deletion nextjs-frontend/components/workflows/node-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,16 @@ export function NodeSettings({
{peek && (
<div className="flex flex-col gap-1 rounded-sm border border-border bg-surface px-3 py-2">
<span className="label-caps">
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"}
</span>
{peek.error && <p className="text-[12.5px] text-red-dark">{peek.error}</p>}
{peek.value && (
Expand Down
Loading
0