ui-server: an in-memory database gets a quarantine temp directory that nothing removes

Aperta Adatta ai principianti
#4,807 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
86/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bun, typescript
Ambito
backend, testing

Direzione di ricerca

Inizia in packages/ui-server/src/brain/host-execution.ts e segui quarantineDirFor, createHostExecution e release() per vedere in cosa differiscono i percorsi in memoria e quelli basati su file. Aggiungi la copertura di pulizia richiesta ai test indicati nei criteri di accettazione, inclusi i casi di chiusura e di errore durante l’avvio. Il lavoro è completo quando al rilascio viene rimosso solo il directory in memoria, mentre una directory di quarantena basata su file rimane; aggiungi anche il changeset richiesto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

agent-ready area: ui-server priority: p3 type: fix

Context

Quarantined files go to a host-private directory beside the database. For a database path of ":memory:"
there is no "beside", so quarantineDirFor (packages/ui-server/src/brain/host-execution.ts:27-30) creates a
fresh directory with mkdtempSync(join(tmpdir(), "brain-ui-quarantine-")).

createHostExecution creates it the first time manifests are opened (open,
packages/ui-server/src/brain/host-execution.ts:84-85), which happens on every boot through attach
(:115-129), and exposes it as quarantinePath() (:99). release() (:130-133) closes an early database
handle and nothing else. The app calls release() on boot failure and on close
(packages/ui-server/src/app.ts:511, :1574), so the directory has no owner that removes it: the file
contains no rmSync or rm call at all.

The in-memory path is a supported configuration, not an accident of tests: it has its own layout test
("an in-memory database refuses private quarantine storage inside the brain",
packages/ui-server/tests/operational-state-layout.test.ts:112-121). 27 test files boot an app or a host
execution with DB_PATH or dbPath set to ":memory:", and each boot leaves one empty directory in the
shared temp root. On a machine that runs the suite repeatedly these accumulate without bound; the audit
counted several hundred left behind within three days on one development machine.

Related: #4467 (the test app's teardown leaves the journal database behind) is the same kind of leak in a
test helper; this one is in production code that tests run.

Scope

  • A quarantine directory that createHostExecution created for an in-memory database is removed,
    recursively and best-effort, when release() runs.
  • A file-backed database's <dir>/brain-ui-quarantine is never removed by release().

Out of scope

  • Creating the directory lazily on first quarantine. The path is handed to the manifest store when it opens
    and quarantinePath() is reported to storage accounting (packages/ui-server/src/app.ts:1280-1281);
    removing what was created is the smaller change.
  • The journal database a test app leaves behind (#4467) and other temp directories tests create.
  • The two cleanup lists of createApp (#2514).
  • Requiring callers that pass ":memory:" to supply their own quarantine directory. That changes a
    published option's meaning.

Acceptance criteria

  • A test boots an app with DB_PATH: ":memory:", reads quarantinePath() (or the "Quarantined changes"
    store path the app reports), closes the app and asserts the directory no longer exists. It fails on
    the tree before the change. Mutation: remove the cleanup from release() and the directory is still
    there.
  • A test asserts the same for a boot that fails after the host execution was created (the boot-failure
    path also calls release()).
  • A test with a file-backed DB_PATH places a file under <dir>/brain-ui-quarantine, closes the app and
    asserts the file is still there. Mutation: remove the directory unconditionally in release() and
    this test fails.
  • packages/ui-server/tests/operational-state-layout.test.ts and
    packages/ui-server/tests/host-execution-boundary.test.ts pass with no expected value changed.

Verification

bun run test packages/ui-server/tests/operational-state-layout.test.ts
bun run test packages/ui-server/tests/host-execution-boundary.test.ts
NODE_OPTIONS=--max-old-space-size=6144 bun run typecheck
bun run lint
bun run check:pr --base origin/main

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: commit prefix, and the doc updated in the same commit.
  • This changes a published package's behaviour, so it needs a changeset.

An embedder that boots @schlessera/brain-ui-server on an in-memory database no longer finds the temporary
quarantine directory after close().

Found by a repository audit on 2026-11-26 (main 87b96b10c); independently reviewed before filing.

Lingua principale
TypeScript
Stelle
5
Fork
0
Merge medio
8h 3m
PR unite (30g)
606

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di schlessera/brain-kit

Tutte le issue di schlessera/brain-kit

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.