You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e6fa510
Browse filesBrowse the repository at this point in the historyBrowse files
feat(approvals): an escalation deadline can count working time on an org calendar (clock: working_time) (#35929)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D62xGLMbyWJaMEVnAMEjTK1)_Fixes#35357
Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: follow-up #35931 —
skills/objectstack-automation/references/state-machines-and-approvals.md
(the escalation row), domain:skills sub-card, Blocked-by this PR
## 维护者速读
-
用户能看到什么变化:审批节点的超时升级可以选择「按工作时间计算」,按组织的工作日历跳过夜间、周末和节假日,并计入调休补班日;日历算不出时,审批收件箱在到期时间处显示「日历算不出」和原因。
- 为什么做:工作日历分期的第四张卡,让审批超时和工作日历一起发布,周五下午提交的审批不再在周五晚上就升级。
- 出错会怎样:只影响选了「工作时间」的审批节点;默认仍按自然小时,已在途的审批到期时间不变,可以直接撤回。
- 要你做什么:无。
## What changes
ADR-0157 D5, D9 and D12, on the approval escalation:
- **Spec** (`ApprovalEscalationSchema`): two optional keys. `clock:
'wall_clock' | 'working_time'`, default `'wall_clock'` (a stored
snapshot carries no `clock`, so every open request keeps its deadline),
and `calendar`, a working-calendar code (`WORK_CALENDAR_CODE_PATTERN`).
The `timeoutHours` describe text and comment no longer say the platform
ships no calendar; they say the clock decides how the hours count. The
describe first sentences stay in business words.
- **Runtime** (`plugin-approvals`): one deadline function,
`ApprovalService.slaDeadline`, serves both the escalation sweep and the
request read projection (D12). `wall_clock` is the unchanged `slaDueAt`
(`created_at + timeoutHours` elapsed). `working_time` counts
`timeoutHours` working hours from `created_at` through the calendar
service (`WORK_CALENDAR_SERVICE`, resolved lazily like the other
providers), naming the request's own `organization_id` and
`escalation.calendar`; the service resolves the named code, else the
organization default, else refuses. It is recomputed on every sweep and
every read, never stored. `slaDueAt` answers nothing for a
`working_time` escalation, so no path can fall back to wall-clock hours
(D2). Single-shot escalation (ADR-0042 §1) is untouched: the `escalate`
audit row is still the only marker, and it does not record the due time.
- **Cannot answer** (D9): a calendar refusal
(`ERR_WORK_CALENDAR_UNRESOLVED`, `ERR_WORK_CALENDAR_NOT_MAINTAINED`,
`ERR_WORK_CALENDAR_INVALID`) is not an escalation: the sweep skips the
request, counts it in one `warn` per sweep, and asks again next sweep. A
kernel with no calendar service refuses the same way. **New served field
(additive): `sla_due_refusal`** on `ApprovalRequestRow` (`code`,
`reason` on unresolved, `calendar`, `date` on not-maintained,
`message`), present in place of `sla_due_at`.
- **Lint** (`@objectstack/lint`):
`approval-escalation-calendar-without-working-time` (error) refuses a
`calendar` beside the wall clock, where nothing reads it. Static only:
no check that the calendar exists (D9).
- **Studio**: the approval inspector's escalation block gains "Count
hours as" (wall-clock / working hours) and "Working calendar", which
shows only under working time, from both descriptor sources
(`SIBLING_GATES` in `json-schema-to-fields.ts` serves the hand-written
table and the engine-published `configSchema`). zh overlay added; the
`timeoutHours` zh help no longer says there is no calendar.
- **Console inbox**: where the SLA countdown sits, a pending row with
`sla_due_refusal` shows "Calendar can't compute" with the reason (no
calendar "X" / no default calendar / not maintained for DATE / fix the
calendar in Setup), in all eleven locale packs (zh-Hans: 「日历算不出」). The
zh-Hant pack is generated from zh-Hans by `gen:zh-hant`, never
hand-edited.
- **Docs**: `content/docs/automation/approvals.mdx` (Timeouts and
escalation) and the generated reference page. ADR anchor for the
deadline function.
Not released alone: ships in the same release as the calendar objects
and service (#35355) and the working-day formula functions (#35356),
ADR-0157 D4.
## Evals
None: no agent-facing prompt or skill text changes here. The skills text
is owed as a follow-up (the `Skills-docs:` line).
## Tests
- `approval-service-sla-calendar-clock.test.ts`, a new top-level
describe on the REAL `WorkCalendarService` over a read double: Friday
17:00 + 4 working hours with Monday a holiday fires Tuesday 12:00 and
not at any earlier instant; before a make-up (调休) Saturday it fires that
Saturday 12:00; a holiday entered later moves the deadline (D12); a
missing calendar serves `sla_due_refusal` (`not_found`), escalates
nothing past every deadline, and the next sweep escalates once the
calendar exists; `no_default` and `ERR_WORK_CALENDAR_NOT_MAINTAINED`
(with its date); no calendar service refuses; an explicit `wall_clock`
equals the default. The four existing wall-clock pins are unchanged and
green.
- Lint: the finding fires on a calendar with no clock and with
`wall_clock`; its control (`working_time` with a calendar that does not
exist, and `working_time` with none) is clean.
- Inspector: the calendar is hidden on the default and an explicit wall
clock, shown under working time, and a typed code round-trips through
`ApprovalNodeConfigSchema`, from both descriptor sources. Inbox: the
reason renders in place of the countdown in English and zh-CN, and a
served due time keeps its countdown.
- Re-measured pins: the inspector's gated-field census 33 → 35, the
declared-default surface ten → eleven (`escalation.clock`), the
escalation round-trip now parses with `clock: 'wall_clock'`
materialized, and the de quote-pairing pin 118 → 119 (the new
`approvalsInbox.slaCalendarNotFound` adds one correctly paired
„{{calendar}}“ span, U+201E … U+201C; ledger line added, assertion
unchanged).
<details><summary>Ablations (both red, both restored to HEAD by
`scripts/ablation-replace.mjs`)</summary>
- Working-time branch (`slaDeadline` answers wall-clock for every
clock): 6 of 12 tests red, the six `working_time` cases; restore blob
equals HEAD, `git diff HEAD` empty.
- Cannot-answer guard (a refusal no longer `continue`s the sweep): 3 of
12 red, each `expected { scanned: 1, escalated: 1 } to match object {
escalated: +0 }`; restored to HEAD. A first attempt whose replacement
was a substring of its anchor was refused by the tool before running and
is not counted.
</details>
## Verification
Read first: `packages/plugins/plugin-approvals/src/approval-service.ts`
(`slaDeadline`, `projectWorkingTimeDue`, the `runEscalations` hunk),
`packages/spec/src/automation/approval.zod.ts`,
`ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx`
(`slaRefusalLabel`).
Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec
vitest run src/approval-service-sla-calendar-clock.test.ts` shows 12
passed.
<details><summary>Local readings</summary>
Fix round on head `f079e34` (`origin/main` merged at `753091e`,
`zh-Hant.ts` regenerated, de pin re-measured), in this container (shared
box), through `scripts/pm/os-verify-lock.sh`:
- `zh-hant-generated.test.ts` red before the regeneration
(`src/locales/zh-Hant.ts is stale`, 1 failed | 10 passed), green after;
`de-quote-pairing-3876.test.ts` red with the old pin (`expected 119 to
be 118`, `{ open: 119, close: 119, rdq: 0 }` vs 118), green after.
- `vitest run packages/i18n/` (ui root): Test Files 105 passed (105),
Tests 1957 passed, 13 skipped.
- `pnpm check:i18n`: OK, 10 packages, all bundles in sync.
- `node scripts/pm/dispatch-gates.mjs --commands` (131 families) on
`f079e34`, each with its exit code; `--ran`: 131 derived, 131 run, 0
NOT-MEASURED (a derived zero). Eight families first refused for missing
builds (exit 3, and ui `scripts/` red for an unbuilt
`@objectstack/client`) and are exit 0 after building `./packages/**`.
- `overlap-check`: VERDICT clean.
Earlier readings, on head `1d5c6fc`:
- `pnpm --filter @objectstack/spec test`: Test Files 866 passed (866),
Tests 27798 passed, 1 todo.
- `pnpm --filter @objectstack/plugin-approvals exec vitest run`: Test
Files 125 passed (125), Tests 1793 passed (one commit earlier; the later
commits touch only this package's clock test file, rerun green: 12
passed).
- `pnpm --filter @objectstack/lint exec vitest run`: Test Files 222
passed (222), Tests 9346 passed.
- ui: `vitest run
packages/app-shell/src/views/metadata-admin/inspectors/
apps/console/src/pages/system/ApprovalsInboxPage`: Test Files 256 passed
(256), Tests 3254 passed, 1 skipped; `vitest run scripts/` (ui): 172
passed, 2 skipped.
- Typecheck: `@objectstack/spec`, `@objectstack/lint`,
`@objectstack/plugin-approvals` (incl. `check:test-typecheck`) green;
`type-check` of `@object-ui/i18n`, `@object-ui/app-shell`,
`@object-ui/console` green after building their closure.
- `pnpm --filter @objectstack/spec check:generated --fix`: regenerated
`content/docs/references/**` only; every other artifact current.
- `pnpm check:i18n`: OK, 10 packages, all bundles in sync.
- `node scripts/pm/dispatch-gates.mjs --commands` (131 families) run on
this head, each exit 0; `--ran` reconciliation: 131 derived, 131 run, 0
NOT-MEASURED (a derived zero, every line carries its exit code).
- `node scripts/pm/overlap-check.mjs --branch=claude/area-a4W-35357`:
VERDICT clean (origin/main, #35789, #35909, #35910).
- Size (on `f079e34`, against merged `origin/main`): +875 / -48 across
35 files, tests and generated files included.
</details>
## Acceptance notes
- The served shape is additive: `sla_due_refusal` is new and optional;
`sla_due_at` keeps its meaning under `wall_clock`.
- The `escalate` audit row does not record the due time it fired on (the
ADR left this to this card); the deadline is never stored anywhere.
- A deadline is computed once per row per read and sweep. A calendar the
service answers is served from its 60-second cache; a refusal is never
cached, so every read and sweep asks again; reads of decided requests
compute it too, so the projection stays one function for every status.
- The inbox reason is localized from the refusal's code; the server's
English `message` is served but not shown.
- `origin/main` is merged in (at `753091e`, a clean merge);
`overlap-check` reports clean merges against `origin/main`, #35789, the
open locale-pack PRs and the two open lint PRs.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- signed: repo:objectstack#4 · os-elon-musk ·
session_016WV4czKnDE6hsyXQzB9wB2 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
An approval node's `escalation` gains two optional keys (ADR-0157 D5):
16
+
17
+
-**`clock`**: `'wall_clock'` (the default) or `'working_time'`. Under `wall_clock` nothing changes: `timeoutHours` counts elapsed hours from `created_at`, nights, weekends and holidays included, and every request already open keeps its deadline (a stored snapshot carries no `clock`). Under `working_time` the hours count only the working periods of a working calendar (`sys_work_calendar`), skipping its holidays and counting its make-up workdays: a request opened at 17:00 on a Friday with `timeoutHours: 4`, on 09:00-12:00 and 13:00-18:00 periods, escalates at 12:00 on the next working day.
18
+
-**`calendar`**: the code of the working calendar to count on. Left out, the request organization's default calendar counts. There is never a fallback to wall-clock hours.
19
+
20
+
The approvals sweep and the request read share one deadline function. A `working_time` deadline is counted again on every sweep and every read and is never stored, so a holiday entered after a request opened moves its deadline; an escalation that already fired stays fired (single-shot, ADR-0042). When the calendar cannot count the deadline (no calendar has the code, the organization has no default, or the calendar is not maintained as far as the deadline needs), the request does not escalate, the next sweep tries again, and the request read carries a new additive field, `sla_due_refusal` (`code`, `reason` or `date`, `message`), in place of `sla_due_at`. The approvals inbox shows "Calendar can't compute" with the reason where the SLA countdown sits, in every console language.
21
+
22
+
`@objectstack/lint` refuses a `calendar` written beside the wall clock (`approval-escalation-calendar-without-working-time`, error): nothing would read it. Whether the named calendar exists is the organization's runtime data and is never checked at publish. The Studio approval inspector offers the clock and, under working time only, the calendar.
23
+
24
+
Not released alone: this ships in the same release as the working-calendar objects and service and the working-day formula functions (ADR-0157 D4).
Copy file name to clipboardExpand all lines: content/docs/references/automation/approval.mdx
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,9 @@ const result = ApprovalDecision.parse(data);
39
39
| Property | Type | Required | Description |
40
40
| :--- | :--- | :--- | :--- |
41
41
|**enabled**|`boolean`| optional (default: `true`) | Turns this step's deadline on or off. It is on by default once a deadline is set: switch it off to keep the settings without acting on them, or remove the escalation to drop the deadline altogether |
42
-
|**timeoutHours**|`number`| ✅ | How many hours a request may wait before the escalation runs. These are calendar (wall-clock) hours — nights, weekends and holidays count. The platform ships no business-hours calendar: a request opened at 17:00 on a Friday with 4 hours escalates at 21:00 that same Friday |
42
+
|**timeoutHours**|`number`| ✅ | How many hours a request may wait before the escalation runs, counted from when it was submitted. The clock decides how the hours count: wall-clock hours (the default) count nights, weekends and holidays, so a request opened at 17:00 on a Friday with 4 hours escalates at 21:00 that Friday; working hours count only the working periods of a working calendar |
43
+
|**clock**|`Enum<'wall_clock' \| 'working_time'>`| optional (default: `"wall_clock"`) | How the timeout's hours count: every hour, or only working hours. Wall-clock hours ('wall_clock', the default) count nights, weekends and holidays. Working hours ('working_time') count only the working periods of the organization's working calendar, skipping its holidays and counting its make-up workdays; when the calendar cannot count the deadline (no such calendar, or not maintained that far) the request does not escalate and shows why, until the calendar is fixed |
44
+
|**calendar**|`string`| optional | Which working calendar counts the hours under working time, by its code. Leave it empty to use the organization's default calendar |
43
45
|**action**|`Enum<'reassign' \| 'auto_approve' \| 'auto_reject' \| 'notify'>`| optional (default: `"notify"`) | What happens when the deadline passes: hand the request to someone else, approve it, reject it, or notify someone (the default) |
44
46
|**escalateTo**|`string`| optional | Who takes over or is notified when the deadline passes: usually a position, or a specific person. Write a position machine name or 'position:`<name>`', a user id or an email. A 'team:', 'department:', 'org_membership_level:' or 'role:' address is refused: no approver acts under one |
45
47
|**notifySubmitter**|`boolean`| optional (default: `true`) | Tell the person who submitted the request when it escalates |
@@ -77,7 +79,7 @@ const result = ApprovalDecision.parse(data);
77
79
|**onEmptyApprovers**|`Enum<'admin_rescue' \| 'fail' \| 'auto_approve' \| 'fallback'>`| optional (default: `"admin_rescue"`) | What happens when this step finds no one to approve: by default the organization's administrators decide; you can instead name backup approvers, fail the step, or approve it automatically. 'admin_rescue' (default) opens the request on the administrators; 'fallback' opens it on fallbackApprovers instead, naming who decides; 'fail' fails the step; 'auto_approve' approves it with no one deciding |
78
80
|**fallbackApprovers**|`{ type: Enum<'manager' \| 'position' \| 'department' \| 'team' \| 'queue' \| 'field' \| …>; value?: string; resolveAs?: Enum<'user' \| 'department' \| 'position' \| 'team'>; group?: string; … }[]`| optional | Backup approvers who decide when this step finds no one else. Read only when onEmptyApprovers is 'fallback' |
79
81
|**decisionOutputs**|`(string \| { key: string; label?: string; type?: Enum<'text' \| 'user' \| 'department' \| 'position' \| 'team'>; multiple?: boolean; … })[]`| optional | Extra answers the approver gives with the decision, such as who approves a later step; later steps read them. Each entry is a plain name (a text box) or `{ key, type, multiple }` to show a picker |
80
-
|**escalation**|`{ enabled?: boolean; timeoutHours: number; action?: Enum<'reassign' \| 'auto_approve' \| 'auto_reject' \| 'notify'>; escalateTo?: string; … }`| optional | A deadline for this step, and what happens when it passes |
82
+
|**escalation**|`{ enabled?: boolean; timeoutHours: number; clock?: Enum<'wall_clock' \| 'working_time'>; calendar?: string; … }`| optional | A deadline for this step, and what happens when it passes |
81
83
|**maxRevisions**|`integer`| optional (default: `3`) | How many times a request can be sent back for changes before it is rejected automatically (0 turns send-back off) |
@@ -115,7 +117,9 @@ const result = ApprovalDecision.parse(data);
115
117
| Property | Type | Required | Description |
116
118
| :--- | :--- | :--- | :--- |
117
119
|**enabled**|`boolean`| optional (default: `true`) | Turns this step's deadline on or off. It is on by default once a deadline is set: switch it off to keep the settings without acting on them, or remove the escalation to drop the deadline altogether |
118
-
|**timeoutHours**|`number`| ✅ | How many hours a request may wait before the escalation runs. These are calendar (wall-clock) hours — nights, weekends and holidays count. The platform ships no business-hours calendar: a request opened at 17:00 on a Friday with 4 hours escalates at 21:00 that same Friday |
120
+
|**timeoutHours**|`number`| ✅ | How many hours a request may wait before the escalation runs, counted from when it was submitted. The clock decides how the hours count: wall-clock hours (the default) count nights, weekends and holidays, so a request opened at 17:00 on a Friday with 4 hours escalates at 21:00 that Friday; working hours count only the working periods of a working calendar |
121
+
|**clock**|`Enum<'wall_clock' \| 'working_time'>`| optional (default: `"wall_clock"`) | How the timeout's hours count: every hour, or only working hours. Wall-clock hours ('wall_clock', the default) count nights, weekends and holidays. Working hours ('working_time') count only the working periods of the organization's working calendar, skipping its holidays and counting its make-up workdays; when the calendar cannot count the deadline (no such calendar, or not maintained that far) the request does not escalate and shows why, until the calendar is fixed |
122
+
|**calendar**|`string`| optional | Which working calendar counts the hours under working time, by its code. Leave it empty to use the organization's default calendar |
119
123
|**action**|`Enum<'reassign' \| 'auto_approve' \| 'auto_reject' \| 'notify'>`| optional (default: `"notify"`) | What happens when the deadline passes: hand the request to someone else, approve it, reject it, or notify someone (the default) |
120
124
|**escalateTo**|`string`| optional | Who takes over or is notified when the deadline passes: usually a position, or a specific person. Write a position machine name or 'position:`<name>`', a user id or an email. A 'team:', 'department:', 'org_membership_level:' or 'role:' address is refused: no approver acts under one |
121
125
|**notifySubmitter**|`boolean`| optional (default: `true`) | Tell the person who submitted the request when it escalates |
0 commit comments