Skip to content

ui-server: type-selector folders are planned only by the process that translated them, and only until it restarts #2836

Closed

Description

@schlessera

Context

The writer gate plans each writer's retained folders when it is acquired (const folderPaths = mergeFolderPlans(held, retainedFolderRoots(, packages/ui-server/src/brain/writer-gate.ts:148). A type selector's folders enter that plan only through rememberedProviderTypeFolders (packages/ui-server/src/brain/governance-policy.ts:264), which reads a module-level map (const lastTypeFolders = new Map, packages/ui-server/src/brain/governance-policy.ts:259) filled only when a hosted turn translates the policy's types (rememberProviderTypeFolders(options.brainPath, policy.hash, typeFolderList), packages/ui-server/src/brain/governed-turn.ts:144).

The map is per process and starts empty. So:

  • every writer the cron runner acquires (createHostExecution, packages/ui-server/src/bin/brain-ui-cron.ts:127) plans no type-selector folder unless a turn holding them happens to be active at that moment;
  • every server writer acquired after a restart and before the first provider-policy turn plans none either.

The server-start case is what #2832 hit (the boot-time brain scratch prune pass). The #2832 follow-up describes a proposed bounded wait (PEER_FOLDER_PLAN_WAIT_MS, 30 s) for that earlier writer; this constant/wait is not present on inspected main, so it is not a delivered fix here. A cron job that holds the gate longer than that bound still refuses a provider-policy turn with "An active peer did not retain the requested provider folders", although nothing about the job is unsafe except that its process never learned the translation.

Observed in the code, not yet reproduced with a long cron job. Needs scoping.

Scope

  • Make a writer's plan include the type-selector folders last translated under the current policy version whichever process acquires it and whether or not the server restarted, for example by recording the translation (policy hash and folders) in the UI database next to writer_gate.

Out of scope

  • Translating type selectors at gate acquisition (it runs brain configuration in a worker).
  • Changing which folders a policy masks, or the bounded wait itself.

Acceptance criteria

  • A real second Bun process with an initially empty module cache, opening the same UI database and brain after a hosted turn translated a type selector, plans those folders. A second handle in the original process is insufficient because it shares lastTypeFolders. Prove this test fails on the old process-local implementation.

  • After the translating process exits, a new process under the same policy version retains the recorded translation when it acquires a writer. Recreating a gate object without restarting the module does not qualify as restart proof.

  • A translation recorded under a different policy hash is not used.

  • Bind any stored translation to the canonical brain and exact policy hash; a missing/unreadable/stale translation never fabricates permission. Admission still translates under its existing worker boundary and refuses an incompatible peer. Cover policy changes and separate brains with a mutation that ignores the identity/hash.

  • Do not change folder masking, taxonomy execution at admission, live-owner validation, gate atomicity or the existing peer safety check. Persist only the bounded current translation, not unbounded historical runtime data.

Verification

bun run test packages/ui-server.

Contract impact

None expected; a UI database migration if the translation is persisted.

2026-10-24 triage at main 77f35ef1ba34e4fab7092ada5362ae799852ea24: Verified the process-local map, its only writer and acquisition consumer, corrected moved/mistaken source pointers, and replaced same-process handle/object tests with genuine cross-process and restart proof. The requested retention behavior is scoped and factual; p2 sorts this wanted unscheduled follow-up. Preserve existing native #1668 parent. No database schema or bounded-wait implementation is selected or delivered by triage.

Bounded offline cross-process control

At main 77f35ef1ba34e4fab7092ada5362ae799852ea24, an isolated Odysseus brain used the production createUiDb, policy reader, rememberProviderTypeFolders and createWriterGate. Process A seeded the host translation under the exact current policy hash, then acquired/released a real shared gate hold: folderPaths was [".brain-index", "vault"]. A new Bun process opened the same brain and UI database with an empty module cache and acquired/released the same kind of hold: folderPaths was []. Both processes exited 0; the owned fixture was cleaned up.

Command: scripts/test-offline.sh -- bun /tmp/brain-triage-pass4/folder-plan-probe.ts (the diagnostic script and raw output are task-owned scratch outside authored source). This isolates the real gate's process-local retention gap after an explicitly seeded translation; it does not run the taxonomy CLI/admission or reproduce a 30-second cron conflict. The before/after correction still needs true process and restart tests, including policy-hash/brain identity negatives.

Activity

  1. added
    type: fix
    area: ui-server
    on Oct 24, 2026
  2. added
    priority: p2
    agent-ready
    on Oct 24, 2026
  3. schlessera commented on Oct 24, 2026

    @schlessera
    OwnerAuthor

    2026-10-24 triage at main 77f35ef1ba34e4fab7092ada5362ae799852ea24: Verified the process-local map, its only writer and acquisition consumer, corrected moved/mistaken source pointers, and replaced same-process handle/object tests with genuine cross-process and restart proof. The requested retention behavior is scoped and factual; p2 sorts this wanted unscheduled follow-up. Preserve existing native #1668 parent. No database schema or bounded-wait implementation is selected or delivered by triage. A fresh offline production-gate control now observes [.brain-index, vault] in the seeded process and [] in a new Bun process over the same brain/database; both exit 0. This proves the process-boundary retention gap, not the longer cron wait or full taxonomy admission.

  4. added
    priority: p1
    on Oct 24, 2026
  5. added this to the 0.44.0 milestone on Oct 24, 2026
  6. removed
    priority: p2
    on Oct 24, 2026
  7. schlessera commented on Oct 24, 2026

    @schlessera
    OwnerAuthor

    Claim bk044-2836-c7f1: implementing on branch fix/2836-persist-type-folders-044 from main e1ab485 (after #2841). Approach: admission records the type translation (canonical brain, exact policy hash, folders) in a one-row-per-brain UI-database table; every gate acquisition in any process reads it. No host translation, no masking/admission-check change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-serverpriority: p1type: fix

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions