Skip to content

Commit 8d0727a

Browse files
committed
fix(approvals): a working-time deadline whose calendar read errors costs only its row the deadline
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4czKnDE6hsyXQzB9wB2
1 parent 54701f4 commit 8d0727a

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/plugin-approvals': patch
3+
---
4+
5+
fix(approvals): a working-time SLA deadline whose calendar read errors no longer fails the request open or the whole list
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
When an approval step's escalation counts `working_time` and the working calendar read itself fails (an error that is not a calendar refusal, such as a driver error reading `sys_work_calendar`), opening the request threw after the `sys_approval_request` row was written and its approvers were told, so the approval node failed its flow run. The same error failed every list read and single read that included the row, and so every decision that loads it.
11+
12+
That row is now served with no deadline and the error is logged as a warning; the open returns the request, the run suspends as usual, and the other rows of a list keep their deadlines. A calendar refusal is still served as `sla_due_refusal`, the deadline never falls back to wall-clock hours, and the escalation sweep still skips the row and asks the calendar again on its next pass. The served request shape is unchanged.

‎packages/plugins/plugin-approvals/src/approval-service.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8321,7 +8321,9 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
83218321
* organization's calendar, named by `escalation.calendar` or else its default
83228322
* (D2), recomputed on every call and never stored (D12). A calendar refusal
83238323
* (none resolves, or it is not maintained that far, D8) answers
8324-
* `{ refusal }` instead of a deadline (D9); every other failure throws.
8324+
* `{ refusal }` instead of a deadline (D9); every other failure throws, and
8325+
* each caller costs only that row its deadline: the sweep skips it until the
8326+
* next pass, {@link projectWorkingTimeDue} serves it with none.
83258327
*/
83268328
private async slaDeadline(raw: any, cfg: any): Promise<SlaDeadline | undefined> {
83278329
if (!escalationCountsWorkingTime(cfg)) {
@@ -8354,12 +8356,27 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
83548356
* calendar cannot count it, through {@link slaDeadline}. `raws[i]` is the
83558357
* stored row `rows[i]` was mapped from; a `wall_clock` row already carries
83568358
* its deadline from the synchronous mapper and is left alone.
8359+
*
8360+
* A calendar read that errors (not a refusal) costs only its own row the
8361+
* deadline: it is logged and that row is served with none, never a
8362+
* wall-clock one (D2). Every caller serves a row that is already written —
8363+
* `openNodeRequest` after the insert and the approvers' notices, the list
8364+
* and single reads — so the error never fails the write or the other rows.
8365+
* The sweep reads {@link slaDeadline} itself and retries the row next pass.
83578366
*/
83588367
private async projectWorkingTimeDue(raws: readonly any[], rows: ApprovalRequestRow[]): Promise<void> {
83598368
for (let i = 0; i < rows.length; i++) {
83608369
const cfg = parseJson<any>(raws[i]?.node_config_json, undefined);
83618370
if (!escalationCountsWorkingTime(cfg)) continue;
8362-
const deadline = await this.slaDeadline(raws[i], cfg);
8371+
let deadline: SlaDeadline | undefined;
8372+
try {
8373+
deadline = await this.slaDeadline(raws[i], cfg);
8374+
} catch (err: any) {
8375+
this.logger?.warn?.('[approvals] working-time SLA deadline could not be computed; the request is served without one', {
8376+
request: raws[i]?.id, error: err?.message ?? String(err),
8377+
});
8378+
continue;
8379+
}
83638380
if (!deadline) continue;
83648381
if ('refusal' in deadline) rows[i]!.sla_due_refusal = deadline.refusal;
83658382
else rows[i]!.sla_due_at = deadline.due;

0 commit comments

Comments
 (0)