Skip to content

Commit 4550091

Browse files
fix(showcase): notify slots on an optional user field complete the run when it is empty (#29099)
domain:server#5 · os-project-manager · session_01FEkQ5oc56xChD6Wrc4cGSt <!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XRzFmxNqPSgstp8DRYyn2mP)_ Fixes #29028 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:showcase 里 8 个流程的通知在负责人/经办人字段为空时也能跑完,外加预算审批流程的启动条件先判空再比较。关于记录本身的提醒(任务完成、项目结项、并行通知、紧急任务的系统写入、嵌套循环提醒)改发给组织所有者(`role:owner`);只对经办人本人说的话("你被分配了"、"请更新任务"、"任务快到期")没有经办人就直接结束,不发。 - 为什么改:`has(FIELD) ? FIELD : null` 在空字段上返回 null(触发记录上空字段是 null,`has()` 为真),通知没有收件人就让整个运行失败,谁也收不到。参考应用教的正是这种无效写法。 - 风险与回滚:只动示例应用(私有包,不发布),不碰引擎、CEL 和通知节点,通知节点"至少一个收件人"的拒收不变。回滚即 revert。 - 先看:`examples/app-showcase/src/automation/flows/index.ts`(三个 `has_assignee` 决策节点、`role:owner` 兜底、紧急任务的嵌套三元式);新测试 `examples/app-showcase/test/notify-recipient-optional-fields.test.ts`;从 #29018 测试抽出的共用 `test/showcase-flow-run.testkit.ts`。 - 两分钟验证:`pnpm --filter @objectstack/example-showcase exec vitest run test/notify-recipient-optional-fields.test.ts`,预期 `Tests 20 passed (20)`。 - 需要你做的:无,席位落地。 ## What changes `examples/app-showcase/src/automation/flows/index.ts`, one row per measured notify slot (an empty field, the row as stored, on base `6b3ba82c`): | Flow | Node | Field | Base | Reading | Fix | |:--|:--|:--|:--|:--|:--| | `showcase_task_completed` | `notify` | `record.assignee` | fails | a notice about the record | `isBlank(record.assignee) ? 'role:owner' : record.assignee` | | `showcase_task_assigned_notify` | `notify_assignee` | `record.assignee` | fails (unassigning a task) | "you have been assigned": assignee only | `has_assignee` decision, `!isBlank(record.assignee)` edge, `isDefault` edge to `end` | | `showcase_task_follow_up` | `remind` | `record.assignee` | fails (after the wait resumes) | "please update its status": assignee only | `has_assignee` decision after the wait, same shape | | `showcase_project_closure` | `notify_owner` | `record.owner` | fails (after sign-off) | the decision needs a reader | `isBlank(record.owner) ? 'role:owner' : record.owner` | | `showcase_batch_reminders` | `send_reminder` | `task.owner` | completes | each iteration sits in its `try_catch`, by design | none | | `showcase_fan_out_notify` | `notify_owner` | `record.assignee` | fails (the failed branch fails the block, the Slack post with it) | a notice about the record | `isBlank(record.assignee) ? 'role:owner' : record.assignee` | | `showcase_nested_fan_out_reminders` | `notify_owner` | `task.owner` | fails (ends the sweep) | loop rows are caller data, so the key may be absent | `has(task.owner) && !isBlank(task.owner) ? task.owner : 'role:owner'` | | `showcase_nested_fan_out_reminders` | `notify_watcher` | `task.watcher` | fails | same | same spelling on `task.watcher` | | `showcase_task_due_reminder` | `remind_owner` | `record.assignee` | fails | "your task is due": assignee only | `has_assignee` decision, same shape | | `showcase_urgent_task_alert` | `alert` | `record.assignee` | completes on a user's write (`current_user` is the second recipient); fails on a system write | a notice about the record | `!isBlank(record.assignee) ? record.assignee : current_user == null ? 'role:owner' : null` (a user's write still alerts that user, unchanged) | - `showcase_project_escalation`: #29018 left no `has()` slot. - The guarded notifies after a `has_assignee` decision read plain `record.assignee`, as #29018's `alert_owner` does. The notify node's required-recipient refusal is unchanged. - Start conditions: `showcase_budget_approval`'s `budget > 100000 && budget != previous.budget` faults (`no such overload`) when a budget is cleared (`null` against a previous value); it is now `budget != null && budget > 100000 && budget != previous.budget`. `showcase_committee_quorum`'s `total_amount >= 5000` is fine: the sum summary stores `0` on a report with no lines, measured. - Field writes left alone (order ruling 3): `showcase_task_completed` `summarize.inputs.priority`; `showcase_task_done_notify_owner` `call_notify.input.ownerId`; `showcase_inbound_task_webhook` `create_task.fields.assignee` and `.project`. Writing `null` is the correct answer there. - `examples/app-showcase/test/showcase-flow-run.testkit.ts` (new): #29018's harness moved out of its test file, unchanged in behaviour, so both files share one kit (order: reuse it, no second harness). `project-escalation-optional-fields.test.ts` now imports it. ## Tests - New `examples/app-showcase/test/notify-recipient-optional-fields.test.ts`, 20 cases on the shared kit: per fixed flow an empty-field case (asserts the stored row reads `null` first, the run completes, and the fallback audience or no notify) and a filled-field control that still notifies the field's user; plus the batch-reminders, quorum and urgent user-write readings that were already fine. - `showcase_project_closure` runs with a stand-in `showcase_closure_signoff` that decides at once (same name and variables), because the real one waits on a manager approval; the parent flow and its notify are real. - `showcase_task_follow_up` is run, parks at its timer wait, and is resumed with `automation.resume(runId)`. - **Red on base** (flows file at `6b3ba82c`, tests kept): 9 failed / 11 passed. Failing nodes: `notify`, `notify_assignee`, `remind`, `notify_owner`, `fan_out` (branch `notify_owner`), `remind_owner`, `alert` (system write), `fan_out_audiences` (branch `notify_owner`), each `notify: at least one recipient is required …`; and `condition failed to evaluate as CEL` (budget). Restored: blob `9f537eab` equal to HEAD, `git diff HEAD` empty. - **Ablations** (`scripts/ablation-replace.mjs`, each anchor hit once, each restored to blob `9f537eab` with `git diff HEAD` empty), one guard per fixed flow, each run with `-t FLOW`: task_completed fallback → `record.assignee`: 1 failed; task_assigned edge → `true`: 1 failed; follow_up edge → `true`: 1 failed; closure fallback → `record.owner`: 1 failed; fan_out fallback → `record.assignee`: 1 failed; nested owner → `task.owner`: 1 failed; due_reminder edge → `true`: 1 failed; urgent → `… : null`: 1 failed; budget start guard dropped: 1 failed. - No `dist/` on the path: the tests import the flows from `src`. ## Acceptance notes - `pnpm validate` still warns `flow-loop-body-uncontained` on `showcase_nested_fan_out_reminders` (no `try_catch` in the loop body). That is the flow's deliberate shape (its docblock: containment would retag the branch steps); with the fallback an empty recipient no longer fails a row, so the warning's failure mode no longer comes from these slots. - `showcase_task_done_notify_owner` hands `ownerId: has(record.project.owner) ? record.project.owner : null` to the `showcase_notify_owner` subflow, whose notify then has no recipient on a project with no owner. Left alone per order ruling 3 (named as a field write); not measured here. ## Verification Every run here and above is on `fb792a78` (branch base `6b3ba82c`), each test command under `os-verify-lock` (`VERDICT command-exit 0`). The head `7538f3e3` merges `origin/main` on top; that merge changes nothing under `examples/app-showcase/`. - `pnpm --filter @objectstack/example-showcase test`: Test Files 44 passed (44); Tests 538 passed (538). Then `pnpm validate`: exit 0. - `pnpm --filter @objectstack/example-showcase typecheck`: exit 0. - `eslint --no-inline-config` on the four touched files: exit 0. - Derived gates (`dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`, derived on this diff): NOT MEASURED locally, reason: the maintainer asked to wrap up; CI runs the families. - Changeset: none. `@objectstack/example-showcase` is `"private": true`, so nothing here ships; `skip-changeset` rides the create. --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5kD3ghfUkHD1rTdWYc)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3d848df commit 4550091

4 files changed

Lines changed: 556 additions & 107 deletions

File tree

‎examples/app-showcase/src/automation/flows/index.ts‎

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { RecalcEstimatesFlow, RecalcTaskEstimateFlow } from './recalc-estimate.f
88
/**
99
* Task Completed → Notify — an autolaunched, record-triggered flow that fires
1010
* when a task transitions to Done, composes a one-line summary in a registered
11-
* function, and notifies the assignee.
11+
* function, and notifies the assignee (the organization's owners when it has none).
1212
*
1313
* It also carries the two node types #4343 sorted out from each other:
1414
*
@@ -81,11 +81,12 @@ export const TaskCompletedFlow = defineFlow({
8181
// `record.project.owner` would not resolve unless the start node
8282
// declared `expand: ['project']`; the sibling
8383
// `showcase_task_done_notify_owner` is where that hop is demonstrated.
84-
// A CEL value envelope, evaluated per run. `assignee` is optional and
85-
// CEL refuses an absent key, so it is guarded: an unset assignee
86-
// evaluates to `null`, which adds no recipient, and the node — left
87-
// with none — fails as it did when the template resolved to nothing.
88-
recipients: { dialect: 'cel', source: 'has(record.assignee) ? record.assignee : null' },
84+
// A CEL value envelope, evaluated per run. `assignee` is optional, and
85+
// the trigger record carries it as `null` when unset (`has()` is true
86+
// on a null column, so it guards nothing here). A task with no
87+
// assignee tells the organization's owners instead, because a notify
88+
// left with no recipient fails the run.
89+
recipients: { dialect: 'cel', source: "isBlank(record.assignee) ? 'role:owner' : record.assignee" },
8990
title: '✅ Task done: {{ record.title }}',
9091
message: '{{ summary }}',
9192
sourceObject: 'showcase_task',
@@ -180,13 +181,16 @@ export const TaskAssignedNotifyFlow = defineFlow({
180181
condition: 'assignee != previous.assignee',
181182
},
182183
},
184+
// Unassigning a task also changes `assignee`, to `null`. There is nobody
185+
// to tell "you have been assigned", so the run ends there.
186+
{ id: 'has_assignee', type: 'decision', label: 'Assigned to someone?' },
183187
{
184188
id: 'notify_assignee',
185189
type: 'notify',
186190
label: 'Notify Assignee',
187191
config: {
188192
topic: 'task.assigned',
189-
recipients: [{ dialect: 'cel', source: 'has(record.assignee) ? record.assignee : null' }],
193+
recipients: [{ dialect: 'cel', source: 'record.assignee' }],
190194
channels: ['inbox'],
191195
severity: 'info',
192196
title: 'New task assigned: {{ record.title }}',
@@ -197,7 +201,9 @@ export const TaskAssignedNotifyFlow = defineFlow({
197201
{ id: 'end', type: 'end', label: 'End' },
198202
],
199203
edges: [
200-
{ id: 'e1', source: 'start', target: 'notify_assignee' },
204+
{ id: 'e1', source: 'start', target: 'has_assignee' },
205+
{ id: 'e1a', source: 'has_assignee', target: 'notify_assignee', label: 'assigned', condition: '!isBlank(record.assignee)' },
206+
{ id: 'e1b', source: 'has_assignee', target: 'end', label: 'unassigned', isDefault: true },
201207
{ id: 'e2', source: 'notify_assignee', target: 'end' },
202208
],
203209
});
@@ -236,7 +242,10 @@ export const BudgetApprovalFlow = defineFlow({
236242
// project — otherwise any unrelated edit (status, health, …) re-opens
237243
// an approval and collides with other approval flows on the same
238244
// record (the approvals service dedupes pending requests per record).
239-
condition: 'budget > 100000 && budget != previous.budget',
245+
// `budget` is optional, and clearing it hands the trigger `null`,
246+
// which CEL cannot compare: `!= null` first, so a cleared budget
247+
// starts nothing instead of faulting the condition.
248+
condition: 'budget != null && budget > 100000 && budget != previous.budget',
240249
},
241250
},
242251
{
@@ -663,13 +672,16 @@ export const TaskFollowUpFlow = defineFlow({
663672
// `wait` has no timeout, and this run resumes when the timer elapses.
664673
waitEventConfig: { eventType: 'timer', timerDuration: 'PT1M' },
665674
},
675+
// The reminder asks the assignee to update the task. A task created with
676+
// no assignee has nobody to ask, so the run ends there.
677+
{ id: 'has_assignee', type: 'decision', label: 'Assigned to someone?' },
666678
{
667679
id: 'remind',
668680
type: 'notify',
669681
label: 'Remind Assignee',
670682
config: {
671683
topic: 'task.followup',
672-
recipients: [{ dialect: 'cel', source: 'has(record.assignee) ? record.assignee : null' }],
684+
recipients: [{ dialect: 'cel', source: 'record.assignee' }],
673685
channels: ['inbox'],
674686
severity: 'info',
675687
title: 'Follow up on: {{ record.title }}',
@@ -681,7 +693,9 @@ export const TaskFollowUpFlow = defineFlow({
681693
],
682694
edges: [
683695
{ id: 'e1', source: 'start', target: 'hold' },
684-
{ id: 'e2', source: 'hold', target: 'remind' },
696+
{ id: 'e2', source: 'hold', target: 'has_assignee' },
697+
{ id: 'e2a', source: 'has_assignee', target: 'remind', label: 'assigned', condition: '!isBlank(record.assignee)' },
698+
{ id: 'e2b', source: 'has_assignee', target: 'end', label: 'unassigned', isDefault: true },
685699
{ id: 'e3', source: 'remind', target: 'end' },
686700
],
687701
});
@@ -886,7 +900,10 @@ export const ProjectClosureFlow = defineFlow({
886900
label: 'Notify Owner of Decision',
887901
config: {
888902
topic: 'project.closure',
889-
recipients: [{ dialect: 'cel', source: 'has(record.owner) ? record.owner : null' }],
903+
// A project with no owner tells the organization's owners: the
904+
// decision still needs a reader, and a notify left with no recipient
905+
// fails the run after the sign-off already happened.
906+
recipients: [{ dialect: 'cel', source: "isBlank(record.owner) ? 'role:owner' : record.owner" }],
890907
channels: ['inbox'],
891908
severity: 'info',
892909
title: 'Closure sign-off: {{ record.name }}',
@@ -1039,7 +1056,10 @@ export const FanOutNotifyFlow = defineFlow({
10391056
type: 'notify',
10401057
label: 'Notify Owner',
10411058
config: {
1042-
recipients: { dialect: 'cel', source: 'has(record.assignee) ? record.assignee : null' },
1059+
// A failed branch fails the whole block, the Slack post
1060+
// with it, so a task with no assignee tells the
1061+
// organization's owners instead.
1062+
recipients: { dialect: 'cel', source: "isBlank(record.assignee) ? 'role:owner' : record.assignee" },
10431063
title: '✅ Done: {{ record.title }}',
10441064
sourceObject: 'showcase_task',
10451065
sourceId: { dialect: 'cel', source: 'record.id' },
@@ -1116,9 +1136,11 @@ export const FanOutNotifyFlow = defineFlow({
11161136
* demonstrated by `BatchRemindersFlow` instead.
11171137
*
11181138
* Input rows are task-shaped — `{ id, title, owner, watcher }`. `owner` and
1119-
* `watcher` are the two recipients and `notify` refuses an empty resolved
1120-
* recipient set, so a row missing either ends the sweep; drive it with at least
1121-
* two rows so the `(iteration, branch)` pairs have something to distinguish.
1139+
* `watcher` are the two recipients. A row is caller data, so either key may be
1140+
* absent as well as null or blank; such a branch tells the organization's
1141+
* owners instead, because `notify` refuses an empty resolved recipient set and
1142+
* one failed branch would end the sweep. Drive it with at least two rows so the
1143+
* `(iteration, branch)` pairs have something to distinguish.
11221144
*
11231145
* Fixture for `docs/qa/platform-checklist/areas/automation.json`
11241146
* → `automation.flow-run-step-nesting`, the `loop { parallel }` clause.
@@ -1164,7 +1186,7 @@ export const NestedFanOutRemindersFlow = defineFlow({
11641186
type: 'notify',
11651187
label: 'Notify Owner',
11661188
config: {
1167-
recipients: { dialect: 'cel', source: 'has(task.owner) ? task.owner : null' },
1189+
recipients: { dialect: 'cel', source: "has(task.owner) && !isBlank(task.owner) ? task.owner : 'role:owner'" },
11681190
title: 'Overdue ({{ taskIndex }}): {{ task.title }}',
11691191
sourceObject: 'showcase_task',
11701192
sourceId: { dialect: 'cel', source: 'task.id' },
@@ -1181,7 +1203,7 @@ export const NestedFanOutRemindersFlow = defineFlow({
11811203
type: 'notify',
11821204
label: 'Notify Watcher',
11831205
config: {
1184-
recipients: { dialect: 'cel', source: 'has(task.watcher) ? task.watcher : null' },
1206+
recipients: { dialect: 'cel', source: "has(task.watcher) && !isBlank(task.watcher) ? task.watcher : 'role:owner'" },
11851207
title: 'Watching ({{ taskIndex }}): {{ task.title }}',
11861208
sourceObject: 'showcase_task',
11871209
sourceId: { dialect: 'cel', source: 'task.id' },
@@ -2012,6 +2034,9 @@ export const TaskDueReminderFlow = defineFlow({
20122034
// schedule: { type: 'cron', expression: '0 8 * * *' }
20132035
},
20142036
},
2037+
// "Your task is due" has nobody to address on a task with no assignee, so
2038+
// that task's run ends here.
2039+
{ id: 'has_assignee', type: 'decision', label: 'Assigned to someone?' },
20152040
{
20162041
id: 'remind_owner',
20172042
type: 'notify',
@@ -2021,7 +2046,7 @@ export const TaskDueReminderFlow = defineFlow({
20212046
// The contract's required audience — this node used to omit it, so
20222047
// every sweep run FAILED here ("at least one recipient is required")
20232048
// and the #1874 demo never delivered (surfaced by #4277's parse).
2024-
recipients: [{ dialect: 'cel', source: 'has(record.assignee) ? record.assignee : null' }],
2049+
recipients: [{ dialect: 'cel', source: 'record.assignee' }],
20252050
channels: ['inbox'],
20262051
severity: 'warning',
20272052
title: 'Task due soon: {{ record.title }}',
@@ -2032,7 +2057,9 @@ export const TaskDueReminderFlow = defineFlow({
20322057
{ id: 'end', type: 'end', label: 'End' },
20332058
],
20342059
edges: [
2035-
{ id: 'e1', source: 'start', target: 'remind_owner' },
2060+
{ id: 'e1', source: 'start', target: 'has_assignee' },
2061+
{ id: 'e1a', source: 'has_assignee', target: 'remind_owner', label: 'assigned', condition: '!isBlank(record.assignee)' },
2062+
{ id: 'e1b', source: 'has_assignee', target: 'end', label: 'unassigned', isDefault: true },
20362063
{ id: 'e2', source: 'remind_owner', target: 'end' },
20372064
],
20382065
});
@@ -2078,11 +2105,11 @@ export const UrgentTaskAlertFlow = defineFlow({
20782105
// Notify the assignee and whoever raised the priority (`current_user`,
20792106
// the triggering user) so an as-yet-unassigned urgent task still pings
20802107
// someone. Each entry is a CEL value envelope; one that evaluates to
2081-
// `null` is dropped — an unset `assignee`, and `current_user` under a
2082-
// system write, which has no user — so the node fails only when both
2083-
// are absent.
2108+
// `null` is dropped. A system write has no user, so an unassigned
2109+
// urgent task written by one tells the organization's owners instead
2110+
// of leaving the node with no recipient.
20842111
recipients: [
2085-
{ dialect: 'cel', source: 'has(record.assignee) ? record.assignee : null' },
2112+
{ dialect: 'cel', source: "!isBlank(record.assignee) ? record.assignee : current_user == null ? 'role:owner' : null" },
20862113
{ dialect: 'cel', source: 'current_user != null ? current_user.id : null' },
20872114
],
20882115
channels: ['inbox'],

0 commit comments

Comments
 (0)