Skip to content

Logging API

Receives the study data the VR client records (poses, signals, sessions, clock probes) and stores it in ClickHouse. It replaces the logging half of the Database API; scene data stays there.

Source: logging-api/ · Go (standard library only) · ClickHouse over its HTTP interface.

The client side and the wire format are specified in the Va.Si.Li-Lab repository: Documentation/LoggingProtocol.md (IDs, timestamps, segment files, channel catalogue, HTTP rules).

How data arrives

The headset never streams. It writes segment files (gzip-compressed NDJSON, a few seconds each) to local storage and uploads completed ones in the background. Each upload is one idempotent PUT:

  • 201: stored. 200: the identical segment was stored before (a retry). The client deletes the file either way.
  • 4xx for a broken or invalid segment: the client moves it to a quarantine folder and never retries it.
  • 401/403, 429, 5xx or no answer: the client keeps the file and retries with backoff.

So a server outage only delays data; nothing is lost while the headset has storage left.

Running it

cd logging-api
docker compose up -d --build        # ClickHouse + logging-api on port 8020, API key "dev-key"
curl http://127.0.0.1:8020/v1/health

For a deployment, create a .env next to docker-compose.yml with real values for every variable below.

Use 127.0.0.1, not localhost, with Docker Desktop on Windows

Docker Desktop accepts connections on IPv6 [::1] but may never answer them. Unity resolves localhost to ::1 first, so uploads and clock probes hang until they time out. Configure the client with http://127.0.0.1:8020 (or the machine's LAN address for a headset).

Configuration

Variable Default Purpose
LOGGING_API_ADDR :8020 Listen address
LOGGING_API_KEYS (required) Comma-separated ingest keys accepted as Authorization: Bearer <key> (built into the headset app)
LOGGING_API_OPERATOR_KEYS (empty) Comma-separated operator keys: accepted everywhere, and the only keys for the session, experiment and assignment endpoints
LOGGING_API_MAX_BODY_MB 16 Largest accepted upload (compressed)
LOGGING_API_MAX_SEGMENT_MB 64 Largest accepted segment after decompression
CLICKHOUSE_URL http://localhost:8123 ClickHouse HTTP interface
CLICKHOUSE_DATABASE vasili_logging Database (created by the compose file)
CLICKHOUSE_USER / CLICKHOUSE_PASSWORD logging / (empty) ClickHouse credentials

The compose file's defaults (dev-key, dev-operator-key, logging/logging) are for local development only.

On start the service waits for ClickHouse and applies the schema migrations in internal/store/migrations/ that haven't run yet (tracked in schema_migrations; forward only).

Endpoints

Every endpoint except /v1/health needs Authorization: Bearer <key>. Endpoints marked operator need an operator key; an ingest key gets 403 there. The ingest key only syncs the clock, uploads and reads receipts.

Method Path
GET /v1/health 200 if ClickHouse answers, else 503
POST /v1/time Clock probe: {"t0": <client µs>} → {"t0", "t1", "t2"} (server UTC µs at receive and send)
PUT /v1/runs/{run}/segments/{index} Upload one record segment (Content-Encoding: gzip)
PUT /v1/runs/{run}/blobs/{index} Upload one blob segment (audio, avatar stream; Content-Encoding: gzip). Same responses as segments.
GET /v1/runs/{run}/receipt Segments (both kinds), and records and max seq per session and channel, as stored: compare with the client's counters to prove nothing was lost
GET /v1/sessions?device=&room=&experiment=&limit= Operator. Sessions (room joins) summarised from session.* and experiment.context records: room, scene, start/end, previous session, and role, experiment, participant and inclusion after assignments and windows (what the client claimed is kept under captured, the latest correction under assignment, the window that placed it under window)
GET /v1/sessions/{session}/coverage?gapMs= Operator. Per channel (blob channels included): records, seq range and missing seq (client-side drops), first/last time, measured rate, gaps longer than gapMs (default 2000)
GET /v1/sessions/{session}/audio.wav?path=&peer= Operator. One audio stream of the session as one 16-bit mono WAV, gaps filled with silence (streamed): the microphone by default, or with path and peer what the device heard from that peer
GET /v1/sessions/{session}/audio.json?path=&peer= Operator. Manifest of that WAV: where each audio chunk was placed (offset, skip, samples), the mono time of sample 0, and, once the clock was probed, the server time of sample 0 and of every chunk (firstSampleServerUs)
GET /v1/sessions/{session}/audio/streams Operator. The session's audio streams: the microphone (path mic) and every peer it heard (path webrtc, fallback or janus, and peer)
GET /v1/sessions/{session}/clock Operator. Maps the session's mono times onto server UTC: the clock fit of its run, in segments split where the clock jumped, computed from the stored probes on every request
GET /v1/sessions/{session}/assignments Operator. Every correction of the session's assignment, oldest first
POST /v1/sessions/{session}/assignments Operator. Correct the session's experimentId ("" removes it), participant, role and/or included; author and reason required. Fields left out keep their current value. 201 with the new assignment; 404 unknown session, 422 unknown experiment
GET /v1/experiments Operator. Latest version of every experiment
POST /v1/experiments Operator. Create one: scheduleCode (survey token) and/or name, optional isTest, status (planned default, valid, pilot, aborted), source (manual default, import), notes; author required. The server picks the UUID. 409 if another experiment has the schedule code
GET /v1/experiments/{experiment} Operator. The experiment, all its versions, its sessions (after assignments) and the recording.* markers that name it or were logged in its sessions
PATCH /v1/experiments/{experiment} Operator. Change fields of an experiment (same fields as POST, plus reason); author required. Appends a new version
POST /v1/experiments/{experiment}/windows Operator. Start the experiment in a room now: room (a session's room name, or its id) and author. 201 with the window; 404 unknown experiment, 409 if an experiment already runs in that room
POST /v1/windows/{window}/stop Operator. Stop it now (author). Appends a version; 404 unknown, 409 already stopped
GET /v1/windows Operator. Latest version of every window, by start
GET / The experiment overview page: create experiments, start and stop them per room, see their sessions and include or exclude one. It asks for the operator key and keeps it in the browser tab only

Which experiment a session belongs to, in this order: its latest correction (assignment); else the window of its room that overlaps it (the latest started, if several; participant = the logged role); else what the headset claimed (experiment.context). Windows are stamped with the server's time and matched when sessions are read, so headsets never need to know the experiment, and logs uploaded later still land in the right one. Sessions are matched on the headset's own UTC, which is fine at the scale of minutes. The page has no login beyond the operator key: keep it inside the lab network or behind the proxy.

Every segment is validated completely before anything is stored: header against the URL, every record's envelope, and every payload against the schema of its channel and version (internal/protocol/channels.go, blob channels in internal/protocol/blob.go, which also checks body sizes). A new channel or version therefore needs a server update before clients send it; until then its segments are quarantined on the client and can be re-queued afterwards.

How the WAV is put together (internal/audio): a mic run is an uninterrupted stretch of samples; within a run each chunk is placed by its sample index alone (the audio keeps its own clock), each run is placed by the mono time of its first sample. Missing chunks and the time between runs become silence; a run starting before the previous one ended is trimmed.

Lining up recordings: the server time of a WAV sample k is firstSampleServerUs + k / sampleRate within a run. For long recordings, use the chunks' own firstSampleServerUs, since the device clock drifts. Across headsets that is accurate to a few milliseconds. The time a peer's words took to reach a listener (100–300 ms over VoIP) is in the listener's received streams (audio/streams), recorded when the client enables recordReceivedAudio. The fit (internal/clock) is only as good as the server's clock: under Docker Desktop on Windows it jumps by about 30 ms, so use a Linux host for studies.

Storage

Table Content
raw_record Every record as sent: envelope columns plus the payload as a JSON string. Key (run_id, session_id, channel, seq), the protocol's idempotency key. ReplacingMergeTree, partitioned by month of the record's own time.
segment One row per stored segment with its SHA-256, to tell a retry (200) from a conflict (409)
blob_record Blob records: the same columns and key as raw_record, plus body (raw bytes: int16 samples, avatar stream packets)
blob_segment One row per stored blob segment (own index space per run)
experiment One row per experiment version: schedule code, name, is_test, status, source, notes, author, reason. Key (experiment_id, version), so history is never merged away; the current state is the highest version
session_assignment One row per correction of a session (the full state, not a diff): experiment (nil UUID for none), participant, role, included, author, reason. Key (session_id, version)
experiment_window One row per version of an experiment window (start = version 1, stop = version 2): experiment, room, started_at, stopped_at (epoch while running), author. Key (window_id, version)
schema_migrations Applied migrations

Each segment is stored with a single INSERT and an insert deduplication token derived from its identity and content, so a retried upload never duplicates records; FINAL removes anything that slips through.

Typed views over raw_record (plain views: always consistent with raw, nothing to backfill). Poses are flattened to px, py, pz (metres, Unity world space) and rx, ry, rz, rw (quaternion).

View Rows
player_pose player.head, player.root, player.trackingSpace, player.hand; part (head, root, trackingSpace, hand), side
object_motion object.spawn, object.pose, object.rest, object.despawn; object_id, kind (spawn, pose, rest, despawn), has_pose (0 for despawn)
interaction interaction.grab, interaction.ui; action, side, input, interactor, target_id, target_name (grabbed object or UI element)
misc misc.event; key, value (the event's JSON object, read it with JSONExtract*)

Examples:

-- Head height over one session
SELECT mono_us, py AS head_height FROM player_pose
WHERE session_id = '…' AND part = 'head' ORDER BY mono_us;

-- Trajectory of one object: spawn, poses while moving (logged by its owner), rest, despawn
SELECT mono_us, kind, px, py, pz FROM object_motion
WHERE session_id = '…' AND object_id = 'net:0000abcd-00001234' ORDER BY mono_us;

-- Index fingertip of the right hand (OpenXR joint 10) in tracking space, while tracked
SELECT mono_us,
       JSONExtract(data, 'positions', 'Array(Float64)') AS p,
       (p[31], p[32], p[33]) AS index_tip
FROM raw_record FINAL
WHERE session_id = '…' AND channel = 'meta.hand'
  AND JSONExtractString(data, 'side') = 'right' AND JSONExtractBool(data, 'tracked')
ORDER BY mono_us;

-- Dead microphone check: loudness per audio chunk
SELECT mono_us, JSONExtractFloat(data, 'rms') AS rms, JSONExtractFloat(data, 'peak') AS peak
FROM blob_record FINAL
WHERE session_id = '…' AND channel = 'audio.mic' ORDER BY seq;

Experiments

An experiment is a scheduled interview (or a pilot or test run), created before it takes place. Clients log what they believe on experiment.context (experiment, participant slot, recording on/off) and mark recordings with recording.start, recording.stop and recording.aborted (a false start). Mistakes are corrected with assignments afterwards, never by changing raw data: the client's claim stays in raw_record, the correction with its author and reason in session_assignment.

OP="Authorization: Bearer dev-operator-key"
# Create the experiment before the interview; the answer contains its id
curl -H "$OP" -d '{"scheduleCode":"fw2UfYz","name":"Interview 18","author":"ps"}' http://127.0.0.1:8020/v1/experiments
# Afterwards: everything recorded for it
curl -H "$OP" http://127.0.0.1:8020/v1/experiments/<id>
# Tag a headset's session that didn't know the experiment, or exclude one
curl -H "$OP" -d '{"experimentId":"<id>","participant":"B","author":"ps","reason":"set after the session"}' \
  http://127.0.0.1:8020/v1/sessions/<session>/assignments

meta.* poses are in Unity tracking space; combine with player.trackingSpace (same session, nearest mono_us) for world space. Joint and expression names are in the session's meta.status.

Channels without a view are read from raw_record with JSONExtract* on data.

Former Misc events

The events the client used to send to the Database API's /logMisc (MongoDB Misc). The core ones have their own channels. Everything else, such as hearingLoss and visionLoss, goes to the generic misc.event. Role, level, scene and room are not repeated in the payload: take them from the session (session.start, session.roleChanged, level.status). Unset values are sent empty ("", [], 0), never null. avatar_id needs no channel of its own; it is avatar.selected.

Channel Fields Was Misc type
audio.deviceVolume action (baseline, changed, restored, end), volume, max, baseline deviceVolume
conversation.voices action (voicesMuted, voicesUnmuted) conversation
tutorial.step action (started, completed, finished, left), step, stepName vrTutorial
misc.event key (what the event is, dotted like a channel name, e.g. restriction.hearingLoss), data (a string holding any JSON object) everything else

misc.event lets the client log new events without a server change. The server only checks that data is a JSON object, so its fields are documented by whoever logs them. When an event becomes part of the core, give it a channel of its own. The misc view has key as a column and the object as value:

-- Volume changes of one session
SELECT mono_us, JSONExtractString(data, 'action') AS action, JSONExtractInt(data, 'volume') AS volume
FROM raw_record FINAL WHERE session_id = '…' AND channel = 'audio.deviceVolume' ORDER BY mono_us;

-- Vision loss events of one session
SELECT mono_us, JSONExtractString(value, 'action') AS action, JSONExtractFloat(value, 'maxCPD') AS max_cpd
FROM misc WHERE session_id = '…' AND key = 'restriction.visionLoss' ORDER BY mono_us;

Timing accuracy and limitations

The full list, with which timestamp to use per channel, is in the Va.Si.Li-Lab repository: Documentation/LoggingTiming.md. In short, from a reference experiment on 2026-11-25 (a Quest Pro and a Quest 3 in FACES_ on a local server; sessions 5c9f72d0…, 1a09f1b9… and the sync test 93fbee34…):

  • Across headsets the clock fit was accurate to ±1–1.3 ms. No records or segments were missing.
  • For meta.hand, meta.face and meta.eyes, use sampleTime, not mono_us. Face samples are ~64 ms old when written; hand sampleTime is a predicted display time 19–35 ms after the write. The SQL example above orders by mono_us, which is fine for order but not for timing.
  • Audio is stamped ~31 ms late against the hands: 11 claps on a Quest Pro, IQR −37 to −24 ms. The microphone's input latency isn't in the client's timestamps. Subtract it in the analysis; whether it's the same on every headset is unknown.
  • Mic clock drift within a run isn't corrected. No drift was visible over 145 s; a one-hour run hasn't been checked.
  • Hand tracking ran at ~36 Hz and dropped frames for 56–83 ms while the hands touched. Expect single events to be good to about one tracking frame.

tools/av_sync.py repeats the measurement for any session: record ~10 claps with hand tracking on (and ~30 s of speech on a Quest Pro), then run python tools/av_sync.py <session> --clickhouse http://<host>:8123 --user … --password …. It needs numpy and reads ClickHouse directly, since the API doesn't serve tracking records. python tools/av_sync.py --selftest checks it against synthetic data.

Server-side limitations:

  • The clock fit is only as good as the server clock. Docker Desktop on Windows jumps by ~30 ms, which splits fits into extra segments.
  • Experiment windows match by the device's utc, not the clock fit. That's fine at the scale of minutes, but a session starting within seconds of a Start or Stop can land on the wrong side.
  • One running window per room name. Two interviews in the same scene at the same time can't be told apart; the second Start is refused.
  • Windows start and stop now; they can't be backdated. If someone forgets to press Start, fix the sessions with assignments.
  • Nothing is ever deleted (append-only versions), test experiments included.
  • The overview page (/) has no login beyond the operator key. Keep it inside the lab network.

Tests

go test ./...                                                     # unit tests
docker compose up -d clickhouse
LOGGING_TEST_CLICKHOUSE_URL=http://127.0.0.1:8123 go test ./...   # + ClickHouse integration tests

The integration tests create and drop their own database per run.