aeat.application.diagnostics_run_health module¶
Local-only run-health diagnostics: LLM run timing plus auth-session staleness.
Folds two existing local-only signals into one typed operator-facing report so a slow LLM-backed classification run or a stale/expired persisted AEAT auth session is diagnosable without leaving the host:
LLMRunTelemetryRecorderrecords duration/outcome metadata for every LLM classification, split-proposal, and completion run (seeLLMClientand_llm_classification); andtest_operator_auth()reports whether an encrypted AEAT session token is present on disk and whether it has passed its idle deadline.
Nothing here performs a network call or a live AEAT read: the LLM run records
are read from encrypted local secure-object storage and the auth probe reads
only the locally persisted session token’s metadata. This backs the
aeat app diagnostics run-health operator surface (GitHub issue #407).
list_recent_runs() projects the same recorded LLMRunRecord rows
individually (most-recent-first, optionally limited) rather than aggregated
per-provider, backing the sibling aeat app diagnostics runs listing verb
(also GitHub issue #407). It reuses
load_records()
directly – there is no parallel capture or storage path here.
build_latency_report() and build_error_breakdown() project the
same recorded rows into a percentile-latency view and a failed-run
error-kind breakdown, backing the aeat app diagnostics latency and
aeat app diagnostics errors verbs (also GitHub issue #407). Neither
introduces a new capture or storage path – both read
load_records()
exactly as run-health and runs do, honouring
composition-service-no-parallel-write-path.
build_llm_usage_report() projects the same recorded rows into a
run-count/duration/success-rate summary grouped by provider AND by model,
backing the aeat app diagnostics llm-usage verb (also GitHub issue #407).
LLMRunRecord carries only timing and
outcome metadata – no token counts are recorded on this store – so the
usage summary reports run counts, durations, and success rate rather than
token/cost figures (those are covered by the separate
build_llm_diagnostics_report()
usage/cost/confidence report, which folds the distinct completion-call
UsageRecord log). This report again
reuses load_records()
directly – there is no parallel capture or storage path here either.
See also
LLMRunTelemetryRecorderLocal encrypted recorder that supplies every run row this module reads.
LLMRunRecordTiming/outcome-only record projected into each diagnostic report.
test_operator_auth()Local auth-session probe folded into the run-health report.
_app_diagnosticsCLI transport for the run-health, runs, latency, errors, and llm-usage verbs.
diagnostics_telemetryRemote-telemetry posture/flush service that reuses the aggregate LLM-run signal without widening the payload.
- class LlmRunProviderMetrics(**data)[source]¶
Bases:
BaseModelPer-provider aggregate of recent local LLM run-timing telemetry.
Aggregated from
LLMRunRecordrows for a singleprovider. Carries only timing and outcome metadata – never prompt or response text.- Parameters:
- provider: str¶
- runs: int¶
- succeeded: int¶
- failed: int¶
- min_duration_ms: int | None¶
- max_duration_ms: int | None¶
- mean_duration_ms: Decimal | None¶
- class RunHealthReport(**data)[source]¶
Bases:
BaseModelTyped local-only run-health report: LLM run timing plus auth staleness.
Produced by
build_run_health_report().has_run_dataisFalsewhen no LLM run telemetry has been recorded yet, so callers can print an instructive empty message. The auth section always carries a verdict (a fresh profile with no configured provider still reportspersisted_session_present = False).- Parameters:
since (date | None)
until (date | None)
llm_providers (tuple[LlmRunProviderMetrics, ...])
total_runs (int)
total_succeeded (int)
total_failed (int)
auth_provider (str)
auth_configured (bool)
persisted_session_present (bool)
persisted_session_expired (bool | None)
persisted_session_state (str)
probe_summary (str)
- since: date | None¶
- until: date | None¶
- llm_providers: tuple[LlmRunProviderMetrics, ...]¶
- total_runs: int¶
- total_succeeded: int¶
- total_failed: int¶
- auth_provider: str¶
- auth_configured: bool¶
- persisted_session_present: bool¶
- persisted_session_expired: bool | None¶
- persisted_session_state: str¶
- probe_summary: str¶
- build_run_health_report(*, since=None, until=None, provider=None, run_telemetry_recorder=None, auth_probe=None)[source]¶
Aggregate local LLM run telemetry and the auth-session probe into one report.
- Parameters:
since (
date|None) – Inclusive lower date bound on run records, orNone.until (
date|None) – Inclusive upper date bound on run records, orNone.provider (
str|None) – Optional LLM run-record provider label filter (e.g."llm:claude:sonnet","claude"); scopes ONLY the LLM run-timing section. This is distinct from an AEAT auth provider name – the auth-session probe always auto-resolves its provider from workflow state (seeauth_probebelow) and never receives this filter.run_telemetry_recorder (
LLMRunTelemetryRecorder|None) – Injected recorder (dependency injection for tests); defaults to the active-bucketLLMRunTelemetryRecorder.auth_probe (
AuthTestResult|None) – InjectedAuthTestResult(dependency injection for tests); defaults to a fresh call totest_operator_auth()with no provider override, so it reports whatever AEAT auth provider is configured in workflow state (or “none configured”).
- Return type:
- Returns:
The populated
RunHealthReport.
- class RunRecordView(**data)[source]¶
Bases:
BaseModelOne individual local LLM run-timing record, as reported to an operator.
Mirrors
LLMRunRecordfield-for-field; carries only accounting/timing metadata, never prompt or response text.- Parameters:
- run_id: str¶
- caller: str¶
- provider: str¶
- model: str¶
- duration_ms: int¶
- succeeded: bool¶
- error_kind: str¶
- started_at: datetime¶
- list_recent_runs(*, since=None, until=None, provider=None, limit=None, run_telemetry_recorder=None)[source]¶
Return recent local LLM run-timing records, most-recent-first.
Reuses
load_records()directly – the same recorderbuild_run_health_report()reads – so there is no parallel capture or storage path for this listing.- Parameters:
since (
date|None) – Inclusive lower date bound on run records, orNone.until (
date|None) – Inclusive upper date bound on run records, orNone.provider (
str|None) – Optional provider label filter;Nonereturns every provider.limit (
int|None) – Optional cap on the number of most-recent rows returned;Nonereturns every matching record.run_telemetry_recorder (
LLMRunTelemetryRecorder|None) – Injected recorder (dependency injection for tests); defaults to the active-bucketLLMRunTelemetryRecorder.
- Return type:
- Returns:
Matching
RunRecordViewrows ordered most-recent-first (ties broken byrun_iddescending, mirroring the recorder’s own stable ascending order reversed).
- class LatencyPercentiles(**data)[source]¶
Bases:
BaseModelPercentile and summary latency statistics over a set of run durations.
Percentiles are computed with the nearest-rank method (ceil(p * n / 100), 1-indexed into the ascending-sorted duration list) – a deterministic, interpolation-free method whose outputs always equal a recorded duration value. Populated only when at least one duration is present;
entriesis0(all other fields absent) for an empty input.- Parameters:
- entries: int¶
- min_duration_ms: int | None¶
- max_duration_ms: int | None¶
- mean_duration_ms: Decimal | None¶
- p50_duration_ms: int | None¶
- p95_duration_ms: int | None¶
- p99_duration_ms: int | None¶
- class LatencyReport(**data)[source]¶
Bases:
BaseModelTyped local-only latency report: overall plus optional per-provider percentiles.
Produced by
build_latency_report().by_provideris populated only when the caller did not scope the query to a singleproviderfilter (a single-provider query makesoveralland the sole provider row redundant).- Parameters:
since (date | None)
until (date | None)
provider (str | None)
overall (LatencyPercentiles)
by_provider (tuple[tuple[str, LatencyPercentiles], ...])
- since: date | None¶
- until: date | None¶
- provider: str | None¶
- overall: LatencyPercentiles¶
- by_provider: tuple[tuple[str, LatencyPercentiles], ...]¶
- class ErrorKindCount(**data)[source]¶
Bases:
BaseModelOne
error_kindvalue’s failure count, optionally scoped to a provider.- error_kind: str¶
- provider: str¶
- count: int¶
- class ErrorsBreakdownReport(**data)[source]¶
Bases:
BaseModelTyped local-only breakdown of failed LLM runs by provider and error kind.
Produced by
build_error_breakdown(). Rows are sorted by descendingcount, then byprovider, then byerror_kindfor a stable presentation order.- Parameters:
- since: date | None¶
- until: date | None¶
- provider: str | None¶
- total_runs: int¶
- total_failed: int¶
- by_error_kind: tuple[ErrorKindCount, ...]¶
- build_latency_report(*, since=None, until=None, provider=None, run_telemetry_recorder=None)[source]¶
Aggregate recorded run durations into overall and per-provider percentiles.
Reuses
load_records()directly – the same recorderbuild_run_health_report()andlist_recent_runs()read – so there is no parallel capture or storage path for this report.- Parameters:
since (
date|None) – Inclusive lower date bound on run records, orNone.until (
date|None) – Inclusive upper date bound on run records, orNone.provider (
str|None) – Optional provider label filter; when supplied,overallreflects only that provider’s runs andby_provideris left empty (a single-provider breakdown would duplicateoverall).run_telemetry_recorder (
LLMRunTelemetryRecorder|None) – Injected recorder (dependency injection for tests); defaults to the active-bucketLLMRunTelemetryRecorder.
- Return type:
- Returns:
The populated
LatencyReport.
- build_error_breakdown(*, since=None, until=None, provider=None, run_telemetry_recorder=None)[source]¶
Group failed recorded runs by provider and
error_kind.Reuses
load_records()directly – the same recorder every sibling diagnostics report reads – so there is no parallel capture or storage path for this report.- Parameters:
since (
date|None) – Inclusive lower date bound on run records, orNone.until (
date|None) – Inclusive upper date bound on run records, orNone.provider (
str|None) – Optional provider label filter;Nonebreaks down every provider’s failures.run_telemetry_recorder (
LLMRunTelemetryRecorder|None) – Injected recorder (dependency injection for tests); defaults to the active-bucketLLMRunTelemetryRecorder.
- Return type:
- Returns:
The populated
ErrorsBreakdownReport.
- class LlmUsageModelMetrics(**data)[source]¶
Bases:
BaseModelOne provider’s per-model aggregate of recent local LLM run telemetry.
Aggregated from
LLMRunRecordrows sharing a single provider (recorded on the owningLlmUsageProviderMetrics) ANDmodel. Carries only run-count, duration, and outcome metadata –LLMRunRecordrecords no token counts, so this is a run/timing/success-rate summary, not a token-usage summary.- Parameters:
- model: str¶
- runs: int¶
- succeeded: int¶
- failed: int¶
- min_duration_ms: int | None¶
- max_duration_ms: int | None¶
- mean_duration_ms: Decimal | None¶
- total_duration_ms: int¶
- class LlmUsageProviderMetrics(**data)[source]¶
Bases:
BaseModelOne provider’s aggregate of recent local LLM run telemetry, plus its per-model rows.
modelsbreaks the same provider-scoped records down further bymodel, so an operator can see which model within a provider drives run volume, duration, or failures.- Parameters:
- provider: str¶
- runs: int¶
- succeeded: int¶
- failed: int¶
- min_duration_ms: int | None¶
- max_duration_ms: int | None¶
- mean_duration_ms: Decimal | None¶
- total_duration_ms: int¶
- models: tuple[LlmUsageModelMetrics, ...]¶
- class LlmUsageReport(**data)[source]¶
Bases:
BaseModelTyped local-only LLM usage summary: run counts, durations, and success rate.
Produced by
build_llm_usage_report(). Groups the same recordedLLMRunRecordrowsbuild_run_health_report()reads by provider (by_provider), each provider row carrying its own per-model breakdown (models).has_run_dataisFalsewhen no LLM run telemetry has been recorded yet.- Parameters:
- since: date | None¶
- until: date | None¶
- by_provider: tuple[LlmUsageProviderMetrics, ...]¶
- total_runs: int¶
- total_succeeded: int¶
- total_failed: int¶
- build_llm_usage_report(*, since=None, until=None, provider=None, run_telemetry_recorder=None)[source]¶
Aggregate recorded LLM run telemetry into a usage summary by provider and model.
Reuses
load_records()directly – the same recorder every sibling diagnostics report reads – so there is no parallel capture or storage path for this report (composition-service-no-parallel-write-path).LLMRunRecordcarries no token counts, so this is a run-count/duration/success-rate summary rather than a token-usage summary.- Parameters:
since (
date|None) – Inclusive lower date bound on run records, orNone.until (
date|None) – Inclusive upper date bound on run records, orNone.provider (
str|None) – Optional provider label filter;Noneaggregates every provider.run_telemetry_recorder (
LLMRunTelemetryRecorder|None) – Injected recorder (dependency injection for tests); defaults to the active-bucketLLMRunTelemetryRecorder.
- Return type:
- Returns:
The populated
LlmUsageReport.