Skip to main content
Archal has one autonomous trace loop you can drive from a terminal: Use Autoloop when your agent already produces traces and you want Archal to keep checking those traces after they happen. Autoloop imports traces from a read-only source, grades them, tries to reproduce real failures against service clones, and opens a GitHub PR only when a reproducible fix exists. Autoloop is evidence-bounded. It does not replay every arbitrary production trace end to end. It attempts reproduction only when the trace, standing scenario, and seed templates contain enough information to rebuild the relevant clone state. Missing evidence should produce a blocked artifact, not a guessed seed. The important boundary is the same as archal run: your agent and harness keep using normal service SDKs and normal service URLs. Archal handles trace import, isolation, clone routing, scoring, artifacts, and the GitHub workflow behind that boundary.

When to use Autoloop

Use Autoloop for a repo that has all three:
  • a headless command for running the agent
  • production or staging traces that can be normalized into Archal’s trace schema
  • a GitHub repo where fixes can be proposed as PRs
If you are still writing the first scenario for an agent, start with Run scenarios against your agent. If you want to keep a clone alive while debugging manually, use Clone sessions.

How the loop works

Autoloop has two entry points:
  • Hosted database source: archal autoloop --source postgres|supabase ... registers a read-only trace source with Archal. Hosted workers poll it and write run state to the dashboard.
  • Local trace directory: archal autoloop ./traces --repo . watches a local directory with one trace file per run and writes repo-local artifacts under .archal/autoloop/.
Hosted Autoloop supports two ingestion paths: hosted polling for Supabase/Postgres, and client-uploaded normalized traces for file, HTTP/OTel, Langfuse, Braintrust, S3/GCS, and custom sources. Client upload still needs workspace auth. Use archal login for local setup, or set ARCHAL_TOKEN to a workspace API key in CI and include --repository so Archal knows which repo should receive issues or PRs. The phases are: fix is the default policy. Use a narrower policy when you only want part of the loop.

Prerequisites

  1. Install and log in:
In CI or a hosted customer repo, set ARCHAL_TOKEN to a workspace API key (archal_ws_...). Use archal login for local setup.
  1. Install the GitHub App on the target repo:
Install Archal on GitHub This applies whether you register a source from the CLI or connect a trace database from the dashboard. The autoloop opens fixes as pull requests through the Archal GitHub App, so until the app is installed on the repository the fix step blocks instead of opening a PR. The dashboard’s Connect a trace database form shows the same install link beside the repository field.
  1. Make sure the repo has a GitHub origin remote:
Hosted sources and --execution-policy fix require a remote that resolves to github.com/<owner>/<repo>.
  1. Add the agent execution contract under archal/:
harness.json tells Archal how to run the agent. scenario.md gives the standing task and evaluation contract for the trace family. Seed files are optional, but they make reproduction much more reliable when trace evidence is thin.
  1. Export the model keys your agent and the autoloop worker need.
For a local file-backed loop, the worker checks local environment variables before it starts. Hosted database sources are registered locally, then operated by Archal workers. Smoke-test the harness before letting either loop spend attempts:

Add the harness contract

The minimum archal/harness.json is:
The command should run the same headless agent code you would use in archal run: no UI, no browser OAuth, no manual prompts. It should accept the task from AGENT_TASK, call your normal agent runtime, and exit cleanly. Use env only for non-secret defaults that belong in the repo. Keep secrets in your shell, CI, hosted secret manager, or Archal workspace configuration.

Add the standing scenario

archal/scenario.md is not a one-off reproduction. It is the standing contract that tells Autoloop what the agent is supposed to do for this class of traces.
The prompt should describe the real task. Do not put instructions in the scenario that tell the tested agent it is using Archal, clones, or a special environment.

Add seed templates

Autoloop can seed from trace evidence, but the best integrations include repo-owned seed templates. Templates are especially useful when a trace contains IDs and tool calls but not the complete starting state.
Seed templates should match the services in archal/scenario.md. The autoloop worker prefers repo-owned seed templates when they exist, then fills in trace-specific IDs and fields during reproduction. See Seeds for clone seed formats and built-in examples.

Autoloop a Supabase or Postgres trace source

Use this path when traces live in a database table such as ai_traces with child spans in ai_spans. Create a read-only database user first. It should be able to select trace and span rows, but not mutate application data.
Name the source in the harness repo’s .archal.json:
Run a readiness check:
Register the source:
This registers the source with the active Archal workspace. The database URL is sent to Archal during registration and is not written to .archal/autoloop/. If your secret already lives in an external secret manager, pass a reference instead of a local environment variable:
--database-url-secret-ref must be a secret reference, not a plaintext database URL.

Map custom trace tables

The defaults match the common shape: If your schema uses different table or column names, map them in the .archal.json autoloop block:
For append-only tables, use created_at_id and point the updated columns at the creation timestamp too. The updated columns are always required (readiness checks them and the import query projects them), so on tables whose rows never change after insert, map them to created_at:
You can also start from a known cursor: cursor.watermarks is a repair escape hatch for rewinding or skipping the import cursor. Watermarks are server-owned progress state, so leave cursor.watermarks unset in normal operation: streams you do not name keep their stored position across re-registrations. Name a stream to move its cursor, or set its at or id to null to reset that stream and re-import from the beginning. Do not leave null placeholders in the config: { "at": null } is a deliberate reset on every registration, not an unset default.

Filter imported traces

Use filters when the trace source contains many agents, tenants, or statuses.
Metadata is for labels and routing context. Do not put secrets in autoloop.source.metadata.

Autoloop a local trace directory

Use a local directory when you are testing the loop before a hosted source is ready, or when traces arrive as files.
Each file in ./prod-traces should contain one top-level trace and enough child span data for grading. The local loop writes artifacts under:
Stop a local file-backed autoloop with:
archal autoloop detach is for local file-backed autoloops. Hosted database sources are managed from the dashboard. For a terminal-first handoff, keep these commands with the artifact directory:
Use autoloop status to summarize local trace jobs (or pass a hosted run id to inspect one run’s grade evidence and artifacts). Use autoloop reprocess only after fixing the evidence, mapping, credential, harness, or GitHub blocker that caused a terminal job.

Dashboard pages

Autoloop results live in the workspace dashboard. The pages are intentionally split so an operator can answer three different questions:
  • Did Archal receive the trace?
  • Did Archal reproduce a real failure against clones?
  • Did Archal open something reviewable in GitHub?

Artifact contract

Hosted sources surface these artifacts in the dashboard. Local file-backed local autoloops write the same kinds of artifacts under .archal/autoloop/. Artifacts should explain whether a failure was an agent issue, missing trace evidence, clone fidelity gap, harness issue, or GitHub/CI issue. When evidence is missing, Autoloop should say what is missing instead of manufacturing a reproduction.

Troubleshooting

No traces import

Check:
  • archal login or ARCHAL_TOKEN
  • GitHub origin remote
  • the read-only database URL
  • the autoloop.source.mapping tables and columns in .archal.json
  • the autoloop.source.filters block (statuses, agentIds, workspaceIds, traceGroups) is not filtering everything out
  • whether updated_at or created_at values move past the stored cursor
Run the same archal autoloop --source ... --database-url-env ... invocation with --check to validate setup without registering or starting work; the mapping and filters are read from .archal.json either way.

Hosted source registration fails

Common causes:
  • no logged-in Archal account
  • missing ARCHAL_TOKEN in CI
  • --database-url-env points to an unset environment variable
  • --database-url-secret-ref contains a plaintext credential
  • repo remote is missing or is not GitHub

Reproduction is blocked as missing evidence

That usually means the trace does not contain enough state to build the starting clone state. Add one of:
  • richer trace fields such as input_data, output_data, state snapshots, or tool-call arguments
  • child spans for service reads and writes
  • repo-owned seed templates under archal/seeds/
  • a narrower archal/scenario.md that tells Archal what state matters
Blocked reproduction is a useful signal. It means Archal refused to claim a failure was reproducible without enough evidence.

A PR is not opened

Check:
  • the execution policy is fix
  • the GitHub App is installed on the repo
  • the repo has an origin remote on GitHub
  • reproduction status is reproduced or flaky
  • generated changes pass local validation
  • GitHub branch protection and CI status
Autoloop opens PRs for review. It does not auto-merge them.

Safety

  • Use read-only trace source credentials.
  • Do not commit database URLs, API keys, or model keys.
  • Prefer --database-url-env for local setup and secret references for hosted production setup.
  • Keep trace artifacts redacted before sharing them outside the workspace.
  • Do not add model-visible copy telling the tested agent it is in Archal or a clone-backed run.
  • Let the GitHub App open PRs; do not bypass the review path with direct pushes to protected branches.

What to hand off

For every loop, include:
  • exact command and repo
  • scenario paths or source name
  • final status and stop reason
  • artifact directory and the two or three files that justify the decision
  • PR URL, if opened
  • remaining blocker, if any
Do not add model-visible instructions telling the tested agent it is in Archal or in a clone-backed run. That changes the behavior being evaluated.

Next steps