{"record":{"id":"d38051126fee60ec","repo":"toeverything/AFFiNE","slug":"modelcruderror","errorCode":"ModelCRUDError","errorMessage":"updating block: ${model.id} not found","messagePattern":"updating block: (.+?) not found","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"error","filePath":"blocksuite/framework/store/src/model/store/store.ts","lineNumber":893,"sourceCode":"    if (!model) {\n      throw new BlockSuiteError(\n        ErrorCode.ModelCRUDError,\n        `updating block: ${modelOrId} not found`\n      );\n    }\n\n    if (!isCallback) {\n      const parent = this.getParent(model);\n      this.schema.validate(\n        model.flavour,\n        parent?.flavour,\n        callBackOrProps.children?.map(child => child.flavour)\n      );\n    }\n\n    const yBlock = this._yBlocks.get(model.id);\n    if (!yBlock) {\n      throw new BlockSuiteError(\n        ErrorCode.ModelCRUDError,\n        `updating block: ${model.id} not found`\n      );\n    }\n\n    const block = this.getBlock(model.id);\n    if (!block) return;\n\n    this.transact(() => {\n      if (isCallback) {\n        callBackOrProps();\n        this._runQuery(block);\n        return;\n      }\n\n      if (callBackOrProps.children) {\n        this._crud.updateBlockChildren(\n          model.id,","sourceCodeStart":875,"sourceCodeEnd":911,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/framework/store/src/model/store/store.ts#L875-L911","documentation":"Thrown by Store.updateBlock after the model was resolved from the block index but the underlying yBlock is missing from the Yjs map (_yBlocks.get(model.id) is undefined). This indicates the in-memory model and the yjs source of truth have diverged: the block was removed from the yMap (e.g. by a peer's delete replicated mid-call) while the local block index still held the model.","triggerScenarios":"Calling updateBlock on a model that was just deleted by a concurrent/remote operation; a delete transaction that removed the yBlock but the model index hasn't caught up; calling updateBlock inside a sequence where an earlier step deleted the block.","commonSituations":"Collaborative editing race (peer deletes while local user edits); undo/redo that removed the block; batched operations that delete-then-update; a stale model captured before a sync cycle.","solutions":["Re-check existence immediately before mutating: if (!store._yBlocks.has(model.id)) return; or use the block index freshly.","Sequence dependent operations so a delete aborts subsequent updates on the same block.","Subscribe to yMap observe events and invalidate cached model references on delete.","Wrap collaborative-edit handlers so they re-resolve the target after each await/transaction."],"exampleFix":"// before\nstore.updateBlock(model, props);\n\n// after\nif (!store.getBlock(model.id)) return; // model already gone\nstore.updateBlock(model, props);","handlingStrategy":"validation","validationCode":"export function assertYBlockExists(store: Store, model: BlockModel): void {\n  // Re-resolve right before mutating; the block index is the source of truth\n  if (!store.getBlock(model.id)) {\n    throw new Error(`updateBlock aborted: '${model.id}' no longer exists`);\n  }\n}\n\nassertYBlockExists(store, model);\nstore.updateBlock(model, props);","typeGuard":"export const isLiveBlock = (store: Store, model: BlockModel): boolean =>\n  Boolean(store.getBlock(model.id));","tryCatchPattern":"try {\n  store.updateBlock(model, props);\n} catch (e) {\n  if (e instanceof BlockSuiteError && e.code === ErrorCode.ModelCRUDError && /not found/.test(e.message)) {\n    // remote peer deleted the block mid-edit; abort this edit\n    return;\n  } else throw e;\n}","preventionTips":["Re-check the block index immediately before updateBlock in collaborative flows.","Subscribe to yMap observe events to invalidate stale model references on delete.","Sequence dependent ops so a delete cancels subsequent updates on the same block.","Re-resolve targets after each await/transaction in edit handlers."],"tags":["model-crud","updateblock","yjs","collaboration-race"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}