Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

feat(branch): give a line an optional title - #2550

Open
yyhhyyyyyy wants to merge 39 commits into
mainfrom
hui/branch-title
Open

yyhhyyyyyy wants to merge 39 commits into
mainfrom
hui/branch-title

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2549

Refs #2000 #2070

branch create and session.branch_create now take an optional title: one non-empty line of at most 120 characters that names the line. prompt stays the child line's first input exactly as written, and a line without a title is named by the first line of its prompt. The daemon advertises the new request member in hello.features, and a titled creation still reaches older v3 and v4 clients with the event data they already decode.

What changed

  • Event and storage. BranchCreateData carries an optional title that is omitted when absent and rejects an explicit null (events.rs:L1176); is_valid_branch_title accepts one non-empty line of at most 120 Unicode scalar values (events.rs:L1188). The event projection leaves branch/create data in the shape earlier clients decode: title is removed from data for every protocol version and travels only as the optional top-level envelope member of v3 and v4 events (tree_protocol.rs:L201, tree_protocol.rs:L345). The native store format keeps main's v58 marker-only step for Support DeepSeek's first-party web search in the native provider runtime #1835 and gives the title its own v59 marker-only step, (58, &[]), with no table or row rewrite; a new line's directory row stores the name it is shown by, in the same transaction as its branch/create, while a row written before that keeps no name (sqlite.rs:L22, sqlite.rs:L560). The frozen v1 types and the event fixtures are unchanged. branch_contract::a_branch_title_is_optional_and_never_null (branch_contract.rs:L247), storage_flow::a_format_57_store_is_migrated_by_the_title_marker_alone (storage_flow.rs:L10434), tree_protocol::tests::a_v2_branch_create_carries_no_title (tree_protocol.rs:L719) and tree_protocol::tests::a_v3_branch_create_carries_its_title_in_the_envelope (tree_protocol.rs:L750) pin the event, the upgrade and both projections.
  • Directory rows and cold restore. A restore names a line from its directory row, so a cold start reads no branch/create body for a line that enters the directory. timeline_branches.info carries the name from the write that created the row (timeline.rs:L3635). A row written before the row carried a name is read by ensure_title only at the five points where the restore keeps the line, and before that point's side effect: an ended line (timeline_tree.rs:L3360), an ended parent's opened child (timeline_tree.rs:L3385), a line whose own end the restore completes (timeline_tree.rs:L3414), a copied line it closes (timeline_tree.rs:L3460), and a line it mounts (timeline_tree.rs:L3487); the helper projects only data.title and data.prompt (timeline_tree.rs:L2048). The four dropped cases read nothing: a recorded failed creation, a child of an inactive line that never opened, an ended parent's child that never opened, and an interrupted creation. branches::a_cold_restore_names_ended_lines_without_reading_their_creations corrupts both ended lines' creation bodies and checks that the Session still publishes and the directory names them (branches.rs:L1741); branches::a_cold_restore_drops_legacy_rows_without_reading_their_creations corrupts an interrupted creation before the first restart and checks that main publishes, the directory excludes it, its parent records one branch/create-failed, and a second restart still finds one (branches.rs:L1970); branches::a_format_57_directory_keeps_names_for_open_ended_and_copied_lines keeps the names of an open line, an ended line and a fork-copied line (branches.rs:L1877), and branches::a_format_57_ended_line_is_named_by_its_prompt_after_upgrade covers the older ended row (branches.rs:L1808).
  • Tool and boundary validation. BranchInput has an optional title (timeline_tree.rs:L5712) and refuses it on any action other than create (timeline_tree.rs:L5773); title must be one non-empty line of at most 120 characters at the tool (timeline_tree.rs:L5776), at session.branch_create (connection/tree.rs:L961), and at TimelineTree::create_child (timeline_tree.rs:L2841), before any fact is written, through the one shared function. The schema adds title with minLength: 1 and maxLength set to that bound, and restores the prompt description to create: the purpose of the new line. (timeline_tree.rs:L6750). branch_flow::a_branch_title_must_name_one_line_before_any_fact (branch_flow.rs:L5665), branch_flow::a_branch_title_at_the_limit_passes_and_one_more_character_is_refused (branch_flow.rs:L5804), branch_flow::the_tree_takes_a_title_at_the_limit_and_refuses_one_more (branch_flow.rs:L5851) and branches::a_branch_title_at_the_rpc_limit_passes_and_one_more_is_refused (branches.rs:L1616) cover the three boundaries and the bound with multi-byte characters. The same check runs on the title a registered before produced, inside the creation callback and before the appended fact and its reservation exist (timeline_tree.rs:L2840): a rewritten title that names no single line writes no creation fact and reserves no line, while a valid one is the name in both the fact and the directory and the child still receives the prompt. branch_flow::a_rewritten_title_is_validated_before_the_fact_and_names_the_line (branch_flow.rs:L3319) covers both rewrites in one creation flow.
  • Request and hello. session.branch_create takes the optional member (protocol.rs:L992), and the hello advertises session.branch_create.title beside the method through one shared constant (protocol.rs:L336, transport.rs:L733). A client sends title only when the feature is offered; otherwise it omits the member and the daemon names the line by the first line of prompt (timeline-branches.md:L687). branches::branch_create_title_is_advertised_beside_the_method (branches.rs:L1594) asserts both feature strings on a real hello.
  • First input and roster. first_input and recorded_purpose still use data.prompt verbatim (timeline_tree.rs:L6533, timeline_tree.rs:L5308); the roster and the directory name a line by its title and fall back to first_line(prompt) at 120 characters (timeline_tree.rs:L4467). branch_flow::a_load_names_a_titleless_line_by_its_prompts_first_line_in_the_roster (branch_flow.rs:L5915), branches::a_line_without_a_title_is_named_by_its_prompts_first_line (branches.rs:L1297) and branches::a_restarted_session_keeps_titles_and_names_untitled_lines_by_their_prompts (branches.rs:L1676) cover the roster, the fallback and restore.
  • Service and RPC faces. TimelineInfo and BranchOptions carry the optional title (contracts.rs:L158, contracts.rs:L211); session.branch_create accepts it (protocol.rs:L992), and session.branches and session.branch.get return it through BranchInfo (tree_protocol.rs:L27). Protocol v3 and later replies carry the title; a frozen v2 branch/create clears it. branches::branch_create_and_the_directory_carry_a_lines_title (branches.rs:L1221) and branches::a_v2_branch_create_reply_carries_no_title (branches.rs:L1359) cover both directions. The generated declarations publish the optional title for creation options and directory rows as title?: string (branch-services.d.ts:L1546, branch-services.d.ts:L1400), narrowed from the generator's present-or-absent table (types.rs:L841), which refuses a declaration that no longer carries a nullable member to narrow (types.rs:L846); the stored directory row follows the same shape (plugin.d.ts:L818). runtime/plugin-sdk.test.mjs type-checks the packed declarations, where omission and a string compile and an explicit null is an error, and runtime/fixtures/timeline-store.ts checks the stored name on the wire (timeline-store.ts:L70).
  • Older clients. A titled creation reaches a v3 or v4 client with data in the shape it already decodes and the title in the envelope: branches::a_legacy_v3_client_decodes_a_titled_creation_live (branches.rs:L1405) and branches::a_legacy_v3_client_decodes_a_titled_creation_in_history (branches.rs:L1465) decode the real events with a copy of the pre-change strict type.
  • Readers decode only. dim-client's BranchEntry decodes the field (wire.rs:L630) and its event decoder reads the envelope member (wire.rs:L192), npm/client-protocol.d.ts declares both (client-protocol.d.ts:L197, client-protocol.d.ts:L367), and web/src/rpc/read.ts reads it for directory rows and creation facts (read.ts:L321, read.ts:L713). a_branch_create_reads_the_lines_title_from_the_event_envelope (connection.rs:L243) covers the client. This change adds no TUI or Web UI wiring.
  • PostgreSQL. The store marker is 3 (postgres.rs:L30); opening a format 1 store first rewrites the marker to 2 inside the same startup transaction, and a format 1 or format 2 store then applies the format 3 step under the advisory lock, adding timeline_branches.title BYTEA with the root-null check (schema.sql:L19, postgres.rs:L211) and filling each existing child's title from its stored branch/create in keyset pages of 64 rows, each page written back with one array UPDATE (postgres.rs:L54, postgres.rs:L217), before the marker moves (postgres.rs:L219). A child without its creation body fails the upgrade, so the column, the names and the marker roll back together, and a second open skips the backfill. A PostgreSQL format 2 store written before this change, with a step/provider-tool event and untitled creations, opens and moves to 3 with its child names filled from the creation prompts and the event unchanged (postgres_import.rs:L684); a SQLite v58 store does the same at 59 (storage_flow.rs:L10495). A store above this daemon's format is refused at open by the same gate: SQLite by the existing FORMAT+1 case (storage_flow.rs:L4926) and PostgreSQL by the format 4 assertion above. A daemon that knows only 58/2 meets a 59/3 store at those same gates and refuses it at open. A new creation inserts the name's UTF-8 bytes and the directory read validates UTF-8 (timeline.rs:L228, timeline.rs:L444); a fork copies the column unchanged, and the import validates the target name the same way (import.rs:L215). Any other version is refused at open (postgres.rs:L226). The read-only import admits v57, v58 and v59 sources after the source opens read-only (import.rs:L361), and a retry that finds the committed receipt completes the local binding instead of transferring again (import.rs:L281, binding.rs:L109). postgres_upgrades_a_format_one_store_and_keeps_titled_lines (postgres_import.rs:L530), postgres_keeps_nul_titles_across_upgrade_create_import_and_fork (postgres_import.rs:L989), postgres_backfills_format_one_titles_in_batches_and_a_second_open_skips_them (postgres_import.rs:L1175), sqlite_v57_source_imports_directly (postgres_import.rs:L1356), sqlite_v57_pending_import_completes_the_local_binding (postgres_import.rs:L1506) and sqlite_other_source_formats_are_rejected_explicitly (postgres_import.rs:L1591) cover the upgrade, both import paths and the rejected formats against a disposable instance.
  • Documentation. The branch design records title on create, in the schema, in the roster name and in the event envelope, with the hello feature and the fallback (docs/design/timeline-branches.md:L441, docs/design/timeline-branches.md:L446, docs/design/timeline-branches.md:L687), with the Chinese translation (docs/zh/design/timeline-branches.md:L416, docs/zh/design/timeline-branches.md:L421, docs/zh/design/timeline-branches.md:L570); the native storage format records v59 as the title's marker-only step above main's v58 (native-storage-format.md:L3), and the PostgreSQL storage design records the format transition and the import range (the bytea representation and bounded backfill at postgres-session-storage.md:L19, the import range at postgres-session-storage.md:L45); the resume contract states which legacy rows still read a creation body (timeline-branches.md:L988, timeline-branches.md:L857).

Interface change

  • hello.features gains session.branch_create.title. A client sends the request member only when the feature is offered.
  • The branch tool and session.branch_create limit title to 120 characters, declared as maxLength in the tool schema.
  • A PostgreSQL Session store is format 3, and format 3 stores timeline_branches.title as BYTEA UTF-8 bytes with CHECK (branch_id <> 'main' OR title IS NULL); a format 1 store first passes the marker-only format 2 step, and a format 1 or format 2 store then adds the column, fills it in keyset pages of 64 rows with one array UPDATE per page, and moves the marker last, and a daemon that knows only format 1 or format 2 refuses the upgraded store at open.
  • The SQLite directory row stores an optional title in timeline_branches.info; the format moves to 59 by a marker-only step, and neither the v58 step nor the v59 step rewrites a row.
  • The read-only SQLite import accepts v57, v58 and v59 sources; a v57 or v58 source has no branch titles and a v59 source may.
  • The plugin declarations type a stored or requested title as omission or a string; an explicit null is a type error.

Existing tests

branch_flow::a_title_is_refused_with_what_names_a_line (branch_flow.rs:L5535) now asserts that a first call carrying title opens the line, that BranchCreateData.title and the roster entry carry the title, and that the child's first input is still the prompt; its schema assertion adds title and the restored prompt description, and the no-title fallback assertion stays. The interrupted-branch restore fixture that main brings into branch_flow.rs constructs BranchCreateData and gains title: None (branch_flow.rs:L15571), keeping its untitled behaviour. Every other change to an existing test is an additive title: None in a construction literal for BranchOptions, BranchCreateData or BranchEntry. The existing web/src/rpc/read.test.mjs round-trip test keeps its main version byte for byte; title decoding and the refusal of a non-string title are covered by the new branch_create replies keep a line title and refuse a non-string (read.test.mjs:L150) and branch titles are decoded on directory rows and creation facts (read.test.mjs:L160). The postgres import test that main brings in, sqlite_import_rolls_back_retries_and_keeps_history_and_shared_files, gains title: None in its construction literal (postgres_import.rs:L113), and now publishes a titled creation (postgres_import.rs:L138); its original assertions are unchanged.

Design rule checklist

  • Scope: each new part is placed by the owner of its state and lifecycle (process / Session / branch); no wiring module. No part or wiring module is added: the title is an optional member of the existing branch/create fact (events.rs:L1176), the tool and request entries stay in TimelineTree and the App Server (timeline_tree.rs:L5712, protocol.rs:L992), and the directory row is written by the session store that already owns it (storage/timeline.rs:L3635).
  • n/a: Commands and results. The change adds an optional member to the existing creation fact and to the reads that return it; it adds no command, result or change to another module's state.
  • n/a: Handover. No handover point is added or changed; a line's creation keeps its existing branch/create event.
  • Timeline before callbacks only transform the draft synchronously: they never block the write or wait for external work (ask the event owner for a generic field when the draft cannot express it). Entries validate only shape and authorization; feature checks belong to the feature owner. A registered before may rewrite the creation, so the same single-line and length check runs on the rewritten draft inside the creation callback, before the fact and its reservation exist, and it awaits no external work (timeline_tree.rs:L2838); the tool and request entries check only their own input shape (timeline_tree.rs:L5773, connection/tree.rs:L961).
  • Infrastructure (Timeline, Dispatcher, event envelope, assembly and lifecycle, Session and branch facades) is unchanged, or the change comes from and closes within the infrastructure itself. The Timeline, Dispatcher, assembly and the Session and branch facades are unchanged: the creation event's data gains an optional member, the App Server client projection carries it in the envelope for v3 and v4 and keeps v2 frozen (tree_protocol.rs:L201), the SQLite store keeps main's v58 step and moves to 59 by a marker-only step (sqlite.rs:L22), and PostgreSQL adds the directory column in its format 3 step (postgres.rs:L211).
  • Core mechanisms and consumers gain no plugin-specific handling. The Timeline and Dispatcher stay generic; the only per-event shape is the App Server's client projection, which already renders each event kind and moves this title out of data there so v2, v3 and v4 clients decode what they already know (tree_protocol.rs:L201).
  • Batch: facts that take effect together are written in one batch, with the deciding event last. A creation writes its directory row in the same batch as its branch/create (storage/timeline.rs:L3635), the PostgreSQL path inserts the row inside the append transaction (postgres/timeline.rs:L228), and the format steps write no fact (sqlite.rs:L560).
  • Context: only handed-over, consumed facts reach the model context. The roster keeps its existing runtime-context path and reads the line's name from the title when one was recorded, falling back to the prompt's first line (timeline_tree.rs:L4467); no new context input or event path is added.
  • No reading another plugin's internal state or deciding for it. A restore names a line from its own directory row and, only for a row written before rows carried names, reads data.title and data.prompt from that line's creation (timeline_tree.rs:L1987); it consults no other part's state.
  • Cross-language faces: new public services use data faces, existing dependencies state their current face, and a leaf injects and provides only data faces (service faces). No public service is added or renamed: the existing branch service data types gain the optional member (contracts.rs:L158, contracts.rs:L211) and the declarations are regenerated from them (branch-services.d.ts:L1400); the part's injects and provides are unchanged.
  • Business configuration stays out of loader rows; contracts are language-neutral. No configuration is added: the new request and event members are plain data on the existing protocol (protocol.rs:L992), and the tool schema states the bound as data (timeline_tree.rs:L6750).
  • Missing mechanism capabilities are raised as requirements (problem, why existing mechanisms fail, generic capability, ordering impact, owner/issue). None raised: the title fits the existing creation draft and the client envelope, and the declaration narrowing stays in the existing types step because the generated declarations write every optional member as a nullable union (types.rs:L841).
  • Timeline holds only facts later decisions use; UI-only changes go through Session broadcast notices; process-level state is changed through its owner's typed write operation, not the Timeline. The title is recorded once on branch/create, the fact the roster, the directory and a cold restore read, and the directory row is written by its storage owner; no UI-only state enters the Timeline (timeline-branches.md:L687).

Documentation

  • No accepted ADR is modified or deleted; a changed decision is a new ADR, and a link or typo fix uses adr-erratum (ADR 008). No ADR is touched; the branch, storage and export designs and the Chinese mirrors that exist are updated for the title (timeline-branches.md:L441).
  • No other module's design is changed; a cross-module requirement is stated for its owner. Each document states its own part: the branch design the creation input, the roster and the client envelope (timeline-branches.md:L687), the native and PostgreSQL storage designs the format steps and the import range (native-storage-format.md:L3, postgres-session-storage.md:L19), and the export design the directory row member (timeline-export.md:L119).
  • Delivery status is not added to an ADR, index or roadmap; binding details are in a binding appendix. No delivery status or history is added to an ADR, index or roadmap; the binding detail is the optional member in the regenerated declarations (branch-services.d.ts:L1546).

Verification

On commit 7278fa1, the 25 commands of the gate list for this change pass: node scripts/adr-check.mjs --base origin/main, cargo fmt --all -- --check --config error_on_line_overflow=true, cargo clippy --locked -p xtask-check --all-targets -- -D warnings, cargo clippy --workspace --all-targets --locked -- -D warnings, cargo run --locked -p xtask-check, cargo run --locked -p xtask -- check, cargo run --locked -p xtask -- types followed by git diff --exit-code -- npm/branch-services.d.ts, eight cargo test commands, the plugin SDK type check, the ignored PostgreSQL group and seven focused runs. The full workspace regression runs in CI.

  • cargo test --locked -p xtask-check: 127 passed; -p dim-agent-types: 10 lib tests and 54 contract tests passed; -p dim-agent-runtime --lib: 14 passed; -p dim-agent-capabilities --test capabilities_flow: 786 passed, 1 ignored; -p dim-app-server --lib: 166 passed, 12 ignored; -p dim-app-server --test app_server_flow: 622 passed, 12 ignored; -p dim-app-server --test transport_flow: 812 passed, 87 ignored; -p dim-migration --test migration_flow: 19 passed.
  • node --test runtime/plugin-sdk.test.mjs: the packed declarations compile the author guide and enforce the public call shapes, 2 tests passed.
  • The ignored PostgreSQL group ran against a disposable PostgreSQL 17.12 instance with a private URL file: 12 tests passed, including postgres_upgrades_a_format_one_store_and_keeps_titled_lines, postgres_upgrades_a_format_two_store_written_before_the_title_step, a_format_one_line_is_named_by_its_prompt_on_a_cold_restore, postgres_keeps_nul_titles_across_upgrade_create_import_and_fork, postgres_backfills_format_one_titles_in_batches_and_a_second_open_skips_them, sqlite_v57_source_imports_directly, sqlite_v58_source_imports_directly, sqlite_v57_pending_import_completes_the_local_binding and sqlite_other_source_formats_are_rejected_explicitly.
  • The seven focused runs each passed one test: the new PostgreSQL format 2 case, the new SQLite v58 case, postgres_timeline_flow::a_v1_store_upgrades_to_v2_keeping_its_id_and_facts, postgres_keeps_nul_titles_across_upgrade_create_import_and_fork, postgres_backfills_format_one_titles_in_batches_and_a_second_open_skips_them, branches::a_cold_restore_drops_legacy_rows_without_reading_their_creations and branches::a_format_57_directory_keeps_names_for_open_ended_and_copied_lines.
  • One capabilities_flow run hit host_platform_flow::a_slow_reader_frees_space_and_the_pipe_resumes (TaskRunning); the case is registered in the known-failures table, passed alone in 0.23 s and passed in the full rerun.

A branch line takes an optional `title`, one non-empty line, which names it in the Session's directory and in its opener's roster; `prompt` stays the line's first input and its purpose. The branch tool and `session.branch_create` accept it, and the tool no longer refuses the field that `exec` and `collaboration` already take.

`branch/create` carries the title as an optional event field, and the v58 marker step keeps a v57 daemon from opening a store whose events it cannot decode. A title that is blank or carries a line break is refused by the tool, the RPC and `TimelineTree::create_child` before any fact is written. A line without a title is named by the first line of its prompt on creation and after restore, and `session.branches`, `session.branch.get` and the roster return that name. The v1 and v2 encodings stay frozen: v1 through its own event view, v2 through the event projection and the cleared title on the frozen `session.branch_create` reply.

The readers decode the new field only; the terminal and Web wiring follow separately. Refs #2000 #2070.
The client's `BranchEntry` gains an optional `title`; the in-crate directory fixtures carry `title: None` with their other fields. Refs #2000 #2070.
…n a new test

The existing branch_create reply test returns to its main version byte for byte; the title round trip and the refusal of a non-string title move to a new test.
The `BranchCreateData` literal in `sqlite_import_rolls_back_retries_and_keeps_history_and_shared_files` gains the new optional `title` field as `None`; the test's assertions are unchanged.
@zerob13

zerob13 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

在 ec111d0ef 对照刚合入的 PostgreSQL 后端,有两条跨版本路径需要一起验收。

  1. 未启动新 daemon 的 SQLite v57 用户无法按文档直接导入。 --import-postgres 以只读方式打开源库,随后要求 format == STORE_FORMAT;这个 PR 把常量改为 58,v57 因而在读取目标回执之前就被拒绝。若上个版本已提交到目标、还没来得及将本地 pending 改为完成,此时用新版本启动也会要求先完成导入。建议允许已验证结构的 v57 和 v58 分别走现有只读导入,保留其他格式的显式错误。用一次性 PostgreSQL 验收两条路径:v57 无标题历史直接导入,以及 v57 已有目标回执时用新版本重试、完成本地绑定。两者都不需要改写源库。导入门槛 · pending 恢复约束 · 现行 v57 操作说明

  2. 有标题的 branch/create 也会进入 PostgreSQL,而该后端仍按格式 1 开库。 PostgreSQL 持久化整个 EventKind 的 JSON,读回时反序列化为当前类型。上个版本同样接受格式 1,但它的 BranchCreateData 会拒绝未知字段 title。因此旧 reader 打开库后,遇到新写入的带标题事件才会报错。请给 PostgreSQL 明确版本升级和旧 reader 拒开策略,保留 store_id 及已有无标题历史。现有真实 PostgreSQL 导入用例默认 ignore,新改的一行是 title: None;建议显式跑该流程,加入有标题事件,重开后核对标题、原始 prompt 和父子行历史,再验证升级前的打开逻辑会拒绝新格式。以上是对该提交的源码核查,尚无这组跨版本实跑结果。PostgreSQL 格式检查 · 事件写入 · 事件读取 · 旧解码类型 · 导入流程

@yyhhyyyyyy
yyhhyyyyyy marked this pull request as ready for review December 3, 2026 16:24

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

评审 ec111d0。可选 title 与首条输入分开,保留无标题时从 prompt 首行取名,符合 #2549。阻塞是老 v3/v4 客户端仍会收到它们无法读取的 branch/create:新 ProductEvent 只对 v2 去掉 title,现有 v3/v4 客户端可协商相同版本,而且把该事件直接反序列化成 deny_unknown_fields 的旧 BranchCreateData。新端或模型一旦创建有标题的分支,同 Session 的旧客户端收到实时事件或重新读历史时就会拒绝这条事件。目录用的新字段单独看是可加的;可保留 title 在兼容的目录/详情结果里,将实时与历史的事件投影保持旧形状,或用连接显式 opt-in。补一个用旧严格类型读取真实分支创建的实时事件与重新连接后的历史、以及新端仍能读标题的测试。zerob13 已另列 SQLite→PG 导入及 PG 降版本,两条与这个 wire 问题独立。CI 47144584668 通过;上述 wire 行为是源码核查,未独立跑混版本。旧解码 · 旧类型 · 本 PR 事件投影

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes. The tool and RPC now accept an optional title while keeping the child’s prompt verbatim, and the SQLite tests cover restoring explicit titles and the first-line fallback. The remaining issues concern existing databases and clients. Tool flow · RPC flow · Restart flow

  1. Preserve read-only v57 import and recovery. A v57 source now fails the equality check against STORE_FORMAT 58 before the importer can look for a matching PostgreSQL receipt. If the old importer already committed to PostgreSQL but stopped before completing the local binding, startup refuses the pending import and the new importer cannot complete it. Please admit validated v57 and v58 sources through the existing read-only path. Verify that a v57 source can import directly and that restarting an already committed v57 import completes the binding without rewriting SQLite or duplicating PostgreSQL records. Earlier review comment · Import gate · Receipt recovery · Startup binding guard

  2. Version PostgreSQL’s stored event encoding. PostgreSQL saves the full event body, including title, but still admits and writes format 1. An old daemon accepts that marker and then fails when it first encounters a titled branch/create. Give PostgreSQL a format transition under its existing startup transaction. Verify that a format-1 store upgrades with the same store_id and existing history, a titled line keeps its title and full prompt after reopen, and the pre-change daemon rejects the upgraded store at open. Earlier review comment · Format gate · Payload write · Payload read · Pre-change decoder

  3. Keep titled events readable by existing v3 and v4 clients. The server only strips data.title from v2 events. Existing Rust clients negotiate v3 or v4 and decode the known branch/create event with a type that rejects unknown fields. When another caller creates a titled line, an existing client can fail a history page or live notification despite a successful handshake. Please keep the legacy event data shape for existing clients, either by making the field opt-in or by putting it in an extensible part of the event envelope. Verify that the pre-change decoder can read the event in history and live delivery while updated clients can retrieve the title. The directory and create reply can carry their optional field. Event projection · History · Live delivery · Pre-change Rust reader

Optional

The TimelineInfo.title documentation could clarify that an untitled child already carries its derived display name in the populated directory. Current field documentation · Restore projection

CI was green on this head. The focused Web RPC reader tests passed, and the PostgreSQL compatibility findings are from source review.

No formal reviews were recorded when this draft was prepared.

Merge remains gated on resolving these compatibility issues and obtaining the required approvals. TUI and Web interaction work is tracked separately. Accepted scope · TUI #2551 · Web #2552

A v3 or v4 client decodes the `branch/create` event data with a type that refuses unknown fields, so a title inside it fails a live notification or a history page even though the handshake succeeded. The event projection now keeps that data shape for existing clients and carries the title as the optional top-level `title` of the event envelope, which a client that predates the field ignores; v2 keeps its frozen shape and carries none, and an event without a title keeps its previous bytes.

The Rust client and the Web reader decode the envelope member, and the directory, detail and `session.branch_create` reply keep their optional field. Refs #2000 #2070.
`TimelineInfo.title` now states that a populated directory already names an untitled line by the first line of its prompt, so the generated TypeScript declaration follows the Rust contract.

Refs #2000 #2070.

@Simon-He95 Simon-He95 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes on ec111d0e.

The direction is right: title is separate from prompt, prompt stays the child's first input verbatim, the roster/directory fall back to the first prompt line, and the tool/RPC/schema boundaries validate one non-empty line before writing any fact. The title belongs on the branch/create event, TimelineInfo/BranchOptions, session.branch_create and the directory reply. The remaining issues are compatibility and versioning.

P1. Existing v3/v4 clients still receive a branch/create they cannot decode

ProductEvent::new clears title only for protocol v2. An existing Rust client negotiates v3 or v4 and decodes branch/create into dim_agent_types::BranchCreateData, whose deserializer denies unknown fields and has no title on main. When another caller opens a titled line, the old client fails the live notification or history page after a successful handshake. The directory/detail additions are additive and safe; the event projection is not. Projection strip only v2 · Event field

Keep the v3/v4 event-data shape unchanged (derive the title from the directory/reply for old readers) or put the field behind an explicit connection opt-in/protocol version, and verify a pre-change decoder reads both live and replayed events while an updated reader can still retrieve the title.

P1. The request boundary has no negotiated capability

session.branch_create now accepts title, but nothing in hello.features or the protocol version tells a new client whether an older daemon accepts it. A pre-change daemon's BranchCreate request denies unknown fields, so a TUI/Desktop that starts sending title against an older v4 daemon gets invalid_params. Clients either have to fall back on failure or cannot use the field at all. #2549 explicitly wants the TUI and Web line-creation entry points to use this field. Request · Advertised features

Add a hello feature (for example session.branch_create.title) and have clients send the member only when it is advertised, or bump the protocol version; document the fallback. Current dim-electron does not send title yet, so this is not an immediate break, but it is a required guarantee before the Desktop/TUI adopt it.

P1. v57 import and PostgreSQL still need the format transition

These are the two peer findings and I confirm them from the source:

  • The importer compares the source format to STORE_FORMAT 58 and refuses a v57 source before it can look for an already committed PostgreSQL receipt. A v57 import that stopped between the PostgreSQL commit and the local binding cannot be completed. Admit validated v57 and v58 sources on the read-only import path. Import gate
  • PostgreSQL writes the full event body, including title, while still admitting format 1. An old daemon accepts that marker and fails at the first titled branch/create. Give PostgreSQL a format transition (same store_id, existing history preserved) and verify a format-1 store upgrades and a pre-change daemon rejects the upgraded store at open. PostgreSQL marker

P2. Format 58 collides with #2530

#2530 proposes v58 for its input-file representation. If both directions are ever selected, one must move to v59 with an explicit upgrade step. This is not a blocker for this PR on its own, but the format number must be coordinated before merge. v58 decision · #2530 format

Optional

  • The title has minLength: 1 but no maximum, while the roster/directory truncates the fallback at 120 characters. State or enforce the intended title bound so a huge single-line title does not enter the directory verbatim.

Verification: source, event/projection, importer and PostgreSQL review; CI at this head is green. I did not run the storage/import flows locally.

Verdict: REQUEST_CHANGES.

PostgreSQL stores now carry format 2. Opening a format 1 store upgrades it in place inside the startup transaction, keeping the store id and every Session record; a reader that admits only format 1 refuses the upgraded store at open. The SQLite importer admits validated v57 and v58 sources through the same read-only path, so an interrupted import from the previous version can finish its local binding without rewriting the source.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Requesting changes on ec111d0ef92aa44b7167e420f7c7d7b016592534. The title is separated from the prompt, the prompt stays the child's first input verbatim, and the tool, RPC and schema boundaries validate one non-empty line. Those parts match the accepted #2549 scope. Four compatibility items remain, plus a merge conflict with current main. Accepted scope

  1. Existing v3/v4 readers still cannot decode a titled branch/create. ProductEvent::new clears title for v2 only, and a client from main negotiates v3/v4 and decodes the event with BranchCreateData, which denies unknown fields. Another caller opening a titled line fails that client's live stream or history page. Keep the v3/v4 event data unchanged, or gate the field behind an explicit connection capability, and verify a pre-change decoder reads both live delivery and a replayed page while an updated reader still sees the title. Projection · Event field
  2. The create request member has no negotiated capability. BranchCreate now accepts title, but hello.features advertises session.branch_create as a method and nothing that names this member. A pre-change daemon decodes the request with deny_unknown_fields and no title, so a client that sends it gets invalid_params. The catalog contract states that a feature names a method or a request member an older daemon would refuse, which is the precedent this member falls under. Advertise a member feature and have clients send title only when it is offered, or add the equivalent version gate, and document the no-title fallback. Sender wiring stays with #2551, #2552 and Desktop. Request · Advertised features · Pre-change request · Feature contract
  3. Read-only v57 import and pending-import recovery are refused. The importer still compares the source format with STORE_FORMAT 58 before it can look for a matching PostgreSQL receipt, so a v57 source cannot be imported and an import that stopped between the PostgreSQL commit and the local binding cannot be completed. Admit validated v57 and v58 sources on the read-only path and verify both cases against a disposable database. Import gate
  4. PostgreSQL still writes titled events under format 1. The full event body, including title, is stored while the marker stays 1, so an older daemon accepts the store and fails at the first titled branch/create. Give PostgreSQL a format transition under its existing startup transaction with the same store_id, verify that existing history upgrades, that a titled line keeps its title and prompt after reopen, and that the pre-change daemon rejects the store at open. Format gate · Payload write

main has moved to 4b1a783f, and tree_protocol.rs, dim-client/tests/connection.rs and web/src/rpc/read.test.mjs conflict with it. The conflict is mechanical, but it must be resolved before the compatibility items can be verified at the final head.

Optional

  • title has minLength: 1 but no maximum, while the roster and directory truncate the derived name at 120 characters; state or enforce the intended bound.
  • #2530 was withdrawn as the competing implementation, so v58 stays available for this PR's own storage change; item 3's format decision no longer waits on that choice. Owner decision

CI passed on this head. CI run

@zerob13

zerob13 commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

I resolved the three conflicts with main on hui/branch-title. The event constructor retains both the branch’s v2 title omission and main’s negotiated MCP identity projection. The Rust client and Web reader tests retain both parents’ coverage. The merge passed 28 focused Rust tests, 15 Web RPC tests, formatting and whitespace checks. Could you confirm that this resolution preserves the intended behavior? The mixed-version title and PostgreSQL import/format findings still need separate fixes. Conflict resolution · Outstanding review

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow-up on the conflict resolution at a901a2fc. The event constructor retains main's negotiated MCP identity projection and the branch's v2 title omission. That integration does not resolve the earlier mixed-version finding: v3/v4 still receive the new event field. The negotiated request member and PostgreSQL import/format findings from the other reviews also remain open.

There is one new compiler failure from the merge: the interrupted-branch restore fixture on main constructs BranchCreateData without the new field. Both Linux and native macOS report E0063 at branch_flow.rs:15005. Set title: None in that fixture to keep its untitled behavior, then rerun the full selected checks. This is separate from the compatibility work. My prior Request changes stands.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes on a901a2fc. The merge resolved the three content conflicts and preserved both main’s MCP identity projection and the branch’s v2 title omission. It also brought in an interrupted-create fixture whose BranchCreateData initializer lacks title. Set title: None to preserve the untitled fixture, then verify that capabilities_flow builds and that both CI jobs pass. The earlier focused checks did not compile this target. Linux workspace Clippy and the macOS native test build both report E0063 at the same initializer. Fixture · Linux · macOS

The four previous compatibility findings still need fixes. Previous review

  1. Accept validated SQLite v57 sources through the read-only importer, including a retry that must find an existing PostgreSQL receipt and finish the local binding. Import gate
  2. Add a PostgreSQL format transition so old daemons reject the upgraded store at open. Preserve the store identity and existing history, and verify that a titled line and its original prompt survive reopen. PostgreSQL admission
  3. Keep titled branch/create events readable by existing v3/v4 clients in live delivery and history, while letting updated clients retrieve the title. The merged projection still strips the field only below v3. Event projection
  4. Advertise support for the title request member and document the prompt-only fallback so a client can omit title when it connects to an older daemon. The method advertisement is present on both. Request schema · Feature list

CI failed on this head. Eric independently confirmed the fixture failure and the outstanding compatibility findings. Merge remains gated on the fixes, green checks, and required approvals. CI run · Eric’s follow-up

The daemon lists session.branch_create.title beside session.branch_create in hello.features and exports the name as a protocol constant, because an older daemon's request type refuses the member; a client sends title only when it is offered and otherwise the daemon names the line by the prompt's first line. is_valid_branch_title bounds a title at 120 Unicode scalar values, the bound the branch tool's schema declares and a prompt-derived name stops at, so storage, the event envelope, the directory and the roster carry the same title. The tool's title description and the three rejection messages state the bound, and the English and Chinese branch designs document the advertised member and the fallback.
@yyhhyyyyyy
yyhhyyyyyy requested a review from zerob13 December 4, 2026 12:54

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes on c9291bf662452f0edc3fa6e98dcbf86091fce414. The last review's final-title validation and TypeScript omission-or-string fix now appear in source. Rows with a stored name also avoid the creation read at normal cold resume. Moving names into the directory is the right direction. The migration now makes startup depend on a different, wider read.

Structure · Blocking: bound the format-1 PostgreSQL upgrade so a line title cannot stall opening an entire store. The store opener acquires the startup advisory lock, fetches every non-root creation's full payload into a single result, deserializes it in the daemon and awaits one UPDATE per child before committing the format marker. The cost and peak memory depend on all prior creation prompts across all Sessions, including ended ones. Even a healthy format-1 store with many Sessions now pays that cost before it can open any Session. Locked upgrade

Acceptance: use a bounded backfill or another directory-owned approach with bounded transfer/memory and without a round trip per child. In a disposable format-1 store with many existing ended lines and large legacy prompts, show the migration preserves title fallback, the store identity, and atomic format publication. A second open should not re-read the creation bodies. Clarify the paired SQLite path in the resume contract: old rows without a stored name still query the creation's title and prompt, including for ended lines, unlike the new-row test. Verify the v57 fallback separately rather than treating the new-row test as covering upgraded rows. Legacy lookup · Resume contract

Compared the earlier compatibility findings, revised creation/projection/restore paths, SDK types and the PostgreSQL upgrade. This is source-based; I did not benchmark the migration or rerun a real PostgreSQL store. Exact-head Linux CI was still running; macOS-native, Windows CLI and Web passed.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes on c9291bf. The ended-directory restore, post-transform validation, and SDK null-handling changes satisfy the three items in the previous review. The new PostgreSQL directory migration still needs a storage fix. Previous review · Author’s response

Preserve every name the branch contract allows in PostgreSQL. The new directory column is TEXT, which cannot store U+0000. The previous format accepted branch prompts as Rust strings and stored their event bodies as BYTEA. Its RPC checked that the prompt was nonblank. That narrows the set of existing names the upgrade can preserve and can prevent a valid format-1 store from reopening. The same representation affects new creates and SQLite imports, which use the PostgreSQL branch insert. Please use a storage representation that round-trips the accepted title and fallback strings, including existing prompts. Verify that upgrade preserves the store identity and history, and that create, import, and fork preserve the same directory name after reopen. Old prompt check · Old payload format · Upgrade · New writes · PostgreSQL character types

The same upgrade fetches every creation payload across the store into one result and issues one update per child while holding the startup lock. Please backfill in bounded batches with batched writes, keeping schema, names, and marker publication atomic. Verify the first open on a disposable format-1 store with many ended lines and large prompts, and verify a second open skips the backfill. The v57 SQLite fallback remains a separate path that selects title and prompt when a row lacks its stored name. Locked backfill · Eric’s review

All six existing disposable PostgreSQL upgrade and import tests passed, including v57 direct import and committed-receipt recovery. The representation failure and the backfill’s scaling follow from source review and the documented PostgreSQL type contract. Migration latency was not benchmarked. macOS, Windows and Web passed on this head, and Linux verification was still running when checked. CI

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

请求修改 c9291bf。新增一个 SQLite 冷恢复阻塞。上一轮的已结束分支正文读取、before 改写后的标题校验和 SDK 的 title: null 三项已解决。同头正式意见里的 PostgreSQL 名称存储和升级回填问题仍成立。上一轮评审 · 同头 PostgreSQL 评审

Structure · Blocking — 一个未完成子线的标题读取可以阻断整个会话恢复。 v57 目录行缺少名称。父线仍活动、子线没有完成打开、父线也尚未记录 branch/create-failed 时,恢复先读取 data.title 和 data.prompt,之后才判断创建是否完成。这条子线将被剔除,写入失败事实只需要目录锚点,既有恢复契约也允许来源读取失败。此时名称读取失败会提前退出,连 main 都无法加载。已有 create-failed 的行和未打开的 inactive 父线子行已跳过名称读取。缺口在第一次重启收尾。名称读取及错误传播 · 中断创建的收尾 · 既有恢复用例

验证与验收。 在临时副本中,把现有 v57 传输测试对中断行创建正文的损坏提前到第一次重启。会话操作返回 -32603。保持同一损坏数据,仅让该目录行已有名称,相同测试通过。请验证无目录名称时也能首次恢复 main、目录排除该子线、父线恰好写入一次 branch/create-failed,再次重启仍只有一条。同时保留正常活动、已结束及 fork 复制行的名称。现有测试的两次重启顺序

Blocks inspected 已核对完整 diff 中的创建入口和事实写入、目录和名册、恢复和 fork、三种存储及升级导入、实时和历史协议、Rust/Web/SDK 读端、设计文档和替换的测试。旧拒绝 title 的断言由创建与读取的流程测试接替。原始 head 上本地 App Server 分支传输测试 21/21、Web 协议读取测试 15/15 通过。隔离 PostgreSQL 17.12 确认 TEXT 写入 U+0000 返回 22021。

Not verified 本地未跑全工作区和端到端 PostgreSQL 升级,未测量回填耗时。GitHub 上 Linux、macOS、Windows、Web、静态检查、脚本及汇总检查 ci-ok 已通过。CI

@Simon-He95 Simon-He95 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed c9291bf6 (feat(branch): give a line an optional title, fixes #2549). 82 files, +2950 −130.

Scope: contract/state/multi-subsystem.
Direction: aligned with #2549. The title stays separate from prompt, the owner validates one non-empty line before any fact, and the storage/import steps are explicit.
Architecture: held in the owner path; the remaining problems are storage migration and cold restore.
App Server surface: additive.

App Server surface

  • Changed: session.branch_create takes an optional title (crates/dim-app-server/src/protocol.rs:982-989); hello advertises session.branch_create.title (crates/dim-app-server/src/protocol.rs:337, crates/dim-app-server/src/transport.rs:732); branch/create keeps its old data shape for every version and carries the title only in the v3/v4 envelope (crates/dim-app-server/src/tree_protocol.rs:178-195); directory/detail replies add an optional title; SQLite format 58 is a marker-only step; PostgreSQL is format 2 and the read-only import admits v57/v58 (crates/dim-app-server/src/storage/postgres/import.rs:354-358).
  • Consumers: TUI/CLI and Web read paths are updated in this PR; ACP has no branch/create consumer path; dim-electron reads known directory keys and sends session.branch_create without title, so it is unwired for the field but not broken; older strict v3/v4 decoders see the old data shape.
  • Classification: additive/backward-compatible for the wire; the PostgreSQL format transition is a storage change, not a wire break.
  • Required: none for the wire; the storage representation/backfill and the SQLite restore path are the peer blockers below.

Prior finding status

  • Resolved: the v3/v4 event-shape break. ProductEvent::with_identities removes title from data for every version and emits it only as the v3+ envelope member (crates/dim-app-server/src/tree_protocol.rs:178-195); a_v2_branch_create_carries_no_title, the v3 envelope test, and the live/history legacy v3 decoder tests pin it.
  • Resolved: the request capability. BRANCH_CREATE_TITLE_FEATURE is advertised beside session.branch_create (crates/dim-app-server/src/protocol.rs:337, crates/dim-app-server/src/transport.rs:732), and the request accepts the optional member (protocol.rs:982-989).
  • Resolved: the v57 import and PostgreSQL format transition. import_locked admits 57 and the current format (crates/dim-app-server/src/storage/postgres/import.rs:354-358), and PostgreSQL format 2 upgrades under the advisory lock (crates/dim-app-server/src/storage/postgres.rs:99-155).
  • Resolved: the merged fixture compile failure; branch_flow.rs:14782, :14902 and :15199 now construct title: None, and CI is green at this head.
  • Resolved: the optional title bound. BRANCH_TITLE_LIMIT = 120 is enforced at the tool, the RPC and the tree.
  • Withdrawn: the format-58/#2530 collision; #2530 is closed and the SQLite step is marker-only.

Carried peer blockers

The current-head reviews (6189479231, 6189532593, 6189644626) carry the remaining storage issues:

  • PostgreSQL stores the directory name in TEXT (crates/dim-app-server/src/storage/postgres.rs:102), which cannot represent U+0000 that a legacy prompt may contain in a valid format-1 store; use a representation that round-trips the accepted prompt/title.
  • The format-1 backfill fetches every creation body into one result and updates one row per child while holding the startup lock (crates/dim-app-server/src/storage/postgres.rs:110-149); bound it.
  • SQLite cold restore reads data.title/data.prompt for an interrupted child before deciding the creation failed (crates/dim-agent-capabilities/src/timeline_tree.rs:3398-3405); a failed read aborts the whole Session restore instead of writing branch/create-failed and dropping the line.

Verified

  • Read the a901a2fc..c9291bf6 delta and the event, request, hello, import, PostgreSQL, SQLite restore and test paths at c9291bf6; the full PR was reviewed at a901a2fc.
  • Blocks inspected: event projection, request/hello, storage formats, import, cold restore, SDK declarations, docs.
  • CI at c9291bf6: 8 success, 2 skipped.
  • Cross-PR / consumer checks: dim-electron's branch-directory.ts reads known keys and service.ts does not send title; #2530 remains closed.

Not verified

  • Did not run the PostgreSQL upgrade, import or storage flows locally; the peer's disposable PostgreSQL run and the source paths are the evidence.

Verdict: REQUEST_CHANGES — the wire compatibility findings are resolved, but the PostgreSQL representation/backfill and the SQLite restore path still block.

A branch title accepts U+0000, which PostgreSQL text cannot hold, so the directory column holds the name's UTF-8 bytes like stored Session titles and previews; the format 1 upgrade adds the bytea column, and the directory read and the SQLite import validate UTF-8 before returning a name.
Opening a format 1 store reads each child's creation body in keyset pages of 64 rows and writes each page back with one array update, so peak memory and round trips no longer grow with every stored creation; the format marker still moves last, inside the same startup transaction, so a failed backfill leaves the column and the marker untouched.
A directory row written before rows carried names projects its creation title and prompt at the point the restore keeps the line, not before it decides whether to drop it; an interrupted creation whose body is unreadable is settled with one branch/create-failed fact on its parent instead of failing the Session restore.
PostgreSQL tests cover a U+0000 title and prompt through the format 1 upgrade, a new creation, both SQLite import formats and a fork, and a large format 1 store whose failed backfill leaves the marker at 1; the SQLite flow corrupts an interrupted creation before the first restart and keeps the names of open, ended and fork-copied lines.
PostgreSQL storage documents the bytea representation, the paged backfill and the marker publication; the branch design states which legacy rows still read a creation body and which rows a restore drops unread.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Fixed in 5ced606, b02c0a1, 5de017b, 911b8ad, 216ac64, merged with main in 29d0a13.

#2550 (review)

Bound the format 1 upgrade. The backfill now reads directory rows in keyset pages of 64, joins each page to its branch/create body, decodes a body per row and drops it, and writes the page back with one UPDATE over three arrays; the marker still moves last in the same locked startup transaction (postgres.rs:L53, postgres.rs:L201, postgres.rs:L203). A missing creation body fails the whole transaction, so the added column, the names and the marker roll back together. postgres_import::postgres_backfills_format_one_titles_in_batches_and_a_second_open_skips_them builds 130 ended lines with large prompts, deletes one creation body and checks that the open fails with the marker at 1 and no title column, then repairs the body and checks the upgraded marker, the store identity and the names; it corrupts every creation body afterwards and checks that a second open and a cold restore still publish the Session and name its ended lines (postgres_import.rs:L943).

Clarify the SQLite fallback. Resume reads now states that a row written before the directory carried names still projects data.title and data.prompt at its known creation position, including an ended line, while a row the restore drops reads nothing (timeline-branches.md:L988). The v57 fallback has its own test for an ended line (branches.rs:L1801); open, ended and fork-copied legacy rows keep their names in a separate test (branches.rs:L1870).

#2550 (review)

Represent a name as UTF-8 bytes. timeline_branches.title is BYTEA (schema.sql:L19), the format 1 upgrade adds the same type and the backfill writes bytes (postgres.rs:L195), a new creation inserts the name's bytes (timeline.rs:L228), and a fork copies the column unchanged. The directory read and the import check validate UTF-8 with std::str::from_utf8 and report a storage error on invalid bytes (timeline.rs:L444, import.rs:L215). postgres_import::postgres_keeps_nul_titles_across_upgrade_create_import_and_fork carries a U+0000 explicit title and a U+0000 prompt fallback through the format 1 upgrade, a new creation, a v57 and a v58 SQLite import, and a fork reopened after the store closes, checking the same directory name at each step (postgres_import.rs:L757).

Keep the backfill bounded. The keyset paging and the single array UPDATE per page are the same change described above (postgres.rs:L53); the failed-backfill and second-open case is pinned by the large-store test (postgres_import.rs:L943). The v57 SQLite fallback remains its own path, as described in the section above.

#2550 (review)

Read a legacy name only where the line is kept. The unconditional read before the completion decision is gone. A row written before rows carried names is named by ensure_title, called at the five points where the restore keeps a line and before the side effect of that point: an ended line, an ended parent's opened child, a line whose own end the restore completes, a copied line it closes, and a line it mounts (timeline_tree.rs:L2048, timeline_tree.rs:L3360, timeline_tree.rs:L3385, timeline_tree.rs:L3414, timeline_tree.rs:L3460, timeline_tree.rs:L3487). The four dropped cases read nothing: a recorded failed creation, a child of an inactive parent, an ended parent's child that never opened, and an interrupted creation.

Verify the first restart. branches::a_cold_restore_drops_legacy_rows_without_reading_their_creations now corrupts the interrupted creation and the unopened child before the first restart. The Session publishes main, the directory excludes both children, the parent records exactly one branch/create-failed, and a second restart still finds one (branches.rs:L1963). The legacy names of an open line, an ended line and a line a fork copied from one open at its cut survive the same downgrade in branches::a_format_57_directory_keeps_names_for_open_ended_and_copied_lines (branches.rs:L1870), and the untitled ended-line fallback keeps its own test (branches.rs:L1801).

#2550 (review)

The three items in this review are the same changes described above, with the same commits and tests:

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approve on 29d0a13d. The PostgreSQL migration and SQLite restart findings are resolved. Previous review · Author response

  • PostgreSQL now stores directory names as UTF-8 bytes. The new fixture verifies explicit and derived names across upgrade, create, SQLite v57/v58 import, and fork/reopen. The format-1 backfill reads up to 64 rows per page and applies one update per page. The 130-line fixture confirms that a failed backfill rolls back the schema and marker together, a successful upgrade preserves identity and names, and a second open uses the persisted names. Backfill · Round trip · Upgrade fixture
  • SQLite restore looks up a missing name only when it keeps the line. The v57 fixtures verify that main publishes on the first restart despite an unreadable creation body for an interrupted child, that the failure fact is written once across restarts, and that open, ended, and fork-copied lines retain their names. Restore helper · Legacy flows

All eight disposable PostgreSQL tests and 22 branch transport tests passed. The previously accepted wire compatibility, request discovery, final title validation, and SDK contract remain satisfied. CI and independent approvals remain merge gates. CI

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

撤回我在 c9291bf 的变更请求。v1→v2 按键分页,每页最多 64 条 body,并用一次批量更新写回;版本标记仍在同一事务最后落下。130 条夹具覆盖跨页与回滚,升级、创建、导入、fork 验证 U+0000 和历史保留;SQLite 未完成的子分支不会被枚举。当前 head 的 Linux、Windows、macOS、Web 和 ci-ok 已通过;PostgreSQL 专项 10 项是作者报告,未独立重跑。

# Conflicts:
#	crates/dim-app-server/src/storage/postgres.rs
#	crates/dim-app-server/src/storage/sqlite.rs
#	crates/dim-app-server/src/tree_protocol.rs
#	docs/design/appserver/native-storage-format.md

@Simon-He95 Simon-He95 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 29d0a13d5a3c453ad1d3457c19a458b08bb94181 (feat(branch): give a line an optional title, fixes #2549). 82 files, +3530 −150.

Scope: state/persistence/multi-subsystem — the reviewed delta is the PostgreSQL directory column and its format-1 upgrade, the legacy SQLite name reads in cold restore, their tests and docs.
Direction: right level for all three prior items. The directory owns the name, the upgrade stays inside the existing startup transaction, and a restore reads a creation body only where it keeps the line.
Architecture: held for the fixes — one stored name per row, one derivation (dim_agent_types::branch_title), no second name source and no restore-side cache. The format decision is the problem below.
App Server surface: no wire change in this delta; the v3/v4 envelope member, the hello feature and the reply fields are as reviewed at c9291bf6.

App Server surface

  • Changed: nothing on the wire in 5ced6067d..29d0a13d5. session.branch_create.title, hello.features session.branch_create.title, the v2 frozen branch/create data shape and the optional reply title are unchanged; npm/branch-services.d.ts is not regenerated in this range because no service type changed.
  • Consumers: TUI/CLI, Web and dim-electron read the directory as before. The reviewed delta changes only how a name is stored in PostgreSQL and when a legacy SQLite row is read during restore.
  • Classification: no wire change; the storage format numbers are the blocking item below.
  • Required: none for the wire.

Prior findings

  • Resolved · Structure — the PostgreSQL name representation. timeline_branches.title is BYTEA holding UTF-8 bytes (schema.sql:19, postgres.rs:195), writes encode the same way (timeline.rs:228), and both the directory read and the import validate UTF-8 before returning a name (timeline.rs:436-451, import.rs:212-229). A U+0000 title and prompt now round-trip through the upgrade, a new creation, both SQLite source formats and a fork (postgres_import.rs:744-910).
  • Resolved · Structure — the unbounded format-1 backfill. Bodies are read in keyset pages of 64 rows and written back with one UNNEST update per page (postgres.rs:53-140), the marker still moves last inside the same transaction (postgres.rs:193-205), a page that misses its rows aborts, and the child count is rechecked at the end. The 130-line fixture crosses pages, corrupts a payload after the first page, and asserts the failed open leaves both the marker at 1 and no title column, then that a second open reads the persisted names without touching bodies (postgres_import.rs:943-1117).
  • Resolved · Structure — the SQLite interrupted-creation read. ensure_title now runs only at the five points where the restore keeps the line (timeline_tree.rs:2048-2060, call sites at :3360, :3385, :3414, :3460, :3487); the interrupted child reaches record_create_failed with an unreadable body, main still publishes, and the failure fact is written once across two restarts (branches.rs:2029-2090). The resume contract now states which legacy rows read and which are dropped unread (timeline-branches.md:988).
  • Carried · Optional (PostgreSQL tests) — below.

Blocking · Structure — SQLite format 58 and PostgreSQL format 2 now each name two different changes

Root cause & same-source scope. Main moved while this branch did not. b20fabc7b (2026-12-05, ancestor of current main 6f18b1f8, not of this branch's merge parent 8a1bb897) took SQLite format 58 for #1835, "two model-output event kinds and optional fields that a v57 daemon cannot decode", and PostgreSQL format 2 for the same marker-only step: main sqlite.rs:22, :552-557, main postgres.rs:100-108, :133. This head uses the same two numbers for the title: sqlite.rs:22 with the title step at :552-554, and postgres.rs:29 with the column, backfill and marker at :193-205. The PR body's "the format stays 58" and "the store marker moves to 2" were true against 8a1bb897 and are now wrong. Both numbers are marker-only guards whose whole purpose is "an older daemon must refuse this store at open", so reusing them silently disables the guard in both directions.

Failure path. (a) A store current main wrote at 58, holding step/provider-tool or step/source or input/message.web_search, is opened by this daemon: open sees version == FORMAT and upgrades nothing; this head's EventKind has no such variants (grep: 0 matches for provider-tool/ProviderTool in crates/dim-agent-types/src/events.rs at this head), so the first event read fails exactly as the 57 comment predicts. (b) A store this daemon wrote at 58, holding a branch/create with data.title, is opened by a current-main daemon: it accepts 58, and BranchCreateData there has deny_unknown_fields and no title, so the first titled creation fails to decode and the line is unusable. (c) PostgreSQL is worse because the schema differs, not only the decoding: a main-written format 2 store has no timeline_branches.title. This head accepts version 2 without adding the column, then every directory read (timeline.rs:436) and every creation insert (timeline.rs:228) references a missing column, so the store opens and then fails on use instead of refusing at open. (d) A titled format 2 store read by a main daemon keeps working but silently loses every name. The same renumbering also decides the read-only import range, which currently admits "v57 and v58 sources" (import.rs:354-361): after merging, a v58 source may carry #1835 events that this head cannot decode.

Acceptance. Merge current main and give each format step its own number — SQLite 59 and PostgreSQL 3 for the title, with FORMAT, schema_of/format_table, the upgrade admission and the import range stated in the merged numbering — so no store can be admitted under a version it was not written with. Cover both directions: a store written at main's 58/2 (with #1835 content) opens and upgrades on this daemon, and a store written by this daemon at 59/3 is refused at open by a daemon that knows only 58/2. Keep the bounded pages, the last-marker ordering and the rollback assertions in the moved test. The head also conflicts with current main in crates/dim-app-server/src/storage/postgres.rs, crates/dim-app-server/src/storage/sqlite.rs, crates/dim-app-server/src/tree_protocol.rs and docs/design/appserver/native-storage-format.md, so this decision is unavoidable before merge.

Optional · Implementation — the PostgreSQL upgrade, backfill and import tests never run in CI

Every PostgreSQL case is #[ignore = "requires a disposable PostgreSQL database URI in DIM_TEST_POSTGRES_URL_FILE"], and no workflow sets that variable (grep of .github/workflows). The upgrade, the page crossing, the rollback and the U+0000 round trip are therefore evidenced only by the author's local run. Wire the group into a job with a service container, or record the gap on the issue.

Optional · Implementation — a legacy mount reads the same creation position twice

For a pre-name row the mount path calls ensure_title and then creation_source at the same anchor, two projection reads for one creation (timeline_tree.rs:1987-2060, :1931-1985). One field selection returning data.title, data.prompt and data.source would do both. Not blocking.

Verified

  • Read c9291bf6..29d0a13d5 commit by commit (5ced6067d, b02c0a1de, 5de017b9c, 911b8ade5, 216ac643c, merge 29d0a13d5) and the resulting files at the exact head.
  • Blocks inspected: the PostgreSQL schema, startup upgrade, paged backfill and its failure/last-marker ordering, the directory read, the creation insert, the fork copy of the column, the SQLite import checks, the SQLite restore loop and its five naming points, the resume contract in both languages, the new PostgreSQL and transport tests, and npm/branch-services.d.ts against contracts.rs.
  • Format check: origin/main at 6f18b1f8 carries SQLite 58 / PostgreSQL 2 from b20fabc7b (#1835); this head carries SQLite 58 / PostgreSQL 2 for the title. git merge-base --is-ancestor b20fabc7b 8a1bb897 fails, which is why the branch never saw it.
  • Merge check: git merge-tree against origin/main 6f18b1f8 reports content conflicts in postgres.rs, sqlite.rs, tree_protocol.rs and native-storage-format.md; GitHub reports the PR CONFLICTING/DIRTY.
  • Generated bindings: no service type changed in this delta and branch-services.d.ts:1233 and :1379 declare title?: string, matching Option<String>, so no regeneration is due.

Not verified

  • No GitHub check runs exist for this head: gh pr checks 2550 reports none, and commits/29d0a13d5/check-runs and the branch's workflow runs are empty, so the "22 commands pass" in the PR body is author-reported only.
  • Did not run any Rust test locally, including the ignored PostgreSQL group; the upgrade, the page crossing and the U+0000 round trip are source-read plus the author's evidence.
  • Did not run the TUI, Web or dim-electron against a titled or upgraded store; the client compatibility conclusion is from the prior head's review and unchanged code.

Verdict: REQUEST_CHANGES — the three prior storage and restore blockers are fixed, but the title now shares SQLite format 58 and PostgreSQL format 2 with main's #1835, which defeats the very guard those markers exist for.

Open a PostgreSQL format 2 store, as the daemon before the title step writes it, through the 2-to-3 step: the title column and its CHECK arrive, the child names are filled from the untitled creations, the #1835 event reads back unchanged, a failed backfill rolls the whole step back, and a second open reads the filled names.
Open a SQLite format 58 store, as that daemon writes it, through the v59 marker step: the marker moves, no business row changes, the #1835 event reads back, and a cold restore names the child line from its creation prompt.
Refuse format 4 on the upgraded PostgreSQL store with AgentError::Storage, the error kind the same gate returns on a daemon that only knows format 2.
Use qualified paths for the error kind and the provider-tool types so the new tests leave the file's import block byte-identical and the round's unittest diff stays purely additive.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Fixed in 45832e9, 0d2f9fa, 7278fa1, merged with main in 47814b5, 7a03aba, 403b97f.

SQLite keeps main's v58 marker-only step for #1835 and gives the title its own v59 marker-only step: FORMAT is 59, the marker table's CHECK is 59, format_table writes the version it is given, and the title step is (58, &[]) (sqlite.rs:L22, sqlite.rs:L98, sqlite.rs:L557, sqlite.rs:L560, sqlite.rs:L563).

PostgreSQL keeps main's marker-only 1 to 2 step and adds the title as 2 to 3: timeline_branches.title BYTEA, the root-null CHECK, keyset pages of 64 directory rows written back with one array UPDATE, and the marker written last, all inside the opening transaction (postgres.rs:L30, postgres.rs:L194, postgres.rs:L209, schema.sql:L19, schema.sql:L26, postgres.rs:L226).

The read-only import admits v57 through v59; a v57 or v58 source carries no title and a v59 source may (import.rs:L361).

A PostgreSQL format 2 store as main writes it, with a step/provider-tool event and three untitled creations, opens and moves to 3: the column and CHECK exist, the child names come from the creation prompts, every event and id reads back unchanged, a failed backfill leaves the marker at 2 and no column, and the same store opens on retry (postgres_import.rs:L684).

A SQLite v58 store as main writes it, with a step/provider-tool event and an untitled child line, moves to 59 without rewriting a business row, reads the event back unchanged, and a cold restore names the child from the first line of its prompt (storage_flow.rs:L10495).

A store above the daemon's format is refused at open: the SQLite FORMAT+1 case asserts AgentError::Storage and unsupported SQLite schema (storage_flow.rs:L4926), and the PostgreSQL format 2 case asserts AgentError::Storage for format 4 (postgres_import.rs:L684). A daemon that knows only format 1 or format 2 meets a format 3 store at those same gates and refuses it.

The bounded pages, the last-marker ordering and the rollback assertions stay in postgres_backfills_format_one_titles_in_batches_and_a_second_open_skips_them, which crosses pages and corrupts a payload before reopening (postgres_import.rs:L1175).

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved 7278fa1213ab050a7e26c4099da2756f96b819e5. This resolves the format collision with main. SQLite retains v58 for the provider-output events and introduces v59 for branch titles. PostgreSQL retains format 2 and introduces format 3. Its upgrade adds the title column, fills it in bounded pages, and advances the marker after backfill in the same transaction. Previous finding · SQLite steps · PostgreSQL upgrade

I ran 15 focused tests on this commit: three SQLite storage tests, two cold-restore tests, and ten import and upgrade tests against disposable PostgreSQL 17.12. All passed. The format-2 fixture retains an existing provider-tool event and the store ID through upgrade. A failed backfill rolls back the column and marker and permits a clean retry. The tests also cover U+0000 titles, v57/v58 SQLite imports, and reopening a store after a multi-page backfill. I inspected the older daemon’s format gates for downgrade refusal; I did not run an old binary. PostgreSQL fixture · SQLite fixture

The merge tree is clean against main at 7643bd66cf65b82210dc16aff41d1db6fce6bcb1. Windows and macOS passed, and Linux was still running at verification. CI

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

branch: accept an optional title so a line's name is not its prompt

4 participants