Skip to content

Commit dfa5d67

Browse files
Review over SLA per contract type on the legal workbench (#201)
Fixes #31: clm_contract.review_sla_days_offset is a platform stored expression (0 - record.contract_type.review_sla_days); contract_metrics counts in-review contracts past their own type's SLA via the $now anchor, and the legal workbench shows 审查超时限 with a per-type bar instead of the fixed 30-day tile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017nzWFRUo2U7evMkPdVniAn
1 parent 56ebd41 commit dfa5d67

8 files changed

Lines changed: 147 additions & 60 deletions

File tree

‎src/dashboards/legal.dashboard.ts‎

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import type { Dashboard } from '@objectstack/spec/ui';
7373
export const LegalDashboard: Dashboard = {
7474
name: 'legal_workbench',
7575
label: 'Legal Workbench',
76-
description: 'Intake queue, review load, negotiation stalls, pipeline shape and stage durations for the legal team.',
76+
description: 'Intake queue, review load and SLA breaches, negotiation stalls, pipeline shape and stage durations for the legal team.',
7777

7878
columns: 12,
7979
gap: 4,
@@ -152,49 +152,27 @@ export const LegalDashboard: Dashboard = {
152152
},
153153
{
154154
/**
155-
* The review-ageing tile, at a FIXED 30-day threshold written into its
156-
* own title — which is the brick §09 prescribes here, not a degraded
157-
* stand-in for one. §09 places the per-type「超 SLA」 outside the V1.0
158-
* delivery surface (维护者裁定 2026-09-09, PR #40 `1127e52`; §09 as
159-
* merged, PR #70 `30fd863`) and asks in its place for exactly this: a
160-
* fixed threshold, self-declared in the brick's title.
155+
* DESIGN.md §09's「审查超 SLA」 — contracts in review past their OWN
156+
* type's review SLA (`clm_contract_type.review_sla_days`: 2, 3, 5 or 10
157+
* days across the nine seeded types). It replaces the fixed 30-day tile
158+
* that stood in this slot while the per-type comparison could not be
159+
* written (decision #31: 2B held the stand-in, ruling C kept the goal).
161160
*
162-
* The SLA is PER TYPE (`clm_contract_type.review_sla_days`: 2, 3, 5 or
163-
* 10 days across the nine seeded types), and a breach is a row-wise
164-
* comparison of `review_started_at` against "now minus that type's SLA".
165-
* 18.2.0 added the now-anchored comparand
166-
* (`{ $now: true, addDays: { $field } }`, objectstack#25808), but its
167-
* offset reads a numeric column of the SAME record only. Measured on
168-
* 18.2.0 as the head of legal, `addDays: { $field:
169-
* 'contract_type.review_sla_days' }` answers `400 INVALID_FILTER` — as a
170-
* runtime filter "the addDays offset … is a dotted path, and SQL
171-
* push-down compiles same-table column references only", and as a
172-
* measure filter the same code with the reason withheld — while
173-
* `os validate` passes it. The same anchor with a literal `-30` answers
174-
* 200. So the per-type breach is still not expressible, and this tile
175-
* stays.
176-
*
177-
* ⛔ The remaining route — a persisted `review_due_at` stamped by a daily
178-
* job, the §12 gap-#7 shape — is closed for this metric, and not merely
179-
* unbuilt: §09 forbids filling the per-type breach from an
180-
* application-side job because that replicates a platform rule inside the
181-
* application, and decision #31 ruled the same way on the notification
182-
* side (1C + 2B, 2026-09-09 — see `legal-review-sla.flow.ts`, whose F3
183-
* reminder fires on this same fixed 30 days so the tile and the reminder
184-
* cannot tell two stories).
185-
*
186-
* So the threshold is FIXED, stated in the title, and above every seeded
187-
* SLA: a review older than 30 days is late under any of the nine. The
188-
* title says "Over 30 Days" and not "Over SLA" precisely so the tile
189-
* cannot be read as the per-type breach it is not.
161+
* The count is `review_over_sla_count` on `contract_metrics`, one
162+
* definition for this tile and the per-type chart below. It compares
163+
* `review_started_at` with the platform's `$now` anchor shifted by the
164+
* contract's own `review_sla_days_offset`, which the engine stores from
165+
* the contract type on every write (platform 18.3.0; the anchor's offset
166+
* reads a column of the same record only, objectstack#25808 / #26601).
167+
* Nothing in the app stamps it: no hook, no job (§09's ⛔ on app-side
168+
* stamping holds).
190169
*/
191-
id: 'review_ageing',
192-
title: 'In Review Over 30 Days',
193-
description: 'A fixed 30-day threshold, not each contract type\'s own review SLA.',
170+
id: 'review_over_sla',
171+
title: 'In Review Over SLA',
172+
description: 'Contracts in review for longer than their contract type\'s review SLA.',
194173
type: 'metric',
195174
dataset: 'contract_metrics',
196-
values: ['contract_count'],
197-
filter: { status: 'in_review', review_started_at: { $lt: '{30_days_ago}' } },
175+
values: ['review_over_sla_count'],
198176
colorVariant: 'danger',
199177
layout: { x: 6, y: 0, w: 3, h: 2 },
200178
},
@@ -279,7 +257,7 @@ export const LegalDashboard: Dashboard = {
279257
* The criterion that does discriminate, and the one this filter now
280258
* states: WHETHER LEGAL HAS WORK TO DO ON THE STAGE. This is a work-queue
281259
* board — its first five widgets are `awaiting_intake`, `in_review`,
282-
* `review_ageing`, `negotiation_stalled` and `approval_turnaround`, each
260+
* `review_over_sla`, `negotiation_stalled` and `approval_turnaround`, each
283261
* one a queue or a turnaround. `draft` … `signing` are contracts legal is
284262
* moving; `active`, `expired`, `terminated`, `cancelled` and `rejected`
285263
* are contracts legal has finished moving. Legal's work on an in-force
@@ -462,5 +440,33 @@ export const LegalDashboard: Dashboard = {
462440
values: ['avg_days_to_activation'],
463441
layout: { x: 9, y: 6, w: 3, h: 2 },
464442
},
443+
444+
// ─── Row 4: 超 SLA by contract type ──────────────────────────────────
445+
{
446+
/**
447+
* The over-SLA count split by contract type: each type is judged
448+
* against its own SLA, so this is where a reader sees WHICH SLA is being
449+
* missed. A type with no contract over its SLA is not drawn — measured:
450+
* selected alone, the measure's filter narrows the rows, so such a type
451+
* returns no row rather than a zero. Largest count first, like the
452+
* pipeline chart, so no label decides the order in any locale.
453+
*/
454+
// `chart-config-missing` suppressed for the reason measured on
455+
// `stage_funnel` above: a dataset-bound widget derives its series from
456+
// `dimensions` and `values`.
457+
id: 'review_over_sla_by_type',
458+
title: 'In Review Over SLA by Contract Type',
459+
description: 'Contracts in review for longer than their type\'s review SLA, per contract type. A type with none over its SLA is not shown.',
460+
type: 'horizontal-bar',
461+
dataset: 'contract_metrics',
462+
dimensions: ['contract_type_name'],
463+
values: ['review_over_sla_count'],
464+
options: {
465+
sortBy: 'review_over_sla_count',
466+
sortOrder: 'desc',
467+
},
468+
suppressWarnings: ['chart-config-missing'],
469+
layout: { x: 0, y: 8, w: 12, h: 4 },
470+
},
465471
],
466472
};

‎src/datasets/contract.dataset.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,30 @@ export const ContractDataset = defineDataset({
8383
{ name: 'route_finance_count', label: 'Routes: Finance Controller', aggregate: 'count', filter: { route_finance: true } },
8484
{ name: 'route_executive_count', label: 'Routes: Executive', aggregate: 'count', filter: { route_executive: true } },
8585
{ name: 'route_gm_count', label: 'Routes: General Manager', aggregate: 'count', filter: { route_gm: true } },
86+
87+
// DESIGN.md §09's「审查超 SLA」, per contract type (#31): contracts in review
88+
// whose review started more than their type's `review_sla_days` ago. The
89+
// comparand is the platform's `$now` anchor (objectstack#25808): the instant
90+
// the query runs, shifted by the contract's own `review_sla_days_offset`,
91+
// the type's SLA as a negative number of days, stored on the contract by
92+
// the engine from its type (see the field). Its offset may only name a
93+
// column of the SAME record — a `contract_type.review_sla_days` path is
94+
// refused at `os validate` (objectstack#26601) — hence the stored copy.
95+
//
96+
// A measure filter, not a widget filter, so that every widget counting it
97+
// reads one definition (ADR-0021). The anchor is a cross-field comparand,
98+
// which the native-SQL strategy declines, so this measure is served by the
99+
// engine path, where the SQL driver compiles it. The datetime target keeps
100+
// its time of day: a review started at 09:00 three days ago is over a
101+
// three-day SLA from 09:00 today.
102+
{
103+
name: 'review_over_sla_count',
104+
label: 'In Review Over SLA',
105+
aggregate: 'count',
106+
filter: {
107+
status: 'in_review',
108+
review_started_at: { $lt: { $now: true, addDays: { $field: 'review_sla_days_offset' } } },
109+
},
110+
},
86111
],
87112
});

‎src/datasets/cycle-time.dataset.ts‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,13 @@ import { defineDataset } from '@objectstack/spec/ui';
4242
* per-row difference. ⛔ Do not reintroduce a `derived` difference of two
4343
* stamp aggregates.
4444
*
45-
* ## What it does NOT carry: the per-type「超 SLA」
45+
* ## Where the per-type「超 SLA」 lives instead
4646
*
47-
* The review SLA is per contract TYPE (`clm_contract_type.review_sla_days`).
48-
* Comparing `review_started_at` against "now minus that type's SLA" needs the
49-
* `$now` anchor's offset to read a column across the `contract_type` lookup,
50-
* and 18.2.0's anchor (`objectstack-ai/objectstack#25808`, ruling A) reads a
51-
* numeric column of the SAME record only — a dotted path is refused. The one
52-
* remaining route, a per-contract SLA column the app stamps, is the route
53-
* DESIGN.md §09 forbids. The legal workbench therefore keeps its fixed 30-day
54-
* tile, threshold in the title.
47+
* Not here. It is a COUNT of contracts, not a duration, so it is
48+
* `review_over_sla_count` on `contract_metrics` (#31): `review_started_at`
49+
* against the `$now` anchor shifted by the contract's stored
50+
* `review_sla_days_offset`. The `review_sla_days` dimension below still reads
51+
* the type's SLA through the join, which a dimension may do.
5552
*/
5653
export const CycleTimeDataset = defineDataset({
5754
name: 'contract_cycle_time',

‎src/objects/contract.object.ts‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { P } from '@objectstack/spec';
1+
import { F, P } from '@objectstack/spec';
22
import { ObjectSchema, Field } from '@objectstack/spec/data';
33

44
/**
@@ -18,7 +18,9 @@ import { ObjectSchema, Field } from '@objectstack/spec/data';
1818
* `archived_at`) — the state machine and the F2/F5/F9–F14 flows;
1919
* - the four `ai_*` fields — the "adopt suggestion" action only (DESIGN.md
2020
* §07: AI proposes, a person adopts, the field is written on adoption);
21-
* - `is_backfilled` — the F16 `executed_upload` action only (§13 Q8).
21+
* - `is_backfilled` — the F16 `executed_upload` action only (§13 Q8);
22+
* - `review_sla_days_offset` — no app writer at all: a stored `expression`
23+
* the ENGINE computes from the contract type on every write (#31).
2224
*
2325
* The eight roll-ups (`version_count`, `open_deviation_count`,
2426
* `approved_legal_review_count`, `current_clean_version_count`,
@@ -142,6 +144,41 @@ export const Contract = ObjectSchema.create({
142144
{ label: 'Other', value: 'other', color: '#94A3B8' },
143145
],
144146
}),
147+
// The contract type's review SLA, as the NEGATIVE whole-day offset the
148+
// legal workbench's over-SLA count reads (#31). Two platform facts shape it,
149+
// both measured on 18.3.0:
150+
//
151+
// - The analytics `$now` anchor (`{ $now: true, addDays: { $field } }`,
152+
// objectstack#25808, ruling A; #26601 / #26753 declined the one-hop
153+
// offset) reads its offset from a numeric column of the SAME record, so
154+
// the type's `review_sla_days` has to be on the contract.
155+
// - `addDays` ADDS the column's value and has no `subDays`, so "now minus
156+
// the SLA" is a column holding the negative number — the platform's own
157+
// documented spelling for exactly this count (filter.zod.ts, the `$now`
158+
// example, `review_sla_days_offset`).
159+
//
160+
// A stored `expression`, not a hook stamp: the ENGINE computes it from the
161+
// row each write stores — on every insert, and on every update by id, so
162+
// re-picking the type recomputes it — and a client-sent value never stands.
163+
// It reads one hop through `contract_type`. It does NOT follow an edit of
164+
// the type's own SLA: contracts already in flight keep the SLA they were
165+
// filed under until the contract itself is next written.
166+
//
167+
// `hidden`: a negative number of days means nothing on the record page.
168+
// Identity group, beside the other type-derived fields, and outside the
169+
// `lifecycle`/`routing`/`ai` groups the FLS stamp lock is derived from: a
170+
// stored expression needs no lock (the engine replaces any sent value).
171+
review_sla_days_offset: Field.number({
172+
label: 'Review SLA Offset (days)',
173+
group: 'identity',
174+
readonly: true,
175+
hidden: true,
176+
scale: 0,
177+
min: -90,
178+
max: 0,
179+
expression: F`0 - record.contract_type.review_sla_days`,
180+
description: 'The contract type\'s review SLA as a negative number of days, for the over-SLA count. Computed from the contract type on every save.',
181+
}),
145182
status: Field.select({
146183
label: 'Status',
147184
group: 'identity',

‎src/translations/en/app.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export const appSurface: Pick<TranslationData, 'apps' | 'dashboards' | 'datasets
176176
},
177177
legal_workbench: {
178178
label: 'Legal Workbench',
179-
description: 'Intake queue, review load, negotiation stalls, pipeline shape and stage durations for the legal team.',
179+
description: 'Intake queue, review load and SLA breaches, negotiation stalls, pipeline shape and stage durations for the legal team.',
180180
widgets: {
181181
awaiting_intake: {
182182
title: 'Awaiting Intake',
@@ -186,9 +186,9 @@ export const appSurface: Pick<TranslationData, 'apps' | 'dashboards' | 'datasets
186186
title: 'In Review',
187187
description: 'Contracts a lawyer has accepted and not yet routed',
188188
},
189-
review_ageing: {
190-
title: 'In Review Over 30 Days',
191-
description: 'A fixed 30-day threshold, not each contract type\'s own review SLA.',
189+
review_over_sla: {
190+
title: 'In Review Over SLA',
191+
description: 'Contracts in review for longer than their contract type\'s review SLA.',
192192
},
193193
negotiation_stalled: {
194194
title: 'Waiting on Counterparty',
@@ -218,6 +218,10 @@ export const appSurface: Pick<TranslationData, 'apps' | 'dashboards' | 'datasets
218218
title: 'Signed → Active (Avg Days)',
219219
description: 'Average days from signature to the contract coming into force.',
220220
},
221+
review_over_sla_by_type: {
222+
title: 'In Review Over SLA by Contract Type',
223+
description: 'Contracts in review for longer than their type\'s review SLA, per contract type. A type with none over its SLA is not shown.',
224+
},
221225
},
222226
},
223227
},
@@ -297,6 +301,9 @@ export const appSurface: Pick<TranslationData, 'apps' | 'dashboards' | 'datasets
297301
route_gm_count: {
298302
label: 'Routes: General Manager',
299303
},
304+
review_over_sla_count: {
305+
label: 'In Review Over SLA',
306+
},
300307
},
301308
},
302309
contract_cycle_time: {

‎src/translations/en/objects.contract.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export const contract: Record<string, ObjectTranslationData> = {
5353
other: 'Other',
5454
},
5555
},
56+
review_sla_days_offset: {
57+
label: 'Review SLA Offset (days)',
58+
help: 'The contract type\'s review SLA as a negative number of days, for the over-SLA count. Computed from the contract type on every save.',
59+
},
5660
status: {
5761
label: 'Status',
5862
help: 'Where the contract is in its lifecycle. Status changes follow fixed rules; Expired, Terminated and Cancelled are final.',

‎src/translations/zh-CN/app.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export const appSurface: Pick<TranslationData, 'apps' | 'dashboards' | 'datasets
176176
},
177177
legal_workbench: {
178178
label: '法务工作台',
179-
description: '面向法务团队的待受理队列、审查负荷、谈判停滞、各阶段合同分布与各段时长。',
179+
description: '面向法务团队的待受理队列、审查负荷与超时限、谈判停滞、各阶段合同分布与各段时长。',
180180
widgets: {
181181
awaiting_intake: {
182182
title: '待受理',
@@ -186,9 +186,9 @@ export const appSurface: Pick<TranslationData, 'apps' | 'dashboards' | 'datasets
186186
title: '审查中',
187187
description: '已被法务受理、尚未送审的合同',
188188
},
189-
review_ageing: {
190-
title: '审查超过 30 天',
191-
description: '固定的 30 天阈值,不是各合同类型自己的审查时限。',
189+
review_over_sla: {
190+
title: '审查超时限',
191+
description: '审查用时已超出本类型时限的合同。',
192192
},
193193
negotiation_stalled: {
194194
title: '等待对方',
@@ -218,6 +218,10 @@ export const appSurface: Pick<TranslationData, 'apps' | 'dashboards' | 'datasets
218218
title: '签署 → 生效(平均天数)',
219219
description: '从签署到合同生效,平均用了多少天。',
220220
},
221+
review_over_sla_by_type: {
222+
title: '审查超时限(按合同类型)',
223+
description: '按合同类型统计审查时间已超过该类型审查时限的合同。没有超时限合同的类型不显示。',
224+
},
221225
},
222226
},
223227
},
@@ -297,6 +301,9 @@ export const appSurface: Pick<TranslationData, 'apps' | 'dashboards' | 'datasets
297301
route_gm_count: {
298302
label: '需经:总经理',
299303
},
304+
review_over_sla_count: {
305+
label: '审查超时限',
306+
},
300307
},
301308
},
302309
contract_cycle_time: {

‎src/translations/zh-CN/objects.contract.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export const contract: Record<string, ObjectTranslationData> = {
5353
other: '其他',
5454
},
5555
},
56+
review_sla_days_offset: {
57+
label: '审查时限偏移(天)',
58+
help: '合同类型的审查时限,取负的天数,供「审查超时限」统计使用。每次保存时按合同类型重新计算。',
59+
},
5660
status: {
5761
label: '状态',
5862
help: '合同所处的生命周期环节。状态只能按规定的路径流转;已到期、已终止、已作废是终态。',

0 commit comments

Comments
 (0)