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

Open Beginner friendly
#4,807 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
bun, typescript
Domain
backend, testing

Research direction

Start in packages/ui-server/src/brain/host-execution.ts, following quarantineDirFor, createHostExecution, and release() to see how in-memory and file-backed paths differ. Add the requested cleanup coverage to the tests named in the acceptance criteria, including close and boot-failure cases. Done means only the in-memory directory is removed on release, while a file-backed quarantine directory remains; also add the required changeset.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
5
Forks
0
Avg merge
8h 3m
Merged PRs (30d)
606

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from schlessera/brain-kit

All issues in schlessera/brain-kit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.