Repository navigation
Commit 62daf7d
fix(approvals): a working-time deadline whose calendar read errors no longer fails the request open or the list (#35969)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D62xGLMbyWJaMEVnAMEjTK1)_
Fixes #35953
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:审批步骤按工作日历计时时,若读取日历本身出错,提交审批不再失败,流程照常暂停等待审批;收件箱列表和单条审批照常打开,只是这一条暂不显示到期时间。
-
为什么做:属于审批工作时间计时这条线,修补上一轮引入工作日历计时后留下的缺口:日历读取出错会让已建好、已通知审批人的申请所在流程失败,还会让整个收件箱打不开。
- 出错会怎样:最坏情况是出错的那一条暂不显示到期时间、日历恢复前不会升级提醒;其他申请不受影响,改动可直接撤回。
- 要你做什么:无。
## What changes
On `origin/main` at `7de1bad5cb`, `ApprovalService.slaDeadline` serves a
calendar refusal as `sla_due_refusal` (ADR-0157 D9) and rethrows every
other error, and `projectWorkingTimeDue` ran it per row with no guard.
Its three callers all serve a row that is already written:
`openNodeRequest` (after the `sys_approval_request` insert and the
`approval.requested` notices), `listRequests`, and `loadRequest`
(`getRequest`, `listActions`, and the decision paths that load the
request). A calendar read that errored (a driver error reading
`sys_work_calendar`, not a refusal) therefore:
- made the open throw, so the approval node's `catch` answered the run
`success: false` while a pending request it owns existed and its
approvers had been told;
- failed the whole list read, and every single read of that row.
**The fix,
`packages/plugins/plugin-approvals/src/approval-service.ts`:**
`projectWorkingTimeDue` now guards each row. On an error from
`slaDeadline` it logs a `warn` naming the request and the error, and
serves that row with no deadline; the loop goes on to the next row. One
guard covers all three callers, so `openNodeRequest` needs no second
one: the open returns the request it wrote, and the run suspends as
usual.
What does not change:
- A refusal is still served as `sla_due_refusal`; no new refusal code
and no change to the served shape.
- No wall-clock fallback (ADR-0157 D2): the erroring row carries neither
`sla_due_at` nor `sla_due_refusal`.
- The sweep (`runEscalations`) calls `slaDeadline` itself, inside its
existing per-row `try`. It still skips the row, counts nothing for it,
and asks the calendar again next pass; ADR-0042 §1 single shot is
unchanged. The sweep's assertions in the new test pass on `main` too:
they pin this, they do not fix it.
- Log level `warn`: no persisted claim is lost, a read projection is
missing one field (AGENTS.md, degradation log levels).
Not done: the optional per-pass refusal memo. It does not come for free:
it needs a key across rows (organization plus calendar code plus the
start-and-hours inputs) and a decision on whether a memoised refusal may
serve rows of other organizations. It is left for its own card if the
read cost matters.
Changeset `.changeset/35953-sla-deadline-error-guard.md`:
`@objectstack/plugin-approvals` patch.
Read first (risk order):
1. `approval-service.ts`, the `projectWorkingTimeDue` hunk: the
`try`/`catch` around `slaDeadline` and the `continue` that leaves the
row with no deadline.
2. `approval-service-sla-calendar-clock.test.ts`, the new last
`describe`: the calendar double that throws a plain `Error` for a chosen
calendar code and delegates to the real `WorkCalendarService` otherwise.
## Evals
Tests are in the existing harness file
`src/approval-service-sla-calendar-clock.test.ts`, as a new top-level
`describe` (4 tests). The calendar double is the real
`WorkCalendarService` over the file's read double, except that a
calendar code in a test-controlled set throws `new
Error('sys_work_calendar read failed: connection reset')`.
1. The open returns the pending request, the row exists in
`sys_approval_request`, neither `sla_due_at` nor `sla_due_refusal` is
served, and a warning names the request.
2. The approval node, driven through a real `AutomationEngine` flow,
answers `paused` with one suspended run (on `main`: `failed`).
3. A list with one erroring row and one good row: both are listed, the
good row keeps `sla_due_at` (Tuesday 12:00 Shanghai, holiday skipped),
the erroring row has no deadline; `getRequest` of the erroring row
answers it.
4. The sweep: the erroring row is skipped (`escalated: 1`, the good row
only), escalated on the next pass once the calendar reads again, and a
third pass escalates nothing.
## Verification
Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec
vitest run --maxWorkers=2
src/approval-service-sla-calendar-clock.test.ts` prints `Tests 16 passed
(16)`.
<details><summary>Red on main (the guard ablated once)</summary>
`approval-service.ts` restored from `7de1bad5cb` on disk under a trap
(disk hash `f1d462d986` equals main's blob; guard text occurrences 0),
tests from the branch, then restored from `HEAD` (`git diff HEAD` empty,
`git status --porcelain` empty). The subject is imported by relative
path from `src/`, so no `dist/` rebuild sits between the mutation and
the run.
- open: `Error: sys_work_calendar read failed: connection reset` thrown
by `openNodeRequest`
- node: `expected 'failed' to be 'paused'`
- list: the same error thrown by `listRequests`
- sweep: `runEscalations` and the good row's escalation pass; the red is
the erroring row's `listActions` read (it loads the request), the read
seam the fix covers
- `Test Files 1 failed (1)`, `Tests 4 failed | 12 passed (16)`
Green on the fix: `Tests 16 passed (16)`.
</details>
<details><summary>Package suite, typecheck and derived gates at
dd312c3</summary>
- `pnpm --filter @objectstack/plugin-approvals test`: `Test Files 126
passed (126)`, `Tests 1803 passed (1803)`
- `pnpm --filter @objectstack/plugin-approvals typecheck`: exit 0,
`check:test-typecheck: OK`
- `node scripts/pm/dispatch-gates.mjs --commands`: 72 commands; 70 exit
0; `pnpm check:dual-build-cjs-loads` and `pnpm check:i18n` exit 3
PREREQUISITE NOT MET (they need a whole-workspace build and the built
CLI closure), NOT MEASURED locally, CI runs both. `--ran`
reconciliation: `72 derived famil(ies) accounted for — 70 run, 2
NOT-MEASURED`.
- `node scripts/pm/overlap-check.mjs --branch=claude/area-a4W-35953`:
`VERDICT clean exit 0`, merges cleanly into `origin/main`.
- `test:repo` and the full dogfood battery are CI's (no `!` in the
title, no narrowing arm).
</details>
## Acceptance notes
- An erroring row is served with neither `sla_due_at` nor
`sla_due_refusal`, so a reader cannot tell it from a node with no SLA
until the calendar reads again; only the server log says why. A
`calendar_error` refusal code would say it on the row, but that is a
served-shape change that needs a contract read, so it is out of this PR
by the seat's scope.
- The sweep logs its existing `escalation failed for request` warning
for the erroring row on each pass; unchanged.
Session: https://claude.ai/code/session_016WV4czKnDE6hsyXQzB9wB2
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 96b66ca commit 62daf7d
3 files changed
Lines changed: 145 additions & 2 deletions
File tree
- .changeset
- packages/plugins/plugin-approvals/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
390 | 392 | | |
391 | 393 | | |
392 | 394 | | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8336 | 8336 | | |
8337 | 8337 | | |
8338 | 8338 | | |
8339 | | - | |
| 8339 | + | |
| 8340 | + | |
| 8341 | + | |
8340 | 8342 | | |
8341 | 8343 | | |
8342 | 8344 | | |
| |||
8369 | 8371 | | |
8370 | 8372 | | |
8371 | 8373 | | |
| 8374 | + | |
| 8375 | + | |
| 8376 | + | |
| 8377 | + | |
| 8378 | + | |
| 8379 | + | |
| 8380 | + | |
8372 | 8381 | | |
8373 | 8382 | | |
8374 | 8383 | | |
8375 | 8384 | | |
8376 | 8385 | | |
8377 | | - | |
| 8386 | + | |
| 8387 | + | |
| 8388 | + | |
| 8389 | + | |
| 8390 | + | |
| 8391 | + | |
| 8392 | + | |
| 8393 | + | |
| 8394 | + | |
8378 | 8395 | | |
8379 | 8396 | | |
8380 | 8397 | | |
| |||
0 commit comments