Skip to content
This repository was archived by the owner on Nov 21, 2026. It is now read-only.

bench: pin ladybug 0.22.0 (0.21.2 cannot LOAD vector since the vendor overwrote its download) and bake the extension into the image by sha256 - #541

Merged
tae898 merged 1 commit into
mainfrom
bench/ladybug-0.22.0-repin
Oct 25, 2026
Merged

tae898 merged 1 commit into
mainfrom
bench/ladybug-0.22.0-repin

Conversation

@tae898

@tae898 tae898 commented Oct 25, 2026 •

Copy link
Copy Markdown

Stacked on #66 (native-two-dist). Closes the hardest native parity gap: Python functions called from SQL and openCypher, record event callbacks, the Ctrl-C behaviour of a Python function, and the crash in tests/test_async_executor.py. It covers 31 failures of test_python_callbacks.py, 1 of test_python_function_interrupt.py and the crash, from the 68 failures of the native parity run (parity-native-two-dist). Nothing here raises NotOnNativeYet: the features work on the native arcadedb, with the behaviour of arcadedb-jvm.

Status: draft. The code is committed and compiles; the native image with the new entry points is building (~/build-scratch/native-lib/callbacks), and the test counts below are filled in when the run ends.

Design: how the native image calls back into Python

  • One function pointer. Python registers a single ctypes CFUNCTYPE pointer with arcadedb_n_set_upcall (this existed for async callbacks). The image keeps it as a CFunctionPointer and calls it as fn(callbackId, json) -> char*. A Python-side table maps the id to the callable; the table entry is removed when the function is unregistered or replaced, when the listener is removed, and when the database closes, so the table does not grow (the CFUNCTYPE object itself lives as long as the module).
  • Registry entry point. A new arcadedb_n_cb(op, json) registers and removes functions and event listeners. Its checks, error wording, veto and failure rules are those of the JPype bridge (PythonFunctions, PythonRecordEvents): an engine function name is refused, replace=True is needed to replace, a revoked function says it was unregistered, a failing callback is Python function 'x' failed: ValueError: ... or Python 'before_create' callback failed: ..., a before_* callback returning False vetoes. The Python-side checks (name, callable, keyword-only, argument counts, event names) are one shared helper in arcadedb.callbacks now, used by both backends.
  • GIL. ctypes takes the GIL for a CFUNCTYPE call (PyGILState_Ensure), on the calling thread of the query or on a foreign Java thread (an async writer). The foreign-library call that is running the statement released the GIL, so there is no deadlock; a function may call back into the database.
  • Marshalling. Arguments are the tagged JSON of query parameters (NativeCodec), results go back through the same encoder as parameters. A record argument or event record arrives as a dict with @rid, @type and @cat and is wrapped as Document, Vertex or Edge. A result past a Java long is an OverflowError; numpy arrays and Decimal, datetime, list, dict work as on JPype.
  • Exceptions. A Python exception never crosses the C frame. _dispatch catches BaseException and replies {"error": "Type: text"}; the engine turns it into a CommandExecutionException (functions) or DatabaseOperationException (events), so the statement fails with the Python message and the surrounding transaction does not commit.
  • Reply memory. The reply text is allocated by the library (arcadedb_n_alloc); Java copies it and frees it. A thread-local Python buffer is not enough: on an async writer thread the callback's Python thread state ends as the callback returns, and the buffer went with it, so the engine read freed memory.
  • Ctrl-C. A KeyboardInterrupt in a function or callback is remembered per thread; the place that turns the statement's failure into an ArcadeDBError raises the KeyboardInterrupt instead, chained from that error, for query, command, iteration and to_list alike. The interrupt is cleared when a statement starts, so a stale one never turns a later error into a KeyboardInterrupt. A signal that arrives as the callback is entered is raised by CPython before _dispatch reaches its try; ctypes reports it as unraisable and returns NULL. A hook records it, and the engine fails the statement on a NULL reply. This is the same rule as the JPype backend (arcadedb.callbacks).

The async-executor crash

Not related to the callbacks themselves. test_per_record_callback_runs_before_the_batch_commits_and_on_ok_after calls db.count_type from an on_ok callback, which runs on an async writer thread. _thread_handle() saw a thread that was not a Python-created one and attached it to the isolate again as an owned handle. When the callback returned, CPython deleted the callback's thread state, _Thread.__del__ called graal_detach_thread on a thread that was still running Java code, and the image aborted (Fatal Python error: Aborted). The thread handle now asks graal_get_current_thread first: a thread that is attached already gets a handle that is never detached.

Behaviour change

NativeDatabase.register_function had positional min_args and max_args; it has the signature of the JPype one now (keyword-only min_args, max_args, deterministic, replace), and unregister_function and on exist. tests/test_native_udf.py uses the keywords. test_registering_again_and_again_does_not_grow_the_python_heap only forces a JVM gc on the JVM backend.

What is not here

The other parity failures (positional counts, record id values, bulk insert, log directory, PQ settings, docs examples, XML limits) are another change.

🤖 Generated with Claude Code

…nt image at build time

ladybug 0.21.2 can no longer LOAD vector: at 04:28 UTC on 2026-10-25 the vendor overwrote the v0.21.0 vector extension that every 0.21.x client downloads with a build of the 0.22 sources (undefined symbol Transaction::getMinUncommittedNodeOffset, LadybugDB/ladybug#1390). The 0.21.x line has no way back to a working extension, so the pin moves to 0.22.0 on the client and dense images.

The reason for the 0.21.2 pin (DECISIONS #129, 0.20.4 crashes the dense mutation phase after a deleted vector key is re-inserted) was re-run untimed on the laptop: the 0.20.4 control dies at mutate-insert-start in the same harness, 0.22.0 completes the pass.

The vector extension is now installed while the client image is built and checked against a sha256 in build_images.sh (bake_ladybug_extensions.py, LADYBUG_EXTENSIONS). INSTALL is a no-op on a file that is already present, so no lane changes; a replaced binary now stops the build instead of changing the engine under a pinned pass. test_ladybug_pin.py holds the chain.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tae898
tae898 marked this pull request as ready for review October 25, 2026 12:00
@tae898
tae898 merged commit bc1055d into main Oct 25, 2026
4 checks passed
@tae898
tae898 deleted the bench/ladybug-0.22.0-repin branch October 25, 2026 12:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant