Jonathan Haas commited on
Commit ·
39e5a0d
1
Parent(s): 6bf839c
Add taxonomy docs and richer telemetry error accounting
Browse filesFiles changed (5)
91 unmodified lines92939495969791 unmodified lines- Integration runbook: [`docs/operations/integration-policy.md`](docs/operations/integration-policy.md).- Release checklist: [`docs/operations/release-checklist.md`](docs/operations/release-checklist.md).- Security maintenance: [`docs/operations/security-maintenance.md`](docs/operations/security-maintenance.md).- Todoist integration:- `TODOIST_PERMISSION_PROFILE=readonly|control`- `readonly` allows `todoist_list_tasks` and denies `todoist_add_task`91 unmodified lines9293949596979891 unmodified lines- Integration runbook: [`docs/operations/integration-policy.md`](docs/operations/integration-policy.md).- Release checklist: [`docs/operations/release-checklist.md`](docs/operations/release-checklist.md).- Security maintenance: [`docs/operations/security-maintenance.md`](docs/operations/security-maintenance.md).- Error taxonomy: [`docs/operations/error-taxonomy.md`](docs/operations/error-taxonomy.md).- Todoist integration:- `TODOIST_PERMISSION_PROFILE=readonly|control`- `readonly` allows `todoist_list_tasks` and denies `todoist_add_task`
64 unmodified lines656667686970717273747576777864 unmodified lines## 4) Telemetry and Taxonomy (8 items)- [ ] `T01` Add taxonomy reference doc with each error code and owning tool families.- [ ] `T02` Add test asserting taxonomy doc examples stay in sync with constants.- [ ] `T03` Track unknown summary detail count in telemetry snapshot.- [ ] `T04` Add tests for unknown summary detail accounting.- [ ] `T05` Add explicit counter for per-code service error totals in telemetry snapshot.- [ ] `T06` Add tests for per-code aggregation stability.- [ ] `T07` Add NaN/inf guard tests for telemetry averages.- [ ] `T08` Add startup log line summarizing taxonomy sizes (service/storage subsets).Files: `src/jarvis/tool_errors.py`, `src/jarvis/__main__.py`, `tests/test_main_lifecycle.py`, `docs/operations/error-taxonomy.md`64 unmodified lines656667686970717273747576777864 unmodified lines## 4) Telemetry and Taxonomy (8 items)- [x] `T01` Add taxonomy reference doc with each error code and owning tool families.- [x] `T02` Add test asserting taxonomy doc examples stay in sync with constants.- [x] `T03` Track unknown summary detail count in telemetry snapshot.- [x] `T04` Add tests for unknown summary detail accounting.- [x] `T05` Add explicit counter for per-code service error totals in telemetry snapshot.- [x] `T06` Add tests for per-code aggregation stability.- [x] `T07` Add NaN/inf guard tests for telemetry averages.- [x] `T08` Add startup log line summarizing taxonomy sizes (service/storage subsets).Files: `src/jarvis/tool_errors.py`, `src/jarvis/__main__.py`, `tests/test_main_lifecycle.py`, `docs/operations/error-taxonomy.md`
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263# Error Taxonomy Reference
Canonical tool error taxonomy shared by service tools and telemetry.
## Ownership by Tool Family
| Error code | Owning tool families ||---|---|| `api_error` | `pushover_notify` || `auth` | `smart_home`, `smart_home_state`, `todoist_*`, `pushover_notify` || `cancelled` | `smart_home*`, `todoist_*`, `pushover_notify` || `http_error` | `smart_home*`, `todoist_*`, `pushover_notify` || `invalid_data` | `smart_home`, `task_plan_*`, `memory_*` || `invalid_json` | `smart_home*`, `todoist_*`, `pushover_notify` || `invalid_plan` | `task_plan_*` || `invalid_status` | `task_plan_update` || `invalid_steps` | `task_plan_create` || `missing_config` | `smart_home*`, `todoist_*`, `pushover_notify` || `missing_entity` | `smart_home_state` || `missing_fields` | `smart_home`, `todoist_add_task`, `pushover_notify` || `missing_plan` | `task_plan_*` || `missing_query` | `memory_search` || `missing_store` | `memory_*`, `task_plan_*` || `missing_text` | `memory_add` || `network_client_error` | `smart_home*`, `todoist_*`, `pushover_notify` || `not_found` | `smart_home*`, `task_plan_*` || `policy` | cross-cutting tool policy enforcement || `storage_error` | `memory_*`, `task_plan_*` || `summary_unavailable` | `tool_summary*`, `system_status` || `timeout` | `smart_home*`, `todoist_*`, `pushover_notify` || `unexpected` | cross-cutting runtime guard || `unknown_error` | fallback normalization bucket |
## Canonical Code Set (Machine-Checked)
Do not edit this list without updating `src/jarvis/tool_errors.py` and tests.
<!-- SERVICE_ERROR_CODES_START -->api_errorauthcancelledhttp_errorinvalid_datainvalid_jsoninvalid_planinvalid_statusinvalid_stepsmissing_configmissing_entitymissing_fieldsmissing_planmissing_querymissing_storemissing_textnetwork_client_errornot_foundpolicystorage_errorsummary_unavailabletimeoutunexpectedunknown_error<!-- SERVICE_ERROR_CODES_END -->192 unmodified lines19319419519619719819920065 unmodified lines2662672682692702713 unmodified lines2752762772782792801 unmodified line282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311192 unmodified lines"tts_first_audio_count": 0.0,"service_errors": 0.0,"storage_errors": 0.0,"fallback_responses": 0.0,}def start(self) -> None:"""Initialize all subsystems."""65 unmodified linesf"Persona style: {self.config.persona_style}",f"Config warnings: {warning_count}",f"Tool policy: allow={len(self.config.tool_allowlist)} deny={len(self.config.tool_denylist)}",]def _refresh_tool_error_counters(self) -> None:3 unmodified linesreturnservice_errors = 0storage_errors = 0for item in recent:if not isinstance(item, dict):continue1 unmodified linedetail = str(item.get("detail", ""))if status != "error":continueif detail in TELEMETRY_STORAGE_ERROR_DETAILS:storage_errors += 1continueif detail in TELEMETRY_SERVICE_ERROR_DETAILS:service_errors += 1self._telemetry["service_errors"] = float(service_errors)self._telemetry["storage_errors"] = float(storage_errors)def _telemetry_snapshot(self) -> dict[str, float]:def avg(total_key: str, count_key: str) -> float:count = self._telemetry.get(count_key, 0.0)if count <= 0:return 0.0return self._telemetry.get(total_key, 0.0) / countreturn {"turns": self._telemetry.get("turns", 0.0),"barge_ins": self._telemetry.get("barge_ins", 0.0),"avg_stt_latency_ms": avg("stt_latency_total_ms", "stt_latency_count"),"avg_llm_first_sentence_ms": avg("llm_first_sentence_total_ms", "llm_first_sentence_count"),"avg_tts_first_audio_ms": avg("tts_first_audio_total_ms", "tts_first_audio_count"),"service_errors": self._telemetry.get("service_errors", 0.0),"storage_errors": self._telemetry.get("storage_errors", 0.0),"fallback_responses": self._telemetry.get("fallback_responses", 0.0),}def stop(self) -> None:192 unmodified lines19319419519619719819920020120265 unmodified lines2682692702712722732743 unmodified lines2782792802812822832842851 unmodified line287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339192 unmodified lines"tts_first_audio_count": 0.0,"service_errors": 0.0,"storage_errors": 0.0,"unknown_summary_details": 0.0,"fallback_responses": 0.0,}self._telemetry_error_counts: dict[str, float] = {}def start(self) -> None:"""Initialize all subsystems."""65 unmodified linesf"Persona style: {self.config.persona_style}",f"Config warnings: {warning_count}",f"Tool policy: allow={len(self.config.tool_allowlist)} deny={len(self.config.tool_denylist)}",f"Error taxonomy: total={len(TOOL_SERVICE_ERROR_CODES)} service={len(TELEMETRY_SERVICE_ERROR_DETAILS)} storage={len(TELEMETRY_STORAGE_ERROR_DETAILS)}",]def _refresh_tool_error_counters(self) -> None:3 unmodified linesreturnservice_errors = 0storage_errors = 0unknown_summary_details = 0per_code: dict[str, float] = {}for item in recent:if not isinstance(item, dict):continue1 unmodified linedetail = str(item.get("detail", ""))if status != "error":continueif detail in TOOL_SERVICE_ERROR_CODES:per_code[detail] = per_code.get(detail, 0.0) + 1.0if detail in TELEMETRY_STORAGE_ERROR_DETAILS:storage_errors += 1continueif detail in TELEMETRY_SERVICE_ERROR_DETAILS:service_errors += 1continueunknown_summary_details += 1self._telemetry["service_errors"] = float(service_errors)self._telemetry["storage_errors"] = float(storage_errors)self._telemetry["unknown_summary_details"] = float(unknown_summary_details)self._telemetry_error_counts = {name: per_code[name] for name in sorted(per_code)}def _telemetry_snapshot(self) -> dict[str, float | dict[str, float]]:def metric(key: str) -> float:value = self._telemetry.get(key, 0.0)if not math.isfinite(value):return 0.0return valuedef avg(total_key: str, count_key: str) -> float:count = metric(count_key)if count <= 0.0:return 0.0total = metric(total_key)value = total / countif not math.isfinite(value):return 0.0return valuecounts = {name: valuefor name, value in getattr(self, "_telemetry_error_counts", {}).items()if math.isfinite(value)}return {"turns": metric("turns"),"barge_ins": metric("barge_ins"),"avg_stt_latency_ms": avg("stt_latency_total_ms", "stt_latency_count"),"avg_llm_first_sentence_ms": avg("llm_first_sentence_total_ms", "llm_first_sentence_count"),"avg_tts_first_audio_ms": avg("tts_first_audio_total_ms", "tts_first_audio_count"),"service_errors": metric("service_errors"),"storage_errors": metric("storage_errors"),"unknown_summary_details": metric("unknown_summary_details"),"service_error_counts": counts,"fallback_responses": metric("fallback_responses"),}def stop(self) -> None:
12345672 unmodified lines79808182838419 unmodified lines10410510610710810911 unmodified lines12112212312412512610 unmodified lines13713813914014114210 unmodified lines153154155156157158"""Lifecycle robustness tests for jarvis.__main__.Jarvis."""import pytestfrom types import SimpleNamespacefrom unittest.mock import MagicMock, AsyncMock72 unmodified linesassert "Memory: enabled" in joinedassert "Config warnings: 0" in joinedassert "Tool policy: allow=1 deny=2" in joineddef test_telemetry_snapshot_averages():19 unmodified linesassert snapshot["avg_tts_first_audio_ms"] == 250.0assert snapshot["service_errors"] == 3.0assert snapshot["storage_errors"] == 1.0assert snapshot["fallback_responses"] == 4.011 unmodified linesassert jarvis._telemetry["service_errors"] == 1.0assert jarvis._telemetry["storage_errors"] == 1.0def test_refresh_tool_error_counters_classifies_missing_store_as_storage():10 unmodified linesassert jarvis._telemetry["service_errors"] == 1.0assert jarvis._telemetry["storage_errors"] == 2.0def test_refresh_tool_error_counters_includes_network_taxonomy():10 unmodified linesassert jarvis._telemetry["service_errors"] == 3.0assert jarvis._telemetry["storage_errors"] == 0.0def test_telemetry_error_taxonomy_matches_service_error_codes():123456772 unmodified lines808182838485868788899091929394959697989910019 unmodified lines12012112212312412512611 unmodified lines13813914014114214314410 unmodified lines15515615715815916016110 unmodified lines172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251"""Lifecycle robustness tests for jarvis.__main__.Jarvis."""import pytestfrom pathlib import Pathfrom types import SimpleNamespacefrom unittest.mock import MagicMock, AsyncMock72 unmodified linesassert "Memory: enabled" in joinedassert "Config warnings: 0" in joinedassert "Tool policy: allow=1 deny=2" in joinedassert "Error taxonomy: total=" in joineddef test_error_taxonomy_doc_matches_constants():from jarvis.tool_errors import TOOL_SERVICE_ERROR_CODESdoc_path = Path(__file__).resolve().parents[1] / "docs" / "operations" / "error-taxonomy.md"text = doc_path.read_text(encoding="utf-8")start = "<!-- SERVICE_ERROR_CODES_START -->"end = "<!-- SERVICE_ERROR_CODES_END -->"assert start in text and end in textblock = text.split(start, 1)[1].split(end, 1)[0]documented = {line.strip() for line in block.splitlines() if line.strip()}assert documented == TOOL_SERVICE_ERROR_CODESdef test_telemetry_snapshot_averages():19 unmodified linesassert snapshot["avg_tts_first_audio_ms"] == 250.0assert snapshot["service_errors"] == 3.0assert snapshot["storage_errors"] == 1.0assert snapshot["unknown_summary_details"] == 0.0assert snapshot["fallback_responses"] == 4.011 unmodified linesassert jarvis._telemetry["service_errors"] == 1.0assert jarvis._telemetry["storage_errors"] == 1.0assert jarvis._telemetry["unknown_summary_details"] == 0.0def test_refresh_tool_error_counters_classifies_missing_store_as_storage():10 unmodified linesassert jarvis._telemetry["service_errors"] == 1.0assert jarvis._telemetry["storage_errors"] == 2.0assert jarvis._telemetry["unknown_summary_details"] == 0.0def test_refresh_tool_error_counters_includes_network_taxonomy():10 unmodified linesassert jarvis._telemetry["service_errors"] == 3.0assert jarvis._telemetry["storage_errors"] == 0.0assert jarvis._telemetry["unknown_summary_details"] == 0.0def test_refresh_tool_error_counters_tracks_unknown_summary_detail_count():jarvis = Jarvis.__new__(Jarvis)jarvis._telemetry = {"service_errors": 0.0, "storage_errors": 0.0, "unknown_summary_details": 0.0}from unittest.mock import patchwith patch("jarvis.__main__.list_summaries", return_value=[{"status": "error", "detail": "timeout"},{"status": "error", "detail": "not_a_real_code"},{"status": "error", "detail": "another_unknown"},]):Jarvis._refresh_tool_error_counters(jarvis)assert jarvis._telemetry["service_errors"] == 1.0assert jarvis._telemetry["storage_errors"] == 0.0assert jarvis._telemetry["unknown_summary_details"] == 2.0def test_refresh_tool_error_counters_reports_per_code_totals():jarvis = Jarvis.__new__(Jarvis)jarvis._telemetry = {"service_errors": 0.0, "storage_errors": 0.0, "unknown_summary_details": 0.0}from unittest.mock import patchwith patch("jarvis.__main__.list_summaries", return_value=[{"status": "error", "detail": "timeout"},{"status": "error", "detail": "timeout"},{"status": "error", "detail": "storage_error"},{"status": "error", "detail": "unknown_error"},{"status": "error", "detail": "not_a_real_code"},{"status": "ok", "detail": "timeout"},]):Jarvis._refresh_tool_error_counters(jarvis)assert jarvis._telemetry_error_counts == {"storage_error": 1.0,"timeout": 2.0,"unknown_error": 1.0,}snapshot = Jarvis._telemetry_snapshot(jarvis)assert snapshot["service_error_counts"] == jarvis._telemetry_error_countsassert snapshot["unknown_summary_details"] == 1.0def test_telemetry_snapshot_guards_non_finite_values():jarvis = Jarvis.__new__(Jarvis)jarvis._telemetry = {"turns": float("nan"),"barge_ins": float("inf"),"stt_latency_total_ms": float("inf"),"stt_latency_count": 1.0,"llm_first_sentence_total_ms": 100.0,"llm_first_sentence_count": float("nan"),"tts_first_audio_total_ms": 100.0,"tts_first_audio_count": 0.0,"service_errors": float("nan"),"storage_errors": float("inf"),"unknown_summary_details": float("nan"),"fallback_responses": float("inf"),}jarvis._telemetry_error_counts = {"timeout": float("nan"), "auth": 2.0}snapshot = Jarvis._telemetry_snapshot(jarvis)assert snapshot["turns"] == 0.0assert snapshot["barge_ins"] == 0.0assert snapshot["avg_stt_latency_ms"] == 0.0assert snapshot["avg_llm_first_sentence_ms"] == 0.0assert snapshot["service_errors"] == 0.0assert snapshot["storage_errors"] == 0.0assert snapshot["unknown_summary_details"] == 0.0assert snapshot["fallback_responses"] == 0.0assert snapshot["service_error_counts"] == {"auth": 2.0}def test_telemetry_error_taxonomy_matches_service_error_codes():
README.md+1
TODO.md+8-8
docs/operations/error-taxonomy.mdAdded+63
src/jarvis/__main__.py+37-9
tests/test_main_lifecycle.py+93