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
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/.
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
- Install and log in:
ARCHAL_TOKEN to a workspace API key
(archal_ws_...). Use archal login for local setup.
- Install the GitHub App on the target repo:
- Make sure the repo has a GitHub origin remote:
--execution-policy fix require a remote that resolves to
github.com/<owner>/<repo>.
- 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.
- Export the model keys your agent and the autoloop worker need.
Add the harness contract
The minimumarchal/harness.json is:
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.
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.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 asai_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.
.archal.json:
.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:
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:
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.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../prod-traces should contain one top-level trace and enough child
span data for grading. The local loop writes artifacts under:
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:
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 loginorARCHAL_TOKEN- GitHub origin remote
- the read-only database URL
- the
autoloop.source.mappingtables and columns in.archal.json - the
autoloop.source.filtersblock (statuses,agentIds,workspaceIds,traceGroups) is not filtering everything out - whether
updated_atorcreated_atvalues move past the stored cursor
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_TOKENin CI --database-url-envpoints to an unset environment variable--database-url-secret-refcontains 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.mdthat tells Archal what state matters
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
reproducedorflaky - generated changes pass local validation
- GitHub branch protection and CI status
Safety
- Use read-only trace source credentials.
- Do not commit database URLs, API keys, or model keys.
- Prefer
--database-url-envfor 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
