Skip to content

Cactus clean now clears cache, Session metrics initialized properly for telemetry#363

Merged
HenryNdubuaku merged 27 commits intomainfrom
justin/cpp_telemetry
Feb 17, 2026
Merged

Cactus clean now clears cache, Session metrics initialized properly for telemetry#363
HenryNdubuaku merged 27 commits intomainfrom
justin/cpp_telemetry

Conversation

@justinl66
Copy link
Copy Markdown
Member

Cactus clean now clears cache due to telemetry-related bugs that were happening with an old version of the cache causing issues.

justinl66 and others added 27 commits February 7, 2026 01:08
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]>
Copilot AI review requested due to automatic review settings February 17, 2026 04:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clean to 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.

Comment on lines +971 to +974
telemetry_cache = Path.home() / "Library" / "Caches" / "cactus" / "telemetry"
if telemetry_cache.exists():
print(f"Removing telemetry cache: {telemetry_cache}")
shutil.rmtree(telemetry_cache)
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 684 to 689
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) {
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
default:
if (static_cast<unsigned char>(*p) < 0x20) {
char buf[7];
snprintf(buf, sizeof(buf), "\\u%04x", static_cast<unsigned char>(*p));
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
snprintf(buf, sizeof(buf), "\\u%04x", static_cast<unsigned char>(*p));
std::snprintf(buf, sizeof(buf), "\\u%04x", static_cast<unsigned char>(*p));

Copilot uses AI. Check for mistakes.
@HenryNdubuaku HenryNdubuaku merged commit 74cb9a0 into main Feb 17, 2026
7 of 8 checks passed
ncylich pushed a commit that referenced this pull request Feb 24, 2026
…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]>
cattermelon1234 pushed a commit to cattermelon1234/cactus that referenced this pull request Feb 28, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants