Skip to content

fix(transact): a write that asks for reasoning is refused, not ignored - #2464

Open
aaj3f wants to merge 3 commits into
mainfrom
fix/update-refuses-reasoning
Open

aaj3f wants to merge 3 commits into
mainfrom
fix/update-refuses-reasoning

Conversation

@aaj3f

@aaj3f aaj3f commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Problem

A write evaluates no reasoning: an update's where runs through the plain WHERE executor, which takes no reasoning configuration, so it matches stored facts only. But an update that carried "reasoning": "datalog" (top level or in opts) was accepted and the key ignored. An update whose where names a fact only a rule derives matched nothing and committed, and the CLI printed Committed t=3, 0 flakes, which reads exactly like "the rules derived nothing".

What changed

The reasoning keys a query reads are now refused on a write with a 400 whose message says a write does not evaluate reasoning:

`opts.reasoning` applies to queries, not updates: a write does not evaluate reasoning, so an update's where clause matches stored facts only
  • JSON-LD (update / insert / upsert / graph insert / graph sync). The check sits in the JSON-LD transaction parser (parse_rooted in fluree-db-transact/src/parse/jsonld.rs), the one funnel every transport goes through: HTTP /update, /insert, /upsert, /sync, the Rust API (Fluree::update/insert/upsert, the graph(..).transact() and stage_owned builders, the tracked/policy path the server uses), the CLI (local, and remote through the HTTP routes) and the Python binding (which calls the same builders). It extends the existing opts.unionDefaultGraph refusal there.
    • Keys: reasoning, rules, ontology, reasoningBudget, reasoningTime. The list is now the query parser's own REASONING_KEYS (made pub), so a reasoning key a query gains is refused on a write without a second edit.
    • Placement: in opts on every write, and at the top level of an update, whose top-level keys are the request's own. An insert's or upsert's top-level keys are its data (or, in envelope form, txn-meta), so a node property named reasoning stays a property; a test pins that.
  • SPARQL UPDATE. The parser already refused every reasoning* pragma on an update (applies to queries, not updates), so nothing reached the lowering. The message for those pragmas now also says a write does not evaluate reasoning, matching the JSON-LD one.
  • Cypher / Bolt. No reasoning surface on writes; nothing to change.
  • HTTP headers. No header maps to reasoning on any route; nothing to change.
  • Docs. One note in docs/transactions/update-where-delete-insert.md.

The error is a TransactError::Parse, which the API maps to 400 (ApiError::Transact(_) => 400); the SPARQL refusal was already a 400.

Value policy

A reasoning key is refused whenever it is present, unless it is reasoning and its value explicitly turns reasoning off: the single mode "none" (case-insensitive, as a query reads it), which asks for exactly what a write does. Everything else is refused, including values a query reads as no request at all (null) or as no mode (["none"]), and "none" does not excuse another reasoning key beside it.

Open for review: the SPARQL surface refuses # PRAGMA reasoning: none on an update (every query-only pragma is refused there whatever its value, as opts.unionDefaultGraph is in JSON-LD), so the two surfaces differ on none alone. Either JSON-LD can refuse none too, or the pragma can accept it; this PR leaves the pragma as it was.

Tests

  • fluree-db-transact (parse::jsonld::tests):
    • writes_refuse_reasoning_keys: each key × top level of an update, opts on an update, insert, upsert (single node and envelope), graph insert and graph sync. The sample table must list every key of REASONING_KEYS.
    • writes_accept_only_reasoning_none: "none"/"NONE" accepted in both placements; null, ["none"], "rdfs", a list, an unknown mode and a boolean refused; none beside rules refused.
    • an_insert_property_named_reasoning_is_data.
  • fluree-db-sparql: test_reasoning_pragmas_refused_on_update, every reasoning* pragma (and reasoning: none) on an update, with the new message. Twin of the JSON-LD tests.
  • fluree-db-api (grp_reasoning, it_datalog_rules_sparql::writes_refuse_reasoning): the issue's repro. A stored SPARQL rule derives ex:SparqlCandidate; a query under reasoning reads both candidates; the update with reasoning at the top level, in opts, and with rules, an insert with opts.reasoning, and a SPARQL update with the pragma each fail with status_code() == 400 and the message; the ledger's t is unchanged; an update with "reasoning": "none" commits.
  • fluree-db-server (grp_query, sparql_pragmas::writes_refuse_reasoning): 400 with the message on /update (SPARQL pragma, JSON-LD top level, JSON-LD opts), /insert and /upsert (opts); "reasoning": "none" on /update is a 200.

Non-vacuity, run on the committed fix with the fix reverted in place and then restored:

  • JSON-LD refusal disabled (the reasoning-key loop iterates no keys): writes_refuse_reasoning_keys and writes_accept_only_reasoning_none fail; the API test fails at its first write, which commits (flake_count: 0, the issue's symptom); the server test fails with a 200 committing the top-level-reasoning update. an_insert_property_named_reasoning_is_data passes either way, as a boundary test should.
  • SPARQL message reverted: test_reasoning_pragmas_refused_on_update fails, and the server test fails on the SPARQL leg (400, but without the new message).

The issue's repro on a CLI built from this branch (local ledger): the update with reasoning at the top level and in opts now prints error: Transaction error: Parse error: `reasoning` applies to queries, not updates: a write does not evaluate reasoning, so an update's where clause matches stored facts only (exit 1) instead of Committed …, 0 flakes; the SPARQL update with the pragma prints the matching SPARQL message (run with --format sparql: the CLI's format detection does not look past a leading # line, which this PR leaves as it is); the update with "reasoning": "none" over stored facts commits.

Breaking changes

A write that carried a reasoning key (reasoning other than "none", rules, ontology, reasoningBudget or reasoningTime) in opts, or at the top level of an update, used to succeed with the key ignored; it now fails with a 400. Such a write never evaluated reasoning, so removing the key reproduces the old result exactly. A caller that wants the old behaviour removes the key (or sends "reasoning": "none").

Partially addresses #2461. What remains is the design question in the issue: a supported way to commit what a rule run derives (reasoning in an update's where, a rules materialization job, or a documented query-then-insert pattern).

🤖 Generated with Claude Code

https://claude.ai/code/session_018gr44QJuUPpGdwWfXE9Bz9

aaj3f and others added 3 commits November 19, 2026 11:46
…g them

A write evaluates no reasoning: an update's where runs through the plain
WHERE executor and matches stored facts only. An update that carried
"reasoning": "datalog", at the top level or in opts, was accepted and the
key ignored, so a where naming a fact only a rule derives matched nothing
and the write committed. That reads exactly like "the rules derived
nothing".

The JSON-LD transaction parser now refuses, with a 400 that says a write
does not evaluate reasoning, every reasoning key a query reads (reasoning,
rules, ontology, reasoningBudget, reasoningTime): in opts on every write
(update, insert, upsert, graph insert, graph sync), and at the top level
of an update, whose top-level keys are the request's own. An insert's
top-level keys stay data. "reasoning": "none", which asks for what a
write does anyway, is accepted. The check sits in the parser every
transport shares (HTTP routes, the Rust API, the CLI, the Python
binding), beside the existing opts.unionDefaultGraph refusal, and reads
the key list from the query parser's REASONING_KEYS, now public, so a key
the query side gains is refused on a write too.

SPARQL UPDATE already refused the reasoning pragmas; their message now
says the same thing as the JSON-LD one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018gr44QJuUPpGdwWfXE9Bz9
@aaj3f aaj3f added bug Something isn't working as expected breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section area:transact Staging, commit, import/bulk-import, novelty, retraction semantics area:datalog Reasoner, rules, reasoningDefaults labels Nov 19, 2026
@aaj3f
aaj3f requested a review from bplatz November 19, 2026 17:43

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Please review the inline comments before merging.

let Some(value) = keys.get(key) else {
continue;
};
if key == "reasoning" && disables_reasoning(value) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the open question: refuse every reasoning key whatever its value, none included. That matches the SPARQL pragma and opts.unionDefaultGraph (refused even as false), and drops disables_reasoning and the null / ["none"] cases. If writes ever evaluate reasoning, accepting none then is non-breaking, where refusing it later would not be. The docs line in update-where-delete-insert.md and the none legs of the API and server tests change with it.

/// top-level keys are the request's own; an insert's or upsert's top-level
/// keys are its data. `"reasoning": "none"`, which asks for what a write
/// does anyway, is accepted.
fn refuse_query_only_opts(json: &Value, txn_type: TxnType) -> Result<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: parse_graph_insert returns before parse_rooted for an empty document (

if is_empty_document(json) {
), so a graph insert or sync of {"opts": {"reasoning": "datalog"}, "@graph": []} still accepts the key and ignores it, and opts.unionDefaultGraph too. Calling refuse_query_only_opts(json, TxnType::Insert) before that early return, plus an empty-@graph leg in writes_refuse_reasoning_keys, closes it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:datalog Reasoner, rules, reasoningDefaults area:transact Staging, commit, import/bulk-import, novelty, retraction semantics breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants