Skip to content

feat(bolt): work with the official Neo4j drivers (KG-15) - #51

Merged
kamir merged 1 commit into
mainfrom
kg-15-bolt-driver-compat
Dec 4, 2026
Merged

kamir merged 1 commit into
mainfrom
kg-15-bolt-driver-compat

Conversation

@kamir

@kamir kamir commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

What

KafGraph's Bolt server works with the official Neo4j driver (neo4j-go-driver/v5). Smoke cases COMP-kafgraph-03, -05, -06 and -11 now run and pass; they are removed from pending in test/smoke, and KG-15 is no longer named for cases 04 and 12.

  • Handshake (internal/server/bolt.go): accepts the first proposal whose version range includes 4.4. Drivers send [0, range, minor, major], e.g. 4.4 down to 4.2. Before, only the exact value 0x00000404 was accepted, so no driver could connect.
  • Update counters: query.ResultSet has Stats (nodes-created, nodes-deleted, relationships-created, relationships-deleted, properties-set, labels-added). They are set by CREATE (node and edge), MERGE (only when it creates), SET and DELETE, and passed through WHERE/RETURN/ORDER BY/LIMIT. The SUCCESS after PULL carries type (w/r) and stats. In a cluster, the RPC carries the counters and the router adds them up.
  • Graph values: nodes and edges go over the wire as Bolt Node (0x4E) and Relationship (0x52) structures instead of maps. Bolt 4.4 needs integer IDs, and KafGraph IDs are strings, so the integer ID is a 63-bit FNV-1a hash of the KafGraph ID. Start and end node IDs of a relationship match their nodes.
  • GOODBYE (0x02): closes the connection without a reply. Before, the server answered with FAILURE.
  • Docs: docs/query-engine.md (handshake, summary, graph values), docs/architecture.md.

HTTP is unchanged: /api/v1/query builds its own output and keeps returning maps.

Checks

  • Locally: make lint (golangci-lint v2.15.0, 0 issues), gosec, make fmt-check, make vet, make test-race, make cover-check, hack/license-header.sh, make docs-sync-check and make test-smoke passed.
  • make test-smoke: cases 03, 05, 06, 11 and 14 pass with the official driver, and the other 9 are skipped with their KG entries.
  • New tests:
    • handshake with the driver's real proposals and ranges without 4.4;
    • counters for every write path, including two rows with the same node, DELETE of a relationship variable, and null properties;
    • PULL summary;
    • node and relationship structures;
    • nil properties after RPC;
    • GOODBYE;
    • stats over RPC and when shards are merged.

Review

A reviewer with fresh context read the diff. Fixed in this PR:

  • nodes-deleted counted delete attempts. Now each existing node is counted once, and the edges removed with it count as relationships-deleted.
  • After the cluster RPC, nil properties arrived as untyped nil, and remote rows went out as maps. They are now accepted.
  • Null properties were counted as properties-set.

Open, for a decision

  • The KafGraph ID is not visible over Bolt. Bolt 4.4 has only the integer ID; the earlier map carried id. KafGraph's CREATE (a)-[:R]->(b) takes node IDs, so a client that uses only Bolt cannot link the nodes it creates. Bolt 5.0 has element_id, which could carry the KafGraph ID. That would be a new roadmap row.
  • type follows the counters, not the statement. A MERGE that only finds a node reports r; Neo4j reports rw.
  • IDs and the JavaScript driver. The 63-bit IDs exceed the JavaScript driver's safe integer range when its option disableLosslessIntegers is on. They are fine with the default (lossless).
  • Map parameters shaped like a node. A map parameter with exactly the keys of a node map (id, label, properties, createdAt) is sent back as a Node.
  • Existing cluster behaviour, now visible in the counters:
    • The router sends writes to every owner, so a CREATE on N nodes creates N nodes and reports nodes-created: N.
    • A shard's error is dropped when another shard succeeds.
  • The smoke plan's cleanup query (MATCH (n {trace_id:…}) DETACH DELETE n) does not parse, so smoke nodes stay on an external target.
  • Rejecting UPDATE on Decision.immutable=true (from the plan's implementation note) is still not covered.

Ref: KG-15

🤖 Generated with Claude Code

The handshake accepted only the exact proposal 0x00000404, while drivers
offer 4.4 as a range (4.4..4.2), so no official driver could connect. It now
accepts the first proposal whose range includes 4.4.

The SUCCESS after PULL carries type and the update counters. query.ResultSet
gets Stats (nodes-created, nodes-deleted, relationships-created,
relationships-deleted, properties-set, labels-added), set by CREATE, MERGE,
SET and DELETE and kept through WHERE/RETURN/ORDER BY/LIMIT. The cluster RPC
carries them and the router adds them up across shards.

Nodes and edges go over Bolt as Node (0x4E) and Relationship (0x52)
structures instead of maps, with an integer id hashed from the KafGraph id
(Bolt 4.4 needs integers). HTTP is unchanged. GOODBYE closes the connection
without a FAILURE.

Smoke cases COMP-kafgraph-03, -05, -06 and -11 now pass with
neo4j-go-driver/v5 and are no longer pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamir
kamir merged commit 806197c into main Dec 4, 2026
4 checks passed
PaxMachinaOne pushed a commit that referenced this pull request Dec 4, 2026
@kamir
kamir deleted the kg-15-bolt-driver-compat branch December 4, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant