Skip to content

fix(db-sync): the semantic API answers 400 to a write the graph does not allow - #13772

Closed
yuxi-liu-wired wants to merge 5 commits into
logseq:masterfrom
yuxi-liu-wired:fix/semantic-validation-400
Closed

yuxi-liu-wired wants to merge 5 commits into
logseq:masterfrom
yuxi-liu-wired:fix/semantic-validation-400

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

The semantic API answers a write the graph does not allow with 500 "server error" and a debug stack. Examples: POST /semantic/pages with title a/b ("Page name can't include "/""), POST /semantic/tags with #tag, PATCH or DELETE of a built-in page or block ("Built-in nodes can't be modified", "Built-in nodes can't be deleted").

The outliner rejects such writes by throwing an error meant to notify the user (ex-data :type :notification, the message in :payload). The semantic handlers check some inputs themselves and answer 400, but these errors come from inside the outliner call and reach handle-http's catch-all, which answers 500.

semantic/handle now answers 400 with the error's message for an error of :type :notification, synchronous or from a promise. Every other error still reaches the 500 path.

The routes that insert a block tree (/semantic/capture, /semantic/blocks/:block-id/children, /semantic/block-trees) checked that blocks is a non-empty list but not its blocks: a block whose title is not a string ({"blocks": [{"title": 1}]}, or a child {}) failed an assert, (string? title), answered 500. They now check the whole tree (every block a map with a string title and optional children of the same shape) and answer 400 as for a missing list.

The property routes resolved :property-id to the ident of any entity it names: PUT /semantic/blocks/:block-id/properties/logseq.class%2FTask (a class, not a property) set it as a property and failed with "No validation for property type nil", answered 500. resolve-property-ident now returns an ident only for a property, so such a request answers 400 "property not found" as for a missing one.

PATCH /semantic/properties/:property-id took any title: {"title": {}} failed with "str.indexOf is not a function", answered 500. A title there must now be a non-blank string, as on the other write routes.

A value for a ref property (status, priority, tags, node) that is a number went to d/entity as an entity id. Datascript throws on a number that is not one (-1, 1.5: "Expected number or lookup ref for entity id"), answered 500, on PUT /semantic/blocks/:block-id/properties/:property-id and POST /semantic/block-properties/batch-set. Only a positive integer is now looked up; another number resolves to nothing and answers 400 as for a missing entity.

Test: semantic-write-the-graph-does-not-allow-answers-400-test (a page titled a/b, a tag titled #tag, a capture of a block titled 1, a capture of a child without a title, a class named as the property, a property update with an object as title, a status value of -1 and of 1.5).

Found by a fuzzer that sends random semantic API requests to a server on a full graph.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined with the other PRs that change the same files into #13781.

@yuxi-liu-wired
yuxi-liu-wired deleted the fix/semantic-validation-400 branch October 21, 2026 18:01
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