davanstrien/bucket-sqlite-probe-gradio
Bucket mount × SQLite probe — Gradio SDK Space
A minimal reference Space demonstrating how HF Storage Buckets mount into a Gradio SDK Space container, and what SQLite / fcntl.flock / file write operations look like against that mount.
This Space is half of a matched pair used to answer the question: "does the bucket-mount-with-SQLite pattern work on HF Spaces?" — and if so, under what conditions?
What it does
On startup (and on every button click), the app:
- Prints the container's runtime identity (
uid,euid,gid,HOME,SYSTEM,SPACE_ID). - Runs
ls -lan /data,stat /data, andmount | grep /dataagainst the mounted bucket. - Tries to
toucha file on the mount. - Tries to
sqlite3.connect(...).execute("CREATE TABLE ...")— both with the default journal mode and withPRAGMA journal_mode = DELETE(the mode trackio forces on Spaces). - Tries
fcntl.flock(LOCK_EX | LOCK_NB)for POSIX advisory locking.
All output is captured into the log stream at startup (so you can read it via hf api or the Space logs tab) and surfaced via a gr.Textbox for casual browsing.
What we learned (2026-04-08)
With bucket davanstrien/search-v2-chroma attached R/W at /data:
uid=0 user=root euid=0 gid=0
SYSTEM='spaces'
SPACE_ID='davanstrien/bucket-sqlite-probe-gradio'
HOME='/root'Access: (0755/drwxr-xr-x) Uid: (65534/ nobody) Gid: (65534/ nogroup)hf-mount on /data type fuse (rw,nosuid,nodev,relatime,idmapped,user_id=0,group_id=0,default_permissions,allow_other)OK touch /data/gradio_probe_touch
OK sqlite3 connect + CREATE + INSERT
OK sqlite3 journal_mode=DELETE
OK fcntl.flock LOCK_EX|LOCK_NBKey facts established by this Space:
What it implies: Gradio/Streamlit SDK Spaces and any container that runs as root can use bucket mounts for SQLite-style workloads today — this is what trackio does. The idmapped,user_id=0,group_id=0 mount option is the reason — it's also the reason the pattern doesn't work out of the box for Docker SDK Spaces that follow the official `spaces-sdks-docker#permissions` guidance to run as UID 1000 (see the matched Docker SDK probe Space, if published).
How to reproduce
- Fork or duplicate this Space.
- Create a Storage Bucket in your namespace (or reuse one you own).
- Attach it R/W at
/datavia Space settings → Variables and secrets → Volumes (UI), or programmatically:
from huggingface_hub import HfApi, Volume # requires huggingface_hub >= 1.9.1
HfApi().set_space_volumes(
"your-namespace/bucket-sqlite-probe-gradio",
volumes=[Volume(type="bucket", source="your-namespace/your-bucket", mount_path="/data")],
)- Restart the Space. The startup probe output appears in the logs; the button re-runs the probe on demand.
Related
- Matched Docker SDK probe Space (failing, UID 1000): https://huggingface.co/spaces/davanstrien/bucket-sqlite-probe-docker
gradio-app/trackio#465— trackio's PR switching to bucket backendtrackio/sqlite_storage.py— WAL-disable +flockpattern for SQLite on Spaceshuggingface/huggingface_hub#4054—set_space_volumespayload fix (required for this Space to work)- Blog: Buckets as working layer
Throwaway investigative Space. Kept public as a reference example. Do not rely on for production.
