Skip to content

Store command menu item rules as trees - #32398

Open
FelixMalfait wants to merge 14 commits into
mainfrom
felix/command-menu-rule-tree
Open

FelixMalfait wants to merge 14 commits into
mainfrom
felix/command-menu-rule-tree

Conversation

@FelixMalfait

@FelixMalfait FelixMalfait commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

What

Phase 4 of the rule-tree migration: command menu items store their availability and pinning rules as trees, the same way page layout widgets (2-63) and tabs (2-67) already do.

  • Schema: new nullable jsonb columns conditionalAvailability and conditionalPinned on core.commandMenuItem (2-68 fast instance command). Both are exposed on the GraphQL type, and the two text fields are marked deprecated.

  • Writes: every producer now writes the tree next to the expression:

    • standard app
    • app manifest sync
    • createCommandMenuItem
    • object navigation build
    • the object-rename side effect

    As with widgets, an expression that can't be parsed keeps its text and gets a null tree, so installing or re-syncing an app never fails on an old rule.

  • Validation: the flat command menu item validator checks both trees against a new commandMenuItem entry in CONDITIONAL_EVALUATION_CONFIGURATION_BY_METADATA_NAME. Its variables are exactly the keys of CommandMenuContextApi, enforced with satisfies.

  • Upgrade: the upgrade:2-68:copy-command-menu-item-rules-to-trees workspace command:

    • rebuilds every tree from its stored expression when the two differ, so it can be re-run safely;
    • logs any rule it can't read;
    • turns on IS_COMMAND_MENU_ITEM_CONDITIONAL_AVAILABILITY_ENABLED only if every rule was readable;
    • empties nothing, so turning the flag off falls back to the expressions.

    New workspaces get the flag by default. Re-run the command once the 2.67 pods are gone: they keep serving during the upgrade and can write expressions without trees, and the re-run repairs those.

  • Front: evaluateCommandMenuItemRule reads the tree when the flag is on and the expression otherwise. Both places that work out availability use it (CommandMenuContextProviderContent, StandalonePageCommandMenu), and so does pinning (resolveCommandMenuItemPinning).

Removing the legacy expression columns and the front fallback is a later PR. It is gated on:

  • every production workspace having the flag on, which a read-only count of workspaces without it should confirm is zero;
  • no edge still sending text. Phase 3 is not done: the CLI and app manifests still send expressions.

Pinning

conditionalPinnedExpression gets the same treatment as availability: its own tree column, copied by the upgrade command, and read from the tree when the flag is on. Pinning tests cover both branches.

Not in this PR

Note for reviewers

The new required flat fields had to be added as null to a few older upgrade commands and their specs:

  • 1-21;
  • the specs in 2-28, 2-52, 2-53, 2-54, 2-58 and 2-60;
  • build-legacy-navigation-flat-command-menu-item.util.ts.

This is the same pattern used when availabilityCoreObjectName was added. Because it touches previous version folders, the ci:allow-previous-version-upgrade-mutation label is applied so the guard passes.

Testing

  • Unit tests:
    • copy util (new);
    • pinning with the flag on and off (new);
    • command menu item, standard application, workspace migration and application manifest suites.
  • Integration tests:
    • 2-68 copy command (new): dry run, copy, idempotence, flag gating;
    • the catalog-cost suite;
    • all command-menu-item metadata suites;
    • the object rename side effect, which now asserts the tree.
  • A seeded dev workspace has 230 command menu items with trees, and all of them pass the new validator.
  • tsgo passes on server, front and shared. GraphQL and SDK clients were regenerated against a running server.

Generated by Claude Code

Command menu items get conditionalAvailability and conditionalPinned
jsonb columns, mirroring page layout widgets and tabs. Every producer
(standard app, app manifests, the create API, navigation side effects)
writes the tree next to the legacy expression, and the validator checks
trees against a new commandMenuItem evaluation configuration.

A 2-68 workspace command copies stored expressions into trees and turns
on IS_COMMAND_MENU_ITEM_CONDITIONAL_AVAILABILITY_ENABLED only when every
rule could be read. With the flag on, the front evaluates availability
and pinning from the trees. The legacy expression columns stay until a
later release.

Copy link
Copy Markdown
Member Author

server-upgrade-mutation-guard fails on the eight files from the reviewer note in the description:

  • the 1-21 refactor-navigation command;
  • the specs in 2-28, 2-52, 2-53 (two), 2-54, 2-58 and 2-60.

Each change only adds conditionalAvailability: null, conditionalPinned: null to a flat command menu item that the new required fields would otherwise break. No command logic changes. This is the same pattern used when availabilityCoreObjectName was added. Fixing this needs the ci:allow-previous-version-upgrade-mutation label and a re-run, not a code change.


Generated by Claude Code

@greptile-apps

greptile-apps Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge.

Summary

Stores command menu availability and pinning rules as trees while keeping the text form for rollback.

  • Command menu items keep text rules and parsed trees together.
  • Command menus read rule trees when their workspace flag is on.
  • The workspace upgrade copies rules before enabling tree reading.

No actionable issues were found. Review was based on source inspection; tests were not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[New or synced rule text] --> B[Parse and check]
  B --> C[Store text and tree]
  D[Existing rule text] --> E[Workspace copy command]
  E --> F{Every rule readable?}
  F -->|Yes| G[Enable tree reads]
  F -->|No| H[Keep text reads]
  C --> I{Workspace flag enabled?}
  G --> I
  H --> I
  I -->|Yes| J[Evaluate tree]
  I -->|No| K[Evaluate text]
  J --> L[Availability and pinning]
  K --> L
Loading

Reviews (1) · Last reviewed commit: "Store command menu item rules as trees" · Reviewed by Greptile

@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 — 6 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: +1139 / -39 lines across 66 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 · 6 findings

Safe to merge — no high-level findings.

High-level — Follows the widget rule-tree pattern: nullable tree columns are added beside the deprecated expressions, every write path parses leniently, a re-runnable 2-68 copy command turns the flag on per workspace (it stays off if any rule can't be read), and the front keeps reading the legacy expressions while the flag is off, so there is no product, architecture, build or deploy concern.
Low-level — 6 rule violations found — 3377 rule questions over 68 piece(s) of 62 file(s), 3 kept from the previous run

💬 6 inline comments on the diff.


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

Copy link
Copy Markdown
Member Author

Thanks for the review. Going through the findings:

Strict parse on write paths (high-level). Confirmed. App manifest sync and createCommandMenuItem throw on an expression the strict parser rejects. Before this PR, both stored any text unchecked. The widget equivalent (getLegacyWidgetConditionalAvailability) stores a null tree instead. So an existing app that re-syncs an unchanged manifest with such an expression would fail after deploy. Following the widget pattern changes behavior too, though: on a workspace with the flag on, that item would then always be shown. I'm checking with the PR author which way to go before changing it.

Carried into the next push:

  • typing the copy util's expression-to-tree mapping so the Object.entries as cast goes away;
  • typing validateConditionalRules' rules as (ConditionalEvaluationNode | null | undefined)[] instead of unknown[];
  • isDefined in the 2-68 integration spec.

Not changing:

  • Duplicate concepts (fixtures, prefill, global record creation): writing both the expression and the tree is the point of this migration step. The duplicates go away when the legacy columns are dropped.
  • Ternary in the copy command: it copies the 2-63 widget command line for line, and I'd rather the two stay identical.
  • TODO owners: no owner is assigned yet. I'll add one if the author names one.

Generated by Claude Code

Object creation parsed the generated navigation expression, so an
invalid nameSingular threw before the object validator could report
METADATA_VALIDATION_FAILED. The navigation rule is now built as a
tree next to its expression.

Also updates the flat entity properties snapshot for the two new
columns, drops a cast in the 2-68 copy util and types the validator's
rules as trees.
@twenty-ci-bot-public

Copy link
Copy Markdown

🔍 Visual Regression Review — twenty-ui

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

Changed: 3 · Added: 0 · Removed: 0 · Unchanged: 1539

1 item(s) to double-check (uncertain / low confidence)
Story Verdict Confidence Explained by
🟡 ui-surfaces-dialog--non-modal-page-interaction uncertain 60% none
Changed stories
Story Diff %
ui-surfaces-dialog--non-modal-page-interaction 1%
ui-components-codeeditor--display 0%
ui-icon-icon--constrained-rows 0%

View run details · advisory mode

@twenty-ci-bot-public

Copy link
Copy Markdown

🔍 Visual Regression Review — twenty-front

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

Changed: 14 · Added: 0 · Removed: 0 · Unchanged: 2160

11 item(s) to double-check (uncertain / low confidence)
Story Verdict Confidence Explained by
🟡 modules-ai-aichataddmenu--ignore-enter-on-outdated-records uncertain 60% none (likely hover/active-row flakiness)
🟡 modules-recordexport-connection--page-hide uncertain 65% none (focus ring flakiness)
🟡 modules-settings-applications-settingsapplicationiframemediapermissionssection--… uncertain 65% none (focus ring flakiness)
🟡 modules-pagelayout-widgets-recordpagenotewidget--dashboard-selection uncertain 60% none (editor selection state)
🟡 modules-pagelayout-widgets-recordpagenotewidget--align-text uncertain 60% none (editor selection state)
🟡 modules-sidepanel-recordcreationflow--submit-with-button uncertain 75% none (random UUID in story output)
🟡 modules-sidepanel-recordcreationflow--submit-with-command-enter uncertain 75% none (random UUID in story output)
🟡 modules-sidepanel-recordcreationflow--submit-with-control-enter uncertain 75% none (random UUID in story output)
🟡 modules-sidepanel-recordcreationflow--retry-after-failed-creation uncertain 75% none (random UUID in story output)
🟡 modules-ai-aichattab--new-chat-suggested-prompt uncertain 55% none (likely randomized suggested prompt text)
🟡 modules-settings-applications-settingsapplicationiframemediapermissionssection--… uncertain 65% none (sub-pixel text antialiasing noise)
Changed stories
Story Diff %
modules-ai-aichataddmenu--ignore-enter-on-outdated-records 4%
modules-recordexport-connection--page-hide 2%
modules-settings-applications-settingsapplicationiframemediapermissionssection--does-not-apply-rejected-approval 2%
modules-pagelayout-widgets-recordpagenotewidget--dashboard-selection 1%
modules-pagelayout-widgets-recordpagenotewidget--align-text 1%
modules-sidepanel-recordcreationflow--submit-with-button 0%
modules-sidepanel-recordcreationflow--submit-with-command-enter 0%
modules-sidepanel-recordcreationflow--submit-with-control-enter 0%
modules-sidepanel-recordcreationflow--retry-after-failed-creation 0%
modules-ai-aichattab--new-chat-suggested-prompt 0%
modules-settings-applications-settingsapplicationiframemediapermissionssection--reports-failed-refresh 0%
modules-activities-files-videopreview--player 0%
pages-settings-mcpservers-settingsaimcpserverdetail--sync-keeps-unsaved-edits 0%
modules-ai-aichattab--open-original-from-reply 0%

View run details · advisory mode

The merge from main shifted the JSON and UUID type indexes; this also
corrects MinimalView.universalIdentifier, which main's generated client
still pointed at the previous UUID index. The navigation rule tree now
takes its path from buildNavigationConditionalAvailabilityExpression.

Copy link
Copy Markdown
Member Author

server-validation failed on 786dc58 because the generated SDK metadata client was stale against current main. In 62eaf7a I merged main and regenerated the client against a running server.

One of the regenerated lines isn't from this PR: MinimalView.universalIdentifier (#31744) points at the previous UUID type index (585 instead of 587), on main too. #31744 and #32359 each regenerated types.ts on its own base. Main's own SDK check should hit the same line until this PR merges, or until someone regenerates on main.


Generated by Claude Code

@FelixMalfait FelixMalfait added the ci:allow-previous-version-upgrade-mutation Bypass the upgrade mutation guard for previous version directories. label Dec 4, 2026 — with Claude

Copy link
Copy Markdown
Member Author

Follow-up: the author approved the tolerant approach, and it's in f3c24c5. Like widgets, an expression that can't be parsed now keeps its text and gets a null tree instead of failing the write, so re-syncing an app with an old rule no longer breaks. Covered by a unit spec and an integration case on create.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

On the 10 quality nits:

  • Consolidate duplicate concepts (5 threads): this is deliberate. The trees sit beside the expressions only for the rollout, following the widget pattern. The expression columns are removed once every edge sends trees and the flag is on everywhere (see the PR description).
  • Return early (copy command): the ternary is the same as the 2-63 widget copy command, so I kept it identical.
  • Reuse instead of reimplementing (navigation builder, on 786dc58): already fixed. buildNavigationConditionalAvailability now builds its path with buildNavigationConditionalAvailabilityExpression.
  • Owned TODO (4 threads): left for the author to decide who owns removing the legacy columns.

Generated by Claude Code

Copy link
Copy Markdown
Member Author

renderer-sb-test failed on 62eaf7a (superseded by f3c24c5). The failure looks unrelated to this PR: one story, TwentyUiGallery > Phone Country Picker Preact, failed after 2 retries because the simulated click didn't register (Country: US; Changes: 0 instead of GB; 1). This PR doesn't touch twenty-front-component-renderer, twenty-ui or any phone or country code. The other 500 renderer stories passed. I'll check it again on the new head.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

server-integration-test (4) failed on 62eaf7a (superseded by f3c24c5), and it looks unrelated to this PR. One test failed out of 428: core-workflow-execution > refuses a submission while its run is stopping. It expected the form step to stay PENDING but got FAILED, which points to timing in the workflow run or stop path. This PR doesn't touch that path; on the workflow side it only adds null rule fields to the command menu items. The ci-front-component-renderer-status-check failure is the Preact story from my previous comment. Both run again on the new head.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

server-integration-test (14) failed on 62eaf7a (superseded by f3c24c5), and it also looks unrelated. One test failed out of 342: chat-channel-deletion-and-summaries > keeps chats out of a deleted destination that a stale cache still lists. The delete returned CONFLICT / CHAT_CHANNEL_BUSY instead of NOT_FOUND, which looks like a race in chat channel deletion. This PR doesn't touch chat channels. The command menu suites that run in this shard passed.


Generated by Claude Code

…le-tree

# Conflicts:
#	packages/twenty-server/src/database/commands/upgrade-version-command/2-68/2-68-upgrade-version-command.module.ts
@FelixMalfait

Copy link
Copy Markdown
Member Author

Let's address comments

@twenty-ci-bot-public

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

Copy link
Copy Markdown

🚀 Preview Environment Ready!

Your preview environment is available at: https://legs-tan-whilst-charges.trycloudflare.com

This environment will automatically shut down after 5 hours.

Copy link
Copy Markdown
Member Author

Follow-up on server-integration-test (4): refuses a submission while its run is stopping failed again on 93351a5, the same way (FAILED instead of PENDING). What I checked:

  • It passes 3 out of 3 times locally on this branch.
  • It doesn't show up in the last 12 failed server runs on other branches.
  • It was added yesterday in Add the settings search feature flag #32233. It sets the run to STOPPING directly in the database and then expects the form step to still be PENDING. If the worker processes the stopping run in between, it marks the step FAILED, which is a race with the worker.

This PR doesn't touch workflow execution. One plausible reason it hits this PR every time: the PR adds integration specs, which changes how specs are split across shards, so this spec now runs alongside different neighbours. I haven't verified that. I'm leaving the test alone; a re-run of the shard should tell us more.


Generated by Claude Code

@FelixMalfait

Copy link
Copy Markdown
Member Author

Address relevant comments that are still open/resolve all

… so the copy can be re-run after the rollout

Copy link
Copy Markdown
Member Author

Update on server-integration-test (4): the re-run on 93351a5 passed, and that run is green. So refuses a submission while its run is stopping fails intermittently and doesn't fail every time on this PR. That fits the race described above. The race is in that test, not in this PR, so I'm leaving the test as it is.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

server-integration-test (16) failed on 8622937 in test/integration/usage-limit/api-rate-limit.integration-spec.ts, in "over REST › admits a request and rejects the one that follows it". It expected 429 and got 200.

This isn't from this PR: it doesn't touch rate limiting, REST or usage limits. The suite uses a 1-second bucket (WINDOW_SECONDS = 1, LIMIT_VALUE = 1), so if the first REST call takes long enough, the bucket refills before the second call, which then passes. The command-menu suites in the same shard passed. I'll re-run the failed job once when the run finishes.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Update on the two red integration shards on 8622937, after one re-run each:

  • server-integration-test (16), the rate-limit test: passed on the re-run.
  • server-integration-test (14), chat-channel-deletion-and-summaries › keeps chats out of a deleted destination that a stale cache still lists: failed again with the same CONFLICT / CHAT_CHANNEL_BUSY. It isn't caused by this PR:
    • The same test failed the same way today on another branch, claude/app-grants-approval-on-upgrade (run 47373176654), and passed on others.
    • The whole file passes locally on a freshly reset database, both on main (b3f15f0) and on this branch. It also passes locally when run after the two files that come before it in shard 14.
    • This PR doesn't touch chat channels or advisory locks.

It looks like a flaky lock timeout in that suite. I've used this PR's one re-run, so I'm leaving the check red rather than re-running it again.


Generated by Claude Code

…command-menu-rule-tree

# Conflicts:
#	packages/twenty-client-sdk/src/metadata/generated/schema.ts

This branch has not been deployed

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

Labels

-PR: awaiting review ci:allow-previous-version-upgrade-mutation Bypass the upgrade mutation guard for previous version directories.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant