Repository navigation
Description
Context
Under a provider rule that hides folders from the turn's recipient, every hosted turn builds its own private search index from scratch before the provider sees a byte. A warm follow-up pays the same price as the first turn.
Measured on the native hosted fixture (UID 1000, Btrfs loop store, 2,000 notes of 16 KiB, offline fake providers), 10 sessions × first and warm turn per cell. Policy: me/** hidden by path and type private (vault/) hidden by type, from the proven anthropic recipient. Median / p95, ms:
| Claude first | Claude warm | pi first | pi warm | |
|---|---|---|---|---|
| private index build | 35,488 / 37,505 | 35,318 / 36,797 | 27,826 / 34,614 | 30,427 / 34,810 |
| taxonomy CLI + stray-type scan | 409 / 495 | 396 / 472 | 353 / 406 | 357 / 395 |
| hardlink scan | 0 | 0 | 0 | 0 |
| whole admission | 36,334 / 38,425 | 36,262 / 37,750 | 28,540 / 35,654 | 31,234 / 35,676 |
| pre-provider total | 37.1 s / 39.1 s | 36.9 s / 38.5 s | 30.0 s / 37.3 s | 32.4 s / 37.2 s |
The same turn without the policy adds 0.75 s (Claude) and 1.45 s (pi) before the provider. The private index is therefore ~95 % of a restricted turn's overhead. Host load average was 6–8 on 32 cores during these cells; the build is CPU- and I/O-bound, so a quieter host would be faster but would not change its share.
Where it happens, verified on af6300478:
- Admission builds it for every masked turn (
buildPrivateIndex({,packages/ui-server/src/brain/governed-turn.ts:219), into a fresh directory (createPrivateIndexDirectory();, line 218), discarded when the turn ends (discardPrivateIndex(); } finally { hold.release, line 256). - The build (
export async function buildPrivateIndex,packages/ui-server/src/brain/private-index.ts:105) runs the brain CLI's index over the masked startup view in a strict worker (export async function runMaskedBrainCli, line 63), bounded byPRIVATE_INDEX_BUILD_MS = 120_000(line 25). It indexes the whole visible brain each time. - The taxonomy read and stray-type scan before it (
export async function readProviderTaxonomy,packages/ui-server/src/brain/provider-types.ts:35;const strays = strayTypedDocuments(, line 121).
The worker launch inside the build is synchronous on the event loop (#2790), so the build also blocks health and WebSocket traffic for part of each turn (#2416).
Scope
Reuse the private index across turns, or update it incrementally, so that a warm restricted turn does not re-index the brain. Target: a warm provider-restricted turn adds under 1 s over the same turn without the policy, on the native fixture. Implement the approved checkpoint-bound option C below; the existing prompt supplies design inputs subject to that ruling.
Out of scope
- Which folders a policy hides, the recipient proof, and the masking itself: the worker must still see no masked document or generated text from one (core: keep cached generated text of masked documents away from denied turns #2692, core: move the generated-text caches into a masked directory once allowed routes exist #2725).
- The taxonomy CLI and stray scan (~0.4 s), unless the chosen design removes them for free.
- The first restricted turn after a policy change or server start may still build from scratch; state its cost.
Acceptance criteria
- Reuse is bound to exact source/final startup-view identities and canonical brain/policy/effective-mask/recipient identity; incomplete change evidence rebuilds safely rather than serving stale state.
- Worker writes cannot modify the reusable base or another turn index; eviction, restart, missing checkpoint and interrupted update safely rebuild without authoritative data loss.
- Tests cover newly masked prior text remaining in free pages, FTS structures or WAL, not just query results; unsafe transitions use a clean masked build unless physical byte non-disclosure is proved.
- Cache/checkpoint retention is bounded and cleaned under existing native storage guarantees; first/invalidated build costs and fresh-build equivalence are recorded, without weakening the warm-turn target.
- On the native hosted fixture with the policy above, a warm provider-restricted turn's pre-provider overhead is within 1 s of the same cell without the policy (median of 10 warm turns), for both Claude and pi.
- A document added, changed or removed between two turns, inside or outside a masked folder, is reflected in the next turn's private index exactly as a fresh build would reflect it, proven by a test that compares the reused or updated index with a fresh build.
- A masked document never appears in the reused index, including after it moves into or out of a masked folder between turns and after a policy change, proven by tests that fail if the reused index is served stale.
- A policy or recipient change invalidates any reused index.
Verification
Reproduction: run the native hosted proof (bun scripts/prove-native-host.ts --backend=claude --app-uid=1000, and the pi cell, under the exclusive native fixture lock) with a test that writes the policy above, a brain.config.ts taxonomy defining private: { dir: "vault" }, me/ and vault/ documents, and runs first and warm turns in fresh sessions. Time admission from the hosted governedTurns.begin boundary and the private-index build around buildPrivateIndex. Raw per-phase timelines from the measurement run are retained locally by the maintainer.
Then bun run test packages/ui-server packages/ui-sdk.
Contract impact
None expected; a design that changes what the CLI's index writes would need a check against docs/integration-contract/cli.md.
Part of #1668. Event-loop impact: #2416, #2790.
Maintainer decision (2026-10-24)
Option C selected: use a host-owned private-index cache bound to an exact source checkpoint, then reconcile against the exact next admission startup-view diff. Cache identity includes the canonical brain, exact policy, effective masks and proven recipient; timestamps alone or an incomplete journal change list do not prove freshness.
Before exposing an index, establish a complete reconciliation to the final startup view used for that admission. Policy, recipient, effective taxonomy/masks or indexing semantics changes invalidate reuse. If a complete safe transition cannot be proven, rebuild cleanly from the masked view rather than serving a stale index; refusal remains available when no safe index can be supplied under admission policy. No relaxed consistency or latency-bound increase is approved.
Keep the reusable cache host-owned and outside worker write authority. A turn must not poison future reuse; preserve existing turn-local indexing behavior through isolation from the reusable base. Retain exact checkpoint identity for as long as a diff needs it, and integrate cache/checkpoint ownership, bounded storage and cleanup with existing native managed-storage guarantees. Lost state only costs a rebuild; brain.db remains disposable.
A move into a masked folder or any transition that might retain newly forbidden text requires a clean build unless physical byte non-disclosure is proved. Deleting SQLite rows alone is not sufficient: free pages, FTS structures, WAL and other index artifacts must not expose restricted text. Compare updated indexes against a fresh-build oracle and separately prove physical non-disclosure.
Update the G2 decision record and applicable package contract documentation during implementation. No new extension seam, background daemon or source-of-truth store is introduced. First/startup/invalidated-build cost must be reported; the existing warm-turn target remains binding.
2026-10-24 maintainer ruling: selected C with exact-checkpoint freshness, policy/mask/recipient isolation and safe clean-rebuild fallback. This is architecture approval, not an implemented cache or runtime performance receipt.
Activity
schlessera commentedon Oct 24, 2026
Design needed: how a restricted turn's private index survives across turns.
Decided: a masked turn searches an index built only from what its recipient may see (#1668, #2692, #2725), and today that index is rebuilt from scratch on every turn (28–36 s on the native fixture). Still open: which cache or update shape keeps the "never stale, never leaky" guarantee while a warm turn pays under 1 s. The code cannot decide that; it depends on what the masking model may trust between turns.
schlessera commentedon Oct 24, 2026
2026-10-24 triage at main
77f35ef1ba34e4fab7092ada5362ae799852ea24: Classified the remaining private-index lifecycle question as needs: decision. Folded exact options, consequences, recommendations and ruling evidence into the body while preserving the existing technical prompt and measured targets. No option, consistency relaxation, threshold change or new runtime result is approved.schlessera commentedon Oct 24, 2026
Decision (maintainer, 2026-10-24): Option C. Use a host-owned cache bound to an exact source checkpoint, reconciled through a complete diff to the next admission startup view, with exact policy/masks/recipient identity. Rebuild cleanly whenever safe reconciliation cannot be proved; never serve stale or masked text. Row deletion alone is insufficient because restricted bytes can remain in SQLite free pages, search structures and WAL. Keep the reusable base outside worker write authority, integrate bounded checkpoint/cache retention and cleanup, and preserve the existing warm-turn target and disposable-index rule. The body now records the chosen architecture, safety fallback and proof criteria; implementation and performance evidence remain outstanding.
schlessera commentedon Oct 24, 2026
Claim
c2833-a7f1: implementing option C on branchfix/2833-private-index-cache-044.schlessera commentedon Oct 24, 2026
Progress and a question that needs a maintainer ruling (claim
c2833-a7f1, draft PR #2847).Implemented (option C): a host-owned base per exact brain / policy hash / masked folders / proven recipient / mask paths / build command, bound to the native checkpoint it was built from and reconciled to each turn's final startup view through the complete
--no-datasend delta. Unchanged view → copy of the base. Only new.md/asset files outside the masks → the CLI's incrementalbrain indexon the turn's copy (must report nothing updated or deleted), which becomes the next base. Anything else (a change, removal, move into a masked folder, second name, permission/ACL change, unreadable delta, tampered base) → a clean masked build. Physical non-disclosure is tested byte by byte (free pages, FTS segments, WAL); 22 mutations recorded in the PR.Measured on the native fixture (issue's policy and harness, UID 1000, 2,000 × 16 KiB, warm pre-provider median, Δ over the same cell without the policy):
The harness's fake turn writes a new note every turn, so every warm turn takes the incremental path: the brain's own
brain indexre-hashes the corpus (≈0.35 s) and recomputes the graph (≈0.55 s) on the turn path, ≈1.1–1.5 s in total. Over an unchanged brain the 1 s target holds for both backends; after a turn that added notes it does not. First/invalidated builds are unchanged (≈37 s, plus a ≤0.35 s copy into the base).Question: which applies to the acceptance criterion "a warm provider-restricted turn's pre-provider overhead is within 1 s"?
Recommendation: A now, with B or C as a follow-up if captures-between-turns latency matters in practice. Approval is the maintainer's; until then the PR stays a draft with
Refs #2833.schlessera commentedon Oct 24, 2026
Maintainer ruling (2026-10-24): option B. Advance the cached base after the post-turn refresh, off the turn path, so that the next warm turn starts from an up-to-date base, including after a turn that added notes. #2847 (merged) is the first step. Option C's safety rules still apply: an advanced base must be bound to the exact checkpoint it reflects, with policy, mask and recipient identity; it falls back to a clean rebuild whenever reconciliation can't be proved; and it never serves stale or masked text. The target remains under 1 s for a warm turn.
schlessera commentedon Oct 24, 2026
Claim
c2833-b2e4: implementing the option B ruling on branchfix/2833-advance-private-index-044(draft #2856).fix(ui-server): advance private index bases off the turn path (#2856)