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

未关闭
#1,546 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cli, clojure
领域
cli, database

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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!)
主要语言
没有语言数据
星标
29
派生
2
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

logseq/db-test 的其他 Issue

查看 logseq/db-test 的全部 Issue

相似的 Issue

更多 CLI Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。