Wiretrace

Architecture

browser ── Next.js workbench ──► FastAPI /api/v1 ──► PostgreSQL (state, evidence, approvals, job leases)
                                       ▲
       runner (your machine) ──────────┘  outbound HTTPS only: pair, heartbeat, claim, post trials, complete
         ├─ reference trial: official MCP Python SDK ─► stdio observer ─► server instance A
         └─ Kiro trial: kiro-cli chat --v3 ...        ─► stdio observer ─► server instance B
Kiro Crew app ── MCP tools + backend ──► /api/v1/crew/* (propose only)

Components

  • `services/runner` (`wiretrace_runner`): the execution engine and the wiretrace CLI. It runs trials, normalizes evidence, compares traces, runs the oracle and the reducer, verifies repairs and builds exports. It works without the API too (wiretrace run, wiretrace reproduce).
  • `services/api` (`wiretrace_api`): the control plane. It owns workspaces, sessions, the investigation state machine, approvals, the job queue, Server-Sent Events, artifacts and monitors.
  • `apps/web`: the workbench and landing page. It talks only to the API, through a same-origin rewrite.
  • `wiretrace-crew` (separate repository): the Kiro Crew app.

Why the runner pulls jobs

The Kiro trial has to run where the developer's Kiro CLI is installed and signed in. The runner therefore lives on the developer's machine and connects outbound to the API. Jobs are rows in PostgreSQL with a lease: a runner claims one with SELECT ... FOR UPDATE SKIP LOCKED, heartbeats every 10 seconds, and posts each trial as it finishes. A lease that expires marks the run interrupted. It is never replayed automatically, because a lost external call is ambiguous. PostgreSQL is the only store; there is no message broker to expose to the developer's machine.

A trial

1. Create a temporary workspace (mode 700).

2. Build the observer command: python -m wiretrace_runner.observer --log observer.jsonl -- <server command>.

3. Reference side: the SDK Client spawns the observer through StdioServerParameters, negotiates the protocol (server/discover first, legacy initialize as fallback), lists tools and calls the approved tool once.

4. Kiro side: write .kiro/agents/wiretrace-probe.json with the server inline, includeMcpJson: false and tools: ["@server"]. Run kiro-cli chat --v3 --no-interactive --output-format stream-json --require-mcp-startup --agent wiretrace-probe --trust-tools=@server/tool.

5. Normalize observer frames and stream-json records into stage events, redact them and classify the trial.

Stage alignment

Events map to process_start, transport_ready, handshake (legacy initialize or modern server/discover), list, invoke, response and close. The comparator aligns these stages, never timestamps or JSON-RPC ids, and reports the earliest stage where both sides were observed and differ. A protocol era difference is reported as an explanatory note, not as a divergence.

Observed Kiro CLI 3.8.1 behavior

These are recorded observations from real runs, not assumptions:

  • Kiro starts a stdio server, sends server/discover, and then starts a second process for the session, which sends subscriptions/listen, tools/list, resources/list, resources/templates/list and prompts/list before tools/call.
  • When the server does not answer within the configured timeout, Kiro stops that process and retries with the legacy initialize handshake. If that also times out, a --require-mcp-startup run exits with code 3 before any model call.
  • --output-format stream-json uses the ACP payload schema (runStarted, sessionUpdate, metadata, runFinished). Tool calls arrive as tool_call session updates, and metadata.meteringUsage reports credits.
  • kiro-cli whoami exits 0 when signed out. Wiretrace reads sign-in from the JSON accountType field.

Investigation states

awaiting_approval → queued → baseline_running → comparing → baseline_complete → (investigating | reducing) → awaiting_repair_approval → verifying_repair → completed, with cancel_requested → cancelled, failed and interrupted as terminal branches. Every transition is a compare-and-swap on a version number, recorded as a run.state event in the same transaction. Completed runs are immutable; a retry creates a new run linked to the old one.

Data

All tenant rows carry workspace_id, and every route checks ownership. A guessed ID answers 404. Evidence is redacted before it is stored. Credential values never reach the database: imported configurations hold ${secret:NAME} references, and the runner resolves them from its local store when it starts a trial.