agora.observe.jsonl

Structured run logging — JSONL schema v1.

Every Agora run that wires a RunObserver emits two files into a per-run output directory:

  • run.jsonl — a single RunRecord line (the whole-run summary).

  • tasks.jsonl — one TaskRecord line per task (execution order).

Both records carry schema_version = 1. The schema is locked (Phase A, Artifact 1) — fields, names, and closed vocabularies are pinned here as pydantic models so downstream analysis can validate every line it reads.

The observer is intentionally decoupled from the orchestrator’s own types: it exposes two low-level emit methods (RunObserver.record_task() and RunObserver.record_run()) that take plain values, so a test can drive it with a fake orchestrator. The orchestrator-facing convenience (RunObserver.record_task_from_result()) does the derivation from a TaskResult.

Tool-call accounting semantics. The three primary counters share one unit — tool calls — so they reconcile arithmetically:

tool_calls_structured + tool_calls_text_fallback == tool_calls_total

  • tool_calls_total — total model-emitted tool calls executed on the task, summed across stages and attempts (synthetic auto-hook calls are excluded). A call count.

  • tool_calls_structured — calls that arrived via the assistant message’s native tool_calls field. A call count.

  • tool_calls_text_fallback — calls extracted by the Ollama adapter’s _parse_tool_calls_from_text from prose content. A call count, and the headline tool-call-fidelity signal. (The adapter’s fallback only runs when the structured field was empty, so a given turn’s calls are wholly one origin — never a mix — which is what makes the invariant exact.)

Overlap counters (a single call can be counted here and in one of the two origin buckets above — they are NOT part of the reconciliation sum):

  • tool_calls_malformed — tool executions that raised (arg/exec error).

  • tool_call_unknown_name — calls naming a tool that doesn’t exist.

Side-channel turn counter (NOT a call count, named explicitly so it can’t be confused with the primaries):

  • turns_with_text_fallback — number of LLM turns on which the text-fallback parser fired (≥1 call extracted from prose).

  • first_text_fallback_iteration — 0-based index of the first iteration on which the parser extracted ≥1 call from prose; null if it never fired.

Module Attributes

TaskKind

Closed vocabulary for TaskRecord.task_kind.

TaskStatusLiteral

Closed vocabulary for TaskRecord.status.

FailureCategory

Closed vocabulary for TaskRecord.failure_category (when non-null).

ASYNC_LEAK_MARKERS

Log substrings that indicate an asyncio resource leak.

Functions

classify_task_kind(*[, output_path, ...])

Derive a TaskKind from a task's structural signals.

derive_failure(*, status, output, ...[, ...])

Classify a non-passing task into (failure_category, failure_detail).

derive_status(success, output)

Map a task outcome to the TaskStatusLiteral vocabulary.

git_commit_short([repo_dir])

Best-effort HEAD short SHA; "unknown" if git is unavailable.

profile_snapshot_from(profile)

Build a ProfileSnapshot from a ModelProfile.

query_ollama_version(base_url)

Best-effort Ollama daemon version via /api/version; "unknown" on failure.

scan_async_leaks(log_path)

Count run-log lines matching any ASYNC_LEAK_MARKERS (grep -c).

Classes

ArmSpec

The experiment arm a run belongs to.

PhaseGateRecord

One line in phases.jsonl — a phase gate outcome (integration run 1).

PhaseTaskOutcome

One task's contribution to a phase gate (provenance).

PlanEntry

One line of a campaign's plan.jsonl (written by scripts/run_campaign.py).

PostconditionOutcome

One (name, passed) pair from a task's postcondition evaluation.

ProfileSnapshot

Full inference-config snapshot recorded with each run (NOT just the name).

RunObserver

Accumulates run signals and emits run.jsonl + tasks.jsonl.

RunRecord

The single line in run.jsonl — the whole-run summary.

TaskRecord

One line in tasks.jsonl — the outcome of a single task.

class agora.observe.jsonl.ArmSpec[source]

Bases: BaseModel

The experiment arm a run belongs to.

v1 records both axes; only strictness="strict" is scored and scaffolding does not yet switch behaviour (see design notes). The fields exist so future axes can sweep them without a schema bump.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

scaffolding: Literal['lean', 'rich']
strictness: Literal['strict', 'permissive']
class agora.observe.jsonl.PlanEntry[source]

Bases: BaseModel

One line of a campaign’s plan.jsonl (written by scripts/run_campaign.py).

The serialized line carries {id, probe, profile, arm, repeat, params}. run_id is NOT part of that line — it is a load-time enrichment populated by agora.observe.analysis.load_run_records(), which matches this entry’s per-run subdirectory (named by id) to the run.jsonl found inside it. That lets downstream joins map a run’s uuid run_id back to its campaign id and repeat. extra="ignore" keeps the model forward-compatible with future plan keys.

model_config = {'extra': 'ignore'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: str
probe: str
profile: str
arm: ArmSpec
repeat: int
params: dict[str, Any] | None
run_id: str | None
class agora.observe.jsonl.PostconditionOutcome[source]

Bases: BaseModel

One (name, passed) pair from a task’s postcondition evaluation.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
passed: bool
class agora.observe.jsonl.ProfileSnapshot[source]

Bases: BaseModel

Full inference-config snapshot recorded with each run (NOT just the name).

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
model: str
num_ctx: int | None
max_tokens: int
temperature: float
seed: int | None
keep_alive: str
class agora.observe.jsonl.RunObserver[source]

Bases: object

Accumulates run signals and emits run.jsonl + tasks.jsonl.

Construct one per run with the static metadata (profile snapshot, arm, probe name, flow path). The orchestrator calls task_started() each time a task executes (so loop-backs/retries are counted), then record_task_from_result() per task and record_run() once at shutdown. Tests can drive the low-level record_task() / record_run() directly.

The two files are opened (truncated) on construction so a partially completed run still leaves valid lines on disk.

__init__(*, run_id, output_dir, probe_name, flow_path, project_name, profile, arm=None, log_path=None, ollama_version='unknown', git_commit='unknown', host=None, notes='', strategy=None, harness=None, probe_version=None)[source]
static resolve_output_dir(run_id, override=None)[source]

Resolve the run output dir.

Precedence: explicit override → AGORA_RUN_OUTPUT_DIR env → runs_out/_default/<run_id>/.

task_started(task_id)[source]

Record that task_id began an execution (counts retries/loop-backs).

exec_count(task_id)[source]

How many times task_id executed (0 if never).

record_task(**fields)[source]

Validate + append one TaskRecord to tasks.jsonl.

record_phase_gate(result, *, run_id=None)[source]

Append one phase-gate outcome to phases.jsonl (integration run 1).

Accepts a agora.fleet.phase_gate.PhaseGateResult (duck-typed: phase, passed, blockers, and tasks of TaskGateOutcome). Opens phases.jsonl on first call.

record_run(**fields)[source]

Validate + write the single RunRecord to run.jsonl.

Computes async_leak_hits from the wired log path when not supplied.

record_task_from_result(*, task, result, role, task_index)[source]

Build + emit a TaskRecord from a task and its TaskResult.

result is None for tasks that never executed (skipped).

close()[source]

Flush + close both file handles. Idempotent.

class agora.observe.jsonl.RunRecord[source]

Bases: BaseModel

The single line in run.jsonl — the whole-run summary.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

schema_version: Literal[1]
run_id: str
started_at: str
ended_at: str
duration_s: float
probe_name: str
flow_path: str
project_name: str
profile: ProfileSnapshot
arm: ArmSpec
success: bool
exit_code: int
tasks_total: int
tasks_passed: int
tasks_failed: int
tasks_first_pass: int
async_leak_hits: int
model_offloaded: bool | None
tokens_in: int
tokens_out: int
ollama_version: str
git_commit: str
host: str
notes: str
strategy: str | None
harness: dict[str, Any] | None
probe_version: int | None
class agora.observe.jsonl.TaskRecord[source]

Bases: BaseModel

One line in tasks.jsonl — the outcome of a single task.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

schema_version: Literal[1]
run_id: str
task_id: str
task_index: int
role: str
task_kind: TaskKind
status: TaskStatusLiteral
first_pass: bool | None
loopback_count: int | None
iterations: int | None
postconditions: list[PostconditionOutcome]
tool_calls_total: int
tool_calls_structured: int
tool_calls_text_fallback: int
tool_calls_malformed: int
tool_call_unknown_name: int
tools_used: list[str]
turns_with_text_fallback: int
first_text_fallback_iteration: int | None
failure_category: FailureCategory | None
failure_detail: str | None
duration_s: float
artifact_capture: dict[str, Any] | None
reviews_used: int
post_review_action: Literal['confirm', 'revise', 'other'] | None
nudges_used: int
salvages_used: int
turns_reasoning_only: int
phase: str | None
blocking: bool
run_check_records: list[dict[str, Any]]
mechanical: bool
agora.observe.jsonl.classify_task_kind(*, output_path='', postcondition_names=(), stage_kinds=(), role='')[source]

Derive a TaskKind from a task’s structural signals.

Precedence (first match wins): framework stage kinds → reviewer role → api_spec → research (kb/) → test authoring (test-file output) → test run (pytest/imports postconditions) → code_body.

Unclassifiable tasks (no output path, no postconditions, no role) fall back to "code_body" with a warning — the contract never invents a new vocabulary value.

agora.observe.jsonl.derive_failure(*, status, output, postcondition_results, tool_calls_malformed=0, tool_call_unknown_name=0)[source]

Classify a non-passing task into (failure_category, failure_detail).

failure_detail is a short token (predicate name / exception head), never free-form prose.

agora.observe.jsonl.derive_status(success, output)[source]

Map a task outcome to the TaskStatusLiteral vocabulary.

A task whose output begins with "ERROR: " is the orchestrator’s exception wrapper (the agent loop raised), classified "error"; otherwise a non-success is a clean "failed" (postconditions).

agora.observe.jsonl.git_commit_short(repo_dir=None)[source]

Best-effort HEAD short SHA; "unknown" if git is unavailable.

agora.observe.jsonl.profile_snapshot_from(profile)[source]

Build a ProfileSnapshot from a ModelProfile.

temperature and seed are read from the profile itself — the same values agora.fleet.profiles.build_llm_factory() threads into the Ollama options dict — so the recorded snapshot is a true record of what the daemon was told, not a caller-supplied annotation.

agora.observe.jsonl.query_ollama_version(base_url)[source]

Best-effort Ollama daemon version via /api/version; "unknown" on failure.

base_url is required (Q3: no config-shaped default outside Settings) — the caller passes the run’s resolved Ollama endpoint.

agora.observe.jsonl.scan_async_leaks(log_path)[source]

Count run-log lines matching any ASYNC_LEAK_MARKERS (grep -c).

Returns 0 when no log path was wired or the file is unreadable.