Skip to content

ui-server: a turn's data tree holds a full copy per concurrent turn; place it by reflink on the managed volume #2911

Closed

Description

@schlessera

Current state

Managed-volume turn-tree placement is delivered through merged #4050, squash 8e35d4c792c833e5f3ae0727dadad0cde6e35b16 (0.45.0), an ancestor of inspected main 3b104890f8. The recorded hosted heavy-feedback run 43800954882 at 24787de0 passed every category, including separate-UID isolation; this triage checked delivery/source, rather than independently rerunning those jobs. The only remaining handoff is the native --apply-timing allocation/growth/admission measurement below. Preserve all original acceptance criteria and their attributed receipts.

Context

The earlier #2848 temporary-directory tree held a complete document/index copy per concurrent turn. #2891 delivered pooling; it is a completed predecessor, not an active blocker. Historical branch measurements were 43 ms for 2,000 notes and 202 ms for 10,000 notes. They remain the comparison baseline, not a new measurement of main.

The selected implementation uses createTurnDataTree (packages/ui-server/src/brain/turn-data-tree.ts:409) and the manager's prepareTurnTree (packages/ui-sdk/src/server/native-brain-manager.ts:785) and releaseTurnTree (same file:825). The manager retains protected control ancestors, finite-capacity/reserve admission and live-reader-aware cleanup. The tree is outside live-brain/checkpoint inputs; placement does not expand worker authority or change tree contents.

Maintainer decision and scope (2026-10-25)

Option A selected: the native manager provisions a protected server-owned area on the existing managed Btrfs volume for turn data trees, outside the live brain and checkpoint inputs. Place qualified trees there so their document/index seed can reflink the startup view.

  • Keep the managed store and private control ancestors root-owned/protected. Only the authenticated application server owns mutable tree contents; workers receive only their own read-only tree mount. Governed peers, unrelated workers and other server principals cannot mutate or inspect another turn's tree. Specify and verify the separate-UID ownership/mode/traversal arrangement before use; do not make the store or live brain a writable placement bypass.
  • Trees, changed copy-on-write extents, filesystem overhead and outstanding allocations consume the existing finite managed-volume capacity. Account actual filesystem allocation and shared extents without double-counting them as separate physical copies or treating reflinks as zero-cost forever. Do not change logical retained-history charges. Preserve existing admission/reservation rules and emergency recovery reserve; normal tree creation/growth cannot consume that reserve or enlarge the configured limit.
  • Record durable tree ownership and reader/lifecycle evidence. The owner removes its tree only after all workers/readers have released it; crash recovery reclaims only proven abandoned owned trees, never a live tree or arbitrary path. Observe filesystem reclamation before reusing released capacity. Keep cleanup outside the app event loop, cancellable/bounded and recoverable under existing native-manager rules.
  • Preserve the current data-tree contents, binary/Markdown provenance rules, provider isolation, frozen configuration and per-turn read-only behavior. No extra cross-turn data reuse or new storage seam is selected.
  • Use qualified reflink placement; prove physical sharing on the native filesystem and do not silently substitute an unbounded full-copy fallback. Reconcile any existing supported non-native placement without removing a public guarantee incidentally.
  • Record ownership, placement, allocation and recovery rules in docs/decisions/native-brain-storage.md and the applicable governed-worker decision record. Implementation names/modes are concrete design under these rules, not a new public configuration choice.

Out of scope

Acceptance criteria

  • A native tree is placed outside the live brain under the protected server-owned managed-volume area. Separate-UID workers read only their own tree, cannot mutate it or reach peer trees, and governed peers cannot alter it or cause it to enter later brain checkpoints.
  • A native allocation receipt (btrfs filesystem du or equivalent) proves real document/index reflink sharing and allocation far below a plain copy; admission is not slower than the existing ui-server: a strict turn's data tree copies the whole startup view at every admission #2891 pool under the same fixture/load. Record changed-extent growth as well as unchanged seed cost.
  • Concurrent-tree admission and copy-on-write growth respect the existing hard volume bound and protected emergency reserve, using actual physical allocation evidence. Near-capacity operation refuses safely without larger limits, double-counted shared extents or zero-cost assumptions.
  • Normal release and crash/restart recovery retain trees with live owners/readers and reclaim only proven abandoned managed trees. Late cleanup/cancellation cannot delete a reused or foreign tree; reclaimed capacity is credited only after observed filesystem reclamation.
  • The native --apply-timing and prove-worker-identity.ts separate-UID cells pass, along with existing data-tree provenance/provider tests. Record focused failing-first and restored mutations for isolation, live-reader cleanup refusal and capacity/reserve enforcement.
  • Update the native storage/governed-worker records and any affected manager readiness contract/API report; no data-tree content or source-of-truth semantics change.

Verification

bun scripts/prove-native-host.ts --backend=pi --app-uid=1000 --apply-timing, bun scripts/prove-worker-identity.ts, bun run test packages/ui-server/tests/turn-data-tree.test.ts.

Contract impact

Placement/ownership behavior is approved without removing any supported interface. If manager ready facts expose the new area, make that an additive readiness fact with contract label, CONTRACT: commit, same-commit authoritative package documentation/API report and minor changeset. Preserve existing ready fields and storage limits; no field removal/retyping or unsupported authority grant is approved. Keep private paths as opaque operational facts, not public deployment details.

Related: #2891, #2848.

Human verification remaining (2026-11-16)

Implemented in #4050 (Refs, not closing). Its hosted heavy feedback (run 43800954882 at 24787de0) passed every category. That covers prove-worker-identity.ts, where the separate-UID worker reads its own managed tree, gets EROFS writing it, cannot read a peer tree or list the manager's trees/ area, and the manager removes the tree after the turn. It also covers every prove-native-host.ts cell and the full unit suite, including the manager capacity, reserve, reader-refusal and reclamation tests with their mutation receipts.

Remaining action: acceptance criteria 2 and 5 need the opt-in --apply-timing measurement, which hosted CI never runs. On a native host with root, a free loop device and Btrfs, run:

bun scripts/prove-native-host.ts --backend=pi --app-uid=1000 --apply-timing

Completion evidence: post its apply-timing.json allocations (every seeded tree's exclusive bytes below a tenth of its total, which the run asserts), the close-time growth, and the seeds milliseconds compared with the #2891 pool (43 ms and 202 ms). Then remove needs: human and close the issue if they hold.

2026-11-16 triage: Removed the satisfied #2891 blocker declaration and obsolete pre-ruling alternatives, folded merged #4050 into the active specification, and retained the exact native measurement handoff. Added contract for the delivered additive native-manager surface. Assignment and 0.45.0 attribution are preserved; no native measurement is claimed.

Activity

  1. added
    type: refactor
    area: ui-server
    needs: decision
    priority: p2
    blocked
    on Oct 25, 2026
  2. schlessera commented on Oct 25, 2026

    @schlessera
    OwnerAuthor

    2026-10-25 triage at main 541b8d98328a760290ac6dd4a7f065af76153408: Completed the managed-placement ruling with concrete authority/capacity/reserve/recovery alternatives and an explicitly unapproved recommendation; preserve needs: decision. Corrected the pool to open-branch evidence and retained #2891 as its actual baseline prerequisite. p2 records wanted unscheduled work; no manager path or accounting policy is approved.

  3. schlessera commented on Oct 25, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-10-25): Option A. Provision a protected server-owned turn-tree area on the existing managed Btrfs volume, outside live brain/checkpoint inputs; each worker gets only its own read-only tree and peers cannot reach or mutate it. Use real reflink allocation evidence, charge changed extents/overhead within the existing finite volume, preserve emergency recovery reserve and existing logical history charges, and refuse unsafe admission without increasing limits. Track ownership/readers and reclaim only proven abandoned owned trees after crash; observe freed capacity before reuse. Preserve data/provenance/provider/frozen-view rules. The body now specifies the selected ownership/capacity/recovery policy and native proof; priority p2 records wanted unscheduled follow-up.

  4. added
    agent-ready
    area: ui-sdk
    and removed
    needs: decision
    on Oct 25, 2026
  5. added this to the 0.45.0 milestone on Oct 25, 2026
  6. schlessera commented on Oct 25, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #2891 is closed, so scripts/sync-project.ts is removing the blocked label.

  7. removed
    blocked
    on Oct 25, 2026
  8. schlessera commented on Nov 8, 2026

    @schlessera
    OwnerAuthor

    Measured evidence from #3513 (PR #3676, case 19 of the reference pool proof; hosted heavy feedback run 42475041809 at 59caf001, kernel 7.0.0-1017-azure, btrfs-progs 6.6.3). The proof copied an 8 MiB checkout three ways:

    • Same-filesystem cp --reflink=always on the pool: 0 exclusive bytes, 140 ms.
    • --reflink=never: 8,388,608 exclusive bytes, 251 ms.
    • Onto another filesystem: a reflink fails with EXDEV (Invalid cross-device link), and the automatic fallback allocated 8,400,896 bytes.

    createTurnDataTree (packages/ui-server/src/brain/turn-data-tree.ts:315) copies with COPYFILE_FICLONE into mkdtempSync(join(tmpdir(), "brain-turn-data-")), which is that cross-filesystem case: every byte is allocated. The copy is bounded only by the COPY_ENTRIES/COPY_DEPTH limits (turn-data-tree.ts:91), with no byte budget or capacity admission. This is the copy-budget gap #3513 asked to identify. It is recorded here instead of in a duplicate issue, because this issue's placement and capacity criteria already own it.

  9. self-assigned this
    on Nov 15, 2026
  10. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    Claimed for implementation. Claim token: claim-2bce33f1. Branch: refactor/2911-managed-turn-trees.

    path collision with draft #3806 (native manager files)

  11. added
    needs: human
    and removed
    agent-ready
    on Nov 16, 2026
  12. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    2026-11-16: #4050 implements the managed-volume placement. Its hosted heavy feedback (run 43800954882) passed every category, including the separate-UID isolation checks. Acceptance criteria 2 and 5 still need one native-host run of bun scripts/prove-native-host.ts --backend=pi --app-uid=1000 --apply-timing, which hosted CI does not run. #4050 therefore uses Refs #2911, and this issue carries needs: human with the exact command and completion evidence in the body.

  13. added
    contract
    on Nov 16, 2026
  14. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Native --apply-timing run (2026-11-16)

    bun scripts/prove-native-host.ts --backend=pi --app-uid=1000 --apply-timing ran on main at 3b104890f, which contains #4050's squash 8e35d4c79.

    • Host: a disposable 4-vCPU / 8 GB KVM VM (Ubuntu 24.04, rootful Docker, scripts/ci-runtime-setup.sh --native). It is not a hosted runner. The VM is deleted after the runs.
    • Result: exit 0. The native hosted test passed (native hosted pi uid 1000 …, 1 pass, 96 expects), and the loop cleanup receipt is clean (mounted:false, attached:false, backingExists:false, errors:[]).
    • Fixture: 2,000 notes of 16 KiB, the same as the ui-server: a strict turn's data tree copies the whole startup view at every admission #2891 baseline. Load was 0.88 before and 1.06 after (1-minute average).

    allocations (btrfs filesystem du of the turn's managed tree):

    stage total exclusive shared exclusive / total
    seed 153,452,544 32,768 153,419,776 0.02%
    close 153,460,736 630,784 152,829,952 0.41%
    • data: 32,768,000 bytes, fully shared at both stages.
    • index: 120.7 MB, with 32 KiB exclusive at seed and 616 KiB at close.
    • Close-time growth: 598,016 exclusive bytes (584 KiB) after 20 writes and 20 edits.

    seeds: one seed, 54.5 ms (mounted:true, masked:false). The #2891 pool baseline for 2,000 notes is 43 ms (historical branch measurement, different host).

    Apply medians: write 4.9 ms (p95 9.9), edit 5.2 ms (p95 6.9). In-worker brain_search saw the edited notes.

    Assessment:

    • Holds: the allocation criterion. Exclusive bytes stay far below a tenth of the total at both stages, so reflink sharing is real.
    • Holds: growth is recorded, and the cell passes.
    • Open: "admission is not slower than the ui-server: a strict turn's data tree copies the whole startup view at every admission #2891 pool under the same fixture/load". The seed took 54.5 ms against the 43 ms baseline, a single sample on a different host, not the same load. This needs a maintainer call before closing, so needs: human stays for now.
  15. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Four more runs of the same cell on the same VM and commit (3b104890f), all exit 0:

    • Seed ms across the five runs: 54.5, 48.2, 61.9, 53.7, 61.3. Median 54.5, min 48.2, max 61.9. One-minute load before each run was 0.81–1.90.
    • Allocations: identical in every run. Seed is 32,768 exclusive bytes of 153,452,544; close is 630,784 exclusive bytes of 153,460,736.

    The allocation criterion holds. Admission is consistently above the historical #2891 pool figure of 43 ms for 2,000 notes. That figure was measured on a different host, so the same-load comparison the criterion asks for has not been made yet. needs: human stays until the maintainer decides.

  16. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Maintainer decision (2026-11-16): accepted. Every native criterion holds:

    The admission median of 54.5 ms, about 11 ms over the #2891 pool's cross-host 43 ms, is accepted as meeting "not slower than the pool". No same-host pool baseline was run. Delivered by #4050 (8e35d4c79, 0.45.0).

  17. removed
    needs: human
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: ui-sdkarea: ui-servercontractpriority: p2type: refactor

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions