Repository navigation
Batch the drafts of a large copy into a Work - #1663
Conversation
Take document keys in order and classify journal and draft state before seeding. Batch only fresh authorities and drafts; retained or occupied IDs keep the existing single-document path.
|
Tree lead sign-off: plan review p18027 (two-way classifier) → build → code review p18128 approved with one fix (the batch path re-derived branch ownership in SQL), fixed in 063cded: plural loadDocumentOwners in branch-ownership.ts, one draftable rule both paths call, one draft row builder. Reviewer's probes: fresh/pre-seeded/occupied-id/other-branch drafts identical to the single path byte for byte; 3 concurrent admissions over 30 docs in reverse order, no deadlock. Browser run p18148 on 063cded: 20-document copy into a draft, Live untouched, Apply all lands all 20 with text; mock-AI drafts, Discard and restore; New file on Draft. Not run in the browser: a mixed folder with existing history and two tabs (covered by the reviewer's DB probes). Timing: admission 3.88 s → 0.15 s on one run; the controlled comparison is left inconclusive in the body; plural append not built. CI 10/10. |
Changelog
Why
Copying a folder into a Work creates a draft for each tracked file while holding the project tree's list key. On main, one 197-document copy held that key for 6.70 seconds, including 3.88 seconds creating drafts. Other tree writes wait for the key.
Examples
pnpm dev, open a project and select a Work in Draft view.Benchmarks
One instrumented run per version on the same shared 24-CPU host, with 197 numbered text documents and a fresh Work for each copy. The before commit is
d2ebf589f9; after is this branch before the final input-size and classifier refinements. Both copies returned 198 entries. These single runs had different host load and cannot establish a speedup. Before load was 35.04/46.30/48.14; after was 79.74/50.61/47.80. CLI elapsed time includes startup and work outside the lock.Design decisions
installSeeds; fresh drafts share one empty content-only seed. Ownership and liveness are checked before insertion. Draft inserts are bounded and a conflict returns that member to the single path. The list transaction still holds the branch lifecycle fence through commit.Changes
drizzle-created-drafts.ts: set classification, sorted keys, ownership checks, empty authority and draft inserts, and fallback.document-authority-and-schema.md: document the fresh/exceptional boundary.Compatibility and risk
drizzle-created-drafts.ts; seed and insert conflict handling; the unchanged fallback.Verification
Timing content 1in Draft; Apply left the same text live. A new file created from the Work's tree appeared in Draft and not Live. A forced copy whose destination ID already had a seeded head showed both its seed and copied content; Undo of Discard restored both. In Trash, Undo restore discarded the same item again; restoring it once more retained its ID and both paragraphs, with a competing name resolved separately.pnpm test:dbpassed 93 files and 605 tests. Typecheck passed. The first twopnpm checkruns failed on timeouts; the shutdown test passed in a separate server suite. A thirdpnpm checkpassed (301 unit files, then 70 database files); it was started just before a classifier predicate was narrowed to reject any active draft, which the typecheck and tests then read.pnpm test:dbpassed 93 files and 605 tests.pnpm checkpassed (301 unit files and 82 related DB files); it started while the wiring fix was being made, with typecheck and tests reading the final files.Deferred
The requested five-run alternating comparison, with append timed separately, has not been run; the single-run measurements above are inconclusive. Passing snapshots from tree admission to Copy would cross the tree-list store boundary, which currently returns no collab data, and was not a small local change. Copy still reads each draft and its base.
The plural append is not part of this change. Revisit only if a controlled comparison shows the remaining serial append cost matters.
Large Changes loading also occurs on main: 197 copied file rows appeared, but after 30 seconds only 56 had individual Apply buttons and Apply all was absent. The main HAR captured 394 draft-metadata requests and 96 provenance requests, with 186 and 8 unfinished respectively; the database had no lock waits. The lead will open a client investigation from the evidence in
work/evidence/p18066-main-review.md. A main run with one copied file and two mock-AI creates did not reproduce the reported missing copy: Apply all sent three items and all three landed.References