{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/concepts/transactions-and-concurrency/: the program exactly as the page shows it, the standard output a run of it recorded (npm run docs:samples compares every replay with it byte for byte), the relate client build, toolchain and platform of the last replay, and how the docs' sample runner builds and runs it. Before launch every client is a source build, not a published package; verified.client names the upstream commit it was built from, and verified.docs_engine the build the rest of the docs were recorded from.",
  "id": "conflict",
  "url": "https://relatedb.ai/docs/concepts/transactions-and-concurrency/samples/conflict.json",
  "page": {
    "id": "concepts/transactions-and-concurrency",
    "title": "Transactions and concurrency",
    "url": "https://relatedb.ai/docs/concepts/transactions-and-concurrency/",
    "md_url": "https://relatedb.ai/docs/concepts/transactions-and-concurrency.md"
  },
  "section": {
    "anchor": "write-write-conflicts-and-retry",
    "heading": "Write-write conflicts and retry",
    "url": "https://relatedb.ai/docs/concepts/transactions-and-concurrency/#write-write-conflicts-and-retry"
  },
  "language": "js",
  "client": "Node.js",
  "file": "conflict.cjs",
  "env": null,
  "code": "const { Database } = require(\"@relate/relate\");\n\nconst db = Database.open(\":memory:\");\nconst a = db.connect();\nconst b = db.connect();\n\na.query(`CREATE (ada:Person {name: 'Ada', role: 'engineer'}),\n       (grace:Person {name: 'Grace', role: 'engineer'}),\n       (noor:Person {name: 'Noor', role: 'maintainer'}),\n       (relate:Project {name: 'relate', language: 'Rust'}),\n       (tck:Project {name: 'opencypher-tck', language: 'Gherkin'}),\n       (ada)-[:WORKS_ON {since: 2024}]->(relate),\n       (grace)-[:WORKS_ON {since: 2023}]->(relate),\n       (grace)-[:WORKS_ON {since: 2022}]->(tck),\n       (noor)-[:MAINTAINS]->(relate),\n       (ada)-[:KNOWS]->(grace)`);\n\nconst roleOf = (conn) =>\n  conn.query(\"MATCH (p:Person {name: $name}) RETURN p.role AS role\", { name: \"Ada\" }).rows[0].role;\n\n// A begins; its reads now come from the last commit before begin.\na.begin();\nconsole.log(`A reads: ${roleOf(a)}`);\n\n// B changes the same node in autocommit.\nb.query(\"MATCH (p:Person {name: 'Ada'}) SET p.role = 'lead'\");\nconsole.log(`B commits, then reads: ${roleOf(b)}`);\nconsole.log(`A still reads: ${roleOf(a)}`);\n\n// A writes the node B changed; the conflict surfaces at commit.\na.query(\"MATCH (p:Person {name: 'Ada'}) SET p.role = 'architect'\");\ntry {\n  a.commit();\n} catch (e) {\n  console.log(`A's commit fails: ${e.message} (${e.code}, retryable: ${e.retryable})`);\n}\n\n// The failed transaction is gone; the retry starts from the latest commit.\na.begin();\nconsole.log(`A's retry reads: ${roleOf(a)}`);\na.query(\"MATCH (p:Person {name: 'Ada'}) SET p.role = 'architect'\");\na.commit();\nconsole.log(`After the retry: ${roleOf(b)}`);",
  "code_sha256": "16d4bd14e232bcdc1c3df3d44711c033b94c3f77197b49fe6f87cb67ba254d98",
  "source_sha256": "877fa30426c8cb6085bd6602f1bdf018d474810a1cba436d6fe0163523c4e5c4",
  "output": {
    "text": "A reads: engineer\nB commits, then reads: lead\nA still reads: engineer\nA's commit fails: write-write conflict (Neo.TransientError.Transaction.Outdated, retryable: true)\nA's retry reads: lead\nAfter the retry: architect",
    "sha256": "f8555e3a385b802a9093b06fb943b3b8f4cfab0f5f6c2613be6716dd5b81883b"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "Node.js",
      "package": "@relate/relate",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "A copy of clients/javascript at upstream v0.1.2 (f0c09d2) with koffi, loading librelate_ffi built from the same commit (cargo build -p relate-ffi --release), with the pinned frameworks beside it.",
      "toolchain": {
        "node": "26.13.0"
      }
    },
    "packages": [
      "ai@7.0.165",
      "zod@4.6.7",
      "@mastra/core@1.82.0"
    ],
    "replayed": "2026-11-09",
    "platform": "macOS on arm64",
    "docs_engine": {
      "version": "0.1.2",
      "commit": "f0c09d2",
      "source_build": false
    }
  },
  "run": {
    "runner": "npm run docs:samples",
    "setup": "bash scripts/samples/setup.sh --upstream <path to the relate checkout>",
    "variables": [
      "RELATE_NODE",
      "NODE_PATH",
      "RELATE_LIB"
    ],
    "program": "<run dir>/conflict.cjs",
    "files": [
      {
        "path": "<run dir>/node_modules",
        "link": "$NODE_PATH",
        "note": "a link, so require and import both resolve @relate/relate"
      }
    ],
    "build": null,
    "run": {
      "command": [
        "$RELATE_NODE",
        "conflict.cjs"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "unset": [
        "NODE_OPTIONS"
      ],
      "directory": "<run dir>",
      "timeout_s": 60
    },
    "passes": "It exits 0 within 60 s and prints at least one line on standard output.",
    "output": "Standard output, with line endings as \\n, trailing spaces and blank lines removed, and the temporary directories' paths written as `.`; standard error is not recorded.",
    "placeholders": {
      "<run dir>": "a fresh, empty temporary directory: the program's working directory, deleted afterwards",
      "<build dir>": "a second fresh temporary directory, where a compiled sample is built",
      "$NAME": "a variable from the env.sh that scripts/samples/setup.sh writes (described in its header)"
    }
  }
}
