Skip to content

Commit d98ceea

Browse files
A refused renewal, backfill or launch says only why (#170)
Fixes #156: every hotclm flow refusal is an end node with outcome refused and a translated message (objectstack#15788 / #22450) instead of a throwing script; clm_backfill_refuse and clm_intake_refuse are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017nzWFRUo2U7evMkPdVniAn
1 parent e7b56da commit d98ceea

6 files changed

Lines changed: 138 additions & 140 deletions

File tree

‎src/flows/contract-intake.flow.ts‎

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ import { must, ref } from './_values.js';
5858
* surface and `POST /api/v1/actions/...` are actually built from; every
5959
* flow input is an `isInput` variable and a declared action param, so a
6060
* caller that supplies them all completes the run with no screen.
61-
* - Refusals (`clm_intake_refuse`, registered under `functions`) FAIL the run
62-
* with the message: a paused "refusal screen" would leave a headless run
63-
* parked forever, and the console shows a failed run's error as the toast.
61+
* - Refusals are `end` nodes declaring `outcome: 'refused'` with the sentence
62+
* the requester reads (objectstack#15788): the run ends `refused`, never
63+
* parked, so a headless caller is answered at once; the console shows the
64+
* sentence alone, with no success toast. Each one sits before any screen
65+
* and before the first write, so a refused launch leaves nothing behind.
6466
* - The first version's file has two headless spellings — `draft_from_template`
6567
* (the type's `template_file` becomes v1, kind `draft`) or a pre-uploaded
6668
* `first_version_file` id — and one interactive one: an OBJECT-FORM screen
@@ -99,8 +101,9 @@ import { must, ref } from './_values.js';
99101
* create still be refused, it fails ATOMICALLY: `create_party` runs before
100102
* any other write, so the run leaves nothing behind.
101103
*
102-
* Flow copy is English-only (the source language, DESIGN.md §01); a flow has
103-
* no entry in the translation bundles.
104+
* Flow copy is authored in English (the source language, DESIGN.md §01); the
105+
* zh-CN text of each screen and each refusal is its key under
106+
* `flows.contract_intake` in `src/translations/zh-CN/flows.ts`.
104107
*/
105108

106109
interface SelectLike {
@@ -122,27 +125,6 @@ const INTAKE_FIELD_NAMES = ['governing_law', 'payment_terms', 'confidentiality_t
122125
/** Bare CEL over the screen's own fields: shown only when the type lists the field. */
123126
const askedFor = (field: (typeof INTAKE_FIELD_NAMES)[number]): string => `"${field}" in intakeFields`;
124127

125-
/**
126-
* The one registered function of the flow: fail the run with a structured
127-
* refusal that names what was refused. A `script` node is the only node that
128-
* can end a run with a computed message.
129-
*/
130-
export function refuseIntake({ input }: { input: Record<string, unknown> }): never {
131-
const kind = typeof input.kind === 'string' ? input.kind : 'invalid';
132-
const name = typeof input.name === 'string' && input.name ? input.name : 'the counterparty';
133-
const note = typeof input.note === 'string' && input.note.trim() ? input.note.trim() : '';
134-
const MESSAGES: Record<string, string> = {
135-
no_type: 'A contract type is required to launch a contract.',
136-
type_unavailable: 'The chosen contract type does not exist or is inactive; pick an active type.',
137-
party_missing: `Counterparty ${name} does not exist.`,
138-
party_blocked: `Counterparty ${name} is blocked and cannot be put on a new contract${note ? `: ${note}` : '.'}`,
139-
};
140-
const err = new Error(MESSAGES[kind] ?? 'The contract cannot be launched.') as Error & { code: string; status: number };
141-
err.code = kind === 'party_missing' ? 'INVALID_REFERENCE' : 'INVALID_STATE';
142-
err.status = 422;
143-
throw err;
144-
}
145-
146128
// Decided ONCE, before any screen: a headless caller binds `title` up front,
147129
// a person answers it on the core screen — so after that screen the test
148130
// would flip, which is why `interactive` is bound by an assignment on each
@@ -198,17 +180,17 @@ export const ContractIntakeFlow: Flow = {
198180
// ── Step 1: the type decides everything after it ─────────────────────
199181
{ id: 'decision_type_given', type: 'decision', label: 'Type Chosen?' },
200182
{
201-
id: 'refuse_no_type', type: 'script', label: 'Refuse: No Type',
202-
config: { function: 'clm_intake_refuse', inputs: { kind: 'no_type' } },
183+
id: 'refuse_no_type', type: 'end', label: 'Refuse: No Type',
184+
config: { outcome: 'refused', message: 'A contract type is required to launch a contract.' },
203185
},
204186
{
205187
id: 'get_type', type: 'get_record', label: 'Load Contract Type',
206188
config: { objectName: 'clm_contract_type', filter: { id: must('contract_type') }, outputVariable: 'typeRecord' },
207189
},
208190
{ id: 'decision_type_ok', type: 'decision', label: 'Type Active?' },
209191
{
210-
id: 'refuse_type', type: 'script', label: 'Refuse: Type Unavailable',
211-
config: { function: 'clm_intake_refuse', inputs: { kind: 'type_unavailable' } },
192+
id: 'refuse_type', type: 'end', label: 'Refuse: Type Unavailable',
193+
config: { outcome: 'refused', message: 'The chosen contract type does not exist or is inactive; pick an active type.' },
212194
},
213195
// Both branches bind `templateAvailable`, so no later read meets an
214196
// unbound variable (the house rule of the flow-variable conditions table
@@ -316,17 +298,23 @@ export const ContractIntakeFlow: Flow = {
316298
id: 'get_party', type: 'get_record', label: 'Load Counterparty',
317299
config: { objectName: 'clm_party', filter: { id: must('party') }, outputVariable: 'partyRecord' },
318300
},
319-
// The blocked-party refusal, and its two neighbours: a party that does not
320-
// resolve is refused too, and a clean one is used. The three edge
321-
// predicates partition every record shape.
301+
// The blocked-party refusal, and its neighbours: a party that does not
302+
// resolve is refused too, and a clean one is used. A blocked party's
303+
// refusal quotes legal's risk note when there is one, so it has two ends —
304+
// a `{{ }}` hole cannot drop its own punctuation. The four edge predicates
305+
// partition every record shape.
322306
{ id: 'decision_party_state', type: 'decision', label: 'Counterparty Blocked?' },
323307
{
324-
id: 'refuse_party_missing', type: 'script', label: 'Refuse: Counterparty Missing',
325-
config: { function: 'clm_intake_refuse', inputs: { kind: 'party_missing', name: ref('party') } },
308+
id: 'refuse_party_missing', type: 'end', label: 'Refuse: Counterparty Missing',
309+
config: { outcome: 'refused', message: 'Counterparty {{ party }} does not exist.' },
310+
},
311+
{
312+
id: 'refuse_blocked', type: 'end', label: 'Refuse: Counterparty Blocked',
313+
config: { outcome: 'refused', message: 'Counterparty {{ partyRecord.name }} is blocked and cannot be put on a new contract: {{ partyRecord.risk_note }}' },
326314
},
327315
{
328-
id: 'refuse_blocked', type: 'script', label: 'Refuse: Counterparty Blocked',
329-
config: { function: 'clm_intake_refuse', inputs: { kind: 'party_blocked', name: ref('partyRecord.name'), note: ref('partyRecord.risk_note') } },
316+
id: 'refuse_blocked_no_note', type: 'end', label: 'Refuse: Counterparty Blocked (No Note)',
317+
config: { outcome: 'refused', message: 'Counterparty {{ partyRecord.name }} is blocked and cannot be put on a new contract.' },
330318
},
331319
{ id: 'use_picked_party', type: 'assignment', label: 'Use Picked Counterparty', config: { assignments: { partyId: ref('partyRecord.id') } } },
332320

@@ -487,7 +475,8 @@ export const ContractIntakeFlow: Flow = {
487475
{ id: 'e18b', source: 'decision_party_precheck', target: 'decision_core_screen', type: 'default', condition: P`!has(vars.party) || vars.party == null || vars.party == ""`, label: 'Not picked' },
488476
{ id: 'e23', source: 'get_party', target: 'decision_party_state', type: 'default' },
489477
{ id: 'e24', source: 'decision_party_state', target: 'refuse_party_missing', type: 'default', condition: P`vars.partyRecord == null`, label: 'Missing' },
490-
{ id: 'e25', source: 'decision_party_state', target: 'refuse_blocked', type: 'default', condition: P`vars.partyRecord != null && has(vars.partyRecord.risk_flag) && vars.partyRecord.risk_flag == "blocked"`, label: 'Blocked' },
478+
{ id: 'e25', source: 'decision_party_state', target: 'refuse_blocked', type: 'default', condition: P`vars.partyRecord != null && has(vars.partyRecord.risk_flag) && vars.partyRecord.risk_flag == "blocked" && has(vars.partyRecord.risk_note) && vars.partyRecord.risk_note != null && vars.partyRecord.risk_note != ""`, label: 'Blocked, with a note' },
479+
{ id: 'e25b', source: 'decision_party_state', target: 'refuse_blocked_no_note', type: 'default', condition: P`vars.partyRecord != null && has(vars.partyRecord.risk_flag) && vars.partyRecord.risk_flag == "blocked" && (!has(vars.partyRecord.risk_note) || vars.partyRecord.risk_note == null || vars.partyRecord.risk_note == "")`, label: 'Blocked' },
491480
{ id: 'e26', source: 'decision_party_state', target: 'use_picked_party', type: 'default', condition: P`vars.partyRecord != null && (!has(vars.partyRecord.risk_flag) || vars.partyRecord.risk_flag != "blocked")`, label: 'Clear' },
492481
{ id: 'e28', source: 'use_picked_party', target: 'decision_core_screen', type: 'default' },
493482
{ id: 'e27a', source: 'decision_core_screen', target: 'screen_core', type: 'default', condition: INTERACTIVE, label: 'Interactive' },
@@ -519,12 +508,5 @@ export const ContractIntakeFlow: Flow = {
519508
{ id: 'e45', source: 'decision_submit', target: 'submit_contract', type: 'default', condition: P`vars.submit_now == true`, label: 'Submit' },
520509
{ id: 'e46', source: 'decision_submit', target: 'end', type: 'default', condition: P`vars.submit_now != true`, label: 'Keep draft' },
521510
{ id: 'e47', source: 'submit_contract', target: 'end', type: 'default' },
522-
// Every refusal ends the run; a script node that throws fails it with
523-
// its message, so these edges are only ever reached by a function that
524-
// returned — which `clm_intake_refuse` never does.
525-
{ id: 'e48', source: 'refuse_no_type', target: 'end', type: 'default' },
526-
{ id: 'e49', source: 'refuse_type', target: 'end', type: 'default' },
527-
{ id: 'e50', source: 'refuse_party_missing', target: 'end', type: 'default' },
528-
{ id: 'e51', source: 'refuse_blocked', target: 'end', type: 'default' },
529511
],
530512
};

‎src/flows/executed-upload.flow.ts‎

Lines changed: 58 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -58,71 +58,55 @@ import { must, ref } from './_values.js';
5858
* action that collected a file and discarded it would be the "capability the
5959
* runtime does not deliver" AGENTS.md forbids. `version_count` then reads 1,
6060
* which is true.
61+
*
62+
* ## Refusals are refused `end` nodes
63+
*
64+
* A backfill the flow will not record ends at an `end` node declaring
65+
* `outcome: 'refused'` with the sentence the clerk reads
66+
* (objectstack#15788). The run records `refused`, not `failed`, the invoking
67+
* action's "Executed contract recorded." is suppressed, and the console shows
68+
* the sentence alone. Each sentence's other-language text is the
69+
* `flows.executed_upload.refusals.<node_id>.message` key
70+
* (objectstack#22450), which is why the signing date has three refusing ends
71+
* rather than one end echoing a computed string: a sentence assembled in a
72+
* function has no key to translate it. Every refusal sits before the first
73+
* write, so a refused run writes nothing.
6174
*/
6275

76+
/** Why a signing date cannot be recorded: the decision below routes each to its own refusal. */
77+
export type SigningDateProblem = 'missing' | 'invalid' | 'future';
78+
6379
/** Parse a `YYYY-MM-DD` (or ISO) signing date to a UTC instant, or null. */
6480
export function backfillStamps({ input }: { input: Record<string, unknown> }): {
6581
signedAt: string | null;
6682
ok: boolean;
67-
problem: string | null;
83+
problem: SigningDateProblem | null;
6884
} {
6985
const raw = input.signedDate;
7086
const text = typeof raw === 'string' ? raw.trim() : raw instanceof Date ? raw.toISOString() : '';
7187
if (!text) {
72-
return { signedAt: null, ok: false, problem: 'A signing date is required: a backfilled contract is one that was already executed, and the date it was executed is the fact being recorded.' };
88+
return { signedAt: null, ok: false, problem: 'missing' };
7389
}
7490
// A date-only value is midday UTC rather than midnight, so the calendar day
7591
// survives a reader in any timezone — the same trap the `date` vs `datetime`
7692
// split creates everywhere in this model.
7793
const iso = /^\d{4}-\d{2}-\d{2}$/.test(text) ? `${text}T12:00:00.000Z` : text;
7894
const ms = Date.parse(iso);
7995
if (!Number.isFinite(ms)) {
80-
return { signedAt: null, ok: false, problem: `The signing date "${text}" is not a date.` };
96+
return { signedAt: null, ok: false, problem: 'invalid' };
8197
}
8298
if (ms > Date.now()) {
83-
return { signedAt: null, ok: false, problem: 'The signing date is in the future. A backfill records a contract that has already been executed.' };
99+
return { signedAt: null, ok: false, problem: 'future' };
84100
}
85101
return { signedAt: new Date(ms).toISOString(), ok: true, problem: null };
86102
}
87103

88-
/**
89-
* The refusal channel, and why it is a THROWING `script` node rather than an
90-
* `end` node carrying `outcome: 'refused'`.
91-
*
92-
* The spec declares that refusal contract (`EndConfigSchema`) and its own text
93-
* says the halves land in sequence: "this contract, then the engine's `end`
94-
* handling (stamping the outcome, persisting the rendered message), then the
95-
* runner." MEASURED on the pinned 17.4.0 runtime, the second half has not
96-
* landed: a run that took the refusing edge recorded `status: "completed"` in
97-
* `GET /api/v1/automation/executed_upload/runs`, carried no `refusalMessage`,
98-
* and the invoking action's `successMessage` was NOT suppressed — so a
99-
* backfill refused for a future signing date answered HTTP 200 with
100-
* "Executed contract recorded." while recording nothing. The guard protected
101-
* the data and lied to the clerk, which is precisely the dishonest capability
102-
* AGENTS.md forbids.
103-
*
104-
* The engine half is `objectstack-ai/objectstack#15788` — open, "lane 2 of the
105-
* #14945 ruling 2′" — so this is a platform gap already on the record, not one
106-
* to file again and not one to patch here (AGENTS.md: report, never patch).
107-
* When it lands, these two nodes can go back to being `end` nodes.
108-
*
109-
* `contract_intake` (F1) already refuses this way in this very directory —
110-
* `clm_intake_refuse` — because a `script` node is the only node that can end
111-
* a run with a message the caller actually receives. Same idiom, same
112-
* ADR-0112 envelope (`code` + `status`), so both flows refuse alike.
113-
*/
114-
export function refuseBackfill({ input }: { input: Record<string, unknown> }): never {
115-
const message = typeof input.message === 'string' && input.message.trim()
116-
? input.message.trim()
117-
: 'This contract cannot be backfilled.';
118-
const err = new Error(message) as Error & { code: string; status: number };
119-
err.code = typeof input.code === 'string' && input.code ? input.code : 'INVALID_STATE';
120-
err.status = 422;
121-
throw err;
122-
}
123-
124104
const DATE_OK = 'has(vars.stamps) && vars.stamps.ok == true';
125-
const DATE_BAD = '!has(vars.stamps) || vars.stamps.ok != true';
105+
// The three refusals partition the unusable dates; an unbound `stamps` is read
106+
// as a missing date.
107+
const DATE_MISSING = '!has(vars.stamps) || (vars.stamps.ok != true && vars.stamps.problem != "invalid" && vars.stamps.problem != "future")';
108+
const DATE_INVALID = 'has(vars.stamps) && vars.stamps.ok != true && vars.stamps.problem == "invalid"';
109+
const DATE_FUTURE = 'has(vars.stamps) && vars.stamps.ok != true && vars.stamps.problem == "future"';
126110
const PARTY_OK = 'has(vars.partyRecord) && vars.partyRecord != null && has(vars.partyRecord.id) && vars.partyRecord.risk_flag != "blocked"';
127111
const PARTY_BAD = '!has(vars.partyRecord) || vars.partyRecord == null || !has(vars.partyRecord.id) || vars.partyRecord.risk_flag == "blocked"';
128112

@@ -171,13 +155,31 @@ export const ExecutedUploadFlow: Flow = {
171155
config: { function: 'clm_backfill_stamps', inputs: { signedDate: ref('signed_date') }, outputVariable: 'stamps' },
172156
},
173157
{ id: 'decide_date', type: 'decision', label: 'Signing Date Usable?' },
158+
// The three ways a signing date is refused, each the sentence the clerk
159+
// reads (see the header for why there are three).
174160
{
175-
id: 'refuse_date',
176-
type: 'script',
177-
label: 'Refuse — Signing Date',
178-
// The message `check_date` computed, handed back to the caller. See
179-
// `refuseBackfill` for why this is a throwing script and not an `end`.
180-
config: { function: 'clm_backfill_refuse', inputs: { message: ref('stamps.problem'), code: 'VALIDATION_FAILED' } },
161+
id: 'refuse_date_missing',
162+
type: 'end',
163+
label: 'Refuse — No Signing Date',
164+
config: {
165+
outcome: 'refused',
166+
message: 'A signing date is required: a backfilled contract is one that was already executed, and the date it was executed is the fact being recorded.',
167+
},
168+
},
169+
{
170+
id: 'refuse_date_invalid',
171+
type: 'end',
172+
label: 'Refuse — Signing Date Unreadable',
173+
config: { outcome: 'refused', message: 'The signing date "{{ signed_date }}" is not a date.' },
174+
},
175+
{
176+
id: 'refuse_date_future',
177+
type: 'end',
178+
label: 'Refuse — Signing Date In The Future',
179+
config: {
180+
outcome: 'refused',
181+
message: 'The signing date is in the future. A backfill records a contract that has already been executed.',
182+
},
181183
},
182184

183185
{
@@ -194,17 +196,14 @@ export const ExecutedUploadFlow: Flow = {
194196
{ id: 'decide_party', type: 'decision', label: 'Counterparty Usable?' },
195197
{
196198
id: 'refuse_party',
197-
type: 'script',
199+
type: 'end',
198200
label: 'Refuse — Counterparty',
201+
// The same refusal `draft → submitted` makes in `contract.hook.ts`,
202+
// repeated here because the backfill never passes that guard: a blocked
203+
// counterparty is blocked whichever door the contract came in.
199204
config: {
200-
// The same refusal `draft → submitted` makes in `contract.hook.ts`,
201-
// repeated here because the backfill never passes that guard: a
202-
// blocked counterparty is blocked whichever door the contract came in.
203-
function: 'clm_backfill_refuse',
204-
inputs: {
205-
message: 'That counterparty cannot be used: it is either missing or flagged blocked. A contract with a blocked counterparty is not recorded, even retrospectively.',
206-
code: 'INVALID_REFERENCE',
207-
},
205+
outcome: 'refused',
206+
message: 'That counterparty cannot be used: it is either missing or flagged blocked. A contract with a blocked counterparty is not recorded, even retrospectively.',
208207
},
209208
},
210209

@@ -280,18 +279,14 @@ export const ExecutedUploadFlow: Flow = {
280279
edges: [
281280
{ id: 'b1', source: 'start', target: 'check_date', type: 'default' },
282281
{ id: 'b2', source: 'check_date', target: 'decide_date', type: 'default' },
283-
{ id: 'b3', source: 'decide_date', target: 'refuse_date', type: 'default', label: 'Unusable', condition: DATE_BAD },
282+
{ id: 'b3', source: 'decide_date', target: 'refuse_date_missing', type: 'default', label: 'Missing', condition: DATE_MISSING },
283+
{ id: 'b3a', source: 'decide_date', target: 'refuse_date_invalid', type: 'default', label: 'Not a date', condition: DATE_INVALID },
284+
{ id: 'b3b', source: 'decide_date', target: 'refuse_date_future', type: 'default', label: 'In the future', condition: DATE_FUTURE },
284285
{ id: 'b4', source: 'decide_date', target: 'get_party', type: 'default', label: 'Usable', condition: DATE_OK },
285286
{ id: 'b5', source: 'get_party', target: 'decide_party', type: 'default' },
286287
{ id: 'b6', source: 'decide_party', target: 'refuse_party', type: 'default', label: 'Missing or blocked', condition: PARTY_BAD },
287288
{ id: 'b7', source: 'decide_party', target: 'create_contract', type: 'default', label: 'Usable', condition: PARTY_OK },
288289
{ id: 'b8', source: 'create_contract', target: 'file_executed_copy', type: 'default' },
289290
{ id: 'b9', source: 'file_executed_copy', target: 'end', type: 'default' },
290-
291-
// Never traversed: `clm_backfill_refuse` throws, so the run ends at the
292-
// refusal. The edges exist so the graph has no dangling node, exactly as
293-
// `contract_intake` wires its four refusals.
294-
{ id: 'b10', source: 'refuse_date', target: 'end', type: 'default' },
295-
{ id: 'b11', source: 'refuse_party', target: 'end', type: 'default' },
296291
],
297292
};

0 commit comments

Comments
 (0)