Skip to content

Trajectory Converter Job

sciontool trajectory convert is a standalone, Hub-independent storage-to-storage batch job. It reads settled raw L0 trajectory segments and their Hub-authored manifests directly from object storage (gs:// or file://) and writes deterministic L1 outputs back to storage:

  • analytics/v1/usage_records/ (Tier A usage records)
  • analytics/v1/run_inventories/ (Tier A run release inventories)
  • trajectories/v1/atif/ (Tier B ATIF trajectories and per-release completion markers)

The job never contacts the Hub, holds no Hub credentials, and is never scheduled or waited on by the Hub or Runtime Brokers.

Use the standalone deploy/terraform/modules/scion-analytics module to deploy the slim distroless converter image (scion-trajectory-converter) as a Cloud Run v2 Job triggered hourly by Cloud Scheduler:

module "scion_analytics" {
source = "../../modules/scion-analytics"
project_id = var.project_id
region = var.region
hub_id = "my-hub"
bucket_name = "my-project-my-hub-artifacts"
converter_image = "us-central1-docker.pkg.dev/my-project/public-docker/scion-trajectory-converter:v0.4.0"
}

The module provisions a dedicated service account with prefix-conditioned bucket-level IAM (*_iam_member only; requires uniform bucket-level access on the GCS bucket):

  • Read + list (roles/storage.objectViewer): objects.get and prefix-scoped objects.list on <hub_id>/trajectories/v1/raw/, <hub_id>/trajectories/v1/atif/, <hub_id>/analytics/v1/usage_records/, and <hub_id>/analytics/v1/run_inventories/. Read and list on the output prefixes are required for marker discovery and idempotent SHA-256 hash verification on create-if-absent collisions.
  • Create (roles/storage.objectCreator): create-only access on <hub_id>/analytics/v1/usage_records/, <hub_id>/analytics/v1/run_inventories/, and <hub_id>/trajectories/v1/atif/. No write access to trajectories/v1/raw/, no overwrite or delete permissions, no Secret Manager access, and no Hub credentials.
  • Scheduler invoker: when scheduler_enabled = true (default), a separate scheduler service account receives roles/run.invoker on that Cloud Run Job only.

On Cloud Run gen2, in-memory empty_dir volumes count against the container memory limit. The module defaults to 4Gi container memory with a 2Gi in-memory empty_dir mounted at --work-dir /tmp/scion-conv:

  • Each run is isolated in a --single-run child worker (RLIMIT_AS=6144 MiB virtual, GOMEMLIMIT=768MiB) that spawns the harness converter subprocess (RLIMIT_AS=4096 MiB virtual, GOMEMLIMIT=768MiB).
  • Per-run spooled files under --work-dir are deleted immediately after each run completes.
  • Discovery streams per project and per run in storage lexical full-path order (GCS order), so parent memory stays bounded regardless of hub history. When --max-runs N is set, the job processes the first N eligible runs in that lexical order.

The Cloud Run Job runs with task_count = 1, parallelism = 1, task_timeout = 3300s (55 minutes, below the default hourly schedule), and EXECUTION_ENVIRONMENT_GEN2. sciontool internal normalize-exec enforces RLIMIT_AS, RLIMIT_CPU, RLIMIT_FSIZE, RLIMIT_NOFILE=256, PR_SET_DUMPABLE=0, scrubbed env, and process-group SIGKILL cleanup on exit or timeout. Cloud Run v2 Jobs do not expose a configurable pids.max or RLIMIT_NPROC parameter, so per-subprocess PID count is a documented gap on Cloud Run (built-in Go converters do not spawn child processes).

Against local file:// storage, run the same command from cron or by hand using the slim converter image (or sciontool directly). Always run as a non-root user; the sandbox executor fails closed when invoked as UID 0 without a privilege-drop target. Ensure the host storage directory mounted at /data and the scratch directory mounted at /tmp/scion-conv are writable by UID 65532 (or match --user to the host owner).

Terminal window
docker run --rm \
--user 65532:65532 \
-v /path/to/scion-storage:/data \
-v /tmp/scion-conv:/tmp/scion-conv \
us-central1-docker.pkg.dev/<project>/public-docker/scion-trajectory-converter:latest \
--storage file:///data/<hub_id>/ \
--work-dir /tmp/scion-conv \
--settle 2h \
--format json

Example hourly crontab entry:

0 * * * * docker run --rm --user 65532:65532 -v /var/lib/scion/storage:/data -v /tmp/scion-conv:/tmp/scion-conv us-central1-docker.pkg.dev/<project>/public-docker/scion-trajectory-converter:latest --storage file:///data/<hub_id>/ --work-dir /tmp/scion-conv --format json >> /var/log/scion-trajectory-converter.log 2>&1

The default --settle window is 2h. A run is eligible only when its newest committed segment manifest is older than --settle, giving late broker harvests time to commit without coupling conversion to agent lifecycle events.

If a quiet agent later commits additional segments, the run’s inventory_seq (count of manifested segments) increases and a subsequent job invocation writes a new release that supersedes the earlier one.

Parser upgrades never trigger automatic re-conversion. To backfill historical runs or re-convert after a parser version bump, invoke the job manually with --reconvert and an explicit scope:

Terminal window
sciontool trajectory convert \
--storage gs://<bucket>/<hub_id>/ \
--reconvert \
--parser-version claude-1 \
--since 2026-11-01T00:00:00Z \
--until 2026-11-29T00:00:00Z \
--project <project_id> \
--format json

Add --dry-run first to inspect which runs match without writing any objects. Even with --reconvert, all writes remain create-if-absent (ifGenerationMatch=0): existing objects with matching SHA-256 hashes are verified without overwriting, while a hash mismatch fails that run without overwriting.

Exit code Meaning
0 Every selected run converted or skipped cleanly.
2 One or more runs ended in parse_failed while other runs completed normally (and no project listing errors occurred).
1 Fatal error: invalid flags (for example missing --storage, invalid --format, or --max-address-space-mib exceeding --single-run-max-address-space-mib), unsupported --parser-version, storage authentication/authorization failure (aborts immediately), or transient per-project listing errors recorded in project_errors (remaining projects still complete before exiting 1).

With --format json, the command prints a single JSON summary to stdout. To keep parent memory bounded across large hub histories, routine skips (skipped_already_converted, skipped_previously_failed, skipped_no_converter, skipped_filtered) are reported only as per-status counts in skip_counts rather than per-run entries in runs.

{
"hub_id": "hub-prod-1",
"dry_run": false,
"discovered_runs": 3,
"converted_runs": 1,
"parse_failed_runs": 0,
"skipped_runs": 2,
"skip_counts": {
"skipped_already_converted": 2
},
"runs": [
{
"project_id": "proj-1",
"agent_id": "agent-1",
"run_id": "run-1",
"harness": "claude",
"parser_version": "claude-1",
"inventory_seq": 4,
"dt": "2026-11-28",
"status": "converted",
"usage_record_count": 42,
"session_count": 2,
"objects_written": 5,
"peak_rss_bytes": 41943040,
"child_peak_rss_bytes": 67108864,
"marker_path": "hub-prod-1/trajectories/v1/atif/project=proj-1/agent=agent-1/run=run-1/sessions.pclaude-1.s4.json"
}
]
}
Field Description
hub_id Hub identifier parsed from --storage.
dry_run Whether --dry-run was set.
discovered_runs Total runs discovered in the listed scope (in storage lexical full-path order).
converted_runs Runs that produced (or verified) a complete L1 release.
parse_failed_runs Runs that failed permanently or on attempt-counted errors (causes exit code 2 when project_errors is empty).
skipped_runs Total runs skipped across both routine skip_counts and per-run skip statuses (skipped_unsettled, skipped_max_runs).
skip_counts Per-status counts for routine skips (skipped_already_converted, skipped_previously_failed, skipped_no_converter, skipped_filtered), omitted when empty.
project_errors Transient per-project listing errors (project_id, error), omitted when empty. Other projects continue processing, and the command exits 1 at the end.
runs Per-run outcome records for non-routine outcomes (converted, dry_run, parse_failed, skipped_unsettled, skipped_max_runs).
Status Where reported Meaning
converted runs Release written/verified and completion marker recorded.
dry_run runs Run is eligible; no objects were written.
parse_failed runs Run failed validation, hash/contiguity check, timeout, or converter error; other runs continue.
skipped_unsettled runs Newest manifest is newer than --settle.
skipped_max_runs runs Eligible run deferred because --max-runs was reached in this invocation.
skipped_already_converted skip_counts Completion marker already exists for (run_id, parser_version, inventory_seq).
skipped_previously_failed skip_counts Permanent or max-attempt failed marker already exists for (run_id, parser_version, inventory_seq).
skipped_no_converter skip_counts No built-in converter is registered for the run’s harness.
skipped_filtered skip_counts Excluded by --parser-version when the run’s harness does not implement it.