CLI: `upsert block --blocks` with two or more blocks fills an empty last child instead of appending, then fails with `add-id-resolution-failed`

Aperta
#1,546 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cli, clojure
Ambito
cli, database

Direzione di ricerca

Start with insert_opts in cli/lib/add.ml and trace how it sends insert-blocks; then read get-target-block and insert-blocks in deps/outliner/src/logseq/outliner/core.cljs. Check the documented default for replace-empty-target? against the behavior described in the reproduction. Done means multi-block inserts append after empty-title targets without changing those blocks, and the CLI exits successfully with the created IDs.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Search first
  • I searched and no similar issues were found
What Happened?

upsert block --blocks with two or more blocks writes the first new block into an existing block with an empty title instead of after it. With --pos last-child that is the target block's last child, with --target-page the page's last top-level block, and with --pos sibling the target block itself. The empty block takes the first new block's title and keeps its own uuid. The CLI then looks up the uuids it generated, cannot find the first one, and exits 1 with add-id-resolution-failed: unable to resolve created ids, although every block was written.

Anything on the empty block stays there, so it ends up on the first new block. In variant 5 below, the empty block's heading 2 and its child both end up on the new block one.

The block does not have to be an empty line. Any block with an empty title counts, such as a #Query block or a view block (logseq.property/view-for). A query block at the end of a page, or one targeted with --pos sibling, is lost that way: the first new block becomes the query block, tag and query included (variants 6 and 8).

With a single block, or with --pos first-child, nothing is replaced and the command succeeds.

Reproduce the Bug
G=demo                            # any DB graph
P=empty-last-child-repro
id() { jq '.data.result[0]'; }
logseq upsert page --graph $G --page $P >/dev/null
PARENT=$(logseq upsert block --graph $G --target-page $P --content parent --output json | id)
EMPTY=$(logseq upsert block --graph $G --target-id $PARENT --pos last-child --content placeholder --output json | id)
logseq upsert block --graph $G --id $EMPTY --update-properties '{:block/title ""}' >/dev/null

logseq upsert block --graph $G --target-id $PARENT --pos last-child --blocks '- one
- two'; echo "exit $?"
logseq show --graph $G --id $PARENT
logseq query --graph $G --query "[:find ?t . :where [$EMPTY :block/title ?t]]"

Output, run on 18-11-2026:

Error (add-id-resolution-failed): unable to resolve created ids
exit 1
575 > empty-last-child-repro
576 parent
577 ├── one
578 └── two
one

Block 577 is $EMPTY, and the last line shows it is now titled one.

Variants, each on a fresh parent or page:

# --blocks and options Result
1 - one, --pos last-child exit 0; one added after the empty block
2 - one / - two, --pos first-child exit 0; empty block untouched
3 - one with child - one.a, --pos last-child exit 1; empty block becomes one
4 - tree root with child - tree child, then - tree sibling, via --target-page on a page whose last top-level block is empty exit 1; empty block becomes tree root
5 - one / - two, --pos last-child, empty block has heading 2 and a child exit 1; one has heading 2 and the child
6 - one / - two, --target-page on a page whose last top-level block is an untitled #Query block exit 1; the query block is now one #Query
7 same, last top-level block is an untitled block with logseq.property/view-for exit 1; the view block is now one
8 - one / - two, --pos sibling with --target-id an untitled #Query block made in the desktop app exit 1; the query block is now one #Query, and its :block/created-at is reset to the time of the insert
Expected Behavior

--pos last-child, --pos sibling and --target-page add the new blocks after the existing ones and leave existing blocks as they are, empty or not. If filling an empty block is intended, the command should succeed and return the ids of the blocks it actually wrote.

Screenshots

No response

Files

No response

Browser, Desktop or Mobile Platform Information

Linux, logseq --version: revision dad8e9c (nightly 20261118). First seen on 533ac43 on 16-11-2026.

Additional Context

From reading the source at dad8e9c:

  • insert_opts in cli/lib/add.ml sends insert-blocks with sibling? false, bottom? true and keep-uuid? true, and no replace-empty-target?.
  • In deps/outliner/src/logseq/outliner/core.cljs, get-target-block turns bottom? into "sibling of the last child". insert-blocks then derives replace-empty-target? from nil as (and sibling? <blank title> (> (count blocks) 1)), where the count includes children. So it is true for two or more blocks, while the docstring says it "defaults to be false".
  • insert-blocks-aux maps the first block's uuid to the target's, and assign-temp-id gives it the target's db/id. The generated uuid never exists, resolve_created_ids fails on it, and because the target block still exists the error stays add-id-resolution-failed.

Passing :replace-empty-target? false from the CLI would probably avoid it.

This is probably what the master stress run in logseq/logseq#14061 hit (run 44316752188). I searched the logs of the 100 most recent failed CLI sync stress runs (30-09-2026 to 18-11-2026; 21 of the 96 job logs had expired): add-id-resolution-failed appears in 15 of them, every time on create-tree (--target-page with three blocks, the shape of variant 4), and never on create-root or create-child. Those insert a single block and run far more often. They resolve their ids through the same resolve_created_ids, so a race would hit them too, while the two-or-more-blocks rule would not. I could not find which harness operation leaves an untitled block at the end of those pages. The reference views it creates go on the views page, not on the target pages.

Found with the help of an AI coding assistant driving the CLI.

Are you willing to submit a PR? If you know how to fix the bug.
  • I'm willing to submit a PR (Thank you!)
Lingua principale
Nessun dato sulla lingua
Stelle
29
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di logseq/db-test

Tutte le issue di logseq/db-test

Issue simili

Altre issue su CLI

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.