cadrumo.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:
DiagnosticRunTelemetryPortsupplies duration/outcome metadata for every LLM classification, split-proposal, and completion run (seeLLMClientandllm_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.
list_recent_runs() projects the same recorded
DiagnosticRunRecord rows
individually (most-recent-first, optionally limited) rather than aggregated
per-provider, backing the sibling aeat app diagnostics runs listing verb.
It reads them through the injected diagnostic telemetry port – 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. Neither introduces a new capture or
storage path – both read through the diagnostic telemetry port exactly as
run-health and runs do, honouring aeat-architecture-boundaries.
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.
DiagnosticRunRecord 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
reads through the injected diagnostic telemetry port – there is no parallel
capture or storage path here either.
See also
DiagnosticRunTelemetryPortApplication-owned read contract that supplies every run row this module reads.
DiagnosticRunRecordTiming/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
DiagnosticRunRecordrows for a singleprovider. Carries only timing and outcome metadata – never prompt or response text.- Parameters:
- provider: str¶
- runs: NonNegativeInt¶
- succeeded: NonNegativeInt¶
- failed: NonNegativeInt¶
- 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_port, auth_probe_port)[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 and never receives this filter.run_telemetry_port (
DiagnosticRunTelemetryPort) – Injected diagnostic telemetry read port supplied by the outer composition root.auth_probe_port (
DiagnosticAuthProbePort) – Injected redacted auth-readiness probe supplied by the outer composition root.
- Return type:
- Returns:
The populated
RunHealthReport.
- class RunRecordView(**data)[source]¶
Bases:
BaseModelOne individual local LLM run-timing record, as reported to an operator.
Mirrors
DiagnosticRunRecordfield-for-field; carries only accounting/timing metadata, never prompt or response text.- Parameters:
- run_id: str¶
- caller: str¶
- provider: str¶
- model: str¶
- duration_ms: NonNegativeInt¶
- succeeded: bool¶
- error_kind: str¶
- started_at: datetime¶
- list_recent_runs(*, since=None, until=None, provider=None, limit=None, run_telemetry_port)[source]¶
Return recent local LLM run-timing records, most-recent-first.
Reads through the same injected diagnostic telemetry port
build_run_health_report()uses, 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_port (
DiagnosticRunTelemetryPort) – Injected diagnostic telemetry read port supplied by the outer composition root.
- 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_port)[source]¶
Aggregate recorded run durations into overall and per-provider percentiles.
Reads through the same injected diagnostic telemetry port
build_run_health_report()andlist_recent_runs()use, 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_port (
DiagnosticRunTelemetryPort) – Injected diagnostic telemetry read port supplied by the outer composition root.
- Return type:
- Returns:
The populated
LatencyReport.
- build_error_breakdown(*, since=None, until=None, provider=None, run_telemetry_port)[source]¶
Group failed recorded runs by provider and
error_kind.Reads through the same injected diagnostic telemetry port every sibling diagnostics report uses, 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_port (
DiagnosticRunTelemetryPort) – Injected diagnostic telemetry read port supplied by the outer composition root.
- 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
DiagnosticRunRecordrows sharing a single provider (recorded on the owningLlmRunHealthProviderMetrics) ANDmodel. Carries only run-count, duration, and outcome metadata –DiagnosticRunRecordrecords no token counts, so this is a run/timing/success-rate summary, not a token-usage summary.- Parameters:
- model: str¶
- runs: NonNegativeInt¶
- succeeded: NonNegativeInt¶
- failed: NonNegativeInt¶
- min_duration_ms: int | None¶
- max_duration_ms: int | None¶
- mean_duration_ms: Decimal | None¶
- total_duration_ms: int¶
- class LlmRunHealthProviderMetrics(**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: NonNegativeInt¶
- succeeded: NonNegativeInt¶
- failed: NonNegativeInt¶
- 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 recordedDiagnosticRunRecordrowsbuild_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[LlmRunHealthProviderMetrics, ...]¶
- total_runs: int¶
- total_succeeded: int¶
- total_failed: int¶
- build_llm_usage_report(*, since=None, until=None, provider=None, run_telemetry_port)[source]¶
Aggregate recorded LLM run telemetry into a usage summary by provider and model.
Reads through the same injected diagnostic telemetry port every sibling diagnostics report uses, so there is no parallel capture or storage path for this report (
aeat-architecture-boundaries).DiagnosticRunRecordcarries 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_port (
DiagnosticRunTelemetryPort) – Injected diagnostic telemetry read port supplied by the outer composition root.
- Return type:
- Returns:
The populated
LlmUsageReport.