Skip to content

Server & APIs Session file store

Jesus Lara edited this page Nov 5, 2026 · 1 revision

Session file store

Files uploaded in a session, imported from remote storage, or generated by an agent are persisted under a per-session root and addressed by an opaque handle (file_id). Agents only ever see file_id values, never a filesystem path; they pass handles to the tools that consume files.

The implementation is SessionFileStore in packages/ai-parrot/src/parrot/interfaces/file/session.py.

Layout

<OUTPUT_DIR>/sessions/<session_id>/
  <file_id>.bin     # the file itself; the name comes from the handle, never the upload
  <file_id>.json    # manifest: file_id, session_id, filename, mime_type, size, origin, created_at
  • origin is one of upload, remote, generated.
  • Blobs and manifests are written through temporary files (.<name>.*.tmp) and renamed into place, so a partial write never yields a resolvable handle.
  • A session id containing a path separator, or an empty or dot-only id, is rejected.

Handle model and sandbox guarantee

  • A handle resolves only inside its own session root. A manifest or blob that resolves outside the root, or a blob that is a symlink, is refused (OutsideSandbox); an unknown handle raises UnknownHandle; a manifest whose blob is gone raises MissingBlob.
  • The original filename is sanitized and kept only in the manifest, for display and for the Jira attachment name. It never influences the on-disk name.
  • mime_type is advisory only.

Configuration

Setting Default Meaning
OUTPUT_DIR <BASE_DIR>/outputs Base output directory (parrot.conf). The store root is OUTPUT_DIR/sessions. A relative value is resolved against BASE_DIR.
SESSION_FILES_WARN_BYTES 524288000 (500 MiB) Per-session total at which a WARNING is logged. Reporting only: it never rejects an upload. It is a module constant in session.py, not an environment setting.

There is no separate environment variable for the store root: point OUTPUT_DIR at the volume you want. SessionFileStore(root=...) overrides the root in code.

Deployment requirement: shared, persistent storage

The server runs under gunicorn with several workers. An upload may be handled by one worker and the later attachment by another, so the store's root MUST be on storage all workers share, and it must survive a restart. On worker-local or ephemeral storage, handles resolve intermittently or not at all, and the failure looks like a missing file (UnknownHandle / MissingBlob), not a misconfiguration.

Measuring a session

usage_bytes sums the sizes recorded in the manifests (not a disk scan):

store = SessionFileStore()
records = await store.list_files(session_id)      # newest first
total = await store.usage_bytes(session_id)

Both calls create the session directory if it does not exist. Unparseable manifests are skipped with a warning.

When a store operation takes a session's total across SESSION_FILES_WARN_BYTES, the log gets one line of the form:

Session file usage crossed warning threshold for session_id=<id>: <bytes> bytes

Nothing else happens: uploads continue to be accepted.

Cleanup (manual; nothing deletes files automatically)

There is no TTL, no sweeper and no cleanup command. Files persist until an operator removes them, and the aggregate threshold only logs a warning. Before deleting anything:

  1. Dry run. List size and age per session root and review it; delete nothing yet:

    du -sh <OUTPUT_DIR>/sessions/* | sort -h
    find <OUTPUT_DIR>/sessions -mindepth 1 -maxdepth 1 -type d -mtime +30 -print
  2. Confirm the sessions are dead. Removing a session root breaks every handle in that session: a live conversation will then fail with UnknownHandle. Only remove roots whose conversations have ended.

  3. Delete the chosen session roots (a whole directory at a time, so no blob is left without its manifest or vice versa):

    rm -r <OUTPUT_DIR>/sessions/<session_id>

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally