Skip to content
15 changes: 15 additions & 0 deletions .changeset/35114-stdio-mcp-dropped-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/mcp': patch
'@objectstack/lint': patch
---

fix(mcp, lint): `create_record` and `update_record` over stdio answer `droppedFields` and no longer echo a dropped value; a flow write to a roll-up summary field draws a warning

Clause-②: yes
Metadata-protocol: none

On the stdio MCP transport, `create_record` and `update_record` now answer `droppedFields`, as the HTTP transport has: each entry names the object, the fields the engine did not store and the reason. A non-system write of a `readonly: true` column or of a roll-up `summary` field (read-only on create and update whether or not it declares `readonly: true`) reports the field there with reason `readonly`. Before, the stdio answer carried no `droppedFields`, and `update_record` answered the caller's own value for such a field over the stored one, so the answer read as if the write had landed. The `record` in both answers now leaves a dropped key's caller value out: an update answers the stored value, and a create answers what the write stored. A write that drops nothing answers as before, with no `droppedFields` key. No MCP tool input, `@objectstack/mcp` export or metadata key changes.

`os validate`, `os lint` and `os build` now report a new warning, `flow-update-summary-field`, when a flow's `create_record` or `update_record` node that does not run as `runAs: 'system'` writes a roll-up `summary` field that does not declare `readonly: true`. The engine drops that value on create and on update, so the step changes nothing in that column. It is a warning, so no build that passes today fails. Like every warning, it makes `os validate --strict` and `os lint --strict` exit 1; there is no per-rule switch, so a strict run fails until the field is removed from the node. The metadata save and publish answers carry it under `advisories`, never as a refusal: on a flow save whose user-run node writes such a roll-up, and on an object save that makes a field such a roll-up while a live user-run flow of the same package writes it. A roll-up that declares `readonly: true` is reported as `flow-update-readonly-field`, an error, as before. `os explain flow-update-summary-field` gives the details. The fix is to remove the field from the node, since the engine recomputes it from the child records.

New export: `FLOW_UPDATE_SUMMARY_FIELD` from `@objectstack/lint`, the rule id constant.
11 changes: 8 additions & 3 deletions content/docs/data-modeling/fields.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,14 @@ when multiple relationships target the same parent object.

A summary field is read-only on create and on update whether or not it declares
`readonly: true`. A value that a `POST`, an import (any `writeMode`), an MCP
create, a `PATCH` or a bulk update sends for it is dropped, the rest of the write
is stored, and the response's `droppedFields` names the field with reason
`readonly`. A record created that way starts as if no value had been sent: `0`
create or update (over HTTP or stdio), a `PATCH` or a bulk update sends for it
is dropped, the rest of the write is stored, and the response's `droppedFields`
names the field with reason `readonly`. Two more doors end in the same create
and drop the value the same way: the `overrides` of a clone, whose answer names
the field in `droppedFields` as a create's does, and a public form submission,
which is anonymous and answers with the created record's id alone, so the
person who submitted it is not shown the drop. A record created with its value
dropped starts as if no value had been sent: `0`
for `count` and `sum`, empty for `min`, `max` and `avg`, and the next child write
replaces it with the computed value. Under `strictReadonlyWrites` the whole write
is refused. Server code that runs with `isSystem: true` can still write the
Expand Down
13 changes: 13 additions & 0 deletions content/docs/protocol/objectql/security.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ rejecting — the offending key is removed from the payload and the rest of the
committed. The write therefore **succeeds** (REST answers `200`), and the read-only column
simply keeps its stored value.

**A roll-up `summary` field carries this lock implicitly**, whether or not it declares
`readonly: true`: the engine computes its value from the child records, so it reads every
roll-up as `readonly: true` on create and on update. A value a non-system write sends for one
is dropped and reported under the same `readonly` reason, and `strictReadonlyWrites` refuses
the write, exactly as for a declared read-only column; a create that had the value dropped
starts the column as for an empty child list. That covers a flow's `create_record` and
`update_record` steps that do not run as `runAs: 'system'`; `os validate`, `os lint` and
`os build` report such a step as the `flow-update-summary-field` warning, which never blocks a
build, though like every warning it makes `os validate --strict` and `os lint --strict` exit 1
(a roll-up declared `readonly: true` is the `flow-update-readonly-field` error). Rule 1 below
holds for it: seed data, package installs and the roll-up's own recompute write it from a
system context. See [Calculation types](/docs/data-modeling/fields#calculation-types).

Five rules decide whether a given value survives:

| # | Rule | Effect |
Expand Down
1 change: 1 addition & 0 deletions packages/lint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export {
validateReadonlyFlowWrites,
FLOW_UPDATE_READONLY_FIELD,
FLOW_UPDATE_READONLY_WHEN_FIELD,
FLOW_UPDATE_SUMMARY_FIELD,
} from './validate-readonly-flow-writes.js';
export type {
ReadonlyFlowWriteFinding,
Expand Down
22 changes: 22 additions & 0 deletions packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,27 @@ const FLOW_UPDATE_READONLY_WHEN_FIELD_EXPLANATION: RuleExplanation = {
],
};

const FLOW_UPDATE_SUMMARY_FIELD_EXPLANATION: RuleExplanation = {
rule: 'flow-update-summary-field',
covers: 'why a roll-up summary field write is dropped',
paragraphs: [
FLOW_FIELDS_CALLER_PAYLOAD,
'A roll-up `summary` field is computed by the engine from its child records, so the engine treats it ' +
'as `readonly: true` on create and on update whether or not the field declares it. A value a ' +
'non-system write sends for it is dropped, the rest of the write lands, the step still reports ' +
'success and the drop is reported as `readonly`; under `strictReadonlyWrites` the whole write is ' +
'refused. A created record starts the column as if no child record existed: `0` for `count` and ' +
'`sum`, empty for `min`, `max` and `avg`.',
'Reported as a warning, so it never blocks a build. A roll-up that declares `readonly: true` is ' +
'reported as `flow-update-readonly-field` instead, which does. A `runAs: \'system\'` flow writes the ' +
'column and is not reported, and neither is a create on a platform object, which the create-side ' +
'strip does not judge.',
'To fix it, remove the field from the node: the engine recomputes the value whenever a child record ' +
'is created, changed or deleted. To change what it adds up, change the child records or the ' +
'roll-up\'s `summaryOperations`.',
],
};

const HOOK_API_UPDATE_READONLY_FIELD_EXPLANATION: RuleExplanation = {
rule: 'hook-api-update-readonly-field',
covers: 'why a readonly field write is silently dropped',
Expand Down Expand Up @@ -6469,6 +6490,7 @@ export const RULE_EXPLANATIONS: Readonly<Record<string, RuleExplanation>> = Obje
[FLOW_NODE_WRITE_UNPROVISIONED_ANCHOR_EXPLANATION.rule]: FLOW_NODE_WRITE_UNPROVISIONED_ANCHOR_EXPLANATION,
[FLOW_UPDATE_READONLY_FIELD_EXPLANATION.rule]: FLOW_UPDATE_READONLY_FIELD_EXPLANATION,
[FLOW_UPDATE_READONLY_WHEN_FIELD_EXPLANATION.rule]: FLOW_UPDATE_READONLY_WHEN_FIELD_EXPLANATION,
[FLOW_UPDATE_SUMMARY_FIELD_EXPLANATION.rule]: FLOW_UPDATE_SUMMARY_FIELD_EXPLANATION,
[HOOK_API_UPDATE_READONLY_FIELD_EXPLANATION.rule]: HOOK_API_UPDATE_READONLY_FIELD_EXPLANATION,
[HOOK_API_UPDATE_READONLY_WHEN_FIELD_EXPLANATION.rule]: HOOK_API_UPDATE_READONLY_WHEN_FIELD_EXPLANATION,
[ACTION_API_UPDATE_READONLY_WHEN_FIELD_EXPLANATION.rule]: ACTION_API_UPDATE_READONLY_WHEN_FIELD_EXPLANATION,
Expand Down
95 changes: 95 additions & 0 deletions packages/lint/src/validate-readonly-flow-writes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
validateReadonlyFlowWrites as validateReadonlyFlowWritesUnrecorded,
FLOW_UPDATE_READONLY_FIELD,
FLOW_UPDATE_READONLY_WHEN_FIELD,
FLOW_UPDATE_SUMMARY_FIELD,
} from './validate-readonly-flow-writes.js';
import { explainRule } from './rule-explanations.js';
import { ObjectSchema } from '@objectstack/spec/data';
Expand Down Expand Up @@ -828,3 +829,97 @@ describe('[#22161] one-line fixes — the rule ids this file shortened', () => {
for (const fact of MOVED_FROM_FIX[rule]) expect(text, `${rule} explanation names ${fact}`).toContain(fact);
});
});

// [#35114] The implicit roll-up lock: the engine reads every `summary` field as
// `readonly: true` on create and on update, declared or not, so a non-system
// flow write of one is dropped. Reported at its own id as a WARNING (area
// ruling, claim amendment 7035408057, option B), never as the static id's
// ERROR, so a build that passed before keeps passing.
describe('validateReadonlyFlowWrites · a roll-up summary field without readonly: true', () => {
const accountObject = {
name: 'crm_account',
label: 'Account',
fields: {
name: { type: 'text' },
// The card's shape: a roll-up with no `readonly`.
order_total: { type: 'summary', summaryOperations: { object: 'crm_order', field: 'amount', function: 'sum' } },
// A roll-up its author did declare read-only: the static branch's.
order_count: { type: 'summary', readonly: true, summaryOperations: { object: 'crm_order', function: 'count' } },
credit_status: { type: 'text', readonly: true },
},
};

/** A flow with one `nodeType` node writing `fields` on the account. */
const flowWriting = (nodeType: 'create_record' | 'update_record', fields: Record<string, unknown>, runAs?: string) => ({
name: 'sync_account',
type: 'record_change',
...(runAs ? { runAs } : {}),
nodes: [
{ id: 'start', type: 'start', config: {} },
{
id: 'w',
type: nodeType,
label: 'Write account',
config: {
objectName: 'crm_account',
...(nodeType === 'update_record' ? { filter: { id: { dialect: 'cel', source: 'recordId' } } } : {}),
fields,
},
},
],
edges: [],
});

it.each(['create_record', 'update_record'] as const)('a %s writing the roll-up under a user run: one warning, at its own id', (nodeType) => {
const findings = validateReadonlyFlowWrites({
objects: [accountObject],
flows: [flowWriting(nodeType, { name: 'Acme', order_total: 100 })],
});
expect(findings).toHaveLength(1);
expect(findings[0]).toMatchObject({
severity: 'warning',
rule: FLOW_UPDATE_SUMMARY_FIELD,
path: 'flows[0].nodes[1].config.fields.order_total',
where: 'flow "sync_account" › node "Write account"',
});
expect(findings[0].message).toContain("roll-up summary field 'order_total' of object 'crm_account'");
expect(findings[0].message).toContain('on create and update alike');
expect(findings[0].message).not.toContain('\n');
expect(findings[0].message.length).toBeLessThanOrEqual(200);
expect(findings[0].hint).toContain(nodeType);
expect(findings[0].hint.length).toBeLessThanOrEqual(200);
});

it('control: a declared readonly field, roll-up or not, is still the static id at error', () => {
const findings = validateReadonlyFlowWrites({
objects: [accountObject],
flows: [flowWriting('update_record', { order_count: 3, credit_status: 'hold' }, 'user')],
});
expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([
[FLOW_UPDATE_READONLY_FIELD, 'error', 'flows[0].nodes[1].config.fields.order_count'],
[FLOW_UPDATE_READONLY_FIELD, 'error', 'flows[0].nodes[1].config.fields.credit_status'],
]);
});

it('control: a write to a field that is not a roll-up draws nothing', () => {
const findings = validateReadonlyFlowWrites({
objects: [accountObject],
flows: [flowWriting('update_record', { name: 'Acme' }), flowWriting('create_record', { name: 'Acme' })],
});
expect(findings).toEqual([]);
});

it.each(['create_record', 'update_record'] as const)('control: a runAs:system %s writing the roll-up draws nothing', (nodeType) => {
const findings = validateReadonlyFlowWrites({
objects: [accountObject],
flows: [flowWriting(nodeType, { order_total: 100 }, 'system')],
});
expect(findings).toEqual([]);
});

it('`os explain flow-update-summary-field` says the engine drops it on both verbs and that it never blocks a build', () => {
const text = explanationOf(FLOW_UPDATE_SUMMARY_FIELD);
expect(text).toContain('on create and on update');
expect(text).toContain('never blocks a build');
});
});
61 changes: 61 additions & 0 deletions packages/lint/src/validate-readonly-flow-writes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@
// not land → WARNING (advisory). A templated object name or a non-literal
// `fields` map is not statically knowable → skipped, no guess.
//
// • A roll-up `summary` field WITHOUT `readonly: true` is read-only on both
// verbs all the same: the engine reads every roll-up as `readonly: true` in
// the create and the update strip (`withSummaryRollUpsReadonly`, objectql's
// `engine-top-level.ts`), so a non-system write of one is dropped exactly as
// a declared one is. Reported under its own id, `flow-update-summary-field`,
// as a WARNING by the area ruling on the card (claim amendment 7035408057,
// option B): a flow that writes a roll-up passed `os build` before the
// engine lock landed, and ERROR would refuse that build, a narrowing the
// ruling did not take. The branch is THIS rule's (`summaryFieldIndex`): the
// shared `buildReadonlyIndex` and the hook and action rules do not read it.
// A roll-up that also declares `readonly: true` is the static branch's,
// at ERROR, as before. Same gates as the static branch: `runAs:'system'`
// writes it, and a create on an insert-strip-exempt object is not judged.
//
// A pure `(stack) => Finding[]` rule (ADR-0019): no I/O, no runtime. Shared by
// the CLI and any other consumer (AI authoring), so hand-authored and generated
// flows are held to the same bar.
Expand Down Expand Up @@ -93,6 +107,12 @@ export interface ReadonlyFlowWriteFinding {
// suppression, docs and counts in two.
export const FLOW_UPDATE_READONLY_FIELD = 'flow-update-readonly-field';
export const FLOW_UPDATE_READONLY_WHEN_FIELD = 'flow-update-readonly-when-field';
/**
* A non-system `create_record` / `update_record` write to a roll-up `summary`
* field that does not declare `readonly: true` (the header's last bullet). One
* id for both verbs, as the static id is.
*/
export const FLOW_UPDATE_SUMMARY_FIELD = 'flow-update-summary-field';

/**
* [#22161] The clauses the three readonly write rules' one-line verdicts share
Expand Down Expand Up @@ -266,6 +286,28 @@ export function buildInsertStripExemptObjects(objects: AnyRec[]): Set<string> {
return exempt;
}

/**
* object name → the names of its roll-up `summary` fields, over the objects as
* served (the fold {@link buildServedReadonlyIndex} reads, tied fields left
* out). Flow-local on purpose: the engine reads a roll-up as read-only on both
* verbs whether or not it declares `readonly: true`, and only THIS rule reports
* that implicit lock, at its own id and severity; the shared readonly index
* keeps answering what the author declared.
*/
function summaryFieldIndex(stack: AnyRec): Map<string, Set<string>> {
const idx = new Map<string, Set<string>>();
for (const obj of objectsWithoutTiedFields(objectsAsServed(stack))) {
const name = typeof obj.name === 'string' ? obj.name : undefined;
if (!name) continue;
const summaries = new Set<string>();
for (const field of recordsOf(obj.fields)) {
if (typeof field.name === 'string' && field.type === 'summary') summaries.add(field.name);
}
if (summaries.size > 0) idx.set(name, summaries);
}
return idx;
}

/**
* The target object of an `update_record` / `create_record` node, when
* statically knowable. Both node configs anchor the object on the same key
Expand Down Expand Up @@ -300,6 +342,7 @@ export function validateReadonlyFlowWrites(stack: AnyRec): ReadonlyFlowWriteFind
// and stays on the declared objects.
const roIndex = buildServedReadonlyIndex(stack);
const insertStripExempt = buildInsertStripExemptObjects(objects);
const summaryIndex = summaryFieldIndex(stack);

flows.forEach((flow, flowIndex) => {
// `runAs` defaults to 'user' (schema default). Only an explicit 'system'
Expand Down Expand Up @@ -336,6 +379,8 @@ export function validateReadonlyFlowWrites(stack: AnyRec): ReadonlyFlowWriteFind
// `buildInsertStripExemptObjects`); the update branch is not.
if (isCreate && insertStripExempt.has(objectName)) return;

const summaryFields = summaryIndex.get(objectName);

const fields = config.fields;
// A non-literal write map (templated string, spread, array) is not
// statically knowable — skip rather than guess.
Expand Down Expand Up @@ -394,6 +439,22 @@ export function validateReadonlyFlowWrites(stack: AnyRec): ReadonlyFlowWriteFind
: `Declare the flow runAs:'system' if automation maintains '${fieldName}', or remove it from this ` +
`update_record node`,
});
} else if (summaryFields?.has(fieldName) && !isSystemRun) {
// The implicit roll-up lock (header, last bullet): a certain drop on
// both verbs, reported as a warning by the area ruling. A roll-up
// declaring `readonly: true` took the static branch above instead.
findings.push({
severity: 'warning',
rule: FLOW_UPDATE_SUMMARY_FIELD,
where,
path: `${nodePath}.config.fields.${fieldName}`,
message:
`writes roll-up summary field '${fieldName}' of object '${objectName}', which the engine computes and ` +
`drops from a runAs:'${runAs}' write on create and update alike`,
hint:
`Remove '${fieldName}' from this ${nodeType} node; the engine recomputes it whenever a child record ` +
`changes`,
});
} else if (meta.readonlyWhen && !isCreate) {
// `!isCreate`: the conditional lock has no prior record to evaluate on
// an insert and the engine does not run it there ("INSERT stays
Expand Down
Loading
Loading