Skip to content

Serve the reasoning job operations at /reasoning - #2

Merged
harshach merged 6 commits into
release/6.2.0from
openmetadata/reasoning-jobs
Oct 11, 2026
Merged

harshach merged 6 commits into
release/6.2.0from
openmetadata/reasoning-jobs

Conversation

@harshach

Copy link
Copy Markdown

First slice of phase 4 of OpenMetadata's reasoning inside the Fuseki image design: the HTTP job API OpenMetadata will call, with a real lifecycle. Stacked on #1 (base is its branch; retarget to release/6.2.0 after #1 merges).

Included

  • Operations: GET /reasoning/capabilities, POST /reasoning/jobs?dataset=…, GET / DELETE /reasoning/jobs/{id}. GET /reasoning/results/{id} and POST /reasoning/query answer 501 until snapshots exist.

    Request Responses
    GET /reasoning/capabilities 200: protocol version, readiness (READY/NOT_READY/DISABLED with reasons), memory budget, enforced limits
    POST /reasoning/jobs?dataset=X 202 + Location (new job); 200 (same requestId); 400 invalid request or missing dataset; 404 unknown dataset; 409 requestId reused with a different request; 413 over 4 MiB; 415 not JSON; 429 queue full; 503 disabled, not ready, or disk quota reached
    GET /reasoning/jobs/{id} 200 job document; 404
    DELETE /reasoning/jobs/{id} 202 while the job stops; 200 once cancelled or already finished; 404
  • Contract: requests are validated against OpenMetadata's rdfReasoningJobRequest.json and the schemas it references, plus the per-operation rules from Fixes 35198: Keep RDF reasoning freshness exact during rolling upgrades and failed updates OpenMetadata#35199, without OM jars. Every job and capabilities document is checked in tests against copies of OM's schemas (extension/src/test/resources/openmetadata-contract/, from OM 12f9e16e). Every error body is the protocol's problem object.

  • Routing: one servlet registered by the module at /reasoning/*. Fuseki routes a dataset's operations by endpoint name, so /jobs/{id} cannot be a dataset endpoint, and query-parameter dispatch would put ?op=…&id=… on every dataset. The servlet sits behind the same Shiro /* filter, so the image's shiro.ini keeps it admin-only unchanged; the README documents a shiro.ini for a non-admin service account with a reasoning role.

  • Execution: admitted on the memory budget and a disk quota; one job at a time on a dedicated thread, never a Jetty request thread; a bounded FIFO queue (429 when full); idempotent by requestId within a bounded history; durable job.json manifests written atomically in /fuseki/reasoning/jobs/<id>/. Worker steps share the container worker lock with bin/reasoner.

  • Cancel: a queued job is cancelled at once; a running job reports CANCELLED only after its worker has exited (SIGTERM, then SIGKILL). A cancel never reaches a later step.

  • Restart: unfinished jobs become INTERRUPTED, their working data is removed, and a worker recorded in a <step>.pid file is killed only if that process is still the worker for a step in that job's directory.

  • Retention: finished jobs are evicted by count and age, oldest first; directories without a manifest (steps run by hand) are never touched. With reasoning disabled nothing is written.

  • Settings (entrypoint/Java parity, pinned in test/reasoning-settings.cases): OPENMETADATA_REASONING_MAX_QUEUED_JOBS (16), OPENMETADATA_REASONING_JOB_HISTORY (1000), OPENMETADATA_REASONING_JOB_RETENTION_HOURS (168), OPENMETADATA_REASONING_DISK_QUOTA (size or percentage of the volume, 25%).

Not yet

Capture, snapshots, generation checks and engine work are the next slices. Every job currently ends FAILED at its capture step with problem code NOT_READY and a message starting NOT_IMPLEMENTED:; the protocol has no not-implemented code, and an unknown value would break OM's client. Capabilities list no engines or coverage until an operation reaches one.

Schema gaps to raise in OpenMetadata: capabilities has no list of supported operations; the problem-code enum has no not-implemented value; the limits description asks for NOT_READY when a limit is unset, while this slice reports readiness from the memory budget and lists only the limits it enforces.

Tests

  • extension mvn verify: 251 tests, including JobRequestTest (OM's examples and violation cases), JobServiceTest (ordering, queue limit, cancel only after a real worker exits, busy lock, restart recovery that kills a real orphan and spares an unrelated pid, retention, quota), and ReasoningOperationsIT on a real Fuseki server with Shiro (admin 200; anonymous and wrong password 401; service account reaches /reasoning but gets 403 on /ds/sparql; submit, retry, cancel, every error code).
  • reasoner mvn verify: 151 unit + 5 integration tests.
  • Image smoke test: 93/93 checks, including DISABLED with nothing written, NOT_READY in an undersized container, admin-only capabilities, submit then idempotent retry, structured capture failure, cancel, 501 for results, and the job surviving docker restart.

Queue length, finished-job history and age, and the reasoning disk quota are
read by JobSettings with the entrypoint's rules, and test/reasoning-settings.cases
pins both, as it already does for the worker settings. Queued and kept jobs are
held in memory, so their counts have at most four digits. The quota is a size
or a share of the data volume, 25% by default until snapshot sizes are measured.
The extension cannot depend on OpenMetadata's jars, so JobRequest checks a
request against rdfReasoningJobRequest.json and the schemas it references with
Jena's JSON, including the per-operation and per-check requirements of
OpenMetadata pull request 35199 and the prose rule that a REFRESH accepts only
APPROVED ontologies. Bodies are bounded in size, and in nesting before parsing,
since the parser recurses per level. A canonical digest tells a retry from a
different request that reuses its ID.

OpenMetadata's schemas and examples are copied into test resources, with the
commit they came from, and a small checker validates the store's documents
against them.
A job service needs two things from the launcher. After a restart it must find
and kill a worker that outlived the server, so the launcher records the
worker's pid next to the step while it runs. And a cancellation must reach a
step whether or not it has started: run(step, cancelled) cancels the step at
launch when the caller's flag is already set, so a caller that sets its flag
and then calls cancel() stops its own step and never a later one.
…ention

JobService admits a job only when the memory budget fits and the reasoning
root is under its disk quota, queues at most OPENMETADATA_REASONING_MAX_QUEUED_JOBS
behind the running one, and runs them in order on a thread of its own. Each job
has a directory under /fuseki/reasoning/jobs/<id>/ with its request and a
manifest replaced atomically on every change. A request ID returns its job for
as long as the job is kept; finished jobs are kept up to a count and an age.

A queued job is cancelled at once; a running one stays RUNNING with
cancelRequested until its worker has exited. After a restart, unfinished jobs
become INTERRUPTED, their unpublished work is removed, and a worker recorded in
their directory is killed if it is still that directory's worker.

Worker steps run through the launcher and map its outcomes to the protocol's
problems. Capture of a serving dataset is the next change, so every
operation's plan fails at its capture step for now, with NOT_READY and a
NOT_IMPLEMENTED message, since the protocol has no code for it. The tests run
real stand-in worker processes and check every job document against
OpenMetadata's schema.
The module registers one servlet at /reasoning/* that routes capabilities, job
submission, status and cancellation itself, and answers results and query with
501 until snapshots exist.

Routing: Fuseki dispatches a dataset's operations by endpoint name, so
/reasoning/jobs/{id} cannot be an endpoint; query-parameter dispatch on one
endpoint would work but turns a resource API into ?op=...&id=... on every
dataset. A servlet added with FusekiServer.Builder.addServlet sits after
Fuseki's dataset dispatch and behind the same Shiro filter as every other path,
so the image's shiro.ini keeps it admin-only with no change, and its paths are
the plan's. The serving dataset a job reads is the dataset parameter, checked
against the datasets the server serves. A dataset named reasoning would hide
the operations, which the module logs.

With reasoning disabled the operations still answer, DISABLED and 503, and
nothing is written to disk. The integration test runs a real Fuseki server with
Shiro, once with the image's shiro.ini (admin only) and once with the
documented operator file that grants a non-admin service account the
reasoning role and nothing else.
README.md describes the operations, their answers and limits, the routing,
execution, cancellation, restart and disk policies, what a job does in this
release, and the shiro.ini that grants a non-admin service account reasoning
alone. The smoke test checks, in the built image: DISABLED and 503 with
reasoning off; NOT_READY and 503 in an undersized container; and with the
budget met, admin-only capabilities, a job accepted with 202 and returned by
its request ID with 200, a 400 for an invalid request, the job failing at
capture with a structured problem, cancellation answers, a 501 for results,
and the job and its request ID surviving a container restart. Invalid queue
and quota settings stop the container.
@harshach
harshach changed the base branch from openmetadata/reasoner-worker to release/6.2.0 October 11, 2026 16:10
@harshach
harshach merged commit 600514c 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