fix: keep regex query inputs from crashing graphs by tiensonqin · Pull Request #13155 · logseq/logseq · GitHub
Skip to content

fix: keep regex query inputs from crashing graphs - #13155

Open
tiensonqin wants to merge 5 commits into
masterfrom
logseq/fix-graph-open-crash-d500
Open

fix: keep regex query inputs from crashing graphs#13155
tiensonqin wants to merge 5 commits into
masterfrom
logseq/fix-graph-open-crash-d500

Conversation

@tiensonqin

@tiensonqin tiensonqin commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes graph open crashes on graphs whose journal default queries use regex :inputs that start with an escaped parenthesis.

logseq/db-test#1136

Behavior

Opening the attached DB graph showed journals briefly, then the “Something went wrong” recovery screen. The worker died in :thread-api/get-render-snapshots with Invalid regular expression: /(/.

The graph’s “Broken references” advanced query uses:

:inputs ["\\([0-9a-f]{8}-...\\)"]

query-input-value parsed that string with cljs.reader/read-string, which treats \( as the character (. re-pattern then compiled /(/ and the failed query took down the whole renderer snapshot batch, including block reactions.

Change

  • Parse stringified EDN query inputs as before, but keep the original string when the reader returns a character literal. Plugin UUID, quoted string, and collection inputs stay parsed.
  • Isolate query SyntaxError (for leftover invalid regex) so one query cannot fail sibling resources in the same snapshot. Invalid/unknown resource keys still fail-fast.
  • Query components throw that error after hooks so the existing query error boundary can show it.

Tests

  • Regex :inputs stay strings through resolve-query-inputs and query render resources.
  • Plugin EDN UUID, quoted string, and collection inputs still parse.
  • A query that compiles re-pattern with "(" does not fail journals in the same snapshot.
  • use-query-result rethrows worker query syntax errors for the query error boundary.
Open in Web Open in Cursor 

String query inputs that start with an escaped paren were read as a
character literal, so journal default queries like Broken references
compiled re-pattern as /(/ and took down the whole renderer snapshot.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
@tiensonqin
tiensonqin force-pushed the logseq/fix-graph-open-crash-d500 branch from 320670d to 6ce3f05 Compare September 1, 2026 11:04
@tiensonqin
tiensonqin marked this pull request as ready for review September 1, 2026 11:04
Copilot AI lite review requested due to automatic review settings September 1, 2026 11:04
@tiensonqin

Copy link
Copy Markdown
Contributor Author

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T11:14:14.344997Z 6ce3f05 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tiensonqin

Copy link
Copy Markdown
Contributor Author

@codex review

Keep invalid renderer resource keys fail-fast. Query SyntaxError now
returns an error value so sibling snapshot resources still render.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>

Copilot AI 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.

🔵 Needs a closer look

The new :error resource-slot decoding drops required slot fields (:basis-rev and :watch), which can break resource ordering and delta/watch handling in frontend.db.subs.

Pull request overview

Prevents renderer snapshot batches from crashing when journal default queries include regex :inputs that begin with an escaped parenthesis, and ensures a single failing renderer resource does not take down sibling resources (e.g., journals) in the same snapshot.

Changes:

  • Restricts query-input-value parsing to only stringified keywords/numbers/booleans so literal regex strings (e.g. "\\(") aren’t reader-coerced into invalid regex patterns.
  • Wraps renderer resource evaluation so per-resource failures are logged and returned on the wire as :error, rather than crashing the full snapshot build.
  • Updates renderer-side snapshot decoding to surface resource failures as {:status :error} without failing sibling resource subscriptions; adds regression tests for both behaviors.
File summaries
File Description
src/main/frontend/worker/handler/query.cljs Limits EDN parsing of query inputs to avoid corrupting literal regex strings.
src/main/frontend/worker/handler/render_resource/engine.cljs Catches per-resource failures and emits an :error payload so snapshots can continue.
src/main/frontend/db/subs.cljs Decodes resource :error wires into {:status :error} resource snapshots.
src/test/frontend/worker/handler/render_resource_test.cljs Adds regression tests for escaped-paren regex inputs and snapshot isolation.
src/test/frontend/worker/db_core_test.cljs Adds regression test that escaped-paren regex inputs remain strings through resolve-inputs.
src/test/frontend/db/subs_test.cljs Adds regression test that an errored resource snapshot doesn’t break sibling resources.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

cursoragent and others added 2 commits September 1, 2026 11:12
Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
Co-authored-by: Tienson Qin <tiensonqin@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ce3f05465

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/frontend/worker/handler/query.cljs Outdated
Comment thread src/main/frontend/db/subs.cljs Outdated
Comment thread src/main/frontend/worker/handler/render_resource/engine.cljs Outdated
Plugin callers still pass UUIDs, quoted strings, and collections as
EDN. Only reject cljs.reader character literals so regex matchers
that start with an escaped paren stay intact.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
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.

3 participants