twentyhq/twenty · error · Error

Failed to fix merge command menu item expression for workspa

Error message

Failed to fix merge command menu item expression for workspace ${workspaceId}

What it means

Thrown by the 1.22 workspace upgrade command when validateBuildAndRunLegacyWorkspaceMigration returns 'fail' while fixing the 'select all' expression on the merge command menu item. The failure JSON is logged first, then the command aborts for that workspace.

Source

Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/1-22/1-22-workspace-command-1780000003000-fix-merge-command-select-all.command.ts:130

          allFlatEntityOperationByMetadataName: {
            commandMenuItem: {
              flatEntityToCreate: [],
              flatEntityToDelete: [],
              flatEntityToUpdate: itemsToUpdate,
            },
          },
          workspaceId,
          applicationUniversalIdentifier:
            twentyStandardFlatApplication.universalIdentifier,
        },
      );

    if (validateAndBuildResult.status === 'fail') {
      this.logger.error(
        `Failed to fix merge command expression:\n${JSON.stringify(validateAndBuildResult, null, 2)}`,
      );

      throw new Error(
        `Failed to fix merge command menu item expression for workspace ${workspaceId}`,
      );
    }

    this.logger.log(
      `Successfully updated ${itemsToUpdate.length} command menu item expression(s) for workspace ${workspaceId}`,
    );
  }
}

View on GitHub (pinned to 1f5dd2bbd2)

Solutions

  1. Inspect the logged validateAndBuildResult JSON for the exact expression or lookup error.
  2. Recompute the workspace cache and re-run.
  3. Run --dryRun to confirm itemsToUpdate is non-empty and targets the merge command.
  4. Isolate the failing workspace and reconcile its merge command metadata.
Defensive patterns

Strategy: validation

Validate before calling

// Dry-run and confirm the merge command menu item exists in cache before the real run:
await workspaceCacheService.invalidate(workspaceId);
const { flatCommandMenuItemMaps } = await workspaceCacheService.getOrRecompute(workspaceId, ['flatCommandMenuItemMaps']);
if (!isDefined(flatCommandMenuItemMaps.byUniversalIdentifier[MERGE_COMMAND_ITEM_ID])) {
  throw new Error('Merge command menu item missing; cannot patch select-all expression');
}

Try / catch

try {
  await command.runOnWorkspace({ workspaceId, options });
} catch (err) {
  logger.error(`Merge command expression fix failed for workspace ${workspaceId}`, err);
  failedWorkspaces.push(workspaceId);
}

Prevention

When it happens

Trigger: Running the merge-command select-all fix on a workspace where the merge command menu item is absent from cache, or the new expression fails the builder's expression validation.

Common situations: Workspace cache missing the merge command item so the update targets nothing; expression syntax rejected by the validator; partial prior upgrade left the item in an inconsistent state.

Related errors


AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12). Data as JSON: /api/errors/1f8d638ae394175f. Report an issue: GitHub.