Skip to content

Self-improving AI Employees for everyone

fix(approvals): judge a call on the settings it runs with; server-worded outcomes

trohitg333add3dcd78
diff --git a/client/src/features/chat/__tests__/approvals.test.tsx b/client/src/features/chat/__tests__/approvals.test.tsx
index 03ff4249..c9d7ca1d 100644
--- a/client/src/features/chat/__tests__/approvals.test.tsx
+++ b/client/src/features/chat/__tests__/approvals.test.tsx
@@ -87,6 +87,12 @@ describe('the card says what happened', () => {
expect(view({ status: 'cancelled' }).title).toBe('Draft cancelled');
});
+ it('words what happened as the server does', () => {
+ const labels = { outcome_labels: { sent: 'Email sent', failed: 'Email not sent' } };
+ expect(view({ ...labels, status: 'sent' }).title).toBe('Email sent');
+ expect(view({ ...labels, status: 'failed' }).title).toBe('Email not sent');
+ });
+
it('a discarded draft can come back while its window lasts', () => {
const gate = view({ kind: 'gate', status: 'discarded', restore_until: '2026-10-04T09:00:03Z' });
expect(gate.footer).toEqual({ kind: 'discarded', text: 'Discarded. Maya won’t send this.', restoreSeconds: 3, canRestore: true });
@@ -188,6 +194,15 @@ describe('a draft in the chat', () => {
expect(server.decisions[0].decision_key).not.toBe(server.decisions[1].decision_key);
});
+ it('sends a call that has no message to edit as it is', async () => {
+ server.approvals = [summary({ channel: 'Custom connector', action: 'Use a connector tool', recipient: '', recipient_label: '', body: '', editable: false })];
+ renderPane();
+ const card = (await screen.findByText('Maya wants to use a connector tool')).closest('[data-approval]') as HTMLElement;
+ fireEvent.click(within(card).getByRole('button', { name: /^Send$/ }));
+ await waitFor(() => expect(server.decisions).toHaveLength(1));
+ expect(server.decisions[0]).toMatchObject({ approval_id: 'ap1', decision: 'send' });
+ });
+
it('sends an edit with Ctrl+Enter', async () => {
renderPane();
const card = (await screen.findByText('Maya wants to send a WhatsApp message')).closest('[data-approval]') as HTMLElement;
diff --git a/client/src/features/chat/approval/ApprovalCard.tsx b/client/src/features/chat/approval/ApprovalCard.tsx
index 00496c38..da8769d7 100644
--- a/client/src/features/chat/approval/ApprovalCard.tsx
+++ b/client/src/features/chat/approval/ApprovalCard.tsx
@@ -107,7 +107,8 @@ function Card({ approval, className }: { approval: ChatApproval; className?: str
const edited = text.trim() !== approval.body.trim() || (subject.trim() || null) !== (approval.subject ?? null);
const tooLong = text.length > approval.maxLength;
- const canSend = approval.status === 'pending' && !busy && text.trim().length > 0 && !tooLong;
+ // A draft with no message to edit (a tool call) sends as it is.
+ const canSend = approval.status === 'pending' && !busy && !tooLong && (!approval.editable || text.trim().length > 0);
const send = () => {
if (!canSend) return;
diff --git a/client/src/features/chat/approval/view.ts b/client/src/features/chat/approval/view.ts
index 56bfe5cb..2b0c46a8 100644
--- a/client/src/features/chat/approval/view.ts
+++ b/client/src/features/chat/approval/view.ts
@@ -48,14 +48,6 @@ function lowerFirst(text: string): string {
return text ? text.charAt(0).toLowerCase() + text.slice(1) : text;
}
-function nouns(approval: ChatApproval): { sent: string; failed: string } {
- const action = (approval.action ?? '').toLowerCase();
- if (action.includes('email')) return { sent: 'Email sent', failed: 'Email not sent' };
- if (action.includes('invite')) return { sent: 'Invites sent', failed: 'Invites not sent' };
- if (action.includes('share')) return { sent: 'File shared', failed: 'File not shared' };
- return { sent: 'Message sent', failed: 'Message not sent' };
-}
-
export interface ViewOptions {
name: string;
nowMs: number;
@@ -69,7 +61,7 @@ export function approvalView(approval: ChatApproval, { name, nowMs, offsetMs, ed
const channel = approval.channel || 'the app';
const drafted = timeLabel(approval.createdAt, now);
const sub = drafted ? `${channel} · drafted ${/\d/.test(drafted.charAt(0)) ? 'at ' : ''}${drafted}` : channel;
- const noun = nouns(approval);
+ const noun = approval.outcomeLabels;
const action = approval.action ? lowerFirst(approval.action) : 'send a message';
switch (approval.status) {
diff --git a/client/src/features/chat/data/approvals.ts b/client/src/features/chat/data/approvals.ts
index 20b52604..bf3c1ca9 100644
--- a/client/src/features/chat/data/approvals.ts
+++ b/client/src/features/chat/data/approvals.ts
@@ -67,6 +67,7 @@ const summarySchema = z
})
.optional()
.catch(undefined),
+ outcome_labels: z.object({ sent: z.string(), failed: z.string() }).catch({ sent: 'Message sent', failed: 'Message not sent' }),
run_id: optionalText,
tool_call_id: optionalText,
ui_part_id: optionalText,
@@ -96,6 +97,8 @@ const summarySchema = z
restoreUntil: raw.restore_until,
consumedAt: raw.consumed_at,
outcome: raw.outcome ? { certainty: raw.outcome.certainty, error: raw.outcome.error ?? null, at: raw.outcome.at ?? null } : null,
+ /** What the card says once it went, and when it did not (the server's words). */
+ outcomeLabels: raw.outcome_labels,
runId: raw.run_id,
toolCallId: raw.tool_call_id,
uiPartId: raw.ui_part_id,
diff --git a/docs-internal/chat_protocol.md b/docs-internal/chat_protocol.md
index c97c2ad9..a8fed37c 100644
--- a/docs-internal/chat_protocol.md
+++ b/docs-internal/chat_protocol.md
@@ -173,9 +173,12 @@ broke off), `approval_conflict`, `send_unavailable` (nothing could start the sen
**ApprovalSummary**: `{approval_id, workflow_id, node_id, kind: "gate" | "tool_call", status, channel,
channel_label, action?, recipient, recipient_label, body, subject?, context_excerpt?, details: [{label, value}],
created_at, expires_at, revision, max_length, editable, approved_by?: "owner" | "auto", edited?, undo_until?,
-restore_until?, consumed_at?, outcome?: {certainty: "sent" | "not_sent" | "unknown", error?, at?}, run_id?,
-tool_call_id?, ui_part_id?, agent_node_id?, deployment_state?}`. `status` is `pending`, `approved`, `sending`,
-`sent`, `failed`, `discarded`, `expired` or `cancelled`; see [Approvals](#approvals).
+restore_until?, consumed_at?, outcome?: {certainty: "sent" | "not_sent" | "unknown", error?, at?},
+outcome_labels: {sent, failed}, run_id?, tool_call_id?, ui_part_id?, agent_node_id?, deployment_state?}`. `status`
+is `pending`, `approved`, `sending`, `sent`, `failed`, `discarded`, `expired` or `cancelled`; see
+[Approvals](#approvals). `outcome_labels` is what the card says once it went and when it did not: a held tool
+call's plugin words it (its `ApprovalSpec.outcome_labels`, "Email sent" for the email apps), a gate's draft says
+"Message sent". A draft that is not `editable` has no message to edit, and the card sends it as it is.
### Plugins
@@ -540,9 +543,11 @@ What an employee sends to someone waits for the owner's OK while its workflow as
who it goes to, the body and subject the owner may edit, the card's other lines). `BaseNode.as_activity` checks
every agent tool call (`services/approvals/tool_calls.py`): with Ask first on, a call that sends does not run; its
row keeps what would run (the node's settings with the call's arguments over them, never the identity the node
- sends as) and the model reads that it waits for the owner. A tool that cannot wait is refused (Stripe) or runs
- restricted (the browser, read-only). With Ask first off the call runs; one made answering the owner in the chat
- leaves a row (`approved_by: auto`) with how it went. An approval gate with the rule off lets its draft through at
+ sends as) and the model reads that it waits for the owner. Whether a call sends is judged on what it runs with: a
+ locked field (`server_controlled_fields`) the model set is put back to the node's setting first
+ (`tool_calls.as_it_runs`, NodeExecutor's rule), so a model cannot talk a call out of being held. A tool that cannot
+ wait is refused (Stripe) or runs restricted (the browser, read-only). With Ask first off the call runs; one made
+ answering the owner in the chat leaves a row (`approved_by: auto`) with how it went. An approval gate with the rule off lets its draft through at
once, recorded the same way.
- **Agents that are not AgentWorkflows** (Claude Code, Codex, RLM, Vertex; see [Streaming, steps and
Stop](#streaming-steps-and-stop)) call their tools in process (`services/handlers/tools.py` `execute_tool`), where
diff --git a/server/nodes/email/email_send/__init__.py b/server/nodes/email/email_send/__init__.py
index 9913f86c..779ff43b 100644
--- a/server/nodes/email/email_send/__init__.py
+++ b/server/nodes/email/email_send/__init__.py
@@ -58,6 +58,7 @@ class EmailSendNode(ActionNode):
approval = ApprovalSpec(
channel="Email",
action="Send an email",
+ outcome_labels=("Email sent", "Email not sent"),
recipient=("to",),
body=("body",),
subject="subject",
diff --git a/server/nodes/google/calendar/__init__.py b/server/nodes/google/calendar/__init__.py
index f1cafdcf..d5142f7b 100644
--- a/server/nodes/google/calendar/__init__.py
+++ b/server/nodes/google/calendar/__init__.py
@@ -116,6 +116,7 @@ class CalendarNode(ActionNode):
approval = ApprovalSpec(
channel="Google Calendar",
action="Send calendar invites",
+ outcome_labels=("Invites sent", "Invites not sent"),
operations=frozenset({"create", "update", "delete"}),
when=lambda data: (data.get("send_updates") or "all") != "none"
and (bool(str(data.get("attendees") or "").strip()) or data.get("operation") in ("update", "delete")),
diff --git a/server/nodes/google/drive/__init__.py b/server/nodes/google/drive/__init__.py
index 142b395d..040c03b7 100644
--- a/server/nodes/google/drive/__init__.py
+++ b/server/nodes/google/drive/__init__.py
@@ -114,6 +114,7 @@ class DriveNode(ActionNode):
approval = ApprovalSpec(
channel="Google Drive",
action="Share a file",
+ outcome_labels=("File shared", "File not shared"),
operations=frozenset({"share"}),
recipient=("email",),
body=("message",),
diff --git a/server/nodes/google/gmail/__init__.py b/server/nodes/google/gmail/__init__.py
index bbdbb5ca..0d9d3952 100644
--- a/server/nodes/google/gmail/__init__.py
+++ b/server/nodes/google/gmail/__init__.py
@@ -117,6 +117,7 @@ class GmailNode(ActionNode):
approval = ApprovalSpec(
channel="Gmail",
action="Send an email",
+ outcome_labels=("Email sent", "Email not sent"),
operations=frozenset({"send"}),
recipient=("to",),
body=("body",),
diff --git a/server/nodes/microsoft/calendar/__init__.py b/server/nodes/microsoft/calendar/__init__.py
index 2f2edb68..55175de4 100644
--- a/server/nodes/microsoft/calendar/__init__.py
+++ b/server/nodes/microsoft/calendar/__init__.py
@@ -141,6 +141,7 @@ class CalendarNode(ActionNode):
approval = ApprovalSpec(
channel="Outlook Calendar",
action="Send meeting invites",
+ outcome_labels=("Invites sent", "Invites not sent"),
operations=frozenset({"create", "update"}),
when=lambda data: bool(str(data.get("attendees") or "").strip()),
recipient=("attendees",),
diff --git a/server/nodes/microsoft/mail/__init__.py b/server/nodes/microsoft/mail/__init__.py
index 242ba342..8b77bd52 100644
--- a/server/nodes/microsoft/mail/__init__.py
+++ b/server/nodes/microsoft/mail/__init__.py
@@ -172,6 +172,7 @@ class MailNode(ActionNode):
approval = ApprovalSpec(
channel="Outlook",
action="Send an email",
+ outcome_labels=("Email sent", "Email not sent"),
operations=frozenset({"send", "reply"}),
recipient=("to",),
recipient_otherwise="the sender",
diff --git a/server/services/approvals/store.py b/server/services/approvals/store.py
index 904dae1e..eef34f7f 100644
--- a/server/services/approvals/store.py
+++ b/server/services/approvals/store.py
@@ -343,6 +343,17 @@ def _iso(moment: Optional[datetime]) -> Optional[str]:
return moment.isoformat() if moment is not None else None
+def _outcome_labels(row: ApprovalRequest) -> Tuple[str, str]:
+ """What the card says once it went, and when it did not: a held tool
+ call's plugin words it (its ``approval`` spec); a gate's draft is a
+ message."""
+ from services.node_registry import get_node_class
+ from services.plugin.approval import MESSAGE_OUTCOME, approval_spec
+
+ spec = approval_spec(get_node_class(row.node_type)) if row.kind == "tool_call" and row.node_type else None
+ return spec.outcome_labels if spec is not None else MESSAGE_OUTCOME
+
+
def summary(row: ApprovalRequest, *, deployment_state: Optional[str] = None, now: Optional[datetime] = None) -> Dict[str, Any]:
"""What a card shows for one row (``ApprovalSummary``,
docs-internal/chat_protocol.md)."""
@@ -367,6 +378,8 @@ def summary(row: ApprovalRequest, *, deployment_state: Optional[str] = None, now
"editable": row.status == "pending" and (kind == "gate" or bool(row.body_field)),
"details": [dict(item) for item in (row.details or []) if isinstance(item, dict)],
}
+ sent, failed = _outcome_labels(row)
+ out["outcome_labels"] = {"sent": sent, "failed": failed}
if row.action:
out["action"] = row.action
subject = row.final_subject if decided and row.final_subject else row.subject
diff --git a/server/services/approvals/tool_calls.py b/server/services/approvals/tool_calls.py
index 4c1006ac..37a207aa 100644
--- a/server/services/approvals/tool_calls.py
+++ b/server/services/approvals/tool_calls.py
@@ -37,6 +37,9 @@ attempt resumes a wait the worker cut short (``NodeWaitInterrupted``).
What a node sends as (its locked ``server_controlled_fields``: the account,
the mailbox) never comes from the model, so the row keeps the call's
arguments without them; the node's own settings supply them when it runs.
+For the same reason a call is judged on what it runs with
+(:func:`as_it_runs`): a locked field the model set is put back to the node's
+setting first, so it can never talk a call out of being held.
"""
from __future__ import annotations
@@ -112,6 +115,20 @@ def _clean_args(node_cls: Any, args: Mapping[str, Any]) -> Dict[str, Any]:
return {key: value for key, value in dict(args or {}).items() if key not in locked}
+async def as_it_runs(context: Mapping[str, Any], node_cls: Any) -> Dict[str, Any]:
+ """The call's ``node_data`` as the node will run with it: each locked
+ field the model set put back to the node's saved setting (NodeExecutor's
+ rule). :func:`check` judges the call on this."""
+ from services.plugin.base import restore_locked_fields, saved_settings
+
+ node_data = dict(context.get("node_data") or {})
+ tool_args = context.get("tool_args")
+ if not isinstance(tool_args, Mapping) or not (_locked(node_cls) & tool_args.keys()):
+ return node_data
+ saved = await saved_settings(_database(), str(context.get("node_id") or ""), context.get("parameter_snapshot"))
+ return restore_locked_fields(node_cls, node_data, tool_args, saved)
+
+
def _clean_node_data(node_cls: Any, node_data: Mapping[str, Any], args: Mapping[str, Any]) -> Dict[str, Any]:
"""The node's settings with the call's arguments over them, minus the
locked fields the model set (the node's own value comes back when it
@@ -178,7 +195,7 @@ async def check(context: Mapping[str, Any], node_cls: Any) -> Checked:
)
if spec is None or not is_agent_tool_call(context):
return RUN
- node_data = dict(context.get("node_data") or {})
+ node_data = await as_it_runs(context, node_cls)
if not spec.sends(node_data):
return RUN
database = _database()
@@ -217,11 +234,13 @@ async def check_in_process(
process (see the module docstring). ``result`` is the flat answer the
model reads, as ``execute_as_tool`` gives one."""
from services.plugin.approval import approval_spec
+ from services.plugin.base import restore_locked_fields
spec = approval_spec(node_cls)
if spec is None or not context.get("parent_node_id"):
return RUN
- if not spec.sends({**dict(params or {}), **dict(tool_args or {})}):
+ # Judged on what runs: a locked field comes from the node's settings.
+ if not spec.sends(restore_locked_fields(node_cls, {**dict(params or {}), **dict(tool_args or {})}, tool_args, params or {})):
return RUN
if not await _asks_first(_database(), context.get("workflow_id")):
return RUN
@@ -369,6 +388,7 @@ __all__ = [
"HELD_MESSAGE",
"RESEND_MESSAGE",
"RUN",
+ "as_it_runs",
"call_key",
"check",
"check_in_process",
diff --git a/server/services/node_executor.py b/server/services/node_executor.py
index cac478f9..77e48b34 100644
--- a/server/services/node_executor.py
+++ b/server/services/node_executor.py
@@ -19,7 +19,7 @@ from constants import (
from pydantic import ValidationError
from services.node_registry import get_node_class
from services.parameter_resolver import template_view
-from services.plugin.base import locked_tool_fields
+from services.plugin.base import locked_tool_fields, restore_locked_fields, saved_settings
# Wave 11.D.13 sunset: every handler that was imported here is now
# either (a) called lazily from a plugin's execute_op / execute method,
# or (b) retired entirely. The dispatcher itself only needs the
@@ -253,7 +253,7 @@ class NodeExecutor:
) -> Dict:
"""Load from DB, validate, inject API keys."""
# Merge with DB parameters (DB provides defaults, frontend can override)
- db_params = dict(parameter_snapshot[node_id] or {}) if isinstance(parameter_snapshot, dict) and node_id in parameter_snapshot else await self.database.get_node_parameters(node_id) or {}
+ db_params = await saved_settings(self.database, node_id, parameter_snapshot)
merged = {**db_params, **params} if params else db_params
# On an LLM tool call the model never chooses a node's locked fields
@@ -261,14 +261,7 @@ class NodeExecutor:
# profile, data mounts...). The saved setting wins; with none saved,
# the field falls back to its default rather than to the model's value.
if tool_args:
- locked = locked_tool_fields(get_node_class(node_type))
- if locked & tool_args.keys():
- merged = dict(merged)
- for field_name in locked & tool_args.keys():
- if field_name in db_params:
- merged[field_name] = db_params[field_name]
- else:
- merged.pop(field_name, None)
+ merged = restore_locked_fields(get_node_class(node_type), merged, tool_args, db_params)
# Validate via plugin Params (snake_case, plugin-only path).
node_cls = get_node_class(node_type)
diff --git a/server/services/plugin/approval.py b/server/services/plugin/approval.py
index 22520365..8c570d24 100644
--- a/server/services/plugin/approval.py
+++ b/server/services/plugin/approval.py
@@ -22,6 +22,9 @@ Predicate = Callable[[Mapping[str, Any]], bool]
_MAX_DETAIL = 300
+#: What a card says once a message went, and when it did not.
+MESSAGE_OUTCOME = ("Message sent", "Message not sent")
+
def _text(value: Any) -> str:
if value is None or isinstance(value, bool):
@@ -64,6 +67,8 @@ class ApprovalSpec:
refuse_while_asking: bool = False
#: While Ask first is on, runs with these settings instead of being held.
restrict_while_asking: Mapping[str, Any] = field(default_factory=dict)
+ #: What the card says once the call went, and when it did not.
+ outcome_labels: Tuple[str, str] = MESSAGE_OUTCOME
def sends(self, data: Mapping[str, Any]) -> bool:
"""Whether this call reaches someone (and so waits for the owner)."""
@@ -123,4 +128,4 @@ def approval_spec(node_cls: Any) -> Optional[ApprovalSpec]:
return spec if isinstance(spec, ApprovalSpec) else None
-__all__ = ["ApprovalSpec", "approval_spec"]
+__all__ = ["ApprovalSpec", "MESSAGE_OUTCOME", "approval_spec"]
diff --git a/server/services/plugin/base.py b/server/services/plugin/base.py
index 30c74956..07b232d3 100644
--- a/server/services/plugin/base.py
+++ b/server/services/plugin/base.py
@@ -21,7 +21,7 @@ from __future__ import annotations
import asyncio
import time
from datetime import datetime, timezone
-from typing import Any, Awaitable, Callable, ClassVar, Dict, Optional, Sequence, Type
+from typing import Any, Awaitable, Callable, ClassVar, Dict, Mapping, Optional, Sequence, Type
from opentelemetry import trace
from pydantic import BaseModel, ValidationError
@@ -94,6 +94,31 @@ def locked_tool_fields(node_cls: Any) -> frozenset:
return frozenset(getattr(node_cls, "server_controlled_fields", ()) or ())
+def restore_locked_fields(
+ node_cls: Any,
+ data: Mapping[str, Any],
+ tool_args: Optional[Mapping[str, Any]],
+ saved: Mapping[str, Any],
+) -> Dict[str, Any]:
+ """``data`` with each locked field the model set in ``tool_args`` put back
+ to the node's saved setting, or left out when none is saved so that the
+ field's default applies: the model never chooses a locked field."""
+ out = dict(data)
+ for name in locked_tool_fields(node_cls) & (tool_args or {}).keys():
+ if name in saved:
+ out[name] = saved[name]
+ else:
+ out.pop(name, None)
+ return out
+
+
+async def saved_settings(database: Any, node_id: str, parameter_snapshot: Any = None) -> Dict[str, Any]:
+ """A node's own settings: the run's captured copy, else its saved row."""
+ if isinstance(parameter_snapshot, dict) and node_id in parameter_snapshot:
+ return dict(parameter_snapshot[node_id] or {})
+ return dict(await database.get_node_parameters(node_id) or {})
+
+
NODE_WAIT_INTERRUPTED = "NodeWaitInterrupted"
diff --git a/server/tests/services/approvals/test_tool_calls.py b/server/tests/services/approvals/test_tool_calls.py
index 1e4e0023..e449aee6 100644
--- a/server/tests/services/approvals/test_tool_calls.py
+++ b/server/tests/services/approvals/test_tool_calls.py
@@ -64,6 +64,7 @@ async def test_asking_first_holds_the_call_once(harness, nodes_loaded):
"message",
)
assert row.tool_call_id == "call_1" and row.agent_node_id == "wf:aiAgent:1" and row.node_type == "whatsappSend"
+ assert store.summary(row)["outcome_labels"] == {"sent": "Message sent", "failed": "Message not sent"}
# Only calls that send are held, and only an agent's.
assert await tool_calls.check({**call(), "tool_call_id": None}, node_cls) is tool_calls.RUN
assert await tool_calls.check(call("googleGmail", {"operation": "search", "query": "x"}), get_node_class("googleGmail")) is tool_calls.RUN
@@ -77,6 +78,21 @@ async def test_the_model_never_chooses_who_sends(harness, nodes_loaded):
assert "mailbox" not in row.args and "mailbox" not in row.node_data
assert row.original_args["mailbox"] == "[email protected]"
assert (row.subject, row.subject_field) == ("Hi", "subject")
+ # The plugin words what happened.
+ assert store.summary(row)["outcome_labels"] == {"sent": "Email sent", "failed": "Email not sent"}
+
+
+async def test_a_call_is_judged_on_the_settings_it_runs_with(harness, nodes_loaded):
+ # A locked field the model set is put back to the node's own setting
+ # before the call is judged, so it cannot talk a call out of a hold.
+ args = {"operation": "send", "to": "[email protected]", "body": "Hello", "mailbox": "[email protected]"}
+ node_cls = get_node_class("msMail")
+ saved = {"wf:msMail:1": {"mailbox": "[email protected]"}}
+ data = await tool_calls.as_it_runs(call("msMail", args, node_data={"mailbox": "[email protected]"}, parameter_snapshot=saved), node_cls)
+ assert data["mailbox"] == "[email protected]"
+ # With nothing saved, the model's value is left out and the default applies.
+ data = await tool_calls.as_it_runs(call("msMail", args, parameter_snapshot={"wf:msMail:1": {}}), node_cls)
+ assert "mailbox" not in data
async def test_a_call_in_the_chat_shows_its_card_there(harness, nodes_loaded, monkeypatch):