Skip to content

Add the reasoner worker, launcher and memory budget to the Fuseki image - #1

Merged
harshach merged 20 commits into
release/6.2.0from
openmetadata/reasoner-worker
Oct 11, 2026
Merged

harshach merged 20 commits into
release/6.2.0from
openmetadata/reasoner-worker

Conversation

@harshach

@harshach harshach commented Oct 9, 2026 •

Copy link
Copy Markdown

Phase 1 of OpenMetadata's reasoning inside the Fuseki image design: a reasoner worker that the Fuseki extension launches as a separate JVM inside the existing image, the launcher and its memory-budget check, and the image packaging. No new service, port or container. HTTP job operations come in a later PR; until then reasoning runs only through /jena-fuseki/reasoner/bin/reasoner, and nothing launches a worker unless OPENMETADATA_REASONING_ENABLED=true and the extension is enabled.

Included

  • openmetadata/fuseki/reasoner/: worker (org.openmetadata.reasoner.Main <step-file>) on OWL API 5.5.1, OpenMetadata's HermiT build (LGPL-3.0, built from pinned commit bb78447a of open-metadata/hermit-reasoner) and ELK 0.6.0; Jena is provided by fuseki-server.jar.
    • Steps: LOAD, CLASSIFY, EXPLAIN, COMPACT.
    • ELK only for OWL 2 EL closures with no known ELK gap and only asserted property values; otherwise HermiT, which is asked only for property values it can entail (sub/inverse/chain/symmetric/transitive/reflexive/has-value/has-self), with a full query when nominals, anonymous individuals or functional constraints can connect individuals.
    • Entailments stream into the output graph in one TDB2 write transaction that commits only on completion. The sorted fact report is opt-in and bounded.
    • Admission limits scale with the worker heap (2 GiB default: 300k closure triples, 200k axioms, 50k individuals, 1M output triples). EXPLAIN is capped at 1,000 consistency checks.
  • Extension: WorkerLauncher takes a per-container lock and then checks the memory budget (a concurrent step gets BUSY), passes only an allowlisted environment (no ADMIN_PASSWORD), cancels only the running step (SIGTERM, then SIGKILL after the grace period), kills and waits for the worker if the caller is interrupted, removes leftovers after a failed step, keeps a bounded log, and reports a SIGKILL it did not send as INCOMPLETE MEMORY_BUDGET (probable cgroup OOM). Plus Readiness, ReasoningSettings, ReasoningModule and bin/reasoner.
  • Image: a builder stage (pinned by digest) builds HermiT and the worker into /jena-fuseki/reasoner/ with NOTICE, THIRD-PARTY.md, licence texts and the HermiT sources; the build fails on any jar checksum drift.
  • Entrypoint: validates OPENMETADATA_REASONING_ENABLED and OPENMETADATA_REASONER_{HEAP,OFF_HEAP,PAGE_CACHE_FLOOR,CPUS} with the same rules as the extension (one shared case table runs through both). Nothing changes when they are unset; an invalid value stops the container at startup.
  • Workflow: runs the extension and reasoner tests, builds the image and runs the smoke test.

Test evidence

  • extension mvn verify: 127 unit + 7 integration tests.
  • reasoner mvn verify: 152 unit + 5 integration tests, including 53 hand-derived conformance fixtures (ELK-routed fixtures cross-checked against HermiT), a differential test of property values against HermiT asked about every property, integration tests through the launcher's real command, and a catalog-shaped scale test.
  • Scale (HermiT, 2 GiB worker heap): 20k individuals in ~16 s, 0.27 GiB after collection (44 s before the property-value change); 50k individuals in ~44 s, 0.67 GiB.
  • Smoke test on the built image (arm64 native build): all 69 checks pass, including all 53 fixtures, out-of-heap, deadline, stopped-worker and SIGKILL containment, no ADMIN_PASSWORD in the worker, and BUSY while a worker runs.

Open decisions

  • Default sizes are provisional until measured in a deployment: worker heap 2 GiB, the per-GiB limits above, and the off-heap starting values.
  • Asserted values in the output: VALUE output still contains asserted property values. Dropping them would shrink the output graph but changes the output contract and the fixtures.
  • The :6.2.0 tag: merging publishes openmetadata/fuseki:6.2.0 and :6.2.0-<sha> from a multi-arch build that is smoke-tested on amd64 only. Proposed follow-up workflow change: publish only 6.2.0-<sha>, smoke-test the pushed digest on amd64 and arm64, then retag that digest as :6.2.0.

A standalone Maven project, openmetadata/fuseki/reasoner, for the batch
program that the Fuseki extension will launch as a separate JVM, one step
at a time. It never runs inside the Fuseki JVM, opens only its job's
private TDB2 dataset, has no network listener and fetches nothing.

Each step is a JSON step file in a job directory; every path it names must
stay inside that directory. The worker writes a result manifest atomically
next to it and exits with an explicit status: 0 completed, 1 internal
error, 2 invalid step, 3 out of memory (reserved for
-XX:+ExitOnOutOfMemoryError), 4 input rejected, 5 time budget.

Steps:
- LOAD bulk-loads N-Quads or TriG into a fresh dataset with the phased
  loader.
- CLASSIFY exports one import closure in a read transaction, resolves
  owl:imports only against the closure's own graphs, parses it with OWL
  API, rejects anything outside OWL 2 DL or the admission limits, routes
  it, and writes the finite named entailments into an output graph:
  direct subclasses, equivalences, unsatisfiable classes, direct types
  and, with HermiT, property values and equalities. It also answers
  entailment checks: ENTAILED, NOT_ENTAILED (never a proven negation),
  INCONSISTENT or INVALID.
- EXPLAIN computes one justification with OWL API's black-box explanation
  over HermiT.
- COMPACT compacts the dataset before publication.

Routing sends a closure to ELK only when it is in OWL 2 EL and uses
nothing ELK 0.6.0 reports as incomplete, and falls back to HermiT if ELK
still reports incompleteness. HermiT runs with an explicit configuration,
with disjunction learning off.

Jena is provided by fuseki-server.jar, and libraries it already bundles at
newer versions are excluded rather than shadowed, as are Woodstox, the
StAX API, commons-logging and the OWL API's RDF4J, JSON-LD and HTTP
modules.
Fifty fixtures, each a TriG input, a CLASSIFY step file, optional
entailment checks in OWL functional syntax, and an expected canonical
report derived by hand from the OWL 2 Direct Semantics. They cover every
construct in the design's coverage table, combinations, local imports
(including import by version IRI, a missing import and two contexts that
share IRIs without leaking conclusions), inconsistency, open-world
counterexamples where a statement and its negation are both NOT_ENTAILED,
and closures outside OWL 2 DL that must be rejected rather than
classified.

routing.expected names the engine production routing must pick. Every
fixture routed to ELK runs through both ELK and HermiT with identical
reports, and every OWL 2 EL fixture that ELK would answer incompletely is
refused when ELK is forced.
The extension now holds the launcher the Fuseki module will use to run
worker steps, with JDK and Jena classes only.

Readiness reads the container limit from cgroup v2 memory.max, else
cgroup v1, else physical memory, and requires
limit >= (H_f + O_f + H_w + O_w + C_min) / 0.9. Before every step it also
reads the container's anonymous memory, and refuses to launch when
Fuseki's has outgrown H_f + O_f. When the budget does not fit it reports
NOT_READY with the required and available bytes and admits nothing.

The launcher runs the worker with its own flags, never the server's:
choom -n 1000, nice and ionice, a fixed heap, capped metaspace, code
cache and direct memory, -XX:+ExitOnOutOfMemoryError, a processor count
and fuseki-server.jar first on the classpath. It holds a file lock so one
worker runs per container, terminates a worker that outlives its own
deadline (SIGTERM, then SIGKILL) and maps exit statuses to SUCCEEDED,
FAILED, INCOMPLETE or INTERRUPTED in a status file next to the step.

A second Fuseki module logs readiness at startup when reasoning is
enabled and does nothing otherwise. ReasonerCli exposes readiness and
step runs to operators and the image tests.
A new builder stage, run on the build platform like the extension's,
builds HermiT from open-metadata/hermit-reasoner at a pinned commit and
then the worker. The build fails unless the fuseki-server.jar Maven
compiled against is byte for byte the one the image ships, and unless
every third-party jar matches dependencies.sha256.

The worker and its 32 dependency jars go to /jena-fuseki/reasoner, in the
image and never on the volume, with the HermiT source jar, NOTICE,
THIRD-PARTY.md, the licence texts and bin/reasoner, the launcher's
command line. The image grows by about 15 MB.
OPENMETADATA_REASONING_ENABLED, OPENMETADATA_REASONER_HEAP, _OFF_HEAP,
_PAGE_CACHE_FLOOR and _CPUS are checked whenever they are set, and an
invalid value stops the container with an ERROR naming the variable.
Reasoning needs the extension, whose module launches the worker. With the
variables unset nothing changes.
OWL API's black-box explanation expands from the signature of the class
it explains, and owl:Thing has none, so it returned an empty justification
for an inconsistent closure. EXPLAIN now finds a minimal inconsistent
subset with QuickXplain over HermiT consistency checks, each interruptible
by the step's deadline; entailments keep the black-box generator.

An import smuggled into a checks file or an explanation target surfaced
as an unchecked OWL API exception, reported as an internal error. It is
now rejected as IMPORT_NOT_ALLOWED, still without any fetch.
- StepContractTest: invalid step files, paths that leave the job
  directory (including through a symbolic link), loads that need a fresh
  dataset and quads, admission limits that reject rather than truncate,
  and checks about unknown entities answered INVALID.
- NoNetworkTest: an HTTP server on localhost serves every IRI the inputs
  name and must receive no request, whether an import is missing,
  resolvable inside the closure, or smuggled into checks or an
  explanation target.
- TimeBudgetTest: a generated closure HermiT cannot classify in minutes
  ends INCOMPLETE at its deadline, with the interrupt latency recorded.
- ExplainStepTest and EntailmentGraphTest: one justification per target,
  and the persisted hierarchy answering the design's discovery query after
  compaction.
- WorkerProcessIT, in the integration-test phase: the packaged worker on
  fuseki-server.jar plus target/reasoner/* with the launcher's JVM flags,
  exit status 3 on heap exhaustion and 5 at its deadline, and the shipped
  jars exactly the pinned ones, each listed in THIRD-PARTY.md.
A job directory the server's uid cannot write made the command line fail
with a stack trace and print nothing. The launcher now logs the failed
write and still returns the outcome.
The smoke test now covers the reasoner through the image's real launcher,
command line and classpath:

- Settings: reasoning is off by default and every OPENMETADATA_REASONER_*
  variable fails fast on an invalid value; reasoning without the
  extension is refused.
- Readiness: a 1 GiB container logs and reports NOT_READY with required
  and available bytes, refuses a step and starts no worker, and Fuseki
  serves as usual.
- Conformance: in a container whose --memory is exactly the budget's
  minimum, every conformance fixture's report matches, each answered
  fixture is routed to its expected engine, and every ELK-routed fixture
  gives the identical report through HermiT.
- Containment: with 1,000 serving triples seeded, a worker exhausting a
  48m heap ends INCOMPLETE with exit status 3, a classification past its
  5 s budget ends INCOMPLETE, a stopped worker is killed after its
  deadline, and a worker killed with SIGKILL during a bulk load ends
  INTERRUPTED without a result manifest. Fuseki answers queries
  throughout, and after each case it is the same process, was never OOM
  killed, keeps its heap, serves the same data and still commits writes.

hard-ontology.awk generates the 58 KB closure HermiT cannot classify in
minutes, byte for byte the same as the reasoner tests' generator. The
smoke test now needs jq.
Before the image build, install OpenMetadata's HermiT build from the
commit the Dockerfile pins, then run mvn -B -ntp verify for the reasoner:
its unit and conformance tests and the integration tests of the packaged
worker. Publishing is unchanged.
A Reasoner section in the README: what runs where, the engines and the
routing between them, HermiT's configuration and the measurements behind
turning disjunction learning off, the step contract and outcomes, the
memory-budget formula with a worked example, what readiness reports and
where, the launch command, licences and the HermiT source, and how to
build and test the reasoner. The environment variable table and the
layout list the new variables and directories.
@harshach
harshach marked this pull request as ready for review October 10, 2026 15:28
Classification asked HermiT for the values of every object property of
every named individual, and routed every closure with an object property
assertion to HermiT. Most catalog properties only ever have their
asserted values. PropertyValues now finds the properties that can gain
values (sub-, equivalent and inverse properties, chains, symmetry and
transitivity, reflexivity, has-value and has-self) and the constructs
that defeat a per-property analysis, which fall back to asking about
every property. Asserted values are read from the closure and moved
across equal individuals; a closure in OWL 2 EL whose values are all
asserted stays with ELK.

The output is unchanged: every conformance report and routing is the
same, and a differential test compares the values with HermiT's for
every property on every answered fixture and on closures that reach
named individuals through anonymous ones. On a catalog-shaped closure
of 20,000 individuals and 30 properties, classification takes 16 s
instead of 44 s.
A classification held its facts in a TreeSet, then copied them into
report lines, a sorted report, an immutable copy, a list of triples and
a StringBuilder, and counted each kind by streaming the set again. Facts
now go to the output graph as the classifier finds them, inside one
write transaction that commits only when the step completes, so a
failed step still leaves the graph's previous contents. Each pair is
recorded once, from its first member in IRI order, so nothing needs
deduplicating; counts are kept as facts arrive.

The opt-in report, which repeats the output graph, keeps only its first
100,000 lines in order and says how many it left out, and is written to
disk as a stream. Sorting it is all that determinism requires; the
output graph is a set.
The default limits (2M closure triples, 500k axioms, 5M output triples)
were far beyond what the 2 GiB default worker heap holds. The limits
that bound the heap now default to a size per GiB of it, measured on a
catalog-shaped closure: 300k triples, 200k axioms, 50k individuals and
1M output triples with a 2 GiB heap. The manifest records the limits a
step ran with.

Limits accepted fractions and silently truncated them. Every integer in
a step file is now parsed exactly; fractions and values outside a long
are invalid.

EXPLAIN ran one fresh HermiT per consistency check with only the step's
deadline to stop it. maxExplainChecks (default 1,000) bounds the checks
of both the black-box explanation and QuickXplain, and is reported as
LIMIT_EXCEEDED. QuickXplain reuses one ontology manager instead of one
per check, and returns an empty subset for a closure without logical
axioms instead of recursing without end.
ClosureDocument kept the exported file's path and exposed it and the
triple count through accessors nothing called. Engine.workerVersion()
was never used; the manifest's worker section now carries it, next to
the Java version and heap figures.
- cancel() set a flag that was never cleared, so every later step on
  the same launcher ended CANCELLED. A cancellation now belongs to the
  step running when it is made, gets SIGTERM at once and SIGKILL after
  the grace period, as its javadoc said, and the termination latency is
  measured from it instead of being reported as 0.
- An interrupted caller killed the worker and released the worker lock
  without waiting for it to exit; it now waits, uninterruptibly and for
  a bounded time, so two workers never overlap.
- The worker inherited the server's whole environment, ADMIN_PASSWORD
  included. It now gets only PATH, the locale, TZ and HOME.
- The lock is taken before the memory budget is checked, so a step
  requested while a worker runs is BUSY, not NOT_READY because of the
  running worker's memory. BUSY writes no status file, since the running
  step may be the same file, and nothing is written next to a step file
  outside the reasoning root.
- A step that does not succeed has its exported closure and *.tmp files
  removed; a stale status file is removed before the worker starts.
- Exit statuses come from WorkerExitCodes, which mirrors the worker's
  ExitCodes (this module cannot see them). A SIGKILL the launcher did
  not send is reported INCOMPLETE MEMORY_BUDGET, the cgroup OOM killer.
- The step log keeps the first and last 512 KiB of the worker's output.
- timeoutMillis is read with the worker's rules: the 1 MiB step file
  cap and exact integers, so 1000.5 is refused rather than truncated.
…extension

The entrypoint treated an empty variable as unset, but ReasoningSettings
used containsKey and then failed to parse the empty string, so a
container started fine and docker exec bin/reasoner refused to run.
The two also disagreed on digit limits (CPUs unbounded in the shell, six
digits in Java; sizes 13 and 16 digits), and a 13-digit size with a t
suffix overflowed bash arithmetic into a negative number.

Java now treats an empty value as unset; both cap sizes at 13 digits
and a byte count that fits a signed 64-bit integer, and CPU counts at
six digits. The entrypoint's validation is a function, and sourcing the
script defines its functions without running it.
test/reasoning-settings.cases lists values and verdicts that
ReasoningSettingsParityTest runs through both the entrypoint (with bash
4 or later, as in the image) and ReasoningSettings.
WorkerProcessIT copied the launcher's JVM flags, so a change to the
launch command could break the image without failing a test. The
reasoner's test build now compiles the extension's launcher sources
(build-helper add-test-source; nothing changes in either jar), and the
integration tests lay out the image's directories and start the
packaged worker with WorkerLauncher itself: its command, environment
allowlist, priority commands where the platform has them, and outcome
mapping. They also check that a worker out of heap or past its deadline
leaves no exported closure, and that the manifest carries the worker's
version.

LauncherContractTest compiles WorkerExitCodes next to the worker's
ExitCodes and requires them equal, and runs step ids, deadlines and an
oversized file through both StepFile and the launcher's StepHeader,
which must agree.

A scale test classifies a catalog-shaped closure (20,000 individuals,
30 object properties, a transitive hierarchy and its inverse, routed to
HermiT) in the default 2 GiB heap under the default limits, and bounds
its time and heap. It took 44 s and peaked at 0.28 GiB after collection
before this branch's classifier changes; it now takes about 16 s and
0.27 GiB. At 40,000 individuals: 90 s before, 34 s after.
ELK 0.6.0 reports a property range together with assertions as
possibly incomplete. Before this branch every closure with an assertion
went to HermiT, so the README's claim that such closures never reach
ELK held without a check; now that asserted values stay on ELK, the
router lists the combination as an ELK gap. A new fixture covers it,
and forcing ELK on it is refused like the other gaps.

ClassifierFallbackTest forces ELK on that closure and checks that the
run-time incompleteness report makes HermiT classify it, and that only
HermiT's facts are recorded.
The reasoner builder stage used the floating maven:3.9-eclipse-temurin-21
tag; it is pinned to the digest that tag resolves to today
(3.9.16-eclipse-temurin-21). The HermiT comment named a branch and pull
request that are now merged into master (0e2dbb2f); the pinned commit is
unchanged and reachable from it.

The smoke test now expects a worker SIGKILLed during a load to report
INCOMPLETE MEMORY_BUDGET, and checks in the image that the worker's
environment has no ADMIN_PASSWORD and that a step requested while a
worker runs is BUSY.
@harshach
harshach merged commit ba8c74b into release/6.2.0 Oct 11, 2026
3 checks passed
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