Skip to content

fix(app-server): fork Sessions with sub-branches without reporting failed creations - #2320

Open
eric8810 wants to merge 6 commits into
mainfrom
fix/1978-fork-sub-branch-create
Open

eric8810 wants to merge 6 commits into
mainfrom
fix/1978-fork-sub-branch-create

Conversation

@eric8810

@eric8810 eric8810 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1978.

A fork of a Session with sub-branches opened with one branch/create-failed on the fork's main per sub-branch, which clients render as "Branch <id>: branch creation failed". Nothing failed. The fork transaction copied each child's directory with head 0, and the store writes a child's timeline_branches row in the same transaction as the parent's branch/create, so a directory with no events means a creation still in flight. TimelineTree's restore reads it that way and records the creation as failed on the fork's main. The failure was that fact being read back, not a restore bug.

The fix is at the producer, and it keeps the requirement that a fork's directory lists the lines that ended before its cut with the end the source recorded (timeline branches §10 §acceptance 19, #1165):

  • A child whose conclusion (branch/ended or branch/create-failed) is inside the copied main prefix gets its directory row with head 0. The copied conclusion is what tells the fork's restore the line is over, so F lists it as ended (or as a failed creation) exactly as S does, with no events of its own — and no creation is re-reported.
  • A child still open at the cut gets no directory row at all. A directory without events has no representation other than "creation in flight", so copying one invented a failure for a branch nothing created and that carries no content F could continue.

Nothing else moves: the copied branch/create facts stay in main byte for byte, no child event is copied, no child can start work in F's shared cwd, TimelineTree's crash-recovery contract is unchanged (a directory with no events still means an interrupted creation), and no format changes. The fork reads the source's conclusions through the existing timeline_events_by_kind index, and a source whose root row is gone still reports Closed.

Copying child content instead (the other reading of the report) stays rejected: a child's events are not ordered against main's cut, and its pending inputs and wakes would run again in the shared cwd (§6.2, §6.3, rejected alternatives).

The design is updated with the change: session-deletion-and-fork.md §1, §6.2, §6.3 (including a new rejected alternative), §6.4, §6.5, §6.6/§8, §7, §15; native-storage-format.md S5c; request-delta-storage.md §9; and the docs/zh/ mirrors. The change to §6.3 amends a decision this page made in the S5c review, so it needs maintainer confirmation on this PR.

Design rule checklist

  • Scope: no new part. SessionStore (process) writes fewer of its own rows; TimelineTree's restore is unchanged.
  • Commands and results: no new events. The change removes a fact that only appeared because a copy was indistinguishable from an interrupted creation.
  • Handover: n/a, no handover changes.
  • Timeline before callbacks: n/a, unchanged.
  • Infrastructure: unchanged; the change is inside SessionStore's own fork copy.
  • Core mechanisms and consumers gain no plugin-specific handling: TimelineTree keeps treating a zero-event child directory as an interrupted creation, for the one producer that still writes one.
  • Batch: n/a, the copy writes fewer rows and no event.
  • Context: n/a, no context input changes; the removed row was never model context.
  • No reading another plugin's internal state or deciding for it: the fork stops asserting a creation TimelineTree never performed; the conclusions it reads are main's own copied prefix.
  • Cross-language faces: n/a, no service added or changed.
  • Business configuration: n/a.
  • Missing mechanism capabilities: none.
  • Timeline holds only facts later decisions use: the dropped directory rows were read by no later decision; an open line is not part of the fork either way.

Documentation

  • No accepted ADR is modified or deleted.
  • No other module's design is changed; SessionStore's own fork page, the native format page and the request-list page are updated where they state the copy.
  • Delivery status is not added to an ADR, index or roadmap.

Verification

Red test at the first commit, on the reported symptom:

cargo test --locked -p dim-app-server --test transport_flow a_fork_of_a_session_with_a_child_branch
# FAILED: opening a fork records no creation failure:
#   [... "branch/resume", ..., "branch/create-failed", ...]
#   left: ["d7362601-…"] right: []

After the fix, at f0d5b4e3e:

cargo test --locked -p dim-app-server --test transport_flow fork -- --test-threads=2
# 19 passed; 0 failed; 1 ignored (DIM_TEST_NODE)
cargo test --locked -p dim-app-server --test transport_flow branches:: -- --test-threads=2
# 9 passed; 0 failed  (includes a_fork_lists_the_lines_that_ended_before_the_fork)
cargo test --locked -p dim-app-server --test transport_flow -- --test-threads=4
# 708 passed; 0 failed; 101 ignored
cargo test --locked -p dim-app-server --test app_server_flow a_fork -- --test-threads=2
# 5 passed; 0 failed
cargo test --locked -p dim-app-server --test app_server_flow -- --test-threads=4
# 512 passed; 0 failed; 6 ignored  (includes storage_flow's fork copy assertions)

The new flow a_fork_of_a_session_with_a_child_branch_reports_no_creation_failure creates a Session with one sub-branch still open and one ended before the cut, forks at main's head, then asserts — after a turn the fork accepts, which orders the read after everything its opening wrote — that the fork's main holds no branch/create-failed, its directory is main plus the ended line, session.branches lists the ended line as ended and omits the open one, and neither line is loaded in the fork.

Checks:

./dev check                              # passed (fmt + clippy: cli, app-server, oauth, dimcode)
cargo clippy --locked -p dim-app-server --all-targets -- -D warnings   # passed
cargo fmt --all -- --check               # passed
cargo run --locked -p xtask-check        # passed (comment links: 111 links into docs)
node scripts/adr-check.mjs --base origin/main   # ADR freeze passed: 8 changed files

Not run: cargo test --workspace --locked and the tmux TUI suite. No TUI code changes; the lines panel keeps rendering branch/create-failed, and the fact is no longer produced for a fork.

…iled

A fork of a Session with a child branch opens with a
`branch/create-failed` for the copied child, which clients show as
"branch creation failed". The new flow forks such a Session, runs one
turn in the fork to settle everything its opening wrote, and asserts the
fork's `main` records no creation failure, its directory is its root and
`session.branches` lists only `main`.

Refs #1978
A fork copied each child branch's directory with head 0, and the store
writes a child's row in the same transaction as the parent's
`branch/create`, so a directory with no events means a creation still in
flight. TimelineTree's restore reads it that way and records
`branch/create-failed` on the fork's `main`, which clients show as
"branch creation failed" for every sub-branch of the source (#1978).
Nothing failed, and the copied directory carried no content.

The fork copy now writes `main`'s directory row and no child's. The
copied `branch/create` facts stay in `main` as stored, no child event is
copied, and restore's crash-recovery contract is untouched. A source
whose root row is gone reports `Closed` as before, or a storage error
when its Session row is still there.

Refs #1978
State that a fork copies `main` and no child branch: a child directory
without events is what the store writes for a creation in flight, so
copying one made the fork's own restore report a failed creation for a
branch nothing created (#1978). Keep the rejected alternatives with the
reasons the copy may not carry a child's events either.

Refs #1978
A fork still has to list the lines that ended before its cut with the end
the source recorded (timeline branches §10, acceptance 19). Only those
lines: an ended line carries no pending work, so its directory row with
head 0 is honest, and the copied `branch/ended` on `main` is what tells
the fork's restore the line is over.

A line still open at the cut gets no directory row, which is where the
false `branch/create-failed` came from (#1978): the fork reads the
source's `main` conclusions through `timeline_events_by_kind` and writes
a child's row only when its `branch/ended` or `branch/create-failed` is
within the copied prefix.

Refs #1978
@eric8810
eric8810 marked this pull request as ready for review November 28, 2026 17:31

@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.

The fork no longer records a false creation failure for a child that was open at the cut. One user-visible gap remains: the native TUI still treats the preserved branch/create fact as proof the child exists in the fork. When reopening the fork, replay projects that child into /lines as Waiting and schedules a session.turn.get for it, even though the fork's branch directory excludes it. An isolated client fixture reproduced both behaviors.

Please verify that reopening a fork keeps the historical creation fact in main but does not show the omitted child in /lines or query its turn. A child whose end was recorded before the cut should still appear with its recorded end. Seven isolated App Server cases passed for the cut, copied history, ended-line metadata, and storage recovery; the tested merge's CI passed the selected Linux and macOS checks, including Linux coverage for a genuine interrupted creation. Those results do not cover native TUI replay of an omitted child.

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.

fork的时候,被fork session的branch create会失败

2 participants