Skip to content

Commit 0a1b69c

Browse files
feat(approvals): a decided request's step line says where the record's approval went next (#37148)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBCKqH7woNZCA4ZVP1id8Jp7)_ Fixes #35863 repo:objectstack#3 · os-support-ai · session_01WGufzg3ayWUHg9nLoybejn Clause-②: yes Metadata-protocol: none ## 维护者速读 - 审批人打开自己已经审过的审批单时,「审批进度」里在已决步骤下多出一行:审批已流转到哪一步并在等谁决定,或者整条审批已经结束、结果是什么。 - 属于审批流程体验:解决审过的人看不到「后来怎么样了」的问题。 - 出错时这一行不显示或说法不准,不影响审批本身,撤回这个改动即可恢复原样。 - 无。 ## What changes **Served shape (`@objectstack/spec/contracts`, `ApprovalRequestRow.flow_route`).** One optional member, `outcome`, served only beside `ahead: 'decided'`: - `step?: { id, label }`: the run's latest request when it is a later one than this request (same `flow_run_id`, opened after it, on any node, a later round of the same node included; a pending one wins over a decided one). Absent when no later request was opened. - `status: ApprovalStatus`: that latest request's status, or this request's own when `step` is absent. `pending` with a `step` = the approval went on to that step and waits on its decision. - `ended: boolean`: the record's approval is known to have stopped: a root run, whose own flow body starts no child run (`subflow` / `map`), that has stopped for good. `false` = not known (rounds 1 to 3 below). `outcome` is absent when nothing past the request is known (no later request in the run and the approval not known to have ended, or several later requests are pending at once), so nothing is guessed. A pending request's route never carries it. **Server (`@objectstack/plugin-approvals`).** `routeOutcome` in `approval-route.ts` is the rule, a pure function over the run's own request rows (the same rows `passedSteps` already reads) and whether the run has ended. `flowRoute` calls it for decided rows only. `ApprovalService.attachFlowRoute` reads "ended" off the run itself through `automation.getRun`, judged by the dead-run sweep's own `TERMINAL_RUN_STATUSES` (derived from the total `RUN_STATUS_LIVENESS` map), in the new `runHasEnded`. An unreadable run reads as "not known to have ended", never as a failed read: the field is display-only like the rest of the route. **Docs.** `content/docs/automation/approvals.mdx` gains the decided route's `outcome`, beside the existing `flow_route` example (the docs drift check named that page). **UI (`@object-ui/app-shell`, `@object-ui/i18n`, `@object-ui/console`).** `ApprovalStepLine` takes an `outcome` prop and, with `decided`, draws one line under the decided step, outside the ordered list so assistive tech never counts it as a step: "Went on to STEP, waiting for a decision", "Went on to STEP: DECISION", "Went on to STEP, then ended: DECISION", or "The approval ended here". The approval request page's decision panel hands it the served outcome on a decided route only. Four new `approvalsInbox` rows in all eleven built-in locales. The console's `ApprovalRequest` type and app-shell's `ApprovalRequestLite` mirror the member. ### Why this shape (card option 2, one outcome) and not option 1 (the steps after) - Option 1 needs a `rejected` step state: a widening of the `state` enum every step-line consumer switches on, and it still needs a separate marker for "ended". - The card asks the UI for one line under the decided step; one outcome is exactly that line's data. - Reading the run's latest request (rather than walking the graph) keeps the route's existing rule: history, never the graph, and nothing guessed. ### Read first (by risk) 1. `routeOutcome` in `packages/plugins/plugin-approvals/src/approval-route.ts`: which later row is "the latest", the parallel-pending refusal, and the ended-at-this-request arm. 2. The `outcome` doc on `flow_route` in `packages/spec/src/contracts/approval-service.ts`: the contract text the L2 read judges. 3. `outcomeText` in `ui/packages/app-shell/src/views/approval-progress/ApprovalStepLine.tsx`: which status draws which sentence, and when it draws nothing. ### Two-minute verification `pnpm --filter @objectstack/plugin-approvals exec vitest run --maxWorkers=2 src/flow-route.integration.test.ts`: expect 14 passed, including "a request decided at step 1 of a two-step route: the outcome says step 2 is pending, then that the approval ended there". ## Tests - `approval-route.test.ts`: a new `routeOutcome` describe (9 cases): later pending, ended at a later step (approved and rejected), ended at this request (approved, rejected, recalled, cancelled), not ended and nothing later (no outcome), a later round of the same node, pending wins over decided, parallel pending (no outcome), rows that are not later requests, and `flowRoute` carrying it on decided rows only. - `flow-route.integration.test.ts` (real ObjectQL over SQLite, real AutomationEngine and approval node): the existing decided pin now asserts `outcome: { status: 'approved', ended: true }` at the last step; new pins for the card's two cases (decided at step 1 of a two-step route shows step 2 `pending`, then `rejected, ended` once step 2 is rejected), a first-step rejection ending the approval, and a pending request carrying no outcome. - `ApprovalDecisionPanel.stepLine-12491.test.tsx` (the existing harness, a new top-level describe, 7 cases): each sentence, no line without an outcome or with nothing to say, no line on a pending route, and every locale pack carrying the four rows. ## Acceptance notes - Size: 850 added / 18 removed lines over 24 files at 6080e34, under the 3,000-line human-merge threshold. - The line does not say who holds the later step. The card mentions it in passing; the approver names of a later step are information this request's reader was never served, so naming them is a read-access question, not a display one. Not filed: no defect, and the card's own ask (step N / ended approved / rejected / recalled) is met. - `ended: true` with `status: 'approved'` reports the last decision; a root run that failed after that approval also reads "ended". The run's own status is not served here; that would be a second widening for a rare case. - Claim file surface: the diff also touches `ui/packages/i18n/src/locales/*.ts` (the four rows the line needs), `ui/apps/console/src/services/approvalsApi.ts` (the console's type mirror of `flow_route`) and `content/docs/automation/approvals.mdx` (the page that documents `flow_route`). - The shape reported to the zone named `{ status, step? }`; the landed shape adds `ended`, because "the approval ended" is a fact about the run, not about any one request's status. ## Round 1 (L2 FAIL 7147867236, L1 REWORK 7147881964), head 99ab892 - **M1, a child run's end.** The approval node now records on each new request whether its run is a root run or a child (`subflow` body, `map` item: the engine links those upward by `$parentRunId`), as `__runRoot` on the config snapshot (precedent `__round`; no schema change). `attachFlowRoute` asks the run for "ended" only when the snapshot says root; a child run's request, a request opened before the stamp, or an unreadable run is never served `ended: true`. New pin in `flow-route.integration.test.ts`: an approval inside a `subflow` whose child run completed while the root run went on to the general manager serves no outcome, and the root run's last request then served `{ status: 'approved', ended: true }` (round 2 withdraws that: its flow hosts a `subflow`); a second pin removes the stamp from a decided last-step request and the outcome disappears. Ablations: root-run read forced `true` gives 2 failed / 9 passed; executor stamp forced `true` gives 1 failed / 10 passed; both restored. - **S1, audience.** The `outcome` contract doc and the `attachFlowRoute` docblock state the disclosure: every reader of the request gets the later step's node id and label and that request's status, never its id, approvers, comments or field values, within the request-visibility bound of ruling record 5299823744 as the seat ruled for this card. - **S2, an unreadable run (option a).** `ended` is now defined as "known to have stopped" (`false` = not known, including an unreadable run), and the contract, the changeset and `approvals.mdx` say an outcome with a later request is served even when the run cannot be read. **N1**: the contract says `status` is the last decision only when it is not `pending`. - Checks: `@objectstack/plugin-approvals` full suite Test Files 128 passed (128), Tests 1934 passed (1934); plugin-approvals and spec typecheck exit 0; spec rebuilt and `check:generated` all 14 up to date; overlap-check clean against main and the open PR heads, #37145 included. CI at 99ab892: 70 check-runs, 61 success, 9 skipped, 0 failed, every required context green; mergeable clean. The local re-run of the derived gate list at this head stopped at 9 of 121 (all exit 0) when the container restarted; CI ran the families. ## Round 2 (L2 FAIL 7150840780, L1 REWORK 7150863825), head e264c10 - **M2, a later step in a child run.** Chosen: the second of the two named ways. "Ended" is never claimed for a run whose flow can start a child run; child runs' rows are not read. `flowHostsChildRuns` (`approval-route.ts`) says whether the flow holds a `subflow` or `map` node anywhere, regions included (`loop` body, `parallel` branch, `try_catch`, every graph `collectFlowGraphs` walks), and `attachFlowRoute` asks the run for "ended" only when it does not. Two choices inside it, stated so they can be judged: - It is read off the flow definition (the same body the route's steps are read off), not off the run's step log: the persisted step log is compacted to a bounded number of steps, so "the run never ran a child-run node" cannot be proven from it, while "the flow has none" can. The cost is that a flow with a `subflow` on a branch the run never took also never says "ended"; the line is then left out, never wrong. - It covers the case with a `step` too, not only "ended with no later step": with manager → general manager → subflow legal → end, the manager's outcome would otherwise read `{ step: gm, status: 'approved', ended: true }` and name the general manager's decision as the last one while legal came after. With this rule it reads `{ step: gm, status: 'approved', ended: false }`, which is true. - Not chosen, reading child runs' rows: a request does not record its root run id (only `__runRoot`, a yes/no), the engine serves no "children of a run" read, and walking `$parentRunId` chains from the read side would need a new engine member, outside the claimed surface. - Served shape for the review's setup (manager in the root run, then a subflow holding legal, then the end; legal rejects, the root run completes): the manager's request is served `flow_route: { steps: [manager done], ahead: 'decided' }` with no `outcome`. Pinned exactly in `flow-route.integration.test.ts` ("a later step in a child run: the root run's end is not served as \"ended here\" for the request before it"). The round-1 hosted pin now asserts that the root run's own last request also gets no outcome, its flow hosting a `subflow`. - Contract, changeset and `approvals.mdx`: "known to have stopped" now names "runs a flow that can start a child run" among the `false` cases, and `step` says a request a child run opened is not among the run's requests. - **N4**: the `attachFlowRoute` docblock reads "as the seat ruled on PR #37148". - Unit: a `flowHostsChildRuns` describe (3 cases): `subflow` and `map` at the top level; inside a `loop` body, a `parallel` branch, a `try_catch` catch, and nested two deep; none anywhere (approvals, gateways, a `loop` of approvals, an empty flow). - Ablations (through `scripts/ablation-replace.mjs`, restored to blob == HEAD each time): the gate in `attachFlowRoute` forced off gives Tests 2 failed / 10 passed (the new pin and the hosted pin); `map` removed from the child-run node types gives 2 failed / 26 passed; the region walk replaced by the top-level nodes gives 1 failed / 27 passed. - Checks: targeted `approval-route.test.ts` + `flow-route.integration.test.ts` Test Files 2 passed (2), Tests 40 passed (40); `@objectstack/plugin-approvals` full suite Test Files 128 passed (128), Tests 1938 passed (1938); plugin-approvals and spec typecheck exit 0; spec rebuilt and `check:generated` all 14 up to date; overlap-check clean against origin/main and PR heads #37185, #37173, #37166. CI at e264c10: 70 check-runs, 61 success, 9 skipped, 0 failed, every required context green; mergeable clean. ## Round 3 (L2 PASS with S3 7151818256, L1 REWORK 7151830517), head 6080e34 - **S3, which flow body is judged.** Chosen: refuse "ended" unless the run provably ran the body armed now; no new engine member. `ranArmedBody` (`approval-service.ts`) holds when the armed body is the flow's newest registration in the engine's version history (`getFlowVersionHistory`, compared as the very object) and was registered strictly before the run started (the run log's `startedAt`, which a resume carries over unchanged). A run starts on the body armed at its start and resumes pinned to it, so with nothing registered since, that body is the one it ran. `runHasEnded` now requires it beside the terminal status. - Not the run's `flowVersion`: it is the author's number and an edit need not change it (the edit pin re-registers under the same version). - Not judging the run's own version out of the history: the history is the engine's in-memory list since boot and a version number can repeat, so it can name the wrong body; the run log carries no body checksum to match. - `getFlowVersionHistory` and `startedAt` are declared on the plugin's automation surface as members `AutomationEngine` already implements and returns publicly, the existing precedent for that interface. - Cost, stated: a flow registered again after a run started (an edit, a rollback, the re-registration every restart makes) leaves that run's requests without "ended", so after a restart older decided requests drop the line until a new run. Omitted, never wrong. - **Pins** (`flow-route.integration.test.ts`): a run that started a `subflow` (legal rejects, the root completes), then its flow re-registered under the same version without the subflow: the manager's request still serves no `outcome`; a run started on the edited body then ends at the manager, `{ status: 'approved', ended: true }`. A rollback: version 2 (with the subflow) runs, `rollbackFlow` re-arms version 1 (without): no `outcome`. - **Wording**: the contract, the changeset and `approvals.mdx` now say "the flow body the run ran" and when that body is known, and list "ran a body that is not known (its flow was registered again since it started)" among the `false` cases. - **N5**: the `CHILD_RUN_NODE_TYPES` docblock names the only two executors that set `$parentRunId` (`builtin/subflow-node.ts`, `builtin/map-node.ts`), says `loop`, `parallel` and `try_catch` stay in-run, and that a new child-run starter joins the set in the same change. A pin would have to read `service-automation` sources from this package's tests, which the cross-package test-input gate refuses, so it is a comment. - **Left, with reasons.** N2 (later is measured against `created_at`, not the decision): a run opens its requests one after another, so the order they were opened in is the order the approval moved in; the only same-run overlap is parallel branches, which `routeOutcome` already refuses to pick from. No reachable wrong case, so no change and no card needed in my view. **N3, fixed after all**: both UI mirrors now type `outcome.status` as the row's own `status` (`ApprovalRequestRow['status']` in the console, `ApprovalRequestLite['status']` in app-shell), the open union each already uses, rather than a bare `string`. - Ablations (through `scripts/ablation-replace.mjs`, restored to blob == HEAD each time): `ranArmedBody` dropped from `runHasEnded` gives Tests 1 failed / 12 passed (the edit pin); the time test forced true gives 1 failed / 12 passed (the edit pin); the identity test dropped gives 1 failed / 13 passed (the rollback pin). - Checks: targeted `approval-route.test.ts` + `flow-route.integration.test.ts` Tests 42 passed; `@objectstack/plugin-approvals` full suite Test Files 128 passed (128), Tests 1940 passed (1940) at bfff5d1 (6080e34 adds only the two UI type lines); `ApprovalDecisionPanel.stepLine-12491.test.tsx` Tests 20 passed (20) at 6080e34; plugin-approvals and spec typecheck exit 0; spec rebuilt and `check:generated` all 14 up to date; overlap-check clean against origin/main and the open PR heads before each push. Three pushes this round, not one: 30ec243 (S3), bfff5d1 (the rollback pin, once the identity ablation showed that branch unpinned), 6080e34 (N3); CI on the first two was cancelled by the next push. CI at 6080e34: 70 check-runs, 61 success, 9 skipped, 0 failed, every required context green; merges cleanly with main. ## Verification <details><summary>Targeted tests (code at 19f57ef; later commits touch only the changeset, the docs page and one test import)</summary> - `pnpm --filter @objectstack/plugin-approvals exec vitest run --maxWorkers=2 src/approval-route.test.ts src/flow-route.integration.test.ts`: VERDICT command-exit 0, Test Files 2 passed (2), Tests 34 passed (34). - `pnpm --dir ui exec vitest run packages/app-shell/src/views/approval-decision/ApprovalDecisionPanel.stepLine-12491.test.tsx packages/app-shell/src/views/RecordApprovalsPanel.stepProgressVertical.test.tsx packages/app-shell/src/views/RecordApprovalsPanel.servedRoute-26668.test.tsx`: VERDICT command-exit 0, Test Files 3 passed (3), Tests 29 passed (29). - `pnpm --filter @objectstack/plugin-approvals typecheck && pnpm --filter @objectstack/spec typecheck`: VERDICT command-exit 0. - `pnpm --filter @objectstack/spec check:generated`: all 14 generated artifacts up to date (spec dist built after the contract edit). </details> <details><summary>Ablations (each through scripts/ablation-replace.mjs, mutation proven on disk, restored, tree clean after)</summary> - `flowRoute` outcome replaced by `undefined`: Tests 4 failed / 30 passed (the `flowRoute` unit case and the three integration outcome pins). - `runHasEnded` forced `false`: Tests 3 failed / 6 passed in the integration file (every `ended: true` pin). - The decision panel's `outcome` hand-off deleted: Tests 4 failed / 16 passed (every drawn-line case). All three suites import source, not `dist/`, so no rebuild leg applies. </details> <details><summary>Local gates (dispatch-gates, derived at 19f57ef and again at 1f6480a)</summary> Derived by `node scripts/pm/dispatch-gates.mjs --commands` (120 families once the docs page joined the diff); `--ran` reconciliation: 120 of 120 accounted for. 117 exit 0. Exit 3 (prerequisite not met in this container, nothing measured; CI ran them green): - `node scripts/check-plugin-teardown-shape.mjs --self-test`: exit 3 (shallow clone cannot reach the pinned positive control) - `pnpm check:dual-build-cjs-loads`: exit 3 (reads built output of the whole workspace) - `pnpm check:i18n`: exit 3 (needs its package build closure; nothing compared) Exit 0: - `node scripts/check-adr-0087-registration.mjs --base origin/main` - `node scripts/check-adr-0087-registration.mjs --self-test` - `node scripts/check-changeset-no-major.mjs --base origin/main` - `node scripts/check-closing-keyword-parity.mjs` - `node scripts/check-closing-keyword-parity.mjs --self-test` - `node scripts/check-comment-mask-adoption.mjs` - `node scripts/check-comment-mask-adoption.mjs --self-test` - `node scripts/check-comment-mask-corpus.mjs` - `node scripts/check-dev-prereqs.mjs --self-test` - `node scripts/check-dts-emitted.mjs --self-test` - `node scripts/check-empty-changeset.mjs --base origin/main` - `node scripts/check-empty-changeset.mjs --self-test` - `node scripts/check-issue-citations.mjs` - `node scripts/check-plugin-teardown-shape.mjs` - `node scripts/check-sdui-manifest.mjs` - `node scripts/check-sdui-manifest.mjs --self-test` - `node scripts/check-tenant-audit-census.mjs` - `node scripts/check-tenant-audit-census.mjs --self-test` - `node scripts/ci/assert-turbo-remote-cache.mjs --self-test` - `node scripts/ci/plan-test-core-shards.mjs --self-test` - `node scripts/ci/prune-turbo-cache.mjs --self-test` - `node scripts/ci/snapshot-next.mjs --self-test` - `node scripts/docs-audit/check-affected-docs.mjs` - `node scripts/docs-audit/check-drift-comment.mjs` - `node scripts/pm/check-governed-queue-guard.mjs --self-test` - `node scripts/pm/release-rehearsal-clone.mjs --self-test` - `node scripts/release-pending-publish.mjs --self-test` - `pnpm --dir ui exec vitest run scripts/` - `pnpm --filter @objectstack/lint run check:doc-formula-expressions` - `pnpm --filter @objectstack/spec run check:api-surface` - `pnpm --filter @objectstack/spec run check:authorable-surface` - `pnpm --filter @objectstack/spec run check:browser-reachable-entries` - `pnpm --filter @objectstack/spec run check:docs` - `pnpm --filter @objectstack/spec run check:dual-source-exports` - `pnpm --filter @objectstack/spec run check:duration-unit-keys` - `pnpm --filter @objectstack/spec run check:empty-state` - `pnpm --filter @objectstack/spec run check:entry-nameability` - `pnpm --filter @objectstack/spec run check:error-code-provenance` - `pnpm --filter @objectstack/spec run check:export-origins` - `pnpm --filter @objectstack/spec run check:exported-any` - `pnpm --filter @objectstack/spec run check:liveness` - `pnpm --filter @objectstack/spec run check:llms-txt` - `pnpm --filter @objectstack/spec run check:skill-refs` - `pnpm --filter @objectstack/spec run check:strictness-ledger` - `pnpm --filter @objectstack/spec run check:variant-docs` - `pnpm --filter @objectstack/spec run check:yaml-examples` - `pnpm check:adr-anchors` - `pnpm check:adr-symbol-anchors` - `pnpm check:changeset-gate-self-tests` - `pnpm check:ci-filter-parity` - `pnpm check:cli-command-ids` - `pnpm check:closed-ceremony-text` - `pnpm check:cross-package-test-inputs` - `pnpm check:dispatcher-error-vocabulary` - `pnpm check:doc-authoring` - `pnpm check:driver-memory-census` - `pnpm check:dts-closure` - `pnpm check:engine-double-contract` - `pnpm check:error-status-conformance` - `pnpm check:gitlink-declared` - `pnpm check:i18n-stale-fill` - `pnpm check:issue-citations` - `pnpm check:keyed-text-bounds` - `pnpm check:lean-entry-closure` - `pnpm check:logger-receiver-detach` - `pnpm check:merge-driver` - `pnpm check:nul-bytes` - `pnpm check:object-def-param-keys` - `pnpm check:objectql-double-limit` - `pnpm check:optional-error-sink` - `pnpm check:org-identifier` - `pnpm check:page-declaration-shape` - `pnpm check:platform-object-tenancy-census` - `pnpm check:pm-expected-skips` - `pnpm check:pm-prior-rulings` - `pnpm check:published-files` - `pnpm check:query-options-erasure` - `pnpm check:refd-timer-probe` - `pnpm check:registry-log-declared` - `pnpm check:rest-log-spy-declared` - `pnpm check:role-word` - `pnpm check:settings-bind-window` - `pnpm check:skill-identifier-liveness` - `pnpm check:slot-lookup` - `pnpm check:sourcemap-no-sources-content` - `pnpm check:spec-docblock-symbol-anchors` - `pnpm check:spec-parsed-alias` - `pnpm check:system-context-census` - `pnpm check:test-source-alias` - `pnpm check:tier-file-adoption` - `pnpm check:type-check-coverage` - `pnpm check:type-check-debt` - `pnpm check:undeclared-dep-imports` - `pnpm check:vouch-for-reference-callers` - `pnpm check:watch-hint-literal` - `pnpm check:where-matcher` - `node scripts/check-adr-links.mjs` - `node scripts/check-adr-links.mjs --self-test` - `node scripts/check-doc-route-spelling.mjs --advisory` - `node scripts/check-doc-route-spelling.mjs --self-test` - `node scripts/check-docs-section-name.mjs` - `node scripts/check-docs-section-name.mjs --self-test` - `node scripts/check-section-landing-index.mjs` - `node scripts/check-section-landing-index.mjs --self-test` - `pnpm --filter @objectstack/lint run check:doc-security-posture` - `pnpm --filter @objectstack/spec run check:skill-examples` - `pnpm check:corpus-claim-drift` - `pnpm check:doc-anchors` - `pnpm check:doc-frontmatter` - `pnpm check:docs-audit-scope` - `pnpm check:docs-redirects` - `pnpm check:docs-single-h1` - `pnpm check:docs-spec-enumerations` - `pnpm check:docs-transcript-drift` - `pnpm check:published-readme-links` - `pnpm check:react-page-adapter-contract` - `pnpm check:vendor-version-stamps` </details> - After the docs page and the test import landed: `pnpm check:test-source-alias` exit 0 at 1f6480a (CI had flagged the decision panel harness reaching the lazy `@object-ui/plugin-detail` load without a module-top import; the harness now imports it at collection); the edited harness file re-run, Test Files 1 passed (1), Tests 20 passed (20). CI at head 1f6480a: 61 success, 9 skipped, 0 failed of 70 check-runs; every required context green (Lint & Repo Gates, TypeScript Type Check, Test Core, Build Core, Governed Surface Queue Guard, Lint UI, Type Check UI, Test UI, Build & E2E UI, Live E2E UI, Dogfood Regression Gate) and Check Changeset green. Mergeable: clean. NOT MEASURED locally: `Type Check UI` (`@object-ui/app-shell type-check` needs the UI package closure built; the local run stopped on missing-module errors only, none in a touched line). CI's `Type Check UI` is the reading. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzg3ayWUHg9nLoybejn)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzg3ayWUHg9nLoybejn <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzg3ayWUHg9nLoybejn --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fd462c5 commit 0a1b69c

24 files changed

Lines changed: 850 additions & 18 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/plugin-approvals': patch
4+
'@object-ui/app-shell': patch
5+
'@object-ui/i18n': patch
6+
'@object-ui/console': patch
7+
---
8+
9+
feat(approvals): a decided request's step line says where the record's approval went next: on to a later step, or ended
10+
11+
Clause-②: yes
12+
Metadata-protocol: none
13+
14+
The single approval request read (`GET /api/v1/approvals/requests/ID`) serves one more fact on a decided request's own route: `flow_route.outcome`, beside `ahead: 'decided'`. Before, a decided route stopped at the request's own step, so an approver reopening a request they had decided could not tell whether the record's approval went on to a later step or ended.
15+
16+
- `outcome.step` is the run's latest request when it is a later one than this request (a request of the same flow run opened after it, on any node, a later round of the same node included; a pending one wins over a decided one). It is absent when no later request was opened in that run; a request a child run opened is not among them.
17+
- `outcome.status` is that latest request's status, or this request's own when `step` is absent. `pending` with a `step` means the approval went on to that step and waits on its decision.
18+
- `outcome.ended` is `true` only when the record's approval is known to have stopped: the request's run is a root run (not a `subflow` body or a `map` item, whose end is not the approval's), the flow body the run ran holds no `subflow` or `map` node anywhere, regions included (a child run files its requests under its own run, so this run's requests cannot show what it decided, before or after this request), and the run reports it stopped for good, with the same terminal set the dead-run sweep uses. The body the run ran is known only when the body armed now is the flow's newest registration and was registered before the run started, so a flow edited, rolled back or re-registered after a run started is never judged by its current body for that run. `false` means not known to have stopped: the run goes on, is a child run, ran a body that can start a child run, ran a body that is not known, cannot be read, or was opened before this release (the approval node now records on each new request whether its run is a root run).
19+
20+
`outcome` is absent when nothing past the request is known: no later request was opened and the approval is not known to have ended, or several later requests are pending at once (parallel steps). A pending request's route never carries it. It is served to every reader of the request and says only where the same approval went: the later step's node id and label and that request's status, never the later request's id, approvers, comments or field values. The `ApprovalRequestRow.flow_route` contract type in `@objectstack/spec/contracts` gains the optional member, and `routeOutcome` in `@objectstack/plugin-approvals` is the rule.
21+
22+
The approval request page (`@object-ui/app-shell`) draws one line under the decided step: "Went on to STEP, waiting for a decision", "Went on to STEP: DECISION", "Went on to STEP, then ended: DECISION", or "The approval ended here". No line is drawn when no outcome is served. `@object-ui/i18n` carries the four new `approvalsInbox` rows in every built-in locale, and the console's request type (`@object-ui/console`) mirrors the new member.
23+
24+
Nothing to migrate: a caller that does not read `outcome` is unaffected.

‎content/docs/automation/approvals.mdx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,41 @@ out-edges, a loop back or a `subflow` / `map` / `loop` node, and `ahead` reads
12161216
`decided` for a request already decided. The older `flow_steps` member is the
12171217
graph's first branch at every decision, not the route; nothing draws it.
12181218

1219+
A decided request's route also says where the record's approval stands now,
1220+
in `outcome`, so its step line can answer "what happened next":
1221+
1222+
```jsonc
1223+
// getRequest, for the manager's request after the manager approved:
1224+
"flow_route": {
1225+
"steps": [{ "id": "manager_review", "label": "Manager", "state": "done" }],
1226+
"ahead": "decided",
1227+
"outcome": {
1228+
"step": { "id": "finance_only", "label": "Finance" }, // the run's latest, later request
1229+
"status": "pending", // it waits on its decision
1230+
"ended": false // the run goes on
1231+
}
1232+
}
1233+
```
1234+
1235+
`step` is the run's latest request opened after this one (a pending one first),
1236+
and is absent when none was opened; `status` is that request's status, or this
1237+
request's own without a `step`; `ended` is `true` only when the record's
1238+
approval is known to have stopped: the request's run is a root run (an approval
1239+
inside a `subflow` or a `map` item runs in a child run, whose end is not the
1240+
approval's), the flow body the run ran holds no `subflow` or `map` node
1241+
anywhere (a child run files its requests under its own run, so the root run's
1242+
requests cannot show what it decided), and the run has stopped for good. The
1243+
body the run ran is known only while the flow has not been registered again
1244+
since the run started: after an edit, a rollback or a restart, older runs are
1245+
not judged by today's body, and their requests are not served "ended". `false`
1246+
means not known to have stopped, including a run that cannot be read. So on a
1247+
flow that starts a child run, a decided request's line names the later steps of
1248+
its own run but never says the approval ended. `outcome` is left out when nothing past
1249+
the request is known: no later request and the approval not known to have
1250+
ended, or several later requests pending at once. Every reader of the request
1251+
gets it; it names only the later step and its status, never that request's
1252+
approvers, comments or field values.
1253+
12191254
Approval **notifications deep-link into the request**: `notify()` rewrites the
12201255
inbox action URL to `/system/approvals?request=<id>`, so clicking the bell opens
12211256
that request's drawer directly instead of a generic list.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ export function registerApprovalNode(
209209
// The node object this run executes: a step naming the platform
210210
// administrators opens only when it belongs to the armed body.
211211
node,
212+
// [#35863] Whether this run is the record's whole approval run or a
213+
// child of another (a `subflow` body or a `map` item: the engine
214+
// links those upward by `$parentRunId`). A child run's end is not
215+
// the end of the record's approval, so a decided route may say
216+
// "ended" only for a root run's request.
217+
runRoot: !hasParentRun(context),
212218
}, {
213219
...SYSTEM_CTX,
214220
userId: context?.userId,
@@ -256,3 +262,13 @@ export function registerApprovalNode(
256262

257263
logger?.info?.('[approvals] approval node executor registered');
258264
}
265+
266+
/**
267+
* [#35863] Whether `context` is a child run's: the engine starts a `subflow`
268+
* body or a `map` item with the parent's run id as `$parentRunId`. Read the
269+
* way the engine's own readers read it (a non-empty string).
270+
*/
271+
function hasParentRun(context: unknown): boolean {
272+
const parent = (context as { $parentRunId?: unknown } | undefined)?.$parentRunId;
273+
return typeof parent === 'string' && parent !== '';
274+
}

‎packages/plugins/plugin-approvals/src/approval-route.test.ts‎

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
* the real engine and a real run, is pinned in `flow-route.integration.test.ts`;
66
* these are the cases a real run reaches rarely or slowly: rounds, other runs,
77
* outcomes that are not a pass, and each kind of branch the walk refuses to
8-
* decide.
8+
* decide. [#35863] Then where a decided request's approval stands now
9+
* (`routeOutcome`): what the run's later rows and its end say, and the cases
10+
* where they say nothing; and which flows can start a child run, whose
11+
* requests those rows never hold (`flowHostsChildRuns`).
912
*/
1013

1114
import { describe, it, expect } from 'vitest';
12-
import { flowRoute, passedSteps, stepsAhead, type RouteFlowGraph } from './approval-route.js';
15+
import { flowHostsChildRuns, flowRoute, passedSteps, routeOutcome, stepsAhead, type RouteFlowGraph } from './approval-route.js';
1316

1417
const label = (id: string) => id.toUpperCase();
1518
const row = (flow_node_id: string, status: string, created_at: string, id = `${flow_node_id}@${created_at}`) =>
@@ -146,3 +149,101 @@ describe('flowRoute — the whole route', () => {
146149
expect(flowRoute({ id: 'x', status: 'pending' }, LINE, runRows, label)).toBeUndefined();
147150
});
148151
});
152+
153+
describe('[#35863] routeOutcome — where the record\'s approval stands after a decided request', () => {
154+
const decided = (status: string, created_at = at(2)) => ({ id: `a@${created_at}`, status, created_at });
155+
156+
it('a later request pending: the approval went on to that step and waits, whatever the run says', () => {
157+
const rows = [row('a', 'approved', at(2)), row('b', 'pending', at(3))];
158+
expect(routeOutcome(decided('approved'), rows, false, label)).toEqual({
159+
step: { id: 'b', label: 'B' }, status: 'pending', ended: false,
160+
});
161+
});
162+
163+
it('the last step decided and the run ended: the approval ended with that step\'s decision', () => {
164+
for (const status of ['approved', 'rejected'] as const) {
165+
const rows = [row('a', 'approved', at(2)), row('b', status, at(3))];
166+
expect(routeOutcome(decided('approved'), rows, true, label), status).toEqual({
167+
step: { id: 'b', label: 'B' }, status, ended: true,
168+
});
169+
}
170+
});
171+
172+
it('no later request and the run ended: the approval ended at this request, with its own decision', () => {
173+
for (const status of ['approved', 'rejected', 'recalled', 'cancelled'] as const) {
174+
expect(routeOutcome(decided(status), [row('a', status, at(2))], true, label), status).toEqual({ status, ended: true });
175+
}
176+
});
177+
178+
it('no later request and the run not ended: nothing is known past this request, so no outcome', () => {
179+
expect(routeOutcome(decided('returned'), [row('a', 'returned', at(2))], false, label)).toBeUndefined();
180+
expect(routeOutcome(decided('approved'), [], false, label)).toBeUndefined();
181+
});
182+
183+
it('a later round of the same node counts: a returned request resubmitted waits at its own step again', () => {
184+
const rows = [row('a', 'returned', at(2)), row('a', 'pending', at(3))];
185+
expect(routeOutcome(decided('returned'), rows, false, label)).toEqual({
186+
step: { id: 'a', label: 'A' }, status: 'pending', ended: false,
187+
});
188+
});
189+
190+
it('a pending later request wins over a decided one opened after it; else the latest decided one', () => {
191+
const rows = [row('b', 'pending', at(3)), row('c', 'rejected', at(4))];
192+
expect(routeOutcome(decided('approved'), rows, false, label)?.step?.id).toBe('b');
193+
const decidedOnly = [row('c', 'approved', at(4)), row('b', 'approved', at(3))];
194+
expect(routeOutcome(decided('approved'), decidedOnly, true, label)?.step?.id).toBe('c');
195+
});
196+
197+
it('several later requests pending at once (parallel steps): no single step, no outcome', () => {
198+
const rows = [row('b', 'pending', at(3)), row('c', 'pending', at(3))];
199+
expect(routeOutcome(decided('approved'), rows, false, label)).toBeUndefined();
200+
});
201+
202+
it('earlier rows, the request itself, and rows with no node, time or status are not later requests', () => {
203+
const rows = [
204+
row('z', 'pending', at(1)),
205+
{ id: 'a@' + at(2), flow_node_id: 'a', status: 'pending', created_at: at(5) },
206+
{ id: 'n1', status: 'pending', created_at: at(3) },
207+
{ id: 'n2', flow_node_id: 'b', status: 'pending' },
208+
{ id: 'n3', flow_node_id: 'b', created_at: at(3) },
209+
];
210+
expect(routeOutcome(decided('approved'), rows, false, label)).toBeUndefined();
211+
expect(routeOutcome({ id: 'x', status: 'approved' }, [row('b', 'pending', at(3))], false, label)).toBeUndefined();
212+
});
213+
214+
it('flowRoute carries it on a decided request only, and only when one is known', () => {
215+
const rows = [row('a', 'approved', at(2)), row('b', 'pending', at(3))];
216+
expect(flowRoute({ id: 'a@' + at(2), flow_node_id: 'a', created_at: at(2), status: 'approved' }, LINE, rows, label)).toEqual({
217+
steps: [{ id: 'a', label: 'A', state: 'done' }],
218+
ahead: 'decided',
219+
outcome: { step: { id: 'b', label: 'B' }, status: 'pending', ended: false },
220+
});
221+
// A pending request is never handed an outcome, even with the run's rows and an ended run.
222+
const pending = flowRoute({ id: 'b@' + at(3), flow_node_id: 'b', created_at: at(3), status: 'pending' }, LINE, rows, label, true);
223+
expect(pending && 'outcome' in pending).toBe(false);
224+
});
225+
});
226+
227+
describe('[#35863] flowHostsChildRuns — a flow whose run may file requests under a child run', () => {
228+
const node = (id: string, type: string, config?: Record<string, unknown>) => ({ id, type, label: id, ...(config ? { config } : {}) });
229+
const region = (...nodes: unknown[]) => ({ nodes, edges: [] });
230+
231+
it('a subflow or a map node at the top level', () => {
232+
expect(flowHostsChildRuns({ nodes: [node('s', 'start'), node('legal', 'subflow'), node('e', 'end')] })).toBe(true);
233+
expect(flowHostsChildRuns({ nodes: [node('s', 'start'), node('each', 'map'), node('e', 'end')] })).toBe(true);
234+
});
235+
236+
it('a subflow or a map node inside a container\'s region, at any depth', () => {
237+
const inLoop = { nodes: [node('l', 'loop', { body: region(node('legal', 'subflow')) })] } as RouteFlowGraph;
238+
const inBranch = { nodes: [node('p', 'parallel', { branches: [region(node('a', 'approval')), region(node('each', 'map'))] })] } as RouteFlowGraph;
239+
const inCatch = { nodes: [node('t', 'try_catch', { try: region(node('a', 'approval')), catch: region(node('legal', 'subflow')) })] } as RouteFlowGraph;
240+
const nested = { nodes: [node('l', 'loop', { body: region(node('t', 'try_catch', { try: region(node('legal', 'subflow')) })) })] } as RouteFlowGraph;
241+
for (const flow of [inLoop, inBranch, inCatch, nested]) expect(flowHostsChildRuns(flow)).toBe(true);
242+
});
243+
244+
it('no such node anywhere: approvals, gateways and in-run containers only', () => {
245+
expect(flowHostsChildRuns({ nodes: [node('s', 'start'), node('a', 'approval'), node('d', 'decision'), node('e', 'end')] })).toBe(false);
246+
expect(flowHostsChildRuns({ nodes: [node('l', 'loop', { body: region(node('a', 'approval')) })] } as RouteFlowGraph)).toBe(false);
247+
expect(flowHostsChildRuns({})).toBe(false);
248+
});
249+
});

0 commit comments

Comments
 (0)