Skip to content

JS SDK: provide a way to disable the prompt/parameters disk cache #2054

@hadrien-f

Description

@hadrien-f

Problem

The JS SDK's loadPrompt and loadParameters flows unconditionally construct a DiskCache (js/src/logger.ts, BraintrustState constructor) whenever canUseDiskCache() returns true. The only documented knobs are BRAINTRUST_PROMPT_CACHE_DIR / BRAINTRUST_PARAMETERS_CACHE_DIR (path) and *_CACHE_MEMORY_MAX / *_CACHE_DISK_MAX (size) — none of which disable the cache.

We run our own in-memory cache on top of loadPrompt (refresh-on-interval, cold-start fallbacks) and the SDK's disk cache is redundant. It's also actively harmful when the container's HOME points at a path the runtime user can't mkdir into — we hit this on AWS Fargate with HOME=/tmp, producing repeated warnings in production logs:

Failed to write to disk cache Error: ENOENT: no such file or directory, mkdir '/tmp/.braintrust'
    at async PromptCacheService.refreshOne (...)
    at async PromptCacheService.refreshAll (...)

Request

One of:

  • A public option on loadPrompt({ noDiskCache: true }) / a disableDiskCache arg on initLogger
  • A BRAINTRUST_DISABLE_DISK_CACHE=1 env var
  • Or document that setting BRAINTRUST_PROMPT_CACHE_DIR="" (empty string) disables it, and make the code honor that

Current workaround

Redirect the cache dir to a known-writable path at image build time via BRAINTRUST_PROMPT_CACHE_DIR / BRAINTRUST_PARAMETERS_CACHE_DIR. Works, but persists a redundant on-disk cache for no benefit.

Version

braintrust@3.8.0 (JS SDK)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions