{"record":{"id":"e4fdfc61da9f97e8","repo":"hcengineering/platform","slug":"model-txes-must-target-only-core-space-model","errorCode":null,"errorMessage":"Model txes must target only core.space.Model","messagePattern":"Model txes must target only core\\.space\\.Model","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/tool/src/index.ts","lineNumber":125,"sourceCode":"    txes: JSON.parse(JSON.stringify(rawTxes)) as Tx[]\n  }\n}\n\n/**\n * @public\n */\nexport async function initModel (\n  ctx: MeasureContext,\n  workspaceId: WorkspaceUuid,\n  rawTxes: Tx[],\n  adapter: DbAdapter,\n  storageAdapter: StorageAdapter,\n  logger: ModelLogger = consoleModelLogger,\n  progress: (value: number) => Promise<void>\n): Promise<void> {\n  const { txes } = prepareTools(rawTxes)\n  if (txes.some((tx) => tx.objectSpace !== core.space.Model)) {\n    throw Error('Model txes must target only core.space.Model')\n  }\n\n  try {\n    logger.log('creating database...', { workspaceId })\n    const firstTx: Tx = {\n      _class: core.class.Tx,\n      _id: 'first-tx' as Ref<Tx>,\n      modifiedBy: core.account.System,\n      modifiedOn: Date.now(),\n      space: core.space.DerivedTx,\n      objectSpace: core.space.DerivedTx\n    }\n\n    await adapter.upload(ctx, DOMAIN_TX, [firstTx])\n\n    await progress(30)\n\n    logger.log('creating data...', { workspaceId })","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/tool/src/index.ts#L107-L143","documentation":"initModel (server/tool/src/index.ts:125) validates that every transaction in the provided tx array targets the model space (core.space.Model) before building the workspace model. If any tx has a different objectSpace, model construction would mix domain data into the model, so it throws immediately before creating the database.","triggerScenarios":"Calling createWorkspace (which calls initModel) with raw txes that include transactions whose objectSpace !== core.space.Model — e.g. passing both model and domain/document txes, or hand-built txes missing objectSpace: core.space.Model.","commonSituations":"Custom workspace-creation scripts passing mixed tx sets; plugins whose derived txes lost objectSpace after a refactor; migrating model data from another system where the space field was dropped.","solutions":["Filter txes to model space before calling: `txes.filter(tx => tx.objectSpace === core.space.Model)`.","Ensure every model tx is created via model helpers (Tx.createTxCreate etc.) with `objectSpace: core.space.Model`.","Check the plugin list passed to prepareTools — a custom plugin may emit txes targeting a domain space; fix that plugin.","Log offending txes (`txes.filter(t => t.objectSpace !== core.space.Model)`) to identify the source."],"exampleFix":"// before\nawait initModel(ctx, workspaceId, allTxes, ...)\n// after\nconst modelTxes = allTxes.filter((tx) => tx.objectSpace === core.space.Model)\nawait initModel(ctx, workspaceId, modelTxes, ...)","handlingStrategy":"validation","validationCode":"import { core } from '@hcengineering/core'\nconst bad = txes.filter((tx) => tx.objectSpace !== core.space.Model)\nif (bad.length > 0) throw new Error(`${bad.length} tx(es) do not target core.space.Model`)","typeGuard":"function isModelTx(tx: Tx): boolean {\n  return tx.objectSpace === core.space.Model\n}","tryCatchPattern":"try {\n  await createWorkspace(ctx, workspaceId, txes)\n} catch (err) {\n  if ((err as Error).message === 'Model txes must target only core.space.Model') {\n    console.error('Non-model tx present; filter txes to core.space.Model')\n  }\n  throw err\n}","preventionTips":["Always create model txes via Tx.createTx* helpers with objectSpace: core.space.Model.","Never concatenate document txes with model txes in workspace-creation scripts.","Add a unit assertion that plugin-derived txes target core.space.Model.","Use prepareTools output rather than hand-assembled tx arrays."],"tags":["model","validation","transactions"],"backgroundTag":"invalid-model-transaction","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}