Cactus clean now clears cache, Session metrics initialized properly for telemetry#363
Cactus clean now clears cache, Session metrics initialized properly for telemetry#363HenryNdubuaku merged 27 commits intomainfrom
Conversation
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: Roman Shemet <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
Signed-off-by: justinl66 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR addresses telemetry reliability issues by ensuring stale telemetry cache data is removed during cactus clean, and by making telemetry event serialization safer/more consistent for downstream ingestion.
Changes:
- Extend
cactus cleanto remove the on-disk telemetry cache directory. - Initialize session-level metric fields for extended telemetry events to avoid uninitialized values.
- Add JSON string escaping for selected telemetry fields when sending to the cloud and when writing the local cache.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| python/src/cli.py | Adds deletion of the telemetry cache directory during cmd_clean. |
| cactus/telemetry/telemetry.cpp | Initializes session metrics in extended events and escapes JSON strings for model/message/error in telemetry payloads and cache output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| telemetry_cache = Path.home() / "Library" / "Caches" / "cactus" / "telemetry" | ||
| if telemetry_cache.exists(): | ||
| print(f"Removing telemetry cache: {telemetry_cache}") | ||
| shutil.rmtree(telemetry_cache) |
There was a problem hiding this comment.
telemetry_cache.exists() can be true for a non-directory (file/symlink), in which case shutil.rmtree() will raise and abort clean. Consider reusing remove_if_exists() here (or at least check telemetry_cache.is_dir() / handle file unlink) so cactus clean is resilient.
| std::ostringstream oss; | ||
| oss << "{\"event_type\":\"" << event_type_to_string(e.type) << "\","; | ||
| oss << "\"model\":\"" << e.model << "\","; | ||
| oss << "\"model\":\"" << escape_json_string(e.model) << "\","; | ||
| oss << "\"success\":" << (e.success ? "true" : "false") << ","; | ||
| oss << "\"cloud_handoff\":" << (e.cloud_handoff ? "true" : "false") << ","; | ||
| if (e.type == INIT || !e.success) { |
There was a problem hiding this comment.
escape_json_string() produces escaped quotes/backslashes in cached log lines, but extract_string_field() (used by parse_event_line) looks for the next " without accounting for escapes. Any value containing " will be parsed incorrectly, and cached events may fail to reload or be double-escaped when later sent to the cloud. The cache reader needs JSON-aware string parsing/unescaping (or switch the cache format / use a JSON library) to match the new escaping.
| default: | ||
| if (static_cast<unsigned char>(*p) < 0x20) { | ||
| char buf[7]; | ||
| snprintf(buf, sizeof(buf), "\\u%04x", static_cast<unsigned char>(*p)); |
There was a problem hiding this comment.
In escape_json_string(), snprintf(...) is called unqualified while the rest of the file uses std::snprintf. With <cstdio>, only std::snprintf is guaranteed; using std::snprintf (or ::snprintf explicitly) avoids portability/compile issues on stricter standard library implementations.
| snprintf(buf, sizeof(buf), "\\u%04x", static_cast<unsigned char>(*p)); | |
| std::snprintf(buf, sizeof(buf), "\\u%04x", static_cast<unsigned char>(*p)); |
…or telemetry (#363) * Add basic telemetry setup Signed-off-by: justinl66 <[email protected]> * Add init error logging Signed-off-by: justinl66 <[email protected]> * Update device + project ID Signed-off-by: justinl66 <[email protected]> * Align telemetry POSTs to supabase schema Signed-off-by: justinl66 <[email protected]> * Fixing 35-char UUID format bug to make it the correct 36 Signed-off-by: Roman Shemet <[email protected]> * Update telemetry Signed-off-by: justinl66 <[email protected]> * Fix transcription telemetry event Signed-off-by: justinl66 <[email protected]> * Update telemetry to work with new RLS policy Signed-off-by: justinl66 <[email protected]> * Update response time logging Signed-off-by: justinl66 <[email protected]> * Fix transcribe events Signed-off-by: justinl66 <[email protected]> * Fix init error logging Signed-off-by: justinl66 <[email protected]> * Fix token double count during stream transcription Signed-off-by: justinl66 <[email protected]> * Update telemetry with embedding logs Signed-off-by: justinl66 <[email protected]> * Fix streaming transcription telemetry Signed-off-by: justinl66 <[email protected]> * Remove stray third_party folder Signed-off-by: justinl66 <[email protected]> * Remove duplicate telemetry recording, Point to main DB Signed-off-by: justinl66 <[email protected]> * Remove stray third party repos Signed-off-by: justinl66 <[email protected]> * Remove unneeded telemetry Signed-off-by: justinl66 <[email protected]> * Add proper NULL logging Signed-off-by: justinl66 <[email protected]> * Add init NULL logging Signed-off-by: justinl66 <[email protected]> * Remove dropped columns from payload Signed-off-by: justinl66 <[email protected]> * Update json parsing and fix session metrics Signed-off-by: justinl66 <[email protected]> * Make cactus clean clear cactus cache folder Signed-off-by: justinl66 <[email protected]> --------- Signed-off-by: justinl66 <[email protected]> Signed-off-by: Roman Shemet <[email protected]> Co-authored-by: Roman Shemet <[email protected]>
…or telemetry (cactus-compute#363) * Add basic telemetry setup Signed-off-by: justinl66 <[email protected]> * Add init error logging Signed-off-by: justinl66 <[email protected]> * Update device + project ID Signed-off-by: justinl66 <[email protected]> * Align telemetry POSTs to supabase schema Signed-off-by: justinl66 <[email protected]> * Fixing 35-char UUID format bug to make it the correct 36 Signed-off-by: Roman Shemet <[email protected]> * Update telemetry Signed-off-by: justinl66 <[email protected]> * Fix transcription telemetry event Signed-off-by: justinl66 <[email protected]> * Update telemetry to work with new RLS policy Signed-off-by: justinl66 <[email protected]> * Update response time logging Signed-off-by: justinl66 <[email protected]> * Fix transcribe events Signed-off-by: justinl66 <[email protected]> * Fix init error logging Signed-off-by: justinl66 <[email protected]> * Fix token double count during stream transcription Signed-off-by: justinl66 <[email protected]> * Update telemetry with embedding logs Signed-off-by: justinl66 <[email protected]> * Fix streaming transcription telemetry Signed-off-by: justinl66 <[email protected]> * Remove stray third_party folder Signed-off-by: justinl66 <[email protected]> * Remove duplicate telemetry recording, Point to main DB Signed-off-by: justinl66 <[email protected]> * Remove stray third party repos Signed-off-by: justinl66 <[email protected]> * Remove unneeded telemetry Signed-off-by: justinl66 <[email protected]> * Add proper NULL logging Signed-off-by: justinl66 <[email protected]> * Add init NULL logging Signed-off-by: justinl66 <[email protected]> * Remove dropped columns from payload Signed-off-by: justinl66 <[email protected]> * Update json parsing and fix session metrics Signed-off-by: justinl66 <[email protected]> * Make cactus clean clear cactus cache folder Signed-off-by: justinl66 <[email protected]> --------- Signed-off-by: justinl66 <[email protected]> Signed-off-by: Roman Shemet <[email protected]> Co-authored-by: Roman Shemet <[email protected]>
Cactus clean now clears cache due to telemetry-related bugs that were happening with an old version of the cache causing issues.