Operational analytics and telemetry
Operational analytics is the product telemetry layer for OpenSRE. It records investigation work, agent and gateway turns, integration setup, prompt turns, selected user workflow milestones, hosted gateway activity, remote repair progress, and the user context behind each action. The layer builds stable and safe event properties, then sends them to a first-party analytics service outside the main product work path.
Telemetry scope
The analytics system turns product actions into lifecycle events. These events describe product use, operational health, and selected workflow exposure. They are not a complete audit record or an inventory of configured services.
The capture API also records selected access and workflow milestones. Sign-in and onboarding choices, skill and update use, hosted gateway and CI-repair milestones, commit activity, and secret-detection outcomes help product analysis measure exposure and safety without turning telemetry into a record of raw user input.
Investigation and turn telemetry
Investigation analytics is expressed through terminal action events, bounded ReAct turn events, agent tool-call events, Ask User events, and selected workspace and repository milestones. These signals show planned work, executed work, action success, tool outcomes, model context, and the reason a turn stopped. Tool-call failures can include a redacted and capped error description, while arguments and result evidence stay outside the event. Ask User events add a bounded view of prompt exposure and response disposition.
The turn contract keeps partial work when an agent stops because of an error or cancellation. This lets operational analysis distinguish normal completion from a limit, a failure, rejected tool execution, or work that needed no tools. When a turn runs inside a scheduled tick, the event can also carry the scheduled task ID so the investigation is linked to the loop that produced it.
References: infrastructure/…/events.py• L49-71 infrastructure/…/capture.py• L291-400 infrastructure/…/capture.py• L437-501 infrastructure/…/react_turn.py• L93-171 infrastructure/…/scheduled_task_attribution.py• L1-19
Prompt and response records
Prompt recording follows one conversational turn from its start to its final response or error. A recorder gives the turn a stable turn ID and joins it to the CLI session, then sends sanitized prompt and response text to the enabled local, session, and AI-analytics sinks.
The record also carries model and provider identity, latency, token counts, turn kind, and structured error state when available. It can include the system prompt, loaded skill text, prompt context, and prompt block sizes when the caller provides them. These fields are redacted, capped, or reduced to sizes so they fit the event budget. A scheduled task ID is captured when the turn starts inside a scheduled trace, which keeps delayed background work tied to its task.
Background CLI work has its own recorder. It starts when the task launches and flushes when the watcher knows the task outcome, so its latency and result belong to the task rather than to the earlier interactive turn. Its task ID is used as the turn ID so task views and prompt analytics can be joined.
At flush time, analytics always receives a response field. If no model response exists, the analytics record uses bounded synthetic text, while the session record receives no reply-less assistant turn. This keeps analytics rows complete without feeding invented assistant text back into a later /resume conversation. The event also distinguishes captured output, an error response, and synthetic output, and separates a completed, cancelled, failed, or unknown turn.
Terminal work without a conversational model uses a separate marker from a model call that failed before its provider was known. Operational analysis therefore does not count the two cases as the same kind of turn.
References: infrastructure/…/lifecycle.py• L21-88 infrastructure/…/model_prompt.py• L12-43 infrastructure/…/recorder.py• L100-140 infrastructure/…/recorder.py• L245-300 infrastructure/…/recorder.py• L320-361 infrastructure/…/recorder.py• L363-501 infrastructure/…/recorder.py• L504-555 infrastructure/…/scheduled_task_attribution.py• L13-19
Integration lifecycle
Integration telemetry describes the setup funnel. It records when setup starts and completes, when a service is listed or removed, when verification succeeds, and when the GitHub connection state is sampled. The service name and CLI session make these events useful for support and funnel analysis.
These events describe integration use and setup progress. They do not replace the web application as the source of truth for the configured integration inventory.
References: infrastructure/…/events.py• L41-48 infrastructure/…/capture.py• L241-258 infrastructure/…/event_properties.py• L60-65 infrastructure/…/README.md• L180-187
Agent and gateway turns
Agent turn telemetry measures the bounded ReAct work that supports action selection and evidence gathering. Each event reports its phase, work count, cap state, stop reason, tool-call count, duration, model context, and links to the surrounding CLI turn when those links exist.
Gateway turn telemetry measures chat work on Slack, Telegram, Discord, or Buzz. It records the usage surface, duration, answer state, final intent on success, and error type on failure. A failed gateway turn still produces telemetry when its transport context is incomplete. Hosted gateway task submission and remote CI repair milestones extend this view across the boundary between the signed-in shell and the gateway that performs the work.
Hosted gateway telemetry marks prompt submission, gateway startup, and health checks. The same capture vocabulary joins remote CI repair milestones, so a repair run ID links the accepted work, the failing test, the remote repair attempt, and the successful repair across the surfaces that handle them.
References: infrastructure/…/capture.py• L144-222 infrastructure/…/capture.py• L874-954 infrastructure/…/events.py• L53-75 infrastructure/…/events.py• L107-115 infrastructure/…/react_turn.py• L143-171 infrastructure/…/README.md• L188-205
Scheduled task attribution
Scheduled task attribution links turn-level telemetry to the scheduled task whose tick is running. The scheduler places the task ID in the current trace session before it starts work, and prompt and ReAct telemetry read that context without changing their normal turn contracts.
This link distinguishes scheduled automation from interactive work and lets analysts follow one task through its model turns and outcomes. Outside a scheduled tick, the attribution is absent rather than guessed.
References: infrastructure/…/scheduled_task_attribution.py• L1-19 infrastructure/…/react_turn.py• L143-160 infrastructure/…/recorder.py• L123-127 infrastructure/…/README.md• L189-200
User and surface context
User context attaches an event to the usage channel and the logical session that produced it. A usage surface is the channel such as CLI, Slack, Telegram, Discord, Buzz, or a prompt sent from a signed-in shell to the hosted gateway. A session ID joins related agent work without using the separate PostHog web session concept.
When known, the system adds the platform user ID and organization ID. Slack user and team IDs remain separate fields so transport identity does not get confused with an OpenSRE account. Organization context also maps the event to the PostHog organization group. Context is bound for a process, gateway turn, or interactive-shell turn, then inherited by captures in that scope. A prompt turn ID provides a finer link between the prompt record and related ReAct telemetry.
CLI events can derive their session from the active turn, interactive shell, or process. This fallback keeps one-shot commands attributable without making gateway turns share the CLI process session.
Explicit event values take precedence over bound context. This lets a gateway or integration action use its precise surface or session while still inheriting the process defaults for fields it does not set.
References: infrastructure/…/usage_context.py• L32-57 infrastructure/…/usage_context.py• L70-115 infrastructure/…/usage_context.py• L134-187 infrastructure/…/usage_context.py• L190-212 infrastructure/…/provider.py• L885-922
Event property model
Event properties provide the dimensions needed to understand a product action without sending raw command input or secrets. Builders create properties for a particular event. The capture layer then adds shared runtime and usage context before it queues the event.
Environment and command dimensions
Runtime classification marks test, CI, container, and local activity. The event carries a coarse execution environment such as local, ci, container, or ci_container, plus CI and container flags. Unknown inspection results remain unknown instead of becoming a false local or non-CI result. This lets product analysis separate real use from automated or container-based traffic without creating a separate event format.
Distribution classification describes the code loaded by the process. It distinguishes source checkout, editable package, installed package, and frozen binary. A packaged or frozen form does not prove publisher provenance, and a local environment does not prove human use.
CLI invocation properties describe command shape and display choices. They record entry points, command names, terminal state, and safe boolean flags only. Raw argument values, paths, URLs, and secrets stay outside the event. Install events add bounded source, channel, version, and distribution dimensions when an installer provides them.
The install path also records the state of the pre-install marker. This lets later runtime events distinguish an installer observation from a normal existing-install start without treating a missing marker as proof of first-ever use.
References: infrastructure/…/provider.py• L819-840 infrastructure/…/provider.py• L897-921 infrastructure/…/event_properties.py• L104-124 infrastructure/…/event_properties.py• L127-171 infrastructure/…/README.md• L85-138
Onboarding and integration properties
Onboarding completion properties capture the selected wizard mode, target, and local model settings when those values are present. Integration lifecycle properties carry the service name and the active CLI session.
These builders accept only useful non-empty values. Missing configuration does not become placeholder data, which keeps event queries focused on known choices.
References: infrastructure/…/event_properties.py• L34-65 infrastructure/…/capture.py• L229-258
Duration and success buckets
Turn and action events use bounded categories for duration, percentage, and stop reason. These categories support rates and trend views without making fine-grained values part of the product contract.
Terminal action events retain planned and executed counts. Summary events also retain session-level fallback and action-success buckets so analysts can compare a single turn with its wider session. Numeric values are kept in a provider-compatible form, while nested JSON is allowed for structured AI and prompt properties.
References: infrastructure/…/event_properties.py• L68-89 infrastructure/…/capture.py• L291-433 infrastructure/…/provider.py• L767-813
Identity attribution
Identity attribution gives events a stable install-level identity first, then adds known person and organization context when it becomes available. This supports anonymous product measurement while allowing authenticated use to join to a person profile or organization group.
Anonymous install identity
Every enabled analytics process uses an anonymous distinct ID that is meant to remain stable for an installation. The ID is loaded from the local OpenSRE configuration area or created when needed. If local storage cannot provide a stable ID, telemetry uses an ephemeral ID and records the persistence state.
The provider also sends a one-way composite fingerprint that helps identify repeated runtime use without sending its raw host, user, or CI inputs. A one-time insert ID prevents repeated process starts from counting as repeated installs. Anonymous install counts remain directional because a public client cannot keep its signing secret from the machine owner.
The first sanitized installation observation is persisted before delivery and retained after acknowledgement. Concurrent processes share the first complete observation, so a later retry does not replace its event time or install dimensions. The installer records a bounded marker observation for later runtime context. It writes that state without blocking the install, so an unreadable marker becomes unknown rather than changing the product's install behavior.
References: infrastructure/…/provider.py• L145-168 infrastructure/…/provider.py• L319-394 infrastructure/…/provider.py• L410-455 infrastructure/…/provider.py• L880-939 infrastructure/…/provider.py• L1151-1177 infrastructure/…/METRICS.md• L3-12
Authenticated identity
Signed-in CLI traffic uses a personal bearer so the web application can resolve the account and organization. Silo traffic uses an organization bearer assertion without resolving a Clerk user. Anonymous traffic establishes neither identity, and a chat actor ID is not an OpenSRE account ID.
A saved GitHub username is re-attached when the interactive shell starts. The identity helper sends it both as a person-profile update and as a persistent event property. The two forms serve different query needs: one supports person and cohort views, while the other supports direct event filters.
The username is best-effort and empty values do not create an identity update. A telemetry or storage error does not block the shell.
References: infrastructure/…/README.md• L18-36 infrastructure/…/provider.py• L941-999 infrastructure/…/METRICS.md• L3-7
Organization attribution
An organization ID is copied into event properties when the active context knows it. The provider also creates or reuses the matching organization group so CLI and gateway activity can align with web product views.
Personal events use organization identity resolved from the bearer. Silo events use the authenticated runtime assertion. Caller-provided organization and surface values take precedence when an event has a more precise value. The provider identifies each organization group once per process and destination.
References: infrastructure/…/README.md• L25-31 infrastructure/…/provider.py• L1001-1061 infrastructure/…/usage_context.py• L155-196 infrastructure/…/METRICS.md• L29-40
Runner provenance
Runner provenance adds controller evidence to workloads started by GitHub Actions. The launcher creates a fresh installation profile, places short-lived evidence in a renewable context, and gives the child workload no authority to mint new runner credentials. The resulting manifest records run metadata without credentials.
Ingestion can verify the signed runner evidence against the installation identity, repository, and job context. Until that verification succeeds, events keep reported or unknown automation status. CI detection alone is not proof of runner ownership, and runner verification does not grant account or organization access.
References: infrastructure/…/RUNNERS.md• L1-35 infrastructure/…/runner_launcher.py• L25-73 infrastructure/…/runner_launcher.py• L93-160 infrastructure/…/runner_provenance.py• L19-85
Capture and delivery
Capture is a best-effort boundary between product activity and the analytics transport. Product code calls named capture functions. Those functions build the event contract, while the provider merges shared context, validates property values, and sends the result outside the main product action.
The following flow shows how a product action becomes an attributed analytics event or a prompt-turn record.
flowchart TD
action[Product action] --> builder[Event property builder]
builder --> capture[Named capture function]
prompt[Prompt turn] --> recorder[Prompt recorder]
recorder --> local_prompt[Optional local prompt log]
recorder --> session[Session turn detail]
recorder --> ai[Optional AI generation event]
context[Usage and runtime context] --> merge[Context merge]
capture --> merge
merge --> validate[Property validation]
validate --> queue[Bounded event queue]
queue --> send[First-party analytics ingest]
queue --> local[Optional local event log]
validate --> failure[Failure breadcrumb]
Analytics destination
The analytics destination selects the first-party web application endpoint for each process. A hosted organization silo uses its configured app origin. A signed-in personal CLI uses its saved account origin. Other traffic uses the configured app URL or the public default. Authenticated requests carry a bearer and are signed, while anonymous use has no authorization header.
An explicit but unsafe or incomplete destination disables delivery rather than sending data to an unknown host. The provider resolves the destination when its process-level analytics instance starts. Account authentication can refresh that destination in the same process, so later events use the new account state without changing the capture API.
References: infrastructure/…/README.md• L5-36 infrastructure/…/provider.py• L844-870 infrastructure/…/provider.py• L954-970
Privacy and property safety
The property model accepts JSON-safe values and drops unsupported values before delivery. Numbers are converted to strings for the provider contract. Missing values are omitted instead of represented by placeholder data. The event body has a fixed size limit, so an oversized event is rejected before network delivery.
Command telemetry has an explicit safe boundary around raw arguments. Tool arguments and results are not included. Tool-call error descriptions, Ask User questions, and custom answers are redacted and bounded before capture, while listed answers use option indexes. Browser-open telemetry records only its target category and open outcome, not the URL. Prompt, response, and model-context text is also redacted and capped before it reaches a local prompt record or AI-generation event. Scheduled loop prompts, reports, and run records are user content and use the same bounded, redacted treatment. Error text written to the local failure log is scrubbed of home-directory names and capped in length.
References: infrastructure/…/capture.py• L437-620 infrastructure/…/capture.py• L690-729 infrastructure/…/provider.py• L767-801 infrastructure/…/provider.py• L1183-1251 infrastructure/…/recorder.py• L154-179 infrastructure/…/recorder.py• L500-555 infrastructure/…/README.md• L250-278
Delivery resilience
Events enter a bounded queue and a daemon worker sends them with a short network timeout. A full queue, provider error, oversized payload, or shutdown can lose telemetry, but it does not fail the user action. Failures are recorded through a compact local breadcrumb and may also reach Sentry.
The provider can make a short best-effort drain for one-shot work. Normal interpreter exit does not wait on network I/O, which keeps shell shutdown responsive. A local event log can help developers inspect sent event shapes and rotates at a fixed line limit. The first install observation is a separate immutable local record that protects the event from loss or replacement before delivery. Prompt recorder flushes and local prompt writes are also best effort, while the JSONL sink rotates its own file by size.
References: infrastructure/…/provider.py• L76-92 infrastructure/…/provider.py• L1063-1149 infrastructure/…/provider.py• L1183-1261 infrastructure/…/recorder.py• L343-501
Telemetry opt-out
Telemetry is disabled when a supported no-telemetry or do-not-track switch is set. In that state capture, identity updates, and group updates become no-ops, and destination credentials are not resolved. Product behavior can continue without analytics delivery.
Prompt recording has separate local and PostHog settings. The analytics opt-out stops the PostHog event path through the provider, while a local prompt log remains controlled by its own setting.
References: infrastructure/…/provider.py• L171-188 infrastructure/…/provider.py• L844-870 infrastructure/…/provider.py• L972-1017 infrastructure/…/recorder.py• L245-261 infrastructure/…/README.md• L250-254
Related operational systems
Operational analytics describes what happened during product use. The surrounding operational systems determine how work enters the product and how it reaches users.
- Operational automation describes the broader automation model that produces investigation and delivery work.
- Alert intake and scheduling describes alert arrival and scheduled work that can become analytics events.
- Delivery and deployment describes how the product is released and operated.
- GitHub CI repair automation describes a repair workflow whose investigation and commit activity can produce telemetry.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep event names and property keys aligned between events.py, capture.py, and the builders in event_properties.py. A renamed key can silently break dashboards and rate queries.
- Keep README.md and METRICS.md aligned with the event enum and the identity grain used by each metric. Personal users, gateway organizations, and runner installations must not be counted as the same type of actor.
- Preserve the terminal action, agent tool-call, and ReAct turn contracts when changing investigation paths. Analysts depend on counts, outcomes, stop reasons, and session links to compare work across turns.
- Emit one ReAct completion event for each agent run, including partial counts when an error or cancellation interrupts the run.
- Keep prompt recorder start, flush, session-detail, and AI-generation paths correlated by session ID and turn ID. A missing context binding can split one user turn into unrelated records.
- Keep background task recorder creation at launch and flush it with the task's final outcome. Its task ID must remain the correlation key rather than the earlier interactive turn.
- Keep synthetic analytics responses out of session conversation history. A missing model response must remain distinguishable from captured output without adding invented assistant text to
/resumecontext. - Preserve the distinction between terminal work with no conversational model and a conversational model that failed before provider resolution. Merging these labels changes failure and usage rates.
- Keep loop outcome, response-source, turn-outcome, and token-usage fields aligned with the prompt recorder's response and error state. Changing one without the others can misclassify failed or partial turns.
- Keep the scheduler's trace-session task ID available before scheduled turns start. ReAct and prompt records use that shared context to attribute work to the right task.
- Bind surface, session, user, and organization context at each new gateway or shell boundary. Context that is not bound can produce valid events that cannot be attributed.
- Keep Slack transport IDs separate from the general user ID when changing gateway identity handling. A transport actor is not automatically an OpenSRE account.
- Update both person identity and persistent event-property attribution when changing authenticated GitHub identity handling. They support different query paths.
- Keep install-marker snapshots separate from the durable install marker and the immutable install observation. Do not infer first-ever use from a missing snapshot or replace the first persisted installation event with a later reinstall.
- Keep runner context tied to the installation ID and use renewable short-lived evidence. Do not pass controller token-minting authority into a child workload or treat CI detection as verified ownership.
- Keep destination resolution aligned with account state, request signing, and the schema version. An explicit invalid endpoint or missing credential must fail closed instead of redirecting telemetry to an unintended service.
- Keep new event properties inside the provider's serializable, size-limited, and privacy-safe value rules. Raw command arguments, tool data, secrets, and unbounded prompt or error text must not enter telemetry.
- Keep new event names accepted by the webapp before distributing a client that emits them. Dynamic CLI command names and enum events are validated at ingest.
- Keep new lifecycle events in the event inventory and metric definitions. A vocabulary change without downstream definitions can make events valid but absent from product measures.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Analytics queue reaches its fixed capacity | The event is dropped and the product action continues without that telemetry | _enqueue records a queue-full failure and reports it without raising to the caller |
| Local anonymous ID is missing, invalid, or unreadable on an existing install | Events can use a new non-persistent identity and may split install history | The provider records user_id_load_failed context and reports the persistence state with the event |
| A caller supplies an unsupported property value | That property is omitted and capture remains non-fatal | Property coercion accepts JSON-safe values and records an invalid-property breadcrumb |
| A gateway failure has no bound surface | The failure event arrives but cannot be sliced by transport | The capture contract records surface_missing while preserving the failure event |
| A scheduled tick starts without its task ID in trace metadata | ReAct and prompt telemetry remains valid but cannot be joined to the scheduled task | The scheduler binds the task ID before work starts and attribution returns no guessed ID outside a tick |
| An agent stops with an error or cancellation after partial work | Without partial telemetry, analysts may count the run as missing or successful | The ReAct wrapper builds a partial result and emits one completion event with a stop reason |
| A background task recorder is not created at launch or is flushed before the watcher knows the outcome | Task latency, output, and error state can be absent or attributed to the originating turn | The task owns a recorder from launch through watcher completion and uses the task ID as its turn ID |
| A prompt turn has no model response and its synthetic analytics response is written to the session | /resume can feed invented assistant text back to the model as conversation history | The recorder uses synthetic text only for analytics and appends a session turn only when a genuine response or error exists |
| A prompt recorder cannot start or flush | The turn continues but its prompt, response, or AI-generation record can be absent | Recorder setup and flush are isolated from the host turn, and the active context is reset on exit |
| A conversational model fails before its identity is known | The failed call can be misread as terminal work with no conversational agent | The recorder uses unknown for attempted provider failures and a separate sentinel for terminal work |
| A runner context is missing, mismatched, expired, or invalid | Automation remains unverified or unknown and cannot support trusted runner metrics | The launcher binds evidence to a fresh installation, while ingestion verifies the signed context before upgrading status |
| An event exceeds the ingest body limit | The event is not delivered to the analytics service | The provider checks the serialized payload against ANALYTICS_MAX_PAYLOAD_BYTES before sending |
| The analytics destination is unsafe, incomplete, or unavailable | Events remain local and are not delivered to the product analytics service | Destination resolution validates the origin and required credential before the provider sends a request |
| Telemetry delivery or shutdown waits on the network | Analytics could slow or block a user command | The worker uses a short send timeout and shutdown has a bounded best-effort flush |
| Anonymous install data is used as trusted human acquisition data | Machine owners can alter counts and distort conversion measures | Exclude CI and use server-verified personal-bearer linkage for account metrics |
| Concurrent install processes produce different observations | Install source, time, or deduplication data can vary between retries | The persisted sanitized observation is locked, atomically written, and retained as the first complete event |
| A gateway turn binds only a general user ID and loses Slack identity fields | Transport-level usage cannot be joined reliably to Slack workspace context | The usage context keeps Slack user and team stamps as distinct optional fields |
| A client emits an event name that the webapp does not accept | The event is rejected or cannot enter downstream product measures | Keep the client event enum and webapp validation and inventory in sync before release |
Key files
| File | Why to read it |
|---|---|
| infrastructure/…/events.py | Defines the product event vocabulary and lifecycle groups |
| infrastructure/…/capture.py | Shows the public capture contracts and the main event property shapes |
| infrastructure/…/event_properties.py | Explains how install, onboarding, integration, duration, and CLI properties are built |
| infrastructure/…/README.md | Defines the ingest contract, identity meaning, event inventory, and product metric rules |
| infrastructure/…/METRICS.md | Defines the acquisition, usage, reliability, and latency measures over the event stream |
| infrastructure/…/RUNNERS.md | Defines the trusted launcher contract for GitHub workload telemetry |
| infrastructure/…/analytics_runtime.py | Defines the CI and container dimensions used to classify runtime traffic |
| infrastructure/…/distribution.py | Defines how the loaded code is classified independently of its execution environment |
| infrastructure/…/usage_context.py | Defines surface, session, user, organization, and Slack transport attribution |
| infrastructure/…/provider.py | Explains identity, context merging, queue delivery, opt-out, local diagnostics, and failure handling |
| infrastructure/…/scheduled_task_attribution.py | Connects scheduler trace context to turn-level task attribution |
| infrastructure/…/runner_launcher.py | Shows how fresh runner profiles and renewable evidence reach child workloads |
| infrastructure/…/runner_provenance.py | Defines the boundary between reported runner context and ingestion-verified provenance |
| infrastructure/…/react_turn.py | Shows how bounded agent work becomes turn telemetry, including partial failures and scheduled task links |
| infrastructure/…/lifecycle.py | Defines the prompt-turn boundary and cleanup behavior around one agent turn |
| infrastructure/…/model_prompt.py | Shows how model context is gathered for a prompt record without changing the user turn contract |
| infrastructure/…/recorder.py | Defines prompt, response, model, loop-outcome, error, background-task, and sink-level turn records |
| surfaces/…/investigation_analytics.py | Connects terminal investigation outcomes to analytics |
| surfaces/…/integrations.py | Illustrates integration setup and verification telemetry at a user-facing boundary |