Skip to content

Read visibility rule text through the shared expression parser - #32379

Closed
FelixMalfait wants to merge 4 commits into
mainfrom
felix/upbeat-ritchie-1ir3dn
Closed

FelixMalfait wants to merge 4 commits into
mainfrom
felix/upbeat-ritchie-1ir3dn

Conversation

@FelixMalfait

@FelixMalfait FelixMalfait commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Visibility rules on page layout tabs and widgets were read from text by their own parser. That parser kept field names as written and could not print a field back, so a rule written as text referenced fields by name: a rename broke it silently, the server never checked the field existed, and the filter builder could not open it.

Text rules now go through the parser that formula fields and validation rules already use. currentRecord.stage == "PROPOSAL" becomes the same field node the filter builder writes, keyed by the field's universal identifier. So a rename keeps the rule, the builder can open it, and printing shows the current name.

This is the groundwork for letting app manifests write visibility rules as text and having twenty app pull print them as text. Today apps must write the raw tree.

Changes

  • resolveExpressionFieldReferences takes recordVariableNames. With it, fields are only read through those variables (currentRecord.stage), never by bare name, so a custom field named device cannot shadow the device variable. Visibility rules declare their record variables in ConditionalEvaluationConfiguration.recordVariables. Formulas, validation rules and the 2.65 command do not pass it and behave as before.

  • printExpressionNode writes a field's record variable before its name. printConditionalEvaluationNode takes the fields to name them; it threw on any field node before.

  • parseConditionalEvaluationExpression takes the fields of the object the rule reads, and refuses:

    • a record path that names no field, like currentRecord.stag;
    • a bare field name like stage.

    Operators a rule cannot hold still report Unexpected "+".

  • Removed conditionalEvaluationStrictParser, toConditionalEvaluationNode and CONDITIONAL_EVALUATION_EXPRESSION_MAX_LENGTH; rules use the shared EXPRESSION_MAX_LENGTH, also 2000.

  • Built-in widget rules are read with no fields. None names a field today, so one that does fails at build time.

The 2.63 upgrade command

The shared parser reads length, round, abs, ceil, floor and trunc as operators, so selectedRecords.length > 0 no longer parses. The old parser read them as names. Self-hosters can still upgrade through 2.63, so its command keeps the old parser in its version folder, with its settings copied unchanged. Supporting changes:

  • twenty-server declares expr-eval-fork directly (same 3.0.3, one lockfile line).
  • twenty-shared gains a generic parseExpressionNodeWithParser; the tokens-to-tree converter stays internal.

A temporary test, not committed, compared the old parser with the frozen copy on 64 rules, including the members above. Every rule was accepted or refused the same way and built the same tree. A spec in 2-63/utils/__tests__ covers the main cases.

Testing

  • twenty-shared: full jest suite (3,698 tests), plus new cases for record fields, relations, unknown fields, the device collision, and printing after a rename.
  • twenty-server: 1,090 specs across the 2.63 command, manifest converters, page layout widgets, the standard application, the migration validators, validation rules, formula fields and the event emitter.
  • tsgo --noEmit clean in both packages, apart from server imports of twenty-emails, twenty-client-sdk and twenty-sdk, which were not built in the environment.
  • oxlint and oxfmt clean on changed files.
  • Not run: server integration tests and front tests. Nothing in twenty-front calls the changed functions.

https://claude.ai/code/session_01BC19MSAJVo6nHzxVuvKd9y


Generated by Claude Code

Visibility rules on page layout tabs and widgets were read from text by a
separate parser that kept field names as written and could not print a
field back. They now go through the parser that formula fields and
validation rules use: `currentRecord.stage` resolves to the field's
identifier, the same node the filter builder writes, so a rename keeps
the rule and the builder can open it. A path naming no field is refused.

- resolveExpressionFieldReferences takes the variables that hold a record,
  so fields are only read through them, never by bare name.
- printExpressionNode writes a field's record variable before its name, and
  printConditionalEvaluationNode takes the fields to name them.
- The strict parser and its own length limit are removed from twenty-shared.
- The 2.63 upgrade command keeps the old parser in its version folder,
  through a new parseExpressionNodeWithParser.

Claude-Session: https://claude.ai/code/session_01BC19MSAJVo6nHzxVuvKd9y
@FelixMalfait
FelixMalfait force-pushed the felix/upbeat-ritchie-1ir3dn branch from 28f93a4 to 14bb41d Compare December 4, 2026 11:54

Copy link
Copy Markdown
Member Author

server-upgrade-mutation-guard fails because this PR edits the 2.63 version folder: it changes 2-63/utils/from-legacy-page-layout-widget-rule-to-conditional-availability.util.ts and adds three files next to it.

This is intended. The visibility-rule parser leaves twenty-shared, and the 2.63 command still has to read legacy text rules exactly as before, so a frozen copy of that parser moves into its version folder, as UPGRADE_COMMANDS.md asks for command-only formats. The command's logic is unchanged. A comparison on 64 rules gave the same result and the same tree for each, old parser against frozen copy.

The guard clears with the ci:allow-previous-version-upgrade-mutation label and a re-run. That override is a maintainer's call, so I have not applied it.


Generated by Claude Code

@FelixMalfait
FelixMalfait marked this pull request as ready for review December 4, 2026 11:58
Comment thread packages/twenty-server/package.json Outdated
"dotenv": "16.4.5",
"email-reply-parser": "^2.3.5",
"entities": "^4.5.0",
"esbuild": "^0.28.1",
"expr-eval-fork": "3.0.3",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we need this now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't need it. It was only there because the frozen 2.63 parser built an expr-eval-fork Parser itself. Fixed in aa8759f: parseExpressionNodeWithParser in twenty-shared now takes plain parser options (plus consts and functions) and builds the Parser itself. The 2-63 folder only keeps an options object, so twenty-server no longer imports the library, and its dependency and lockfile line are gone.


Generated by Claude Code

@twenty-ci-bot-public

twenty-ci-bot-public Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

🤖 PR Review

Check Result
🔍 Build safety ⏭️ skipped — external-only
🧭 Triage ⏭️ skipped — external-only
📐 Quality ✅ passed — 5 nit(s)
🛡️ Security ✅ passed
🚦 Auto-approve 👀 needs review — Complexity is high
🔐 Permissions ⏭️ skipped: no endpoint permission change

🛡️ Security Review

✅ No high-severity vulnerabilities detected.


🚦 Auto-approve

🙋 Manual review recommended for the following reason(s):

  • Complexity is high

  • 🧠 Complexity: high

  • 📏 Size: +538 / -132 lines across 24 file(s)


View details

Automated pre-review — human approval still required.

@twenty-ci-bot-public

twenty-ci-bot-public Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

🟡 Quality review · 5 findings

Safe to merge: two non-blocking points carried over, both about how much of the 2.63 legacy parser is really frozen

High-level — Resolving currentRecord fields in the shared rule parser fits the existing FIELD-node evaluator, and its one production caller is updated; the open points are that the frozen 2.63 copy still depends on live shared helpers, and a public twenty-shared export exists only for that copy.
Low-level — 3 rule violations found — 914 rule questions over 23 piece(s) of 21 file(s)

💬 5 inline comments on the diff.


Reviewed against the pr-review standard — high-level then low-level. Advisory; human review still required. Run details.

import {
type ConditionalEvaluationNode,
validateConditionalEvaluationNode,
} from 'twenty-shared/conditional-evaluation';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · High-level · upgrade commands

The 'frozen' 2.63 legacy parser still runs on live twenty-shared code (validateConditionalEvaluationNode, parseExpressionNodeWithParser → toExpressionNodeParseResult, CONDITIONAL_EVALUATION_FUNCTIONS)

A later change to those shared helpers silently changes how the 2.63 command reads legacy rules, so the copy does not freeze what it claims to freeze. Either copy the tree conversion and validation it needs into the version folder too, or state in the PR which parts are frozen and which are not.

import { toExpressionNodeParseResult } from '@/expression/utils/internal/toExpressionNodeParseResult';
import { getExpressionSyntaxError } from '@/utils/expression/getExpressionSyntaxError';

// For a format the shared parser no longer reads, such as an upgrade command's legacy rules

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · High-level · right altitude

twenty-shared gains a new public export, parseExpressionNodeWithParser, whose only consumer is the 2-63 upgrade command

Its comment ties a long-lived shared API to one version folder's legacy format, and it keeps that command coupled to twenty-shared internals. Keep the helper inside the 2-63 utils folder with the frozen parser instead of exporting it from twenty-shared/utils.


export type ConditionalEvaluationConfiguration = {
variables: Record<string, true>;
// Variables holding a record, whose fields text names as currentRecord.stage

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · Low-level · Every added comment passes the deletion test

The added comment restates what the field is for, and a name like recordVariables with the type already conveys that, so removing it loses nothing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 8ddbc02.


Generated by Claude Code

import { getExpressionNodeChildren } from '@/expression/utils/internal/getExpressionNodeChildren';
import { isDefined } from '@/utils/validation/isDefined';

// Names the first computation a rule cannot hold, as the shared parser accepts formulas

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · Low-level · Every added comment passes the deletion test

The added comment paraphrases what the function name and return type already state (it names the first unsupported computation), so deleting it loses nothing the code cannot say.

}: {
expression: string | null | undefined;
metadataName: ConditionalEvaluationMetadataName;
// Fields of the object the rule reads through its record variables

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · Low-level · Every added comment passes the deletion test

The added comment on the fields parameter only restates what the name and type already convey, so deleting it loses nothing.

: undefined;
};

// A path naming no field is kept as written, so the expression still reports it as unknown.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · Low-level · A kept comment is one line

The added comment is split across two consecutive // lines, but the rule allows multi-line comments only when a single line cannot state the reason.

Also on line 96.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the second line in 8ddbc02.


Generated by Claude Code

@greptile-apps

greptile-apps Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The changes reach page-layout visibility rules and the 2.63 upgrade path.

The PR appears safe to merge, with a non-blocking issue in how invalid record-field paths are accepted.

Findings

  1. P2 Invalid field paths pass ▶

Summary

Visibility-rule text now uses the shared expression parser and stores record fields by stable identifiers.

  • Page-layout rules can follow record fields through renames.
  • The 2.63 upgrade command keeps reading old visibility rules the same way.

Tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Visibility rule text] --> B[Shared expression parser]
  B --> C[Resolve record fields to stable identifiers]
  C --> D[Check allowed nodes and names]
  D --> E[Stored rule tree]
  E --> F[Print current field names]
  G[2.63 legacy rule text] --> H[Frozen legacy parser]
  H --> D
Loading

Reviews (1) · Last reviewed commit: "Read visibility rule text through the sh..." · Reviewed by Greptile

Comment on lines +88 to +91
const fieldNode = toFieldNode({ path: fieldSegments.join('.'), fields });

return isDefined(fieldNode)
? { ...fieldNode, record: recordVariableName }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Invalid field paths pass

toRecordVariableFieldNode accepts partial field matches. With an amount currency field, currentRecord.amount.amountMicros.extra > 0 becomes a rule for amount.amountMicros; .extra silently disappears. A misspelled subfield such as currentRecord.amount.amuntMicros also passes validation.

The later unknown-field check only checks remaining VARIABLE nodes, so neither error is caught. Check the full path, including subfield names and depth, before converting it to a field node.

Knowledge Base Used: Shared domain contracts and utilities

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ddbc02: before resolving, each currentRecord.… path now goes through resolveExpressionIdentifierPath, the same check formulas use. Unknown or too-deep subfields, unknown relation targets, to-many relations and previous/now all fail now, and each case has a test.


Generated by Claude Code

};
}

return isDefined(resolution.toManyRelationName)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit · Low-level · Return early

The function ends in a multi-line ternary that returns a seven-line error object literal, which should be an early return instead.

Also on lines 60–66.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d944054.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

server-integration-test (14) failed on d944054 in chat-channel-deletion-and-summaries.integration-spec.ts ("keeps chats out of a deleted destination that a stale cache still lists"). The test expected NOT_FOUND / CHAT_CHANNEL_NOT_FOUND but got CONFLICT / CHAT_CHANNEL_BUSY. This PR doesn't touch chat channels or their tests; it only changes conditional-evaluation parsing in twenty-shared and the 2-63 upgrade folder. It looks like a timing flake in that spec, so a re-run of the failed job should clear it.


Generated by Claude Code

@twenty-ci-bot-public

Copy link
Copy Markdown

🔍 Visual Regression Review — twenty-front

✅ 13 visual change(s) reviewed — all explained by this PR.

Changed: 25 · Added: 0 · Removed: 0 · Unchanged: 2149

13 item(s) to double-check (uncertain / low confidence)
Story Verdict Confidence Explained by
🟡 modules-gettingstarted-gettingstartedpagecontent--optimistic-app-install uncertain 60% none
🟡 modules-ai-aichattab--open-original-from-reply uncertain 65% none
🟡 modules-settings-applications-settingsapplicationiframemediapermissionssection--… uncertain 65% none
🟡 modules-onboarding-onboardingactivationsteps--default uncertain 50% none
🟡 modules-pagelayout-widgets-recordpagenotewidget--align-text uncertain 50% none
🟡 modules-sidepanel-recordcreationflow--retry-after-failed-creation uncertain 50% none
🟡 modules-sidepanel-recordcreationflow--submit-with-button uncertain 50% none
🟡 modules-sidepanel-recordcreationflow--submit-with-command-enter uncertain 50% none
🟡 modules-sidepanel-recordcreationflow--submit-with-control-enter uncertain 50% none
🟡 modules-sidepanel-snoozeaichat--day-and-time-picker uncertain 50% none
🟡 modules-sidepanel-composerpages--calendar-event-without-account-permission uncertain 50% none
🟡 modules-sidepanel-composerpages--calendar-event-without-accounts uncertain 50% none
🟡 modules-sidepanel-composerpages--calendar-event uncertain 50% none
Changed stories
Story Diff %
modules-gettingstarted-gettingstartedpagecontent--optimistic-app-install 9%
modules-ai-aichattab--open-original-from-reply 3%
modules-settings-applications-settingsapplicationiframemediapermissionssection--does-not-apply-rejected-approval 2%
modules-onboarding-onboardingactivationsteps--default 1%
modules-pagelayout-widgets-recordpagenotewidget--align-text 1%
pages-settings-mcpservers-settingsaimcpserverdetail--default 0%
pages-settings-mcpservers-settingsaimcpserverdetail--member-without-connection-starts-the-sign-in 0%
pages-settings-mcpservers-settingsaimcpserverdetail--shared-sign-in-shows-no-member-section 0%
pages-settings-mcpservers-settingsaimcpserverdetail--signed-in-member-sees-only-their-connection-to-this-server 0%
pages-settings-mcpservers-settingsaimcpserverdetail--sign-in-load-error-offers-retry 0%
pages-settings-mcpservers-settingsaimcpserverdetail--sign-in-shows-when-the-cached-providers-predate-the-server 0%
modules-sidepanel-recordcreationflow--submit-with-button 0%
modules-sidepanel-recordcreationflow--submit-with-command-enter 0%
modules-sidepanel-composerpages--calendar-event-without-account-permission 0%
modules-sidepanel-composerpages--calendar-event-without-accounts 0%
modules-sidepanel-recordcreationflow--retry-after-failed-creation 0%
modules-sidepanel-recordcreationflow--submit-with-control-enter 0%
modules-sidepanel-snoozeaichat--day-and-time-picker 0%
modules-sidepanel-composerpages--calendar-event 0%
modules-activities-emails-chatthreadmessagegroup--voice-note 0%
pages-settings-mcpservers-settingsaimcpserverdetail--sync-keeps-unsaved-edits 0%
modules-activity-taskgroups--empty 0%
modules-activities-files-videopreview--player 0%
modules-ai-aichattab--reply-to-teammate 0%
modules-pagelayout-widgets-callrecordingtranscriptbody--audio-seek-interactions 0%

View run details · advisory mode

@twenty-ci-bot-public

Copy link
Copy Markdown

🔍 Visual Regression Review — twenty-ui

✅ 10 visual change(s) reviewed — all explained by this PR.

Changed: 11 · Added: 0 · Removed: 0 · Unchanged: 1530

10 item(s) to double-check (uncertain / low confidence)
Story Verdict Confidence Explained by
🟡 ui-components-codeeditor--display uncertain 50% —
🟡 ui-components-codeeditor--auto-height uncertain 60% —
🟡 ui-components-codeeditor--model-lifecycle uncertain 55% —
🟡 ui-components-codeeditor--default uncertain 60% —
🟡 ui-components-codeeditor--editing uncertain 55% —
🟡 ui-components-codeeditor--theme-precedence uncertain 55% —
🟡 ui-components-codeeditor--dark uncertain 55% —
🟡 ui-components-codeeditor--bounded-resizable uncertain 55% —
🟡 ui-components-codeeditor--css-height-resizable uncertain 55% —
🟡 ui-components-codeeditor--resizable uncertain 55% —
Changed stories
Story Diff %
ui-components-codeeditor--display 5%
ui-components-codeeditor--default 1%
ui-components-codeeditor--auto-height 1%
ui-components-codeeditor--model-lifecycle 1%
ui-components-codeeditor--dark 0%
ui-components-codeeditor--bounded-resizable 0%
ui-components-codeeditor--css-height-resizable 0%
ui-components-codeeditor--editing 0%
ui-components-codeeditor--theme-precedence 0%
ui-components-codeeditor--resizable 0%
ui-components-codeeditor--controlled-value 0%

View run details · advisory mode

@twenty-eng-sync twenty-eng-sync Bot closed this Dec 5, 2026
@twenty-eng-sync twenty-eng-sync Bot added the -PR: stale auto-closed Closed by the stale-draft auto-close cron (no update in 24h) label Dec 5, 2026
@twenty-eng-sync

Copy link
Copy Markdown

Auto-closed: this PR is draft and has had no update in over 24 hours. Please reopen it once you have the bandwidth to take it forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

-PR: draft -PR: stale auto-closed Closed by the stale-draft auto-close cron (no update in 24h)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant