Skip to content

Rebuild Docs on live reads so typing and remote changes coexist - #6146

Merged
ymichael merged 5 commits into
mainfrom
bb/docs-plugin-find-what-s-broken-rebuild-on-today-thr_gf4qmstczc
Oct 23, 2026
Merged

ymichael merged 5 commits into
mainfrom
bb/docs-plugin-find-what-s-broken-rebuild-on-today-thr_gf4qmstczc

Conversation

@ymichael

@ymichael ymichael commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Docs had two document stacks and a hand-rolled tree store, all driven by broad vault-changed signals. The Docs panel (NotePane → useSavedDocument) never listened for changes: saves from another window, bb docs write, agent turns and external editors never showed, and typing on that stale view ended in "Changed on disk / Reload (whole page) / Overwrite". Every save also ran renameToTitle, which renamed the file after its heading. That broke every thread card, Document tab and link pointing at the old path ("HTTP 404: Path does not exist" plus an endless skeleton). The pane was keyed by path, so the rename also destroyed and rebuilt the editor mid-typing: keystrokes were dropped and the caret jumped. Thread cards did refresh, but they compared SHAs and threw a conflict whose Retry re-saved against the old SHA forever. They applied remote text with addToHistory: true, so Cmd+Z reverted an agent's edit and saved it back, and they rebuilt the editor whenever a new preview link was minted. Switching notes blanked the pane and flashed a skeleton, the first click from /docs re-listed the vault and blanked the tree, and clicking the empty space under a note didn't focus it. The native watcher shared one debounce across vaults, so a change in one vault could swallow another's signal, and remote vaults were polled every 10 s even when nobody was looking. Findings with exact steps are in docs-findings.md in the investigation thread's storage.

What changed

Everything is in plugins/docs. There is no other package change, no SDK or plugin API change, no bb.db schema change and no daemon protocol change.

  • One document session for every surface. The Docs panel, thread cards, the Document tab and the Markdown file opener use one session per document (document-session.ts). Reads come from experimental_useRpcQuery and writes go through experimental_useRpcMutation. Views of the same document share one read. The local draft is authoritative:
    • a change from elsewhere that lands while there is unsaved typing keeps the typing and offers Keep mine / Use theirs in place, with no page reload and no silent overwrite;
    • a document moved or deleted by another writer stops saving and offers Save a copy, so saving never recreates it; a view that opens on a missing document shows "This document was moved or deleted." instead of a raw error over an endless skeleton;
    • a removed vault makes the editor read-only.
  • Stable file names. A note's title is its heading (or frontmatter title), and editing it never renames the file, so cards, tabs and links keep working. A new Untitled note takes its first heading as its file name the first time it's saved from the Docs panel, inside the save request. Card labels and the Document tab's header follow the note's opening heading.
  • Reads and writes.
    • readDocument returns the file, its proposal and the preview link as one snapshot, serialized with the vault's writes.
    • saveDocument saves, names an Untitled note when asked, and refuses a stale SHA with a conflict refusal.
    • renameToTitle is gone (only the app called it).
    • contract.ts holds the browser-safe contract and its tags.
  • Scoped invalidation from every write path. RPC, CLI, HTTP, sync and the watcher all invalidate exactly the tags they changed: doc:<vault>:<path>, folder:<vault>:<path>, tree:<vault>, vault:<vault> and vaults.
    • The tree is refreshed only when entries or titles change; opening search refetches it so previews are current.
    • The realtime vault-changed / proposal-changed signals are removed (only the Docs app listened to them).
  • Watching only while watched (vault-watches.ts, via bb.rpc.experimental_whileWatched on listNotes and readDocument).
    • Local vaults are watched natively, with a per-vault debounce and path-scoped invalidation.
    • Events from atomic-write scratch files and echoes of the server's own writes are dropped.
    • Remote vaults are polled every 10 s only while one of their reads is on screen.
    • Preview links are shared per vault root and renewed while a document is on screen.
  • Editor, limited to what the data layer and typing needed (the shared-editor work replaces the rest).
    • The TipTap editor stays mounted across saves and preview-link renewals; only image and embed nodes are refreshed.
    • Outside text is applied without entering undo history, and only blocks whose Markdown changed are replaced.
    • Switching notes keeps the current note on screen while the next loads hidden, then swaps in one frame with the cursor at the end. A note slower than 1 s shows its skeleton as before.
    • Clicking below a note, in the panel or the Document tab, puts the cursor at its end; clicking beside the text puts it on the nearest line.
    • The grey focus ring around card editors is removed.
  • Faster paths.
    • The document loads in parallel with the tree instead of waiting for it.
    • The first open from /docs no longer re-lists the vault, so the tree doesn't blank.
    • Revisited documents show at once from the query cache.
    • A debounced save that finds new typing waits for the next pause instead of saving back-to-back.
  • Docs: README and PLUGIN_OVERVIEW describe live documents, the conflict choices, stable file names and the new tags.

Intended changes users will see

  • Open documents update live; the Docs panel used to stay stale until reopened.
  • "Changed on disk / Reload / Overwrite" in the panel and "copy them before reloading / Retry" in cards are replaced by Keep mine / Use theirs.
  • Editing a note's heading no longer renames its file. Only a new Untitled note is named after its heading, once. The app has no other way to rename a file; bb docs move and the tree's drag-to-folder still move files.
  • Card labels and the Document tab's header follow the note's heading. A tab's title in the tab strip is still the one it opened with.
  • A document moved or deleted elsewhere shows a notice, with Save a copy when there is a draft to keep.
  • Cmd+Z no longer undoes other writers' changes.
  • Switching notes no longer flashes a blank pane or a skeleton.
  • Clicking the empty space below a note focuses it. As a result, a drag selection can't start in that margin.
  • The focus ring around card editors is gone.
  • Opening tree search refetches the tree once. Body edits that only change a note's preview no longer refresh the tree.
  • With no Docs view open, nothing watches the vaults, so the @ mention cache relies on its 10 s expiry for edits made outside bb.

How you verified

Side by side on real browsers

pnpm start:worktree ran for main at 1e80ca7 and for this branch. Each had identical fixtures: vault Alpha with 41 notes plus folders, an image and HTML; vault Beta with 2 notes; and a thread with three Docs cards in two vaults. Headless Chrome drove each flow with real keyboard input, with fetch and WebSocket instrumented in the page. "150 ms" adds that much network latency, roughly a remote bb connect URL. Remote writes were made by another client through the Docs RPC, timed exactly 0 ms or 400 ms after the last keystroke. The CLI, external-editor and agent-turn flows used the real bb docs CLI, a shell write, and a Claude Code Haiku turn. "Requests" counts Docs RPC calls in the window after the action.

Flow main requests branch requests main result branch result
Open Docs panel (/docs) 1 1 tree 948 ms tree 718 ms
First note from /docs 3 1 84 ms 39 ms
Reload on a document, 0 ms 3 2 median 1900 ms to editor median 525 ms to editor
Reload on a document, 150 ms 3 2 median 1089 ms to editor median 938 ms to editor
Switch 7 documents (5 new, 2 revisits), 0 ms 14 7 new 30 ms, revisit 32 ms, 7 blank panes new 32 ms, revisit 20 ms, 0 blank panes
Switch 7 documents (5 new, 2 revisits), 150 ms 14 7 new 177 ms, revisit 179 ms, 7 blank panes new 191 ms, revisit 26 ms, 0 blank panes
Body save in the panel 5 2 saved saved
Change a note's H1, then keep typing 7 3 file renamed to bulk-8-renamed.md, editor replaced; Bulk 8 Renamed file stays bulk-8.md, same editor, focus kept; Bulk 8 Renamed more
New note, type title + line + list at human speed, 0 ms 23 14 text correct, editor replaced text correct, same editor, named meeting-notes-a.md
New note, type title + line + list at human speed, 150 ms 16 15 text wrong: action item one, editor replaced text correct, same editor, named meeting-notes-b.md
Type in an existing note's H1, pause 690 ms, keep typing, 0 ms 17 6 lost/misplaced: Bulk 9 Xy ⏎ Body 9.g to type through the rename, editor replaced text correct, file stays bulk-9.md
Type in an existing note's H1, pause 690 ms, keep typing, 150 ms 20 6 lost/misplaced: Bulk 9 Xyz cont ⏎ Body 9.ype through the rename, editor replaced text correct, file stays bulk-9.md
Second window: A types, B shows it, B types, A shows it 10 6 neither window updates; B's edit never reaches disk B shows A after 738 ms, A shows B after 627 ms (quiet rerun); disk has both
bb docs write to the open panel document 2 1 never shown shown 499 ms after the write
External editor writes the open panel document 1 1 never shown shown 73 ms after the write
Agent turn edits the open panel document (bb docs pull/push) 2 1 never shown shown 0 ms after the write
External edits to two vaults 50 ms apart, cards open 10 2 Alpha card updates both cards within 225 ms
Write in Beta while viewing Alpha 2 0 Alpha re-listed nothing refetched
Open thread with 3 cards in 2 vaults 11 3 median 1794 ms over 3 reruns median 1274 ms over 3 reruns
Save in a card 7 2 saved saved
Save with the same document in a card and the Document tab 7 2 both views show it both views show it
Agent proposal arrives at a card 2 1 shown 60 ms shown 56 ms
Reject the proposal 4 2 restored restored
Remote change 0 ms after a keystroke, panel, other paragraph 3 1 remote never shown; save fails into Reload (page) / Overwrite typing kept; Keep mine / Use theirs offered
Remote change 400 ms after a keystroke, panel, other paragraph 3 1 remote never shown; save fails into Reload (page) / Overwrite typing kept; Keep mine / Use theirs offered
Remote change 0 ms after a keystroke, panel, same paragraph 2 1 remote never shown; save fails into Reload (page) / Overwrite typing kept; Keep mine / Use theirs offered
Remote change 400 ms after a keystroke, panel, same paragraph 2 1 remote never shown; save fails into Reload (page) / Overwrite typing kept; Keep mine / Use theirs offered
Remote change 0 ms after a keystroke, card, other paragraph 7 1 stuck: "copy them before reloading" + Retry that conflicts again; remote never shown typing kept; Keep mine / Use theirs offered
Remote change 400 ms after a keystroke, card, other paragraph 7 1 stuck: "copy them before reloading" + Retry that conflicts again; remote never shown typing kept; Keep mine / Use theirs offered
Remote change 0 ms after a keystroke, card, same paragraph 7 3 stuck: "copy them before reloading" + Retry that conflicts again; remote never shown typing kept; Keep mine / Use theirs offered
Remote change 400 ms after a keystroke, card, same paragraph 17 2 typing lost: replaced by the other writer's text, no notice typing kept; Keep mine / Use theirs offered
Remote change 400 ms after a keystroke, panel, other paragraph, 150 ms 3 1 remote never shown; Reload / Overwrite typing kept; Keep mine / Use theirs offered
Remote change 0 ms after a keystroke, card, other paragraph, 150 ms 7 1 stuck on Retry typing kept; Keep mine / Use theirs offered
Agent rewrites a card, then Cmd+Z in the card - - agent edit reverted and saved back agent edit kept
Another writer moves the open document, then typing - - no notice; typing ends in a conflict whose Overwrite recreates the old file notice + Save a copy; old path not recreated
Preview link renews while typing in a card - - editor rebuilt, focus lost, later keystrokes lost same editor, focus kept, image uses the new link
Remove the vault of the open document 3 1 editor stays editable against a missing vault editor read-only, error shown, tree has Retry
HTML page, new folder, drag into folder, context-menu delete, search 16 10 all work all work

Every flow uses no more requests than main. Rows marked "-" check behavior, not request counts. Each flow is one run, with medians for timing. Single-run milliseconds vary with machine load; the card-thread and two-window rows are quiet reruns.

Switching notes, frame by frame at 300 ms latency: main goes blank for about 200 ms, shows a skeleton for about 100 ms, then the note. The branch keeps the previous note until the new one replaces it at about 330 ms, with no blank or skeleton frame. A revisit takes 56 ms on the branch and 327 ms on main.

The bb docs CLI suite ran against both servers (vaults, list, read, write, pull/status/push, stale-push refusal, propose/reject/undo/accept/undo, mkdir/move/remove, vault-add/vault-remove): 20/20 checks pass on both, with identical results.

Before and after screenshots of every user-facing change are in the verification report in the thread's storage.

Tests

  • New tests that fail on main or on the previous commit, and pass here:
    • a card being edited offers Keep mine / Use theirs instead of getting stuck on Retry;
    • Cmd+Z doesn't undo another writer's change;
    • the Docs page shows another writer's save;
    • a moved document isn't recreated;
    • the editor survives a preview-link renewal;
    • switching notes keeps the current note on screen until the next one loads, then focuses it;
    • clicking below a note focuses its end.
  • Also new:
    • an Untitled note is named after its heading, and a named note keeps its path when its heading changes;
    • session tests for conflicts, own-save echoes, stale reads, rejected saves, renames and proposals;
    • server tests for watched-only vault watchers, echo suppression, and two vaults changing within one debounce.
  • pnpm exec turbo run build typecheck lint test --filter='...[1e80ca7b44]' --continue (the Docs plugin and @bb/bundled-plugins): 60 successful / 60 total. Docs: 125 tests.
  • generate:bb-official-marketplace with --force passes; the overview is 1,918 characters.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 5 commits October 22, 2026 22:20
…exist

The Docs panel, thread cards, the Document tab and the Markdown opener now
share one document session fed by experimental_useRpcQuery reads and
experimental_useRpcMutation writes. The session keeps the local draft
authoritative: remote changes that touch other lines merge into it, and
overlapping ones keep the draft and offer Keep mine / Use theirs in place.

- readDocument returns the file, its proposal and the preview link as one
  serialized snapshot; saveDocument saves and, from the Docs panel, renames
  the file after its first heading in the same vault-serialized request.
- Every write path (RPC, CLI, HTTP, sync, the vault watcher) invalidates the
  document, folder, tree and vault tags it changed; the realtime
  vault-changed / proposal-changed signals and the renameToTitle RPC go away.
- Vault watchers and remote-vault polling run only while a tree or document
  of that vault is watched, debounce per vault, and drop the echo of the
  server's own writes.
- The editor stays mounted across renames and preview-link renewals, applies
  outside text without entering undo history, and reuses its own blocks for
  unchanged Markdown so the paragraph being typed is never replaced.
- A document moved or deleted elsewhere stops saving and offers Save a copy;
  a removed vault makes the editor read-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Editing a heading no longer renames the file, so thread cards, Document
tabs, and links keep pointing at the document. Only a note still named
Untitled takes its first heading as its file name when saved from the
Docs panel. Card and tab labels follow the document's opening heading.

An outside change that lands while there is unsaved typing now keeps the
typing and offers Keep mine or Use theirs instead of merging lines, and a
document that is missing on first load shows one notice instead of a raw
error over an endless skeleton.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Switching notes in the Docs panel used to blank the pane and flash a
skeleton while the next note loaded. The next note now loads hidden and
replaces the current one in a single frame, with focus at its end; a note
that takes longer than a second shows its skeleton as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Clicking below a document, in the Docs panel or a thread's Document tab,
now puts the caret at its end; clicking beside the text puts it on the
nearest line. The Document tab's editor fills the tab so the empty space
under a short document belongs to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit aeeb6d0 into main Oct 23, 2026
31 checks passed
@ymichael
ymichael deleted the bb/docs-plugin-find-what-s-broken-rebuild-on-today-thr_gf4qmstczc branch October 23, 2026 22:25
@ymichael ymichael mentioned this pull request Oct 24, 2026
ymichael added a commit that referenced this pull request Oct 24, 2026
## Human comments

## What was wrong

`main` has 14 commits since 0.47.0, including #6195, which fixes the
timeline staying detached at the bottom (a regression from #5951 that
shipped in 0.47.0). `bb-app` and `@bb/desktop` were still at 0.47.0, so
the publish and desktop workflows can't ship them.

## What changed

- `packages/bb-app/package.json`, `apps/desktop/package.json`: 0.47.0 →
0.47.1 (`node scripts/bump-version.mjs --patch`).
- No `CHANGELOG.md` or `RELEASE_META` entry: like earlier fix-only
patches, these changes go into the 0.48.0 notes.

The release commit sits directly on `b17bfc8fdd` (#6217). Everything
below was tested on `22d41249ee`, and the sidebar was tested again on
`b17bfc8fdd`. This release includes the daemon protocol bump from #6185
(251 → 252), so enrolled machines will update their daemon.

## How you verified

- `node .github/workflows/check-version-lockstep.mjs`: `bb-app=0.47.1
@bb/desktop=0.47.1`.
- Typecheck, tests and the `bb-app` tarball smoke run in CI on this PR,
instead of locally.
- `git diff --check`, and `oxfmt --check` on the changed files: clean.
- Manual QA of `22d41249ee` with `pnpm start:worktree` (production
bundle) and headless Chrome, on a fresh data dir:
- **Timeline (#6195):** a long unread reply stops at NEW, detached. A
short unread reply opens at the end with no jump arrow. Scrolling up 150
px and growing the viewport 900 → 1200 attaches. Scrolling up 400 px and
growing it stays detached. Sending after scrolling up 1,800 px jumps to
the end and follows the streamed Claude Code reply. The view is still at
the end after a reload.
- **Docs (#6146):** typing in a note while `bb docs pull`/`push`
appended a paragraph kept both edits on disk and in the editor. A stale
push after a UI edit was refused as a conflict. A new note was renamed
from its first line and kept its Markdown after a reload.
- **Skills (#6185):** `bb project commands` lists project skills from
the documented roots for Claude Code and Codex, with no duplicate names.
A Codex `/skill` turn ran the skill.
- **Storage & retention (#6190, #6205):** two outside worktrees were
listed. Bulk removal removed the clean one, kept its branch, and kept
the dirty one. The table fits a 390 px viewport.
- **Sidebar multi-select (#6191, #6217), on `b17bfc8fdd`:** with the
experiment on, Cmd+Shift-click selected a second thread without
navigating ("Actions for 2 threads"). Pressing it again on the same
thread deselected it. Shift-click selected a range of 4. Escape cleared
the selection. Cmd-click cleared the selection and opened a split. Bulk
Pin applied to the two selected threads (checked with `bb thread list`).
With the experiment off, Cmd-click opens a split.
- **omp (#6186):** the picker labels GPT-5.6 Terra rows `openai` and
`openai-codex`.

Not exercised: the Ultrafast icon (#6198), because no Codex model on the
test account offers Ultrafast. Also not exercised: the Android
touch-drag attach, the desktop app, the SDK realtime reconnect (#6183)
and retryable host RPCs (#6184). Those last two are covered by unit
tests only.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant