From d706b60b57efaaaef20614ffe9e7b587353f01a1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 17 Sep 2026 16:51:08 +0000 Subject: [PATCH 1/3] refactor(formula)!: remove the never-bound api declaration from EvalContext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `EvalContext.api` declared `exists` / `count` / `lookup` and promised `os.exists / os.count / os.lookup`, "implemented opportunistically by call sites that have a query engine". `buildScope()` read `ctx.api` zero times, so no call site could bind them however well it cooperated: a predicate calling one faulted with `found no matching overload for 'dyn.lookup(string, dyn)'`, and an unevaluable predicate refuses the write it guards — a validation rule authored against the declaration locked every write on its object. The declaration is removed rather than implemented, with the reason written at the deletion site. No shim, no alias, no reserved spelling. Claude-Session: https://claude.ai/code/session_01CqmCgU5RGDoJYhHUMVp2af Co-authored-by: Claude --- .../src/eval-context-no-query-api.test.ts | 49 +++++++++++++++++++ packages/formula/src/types.ts | 20 ++++---- 2 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 packages/formula/src/eval-context-no-query-api.test.ts diff --git a/packages/formula/src/eval-context-no-query-api.test.ts b/packages/formula/src/eval-context-no-query-api.test.ts new file mode 100644 index 00000000000..022fbc58f9c --- /dev/null +++ b/packages/formula/src/eval-context-no-query-api.test.ts @@ -0,0 +1,49 @@ +import { describe, expect, it } from 'vitest'; + +import { celEngine } from './cel-engine'; +import { buildScope } from './stdlib'; +import type { EvalContext } from './types'; +import type { Expression } from '@objectstack/spec'; + +const cel = (source: string): Expression => ({ dialect: 'cel', source }); + +/** + * `EvalContext` once declared an optional `api?: { exists, count, lookup }`, + * and `buildScope()` never read it — so `os.exists` / `os.count` / `os.lookup` + * reached no scope however well a call site cooperated. The member is gone; + * these pins hold it gone in both directions: the type no longer accepts it, + * and a context still carrying one at runtime binds nothing. + * + * The two runtime pins launder their context through `unknown` on purpose — + * the shape they need is exactly the one the type no longer admits. + */ +describe('EvalContext carries no query API', () => { + it('does not declare an `api` member (type-level pin)', () => { + const ctx: EvalContext = { + record: { amount: 10 }, + // @ts-expect-error `api` is not a member of EvalContext. If this + // directive ever reports as unused, the retired kernel query API has + // been re-declared without being bound — reopen the capability question + // rather than restoring the declaration. + api: { lookup: () => null }, + }; + + expect(buildScope(ctx)).toEqual({ record: { amount: 10 } }); + }); + + it('binds no `os` namespace from a context whose only key is a query api', () => { + const scope = buildScope({ api: { exists: () => true } } as unknown as EvalContext); + + expect(scope).toEqual({}); + expect('os' in scope).toBe(false); + }); + + it('refuses a predicate calling os.lookup even when the call site supplies one', () => { + const result = celEngine.evaluate(cel('os.lookup("crm_account", record.account_id) != null'), { + record: { account_id: 'acc_1' }, + api: { lookup: () => ({ type: 'partner' }) }, + } as unknown as EvalContext); + + expect(result.ok).toBe(false); + }); +}); diff --git a/packages/formula/src/types.ts b/packages/formula/src/types.ts index be65387ef43..27f991bbd75 100644 --- a/packages/formula/src/types.ts +++ b/packages/formula/src/types.ts @@ -20,6 +20,17 @@ import type { Expression } from '@objectstack/spec'; * Every field is optional — call sites populate only what they have. The CEL * engine binds `record`, `previous`, `input`, `os` directly as top-level * variables when present. + * + * **It carries data, never a query API.** `buildScope()` binds exactly the + * fields declared here, so an expression reads only what its call site already + * passed in — reaching a row this context does not carry is outside the + * contract. A kernel API (`os.exists` / `os.count` / `os.lookup`) was declared + * here and never bound by `buildScope()`, and it is removed rather than + * implemented because the harm came from the declaration existing, not from + * the implementation missing: a predicate written to it faulted at runtime + * (`found no matching overload for 'dyn.lookup(string, dyn)'`), and an + * unevaluable predicate refuses the write it guards — so a validation rule + * authored against the declaration locked every write on its object. */ export interface EvalContext { /** Logical "now" snapshot — pinned per evaluation run for determinism. */ @@ -63,15 +74,6 @@ export interface EvalContext { previous?: Record; /** Action / flow input payload. */ input?: Record; - /** - * Optional kernel API for `os.exists / os.count / os.lookup`. - * Implemented opportunistically by call sites that have a query engine. - */ - api?: { - exists?: (object: string, predicate: Expression) => boolean; - count?: (object: string, predicate: Expression) => number; - lookup?: (object: string, id: string) => Record | null; - }; /** Free-form bag for niche call sites; merged onto the variable scope. */ extra?: Record; } From 75ca0e2749e3b87dd7f74f1b254b782b5c9023d1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 17 Sep 2026 17:13:48 +0000 Subject: [PATCH 2/3] chore(changeset): minor for the EvalContext query-api removal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clause-② is declared on the card and on the PR body; the changeset body carries the same line. The bump is `minor` rather than `major`: the removed declaration never delivered the semantics it reported, so nothing a consumer could depend on at runtime moves — the whole of the break is a compile error on an `EvalContext` literal that carries `api`. Claude-Session: https://claude.ai/code/session_01CqmCgU5RGDoJYhHUMVp2af Co-authored-by: Claude --- .changeset/18318-evalcontext-no-query-api.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .changeset/18318-evalcontext-no-query-api.md diff --git a/.changeset/18318-evalcontext-no-query-api.md b/.changeset/18318-evalcontext-no-query-api.md new file mode 100644 index 00000000000..a5c469c2103 --- /dev/null +++ b/.changeset/18318-evalcontext-no-query-api.md @@ -0,0 +1,11 @@ +--- +'@objectstack/formula': minor +--- + +`EvalContext` no longer declares `api?: { exists, count, lookup }` — the kernel query API behind `os.exists` / `os.count` / `os.lookup`, which `buildScope()` never bound (#18318). + +The member's docblock said it was "implemented opportunistically by call sites that have a query engine", and no call site ever could: `ctx.api` was read **zero** times in this package — control in the same sweep, `ctx.user`, three reads in `stdlib.ts` — so the three functions reached no evaluation scope however completely a caller populated the member. An author who wrote a predicate to the declaration got `runtime: found no matching overload for 'dyn.lookup(string, dyn)'` instead, and because an unevaluable predicate refuses the write it guards, a validation rule authored that way locked **every** write on its object. The harm came from the declaration existing, not from the implementation missing, so it is removed rather than implemented — with the reason written at the deletion site, and with no shim, alias or reserved spelling left behind. + +**Migration — `api: { … }` → delete the property.** There is no replacement key and nothing to re-point: every implementation ever passed there was discarded before evaluation, so removing the property changes no result your predicates produce. TypeScript is where you will hear about it: an `EvalContext` literal carrying `api` now fails to compile, which is the whole of the break. Reading a related record's field from inside a predicate remains unexpressible in any spelling — that capability is tracked as its own card, relationship traversal (`record.crm_account.type`), and deliberately not as `os.lookup` queries; no schedule is implied by this removal. + +Clause-②: yes From 2b053aebd7ba4bd24fe469c91790308d31333b28 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 17 Sep 2026 17:43:14 +0000 Subject: [PATCH 3/3] chore(changeset): carry breaking-ness on the banner plus an ADR-0087 disposition The launch window refuses `major`, so the level cannot carry breaking-ness: `.github/workflows/pr-automation.yml` puts it on the `**BREAKING**` banner and the ADR-0087 disposition instead. The bump stays `minor`. The disposition is `runtime-interface-only`, named at `packages/formula/src/types.ts#EvalContext` and verified by the gate: a published runtime TypeScript interface with no Zod schema, no `packages/spec` declaration and no stored representation, so the ledger has nothing to project and the compiler is the channel that reaches every affected caller. `type-surface-only` was tried first and refused, twice, on measurement: the dotted member spelling does not resolve through an interface, and at the interface the base side is already concrete, which is the shape predicate 4 exists to refuse. Claude-Session: https://claude.ai/code/session_01CqmCgU5RGDoJYhHUMVp2af Co-authored-by: Claude --- .changeset/18318-evalcontext-no-query-api.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.changeset/18318-evalcontext-no-query-api.md b/.changeset/18318-evalcontext-no-query-api.md index a5c469c2103..bdd8e3e77a4 100644 --- a/.changeset/18318-evalcontext-no-query-api.md +++ b/.changeset/18318-evalcontext-no-query-api.md @@ -4,8 +4,12 @@ `EvalContext` no longer declares `api?: { exists, count, lookup }` — the kernel query API behind `os.exists` / `os.count` / `os.lookup`, which `buildScope()` never bound (#18318). +**BREAKING** for a TypeScript consumer: an `EvalContext` literal that carries `api` stops compiling. The level stays `minor` because the launch window refuses `major` outright — while it is open, breaking-ness is carried by this banner and by the ADR-0087 disposition at the foot of this changeset, not by the bump. + The member's docblock said it was "implemented opportunistically by call sites that have a query engine", and no call site ever could: `ctx.api` was read **zero** times in this package — control in the same sweep, `ctx.user`, three reads in `stdlib.ts` — so the three functions reached no evaluation scope however completely a caller populated the member. An author who wrote a predicate to the declaration got `runtime: found no matching overload for 'dyn.lookup(string, dyn)'` instead, and because an unevaluable predicate refuses the write it guards, a validation rule authored that way locked **every** write on its object. The harm came from the declaration existing, not from the implementation missing, so it is removed rather than implemented — with the reason written at the deletion site, and with no shim, alias or reserved spelling left behind. **Migration — `api: { … }` → delete the property.** There is no replacement key and nothing to re-point: every implementation ever passed there was discarded before evaluation, so removing the property changes no result your predicates produce. TypeScript is where you will hear about it: an `EvalContext` literal carrying `api` now fails to compile, which is the whole of the break. Reading a related record's field from inside a predicate remains unexpressible in any spelling — that capability is tracked as its own card, relationship traversal (`record.crm_account.type`), and deliberately not as `os.lookup` queries; no schedule is implied by this removal. + + Clause-②: yes