Observability and diagnostics

Part of the Workflow Modes reference.

Observability

  • Context budget: at session start, when the project instructions pi reads into every turn total more than 16 KiB, one warning names the total and the heaviest file — if that weight is status or history, it belongs in the tracker and the docs. Never a block; contextBudgetKiB (default 16, 0 off) widens it or turns it off. The files are pi’s context files (AGENTS.md and kin, the global one and one per directory from the root to the cwd), found by pi’s own loadProjectContextFiles, so the names and the walk follow pi. This package’s own .pi/gadhs-guidance.md is not counted.

  • Status line: 🤖 auto · 1 waiting on you · 1 blocked · Explore working · judge $0.012 (7) — the mode, unguarded when no judge guards it, the steps waiting on you, the steps blocked and the ones that asked you, how near the denial-loop limit is, the helpers working, the monitors, jobs and unread messages, and the helpers' and the judge’s spend, all in words. Segments vanish when zero; the model is deliberately absent (pi’s footer already shows it truthfully). On pi’s shared bus, so another extension (the pivot client, forwarding to a phone) can show what the footer shows without reaching into the TUI:

    Event Carries, and when

    gadhs:status

    { modeId, modeLabel, judgeEnabled, ruleCount, stats, text } — the structured input plus text, the line without colour; on every recompute, and once at session start for a late subscriber. The stats are a copy.

    gadhs:mode

    { from, to } — the moment a switch records the new mode, before its model and tools apply (the status that follows carries the applied state).

    gadhs:title

    { state, title } — idle | working | attention and the tab’s text; working includes a helper running with no turn (#786); on every change of either and once at start, on every host (a headless box has no tab but may have a phone).

    gadhs-hub:ask

    no payload — the hub opening (#545); an extension with facts answers at once on gadhs-hub:facts. pi’s bus is synchronous, so answers are in before the hub draws.

    gadhs-hub:facts

    { source, lines } — one extension’s lines for the hub’s Session tab, in answer to an ask. pi-ssh answers while the session has a remote, pi-remote while it has a link or a trusted device.

    gadhs-msg:received

    { space, channel, record: { id, re?, agent, handle?, subject, tags, sent, preview, cut }, from, ownBox, agent, wake, collect, mine, handle? } — an agent message pi-remote delivered to this session (#566): its headline and the body’s first 4 KB (preview, with cut when there is more), and this session’s agent with its subscription’s tags there. pi-modes wakes or collects.

    gadhs-msg:read

    { id } — this session’s agent read a message with msg_read; its headline stops counting as unread.

    gadhs:pending

    { steps: [{ id, shown, why?, full? }] } — every step still waiting on the human, oldest first (the widget’s order), on every change; an empty steps when it empties (#255). why is the step’s reason, omitted when there is none; full is the whole action when shown cut or reflowed it, absent when shown is all of it (#485). An approved step is not listed: it no longer waits (#369). The queue fills only in a mode that queues (pendingAsks: "queue"); a /pending action after a switch still changes it, and is published.

  • Inline traces: every non-allow decision renders in the transcript — policy BLOCKED bash — * | sh (red, will not reconsider) vs judge BLOCKED read (6.2s) — … (amber, an opinion). Expanded view states the remedy. Allows are not traced (~90 % of verdicts; they would bury the rest).

  • node tools/task.mjs verdicts [n] [--why]: the audit trail with the ask and the judge’s reason under each non-allow line.

  • The diagnostics stream (below): lifecycle, guard and run records, always on. pi itself has no logging facility.

Diagnostics

pi has no logging facility, and console.error is unusable under the TUI. The gadhs packages keep one diagnostics stream instead (#484). It is always on, so a rare bug leaves a trail without anyone having switched logging on before it happened.

  • Where. ~/.pi/agent/gadhs-diagnostics/log.jsonl, mode 0600 in a 0700 directory. Past 4 MiB it is renamed to log.jsonl.1 and a fresh file begun, so the stream never holds much more than 8 MiB.

  • What. One JSON object per line, each stamped ts, pid, started and cwd (the review log’s stamp, so the two join by eye), plus event and its details. The records cover mode and model application, session restore, guard decisions, plan reviews, helpers, dialogs, pi-remote’s link events, and:

    • session.start: the pi and pi-modes versions, model, mode, whether there is a UI, and the terminal (term, ssh, mux, and kitty, whether the kitty keyboard protocol is active).

    • run.settled: one per agent run, with whether it was aborted, how long it took (ms), how many assistant turns it had, and the last one’s stopReason and errorMessage. An aborted run’s record also carries input, the last 32 things the terminal sent as control sequences only (^[ for Escape, ^C, [I for a focus report; typed text and pastes as a length, never their content), and sinceEscapeMs / sinceCtrlCMs, how long before the run settled an Escape or Ctrl+C arrived. That is what tells an abort you pressed for from one nobody pressed for (#483).

    • ask.verdict and tool.ran: where a tool call’s time went (#586). ask.verdict, one per permission decision, carries gateMs, the gate’s own time from the ask to its verdict (a person’s wait excluded), and source, the stage that decided: about a millisecond for a rule, the judge’s round trip when it was the judge. tool.ran, one per call that ran, carries the tool’s own execution time (ms, pi’s monotonic measure), whether it failed, and nested for a call another tool made. For a remote session tool.ran is the transport, apart from the gate.

    • request.prefix_changed: a request to the model that did not start by repeating the previous request of the same session (#885). It names the first message that differs (firstChanged, its role, and the block and kind of its first differing block), or toolsChanged / systemChanged, with both requests' message counts. A request that only adds to the previous one writes nothing. The prompt cache charges for everything after the first difference, so this is where a miss within the cache’s lifetime is looked for: a miss with no such record was the provider’s. Messages are compared as short digests with the cache marks left out; no text is logged, and the previous request is held in memory only until the next.

    • remote.abort: a phone’s abort through pi-remote, with the device, written before the abort runs.

    • lone_escape.patch, lone_escape.rescued and mouse_tail.after_escape: the lone-ESC patch and the mouse-report guard (The lone-ESC patch).

    • pending.decided: your /pending approve or decline, with the step’s id, the action, its kind and its shown line (#675). The run an approval lets through is recorded as it happens, in the review log, as gadhs_pending.approved_by_command with the same id and the line as action.

    • escape_confirm.spared, escape_confirm.escape (with cause, timeout or key, and waitedMs) and escape_confirm.dropped: a lone ESC held while streaming, and what it turned out to be (Confirm before Escape acts).

  • What never. Typed text, paste bodies, prompts, file contents, tool output. Every string value is also scrubbed for token shapes (the ten that tool_result redaction catches) before it is written.

  • Reading it. /diag shows the last 20 records, one per line with the time in UTC, and the file’s path; /diag 100 shows 100 (at most 500); /diag path only the path. Paste it into a bug report. An agent asked to read the file directly goes through the judge, as for any file outside the workspace.

  • Turning it off, or elsewhere. GADHS_PI_DIAGNOSTICS=off turns it off; any other value is a path to write to instead, which is what tests and a focused bug hunt use. Records logged before a session opens the stream wait in memory (the last 200) and are written when it opens.

OpenTelemetry export

Every permission decision and every helper run can also go to an OpenTelemetry collector as a span (#272). It is off unless the standard variable names one: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (used as given) or OTEL_EXPORTER_OTLP_ENDPOINT (/v1/traces appended). With neither, nothing is built, no timer runs and no request leaves pi.

  • What. A decision is execute_tool <tool>, from the ask to the verdict (a person’s wait excluded). It carries the GenAI conventions' gen_ai.operation.name, gen_ai.tool.name and, for a helper’s step, gen_ai.agent.name, and our own gadhs.permission.verdict (allow, deny, defer), .source (rule, judge, valve, host, remote, pending and the rest), .channel (desk or phone, when a person decided), .pattern, .mode and .forwarded. A helper run is invoke_agent <agent>, from its launch to its end, with gadhs.helper.outcome (done or failed), .background, .yielded and .model. Every span carries session.id and gadhs.pi_modes.version (the emitting pi-modes' version); the resource’s service.name is pi, or OTEL_SERVICE_NAME. One trace per pi session. The gen_ai.* names are at the conventions' Development status, as read on 2026-11-01, and may be renamed upstream.

  • What never. A verdict’s reason, a helper’s task or yield, or a header value. The command or path goes out as gen_ai.tool.call.arguments only with OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT set (to anything but false).

  • How. OTLP over HTTP with JSON, batched: 64 spans, or whatever waited 5 s, per POST, with OTEL_EXPORTER_OTLP_TRACES_HEADERS, else OTEL_EXPORTER_OTLP_HEADERS (k=v,k2=v2), on each, and a 10 s timeout. At each session’s end what is queued is sent, bounded by the same 10 s. Past 512 queued spans the oldest are dropped and the count rides on the next batch (gadhs.otel.dropped). A failed POST drops its batch, and each distinct failure is one otel.export_failed diagnostics line, naming the collector’s host and the status, never a header. Nothing here waits on the collector: a span is a push onto a queue.

  • Refused. A protocol other than http/json (OTEL_EXPORTER_OTLP_PROTOCOL or _TRACES_PROTOCOL set to grpc or http/protobuf), or an endpoint that is not an http(s) URL: one otel.refused diagnostics line, and nothing is sent. OTEL_SDK_DISABLED=true turns it off.

  • Beside other OTel extensions. pi-modes registers no OpenTelemetry SDK, so an extension that does (pi-otel, for LLM requests and tokens) runs beside it and can send to the same collector. Join the two on session.id.

Pins: test/otel-export.test.ts (the wire format of both spans, batching and the timer, the queue’s bound, a shutdown during a flush, a failure said once, the environment contract, a collector on a socket, any ask encoded), and the wiring in test/judge-wiring-callback.test.ts, test/subagent-wiring.test.ts and test/session-wiring.test.ts.

Review-log events

Everything lands in the permission review log, stamped with mode and session identity (pid, started, cwd):

Event Meaning

gadhs_mode_rule.verdict

A deterministic rule fired (pattern, action, ask), including the outsideWrites stage (pattern: outside-write, #943)

gadhs_workspace_write.allow

Workspace-write stage allowed a path

gadhs_workspace_read.allow

Workspace-read stage allowed an in-tree read/grep/find/ls (tool, path)

gadhs_plain_line.allow

Plain-line stage allowed a bash line whose every command was cleared (ask, byRoster, byRule; #888)

gadhs_high_consequence.defer

Operator-configured pattern deferred to human

gadhs_plan_draft.allow

Plan-draft stage allowed a write to the plans directory (path)

gadhs_mode_judge.call

One model call made (model, wallMs, stopReason, usage) — what the cost line is built from; a call that ended in an error carries the provider’s message, its first 300 characters, as error (#871)

gadhs_mode_judge.auth_unresolved

The judge’s credentials could not be resolved (reason); the call proceeds without them and fails closed

gadhs_mode_judge.verdict

Judge verdict (raw, final, ask, reason in the judge’s own words, rule: the code of the rule a deny or defer named when the rubric holds it, else empty; ruleCited when the judge named a code the rubric does not hold, #946; humanReplied when it read the human’s reply)

gadhs_mode_judge.safety_valve

Valve capped an allow / deferred under yolo

gadhs_mode_judge.repair

An unreadable reply about to be asked again for the object alone (#294); text is the reply’s first 600 characters

gadhs_mode_judge.defer

Fail-safe defer (cause: timeout, unparseable…); an unparseable one, logged when the repair turn’s answer is unreadable too, carries that answer’s first 600 characters as text (#295); a bad_stop one whose call ended in an error carries the provider’s message as error, so a refusal, an overload and a timeout can be told apart afterwards (#871)

gadhs_mode_judge.threshold

Denial-loop guard tripped

gadhs_subagent_gate.verdict / .deny

Delegation gate decision (.deny carries cause, e.g. unparseable_spawn)

gadhs_host_ask.verdict

How a defer was settled beyond the gate (host, deferredBy, verdict, source, by, waitMs); a queued step has source: pending

gadhs_pending.answered

The judge read the human’s reply to a queued step (kind, verdict)

gadhs_pending.threshold_settled

The human’s reply ended a loop-guard wait

Edit this page · latest