Skip to main content

How OmicsBase fits together

The parts of OmicsBase, how a note and a Reports session flow through them, and which secret guards each connection.

OmicsBase has three parts:

In front of everything sits Caddy, a web server that handles HTTPS and passes each request to the right part.

flowchart LR
  B["Browser"] -->|HTTPS| C["Caddy"]
  C --> L["Notes app<br/>LibreChat fork"]
  L --> D[("MongoDB<br/>Meilisearch")]
  L -->|model calls| P["Model providers"]
  L -->|"tools and cells<br/>engine secret"| E["Notes engine"]
  E --> K["R session per note"]
  C -->|"plots<br/>project cookie"| E
  L -->|"FirecREST<br/>user's CSC token"| J["Roihu job<br/>Reports agent"]
  L -->|"router secret"| R["Router"]
  C -->|"/check"| R
  J -->|"tunnel, dials out"| T["Relay"]
  M["User's own computer<br/>Reports agent"] -->|"tunnel, dials out"| T
  C -->|"session cookie"| T

A note, step by step

The model reaches the engine through MCP (Model Context Protocol), a standard way to give a model a set of tools it can call. The engine’s MCP server is called notethreads and is configured in librechat.yaml.

  1. The user asks a question in a note.

  2. LibreChat sends the question to the chosen model, together with the notethreads tools.

  3. The model calls a tool. LibreChat passes the call to the engine. Every call carries the engine secret in the X-Internal-Secret header. Without it, the engine refuses.

  4. The engine answers with one of these tools:

    Tool What it does
    execute_r_cell Runs R code in the note’s R session. Captures output, plots and tables.
    search_bioc_books Searches the curated Bioconductor books.
    r_help Returns the help page of a function, for the installed package version.
    list_datasets Lists the example datasets of an installed package.
    list_thread_files Lists the files in the note’s folder.
    render_quarto_report Turns a report’s Quarto files into a website.
  5. For execute_r_cell, LibreChat does the work itself: it saves the cell, sends the code to the engine’s /api/execute endpoint, and saves the result.

  6. The engine writes plots and tables into the note’s folder, under runs/. The result lists them as plots (URLs) and tables (URL, size and a preview). It also lists, as files, the files the cell itself saved in the note’s folder, such as a write.csv() table, a ggsave() figure or a saveRDS() object: {"path": "results/alpha.csv", "bytes": 1234, "url": "…/projects/<note>/results/alpha.csv"}, with the path relative to the note’s folder and the URL percent-encoded. The engine lists the folder before and after the cell and keeps the files that are new or whose size or modification time changed, at most 50 sorted by path; files_truncated: true says there were more. It leaves out hidden files and folders (the R session’s own files are in .omicsbase/), the top-level runs/, _site/ and _freeze/, and symbolic links. A listing looks at no more than 5,000 entries (NOTE_FILES_MAX_ENTRIES), so in a larger folder some files may be missed.

  7. The browser loads them from /omics-engine/projects/<note>/runs/…. A cookie that LibreChat signed for that note lets it in.

Because of step 5, the engine never calls LibreChat back. The engine can therefore run on a machine that cannot reach LibreChat.

Uploads into a note, and copies of a note when someone continues a shared one, also go from LibreChat to the engine over HTTP. The engine needs no disk shared with LibreChat.

Where notes run

On omicsbase.utu.fi, notes run on CSC’s LUMI-K, a Kubernetes platform. Kubernetes runs containers in units called pods.

  • The engine on LUMI-K is a gateway (NOTE_RUNNER=workers, see engine/note_workers.py). It runs no R itself.
  • Notes run in a few shared worker pods. Each worker is the same engine in local mode and hosts up to NOTE_WORKER_SESSIONS notes’ R sessions, each its own R process. The gateway starts workers from its own pod spec, up to NOTE_WORKERS, keeps NOTE_WORKERS_MIN running, and deletes others that have hosted no note for NOTE_IDLE_SECONDS.
  • A note’s cells go to the worker that hosts its session. A note without a session goes to the worker with the most free memory that has a free session. When every worker is full, a new worker starts if NOTE_WORKERS allows. Otherwise the worker saves and stops its least recently used idle session, which restores on its next cell.
  • Each worker answers GET /api/sessions (engine secret required) with the notes it hosts and the resident memory of each session’s processes. The gateway places notes with it, and a restarted gateway finds every note’s worker again.
  • A watchdog in each worker stops a session that holds more than NOTE_SESSION_MEMORY_LIMIT. The note is told that it ran out of memory.
  • A note whose session passed NOTE_HEAVY_SESSION_MEMORY, or was stopped by the watchdog, is heavy. Its next session runs in a pod of its own, sized by NOTE_POD_*, with at most NOTE_HEAVY_PODS at once. The gateway keeps this mark in memory, so it is lost when the gateway restarts.
  • A session is saved when it stops. It is also saved after any cell that ran 5 seconds or more, unless its saved workspace is larger than NOTE_SAVE_AFTER_CELL_MAX_MB. A failing worker then loses little.
  • A NetworkPolicy lets workers and note pods take connections only from the gateway. They can reach only DNS and the internet, not the gateway, each other or the VM.
  • With NOTE_RUNNER=pods (engine/note_pods.py), every live note gets a pod of its own instead, with NOTE_MAX_SESSIONS pods at most. When a note is idle, its pod saves the R session to the shared volume and is deleted. The next cell starts a new pod, which restores the session.
  • The VM keeps its own engine container as a fallback.

In a local install, notes run in the engine container on the same machine, one R process per note (NOTE_RUNNER=local, the default). With ENGINE_URL set, they run on a server of the user’s choice; see Notes engine on a server.

How a note’s R session is confined

Wherever it runs, the engine starts each note’s R session through engine/kernel/sandbox.py, and so also a Quarto render of a note (confined to that note’s folder) and the r_help tool (confined to a throwaway folder). The file runs as a small launcher: a new process that applies the restrictions to itself and then becomes the command. R gets only the environment variables it needs (path, locale, time zone, R’s own settings and the download caches), never the engine’s secrets, and a private home and temporary folder inside the note’s session folder. On Linux, the session is then confined with Landlock, the kernel’s sandbox for unprivileged processes. It may read and write its own note folder and the shared download caches, read R, its packages and the system, and read /proc, where Landlock still hides the environment, memory and files of every process outside the session (only command lines and status show). Other notes’ folders are out of reach, and with Landlock version 6 or later the session cannot signal processes outside itself. The session is also first in line for the kernel’s out-of-memory killer, so a note that runs out of memory is stopped before the engine. NOTE_SANDBOX sets the policy: auto (the default) confines the session where the kernel offers Landlock and logs a warning where it does not, required refuses to start R without it, and off skips Landlock but still starts R with the minimal environment. The shared caches stay writable for every note.

The knowledge index

search_bioc_books and r_help read one file: engine/knowledge/knowledge.db. It is an SQLite database with a full-text index.

  • scripts/setup_knowledge.py downloads the books listed in knowledge/sources.json, each at a fixed commit, and indexes their chapters. It never runs the code in the books.
  • scripts/build_package_knowledge.py adds the help pages and vignettes of installed R packages.

The database is not stored in Git. The engine image includes it if it exists when the image is built.

A Reports session, step by step

Each user has at most one Reports session at a time. The session serves all of that user’s reports, each in its own folder under /projects/.

Three tools make this work:

  • FirecREST is CSC’s web API for Roihu. It submits jobs and creates folders on the user’s behalf, using the user’s own CSC access token.
  • The router (deployment/roihu/roihu_router.py) keeps a list of routes. A route belongs to one session. It has a tunnel port on the VM, a credential that opens only that port, and a session key that the Reports agent asks for on every request.
  • The relay is a chisel server on the VM. Chisel makes a tunnel over HTTPS. The session dials out to the relay, so nothing needs to reach the session from outside.

On Roihu

  1. On the Reports page, the user enters a CSC project, cores (1–8), memory (2–64 GiB), hours (1–36) and a CSC access token.
  2. LibreChat asks FirecREST whether the user belongs to that project.
  3. LibreChat creates /scratch/<project>/omicsbase-reports/ on Roihu, with an images/ folder and a private folder for the user.
  4. LibreChat asks the router for a new route.
  5. If the project has no image for the current release yet, LibreChat submits deployment/roihu/pull_image.sbatch. This job turns the published image into an Apptainer image. Apptainer runs containers on supercomputers.
  6. LibreChat submits deployment/roihu/reports.sbatch. The job runs under the user’s own Roihu account.
  7. In the job, the agent and the gateway listen only on the compute node’s loopback address. A chisel client dials out to the relay.
  8. To open Reports, LibreChat gets a one-time link from the router. The router swaps it for a signed roihu_route cookie on the Reports host.
  9. On every request, Caddy asks the router’s /check endpoint. For a valid cookie, the router returns the tunnel port and the session key. Caddy adds the key and sends the request through the tunnel.

The session key never reaches the browser. Inside the job, the gateway runs with OMICSBASE_GATEWAY_MODE=roihu. It serves our editor, report viewer and render endpoint, and checks the session key on every request.

The LibreChat side of this flow is in packages/api/src/projects/roihu.ts and the route api/server/routes/roihu.js (/api/roihu/…).

On the user’s own computer

On omicsbase.utu.fi, Use my own computer replaces the Roihu start:

  1. LibreChat asks the router for a one-time pairing code and shows a docker run command that contains it.
  2. The user runs the command. The container’s entrypoint (deployment/roihu/connect.py) sends the code to LibreChat at /api/roihu/attach/claim. The code is the only credential this endpoint accepts.
  3. The router creates a route that does not expire.
  4. The container saves its relay credential and session key in its home volume. It reconnects by itself after a restart.
  5. From here on, the tunnel and the cookie check work as for a Roihu job.

Disconnect removes the route and its credential.

A local install cannot be reached from outside, so the direction is reversed:

  1. The user’s computer runs the same image with serve. It prints a pairing string.
  2. The user pastes the string on the Reports page.
  3. The install’s reports-link service (the same router) keeps a tunnel open to that computer.

A local install also has its own Reports container. It sits behind reports-gate, a small Caddy that lets a request through only with a valid OmicsBase ticket or the gateway’s signed cookie.

Secrets between the parts

Secret Shared by What it protects
OMICSBASE_ENGINE_SECRET LibreChat and the notes engine All of LibreChat’s calls to the engine. LibreChat also signs the browser’s cookie for the engine with it. When it is empty, both sides use OMICSBASE_AUTH_SECRET.
OMICSBASE_AUTH_SECRET LibreChat and a Reports container that serves several users Short-lived launch tickets that LibreChat gives the browser for Reports. Compose does not start without it.
Router secret LibreChat and the router LibreChat’s calls to the router: new routes, pairing codes, open links, sign-out. LibreChat reads it from ROIHU_ROUTER_SECRET. In a local install it is OMICSBASE_LINK_SECRET.
Session key One Reports session The agent and the gateway in that session. Caddy adds it to each request.
Relay credential One route That route’s tunnel port on the relay, and nothing else.

If the engine runs on another machine, give it its own OMICSBASE_ENGINE_SECRET. That machine then never holds the Reports secret.

Where things run in production

  • A CSC cPouta VM serves omicsbase.utu.fi. Docker Compose runs LibreChat, MongoDB, Meilisearch, the file-search services, the admin panel and the fallback engine. Caddy, the router and the relay run outside Compose.
  • LUMI-K runs the notes engine gateway, shared worker pods for notes, and pods of their own for heavy notes.
  • Roihu runs each user’s Reports job, in their own CSC project.
  • Users’ own computers run attached Reports sessions. Their traffic passes through the relay on the VM.

Details for maintainers are on Production deployment.