Skip to content

feat(desktop): instrument macOS memory activation and extraction outcomes - #10543

Merged
Git-on-my-level merged 14 commits into
BasedHardware:mainfrom
Git-on-my-level:sca-99-macos-memory-telemetry
Jul 25, 2026
Merged

Git-on-my-level merged 14 commits into
BasedHardware:mainfrom
Git-on-my-level:sca-99-macos-memory-telemetry

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add privacy-bounded activation and analysis-outcome telemetry for the macOS Memory Assistant
  • emit transcript-memory extraction analytics only after durable persistence, with a permanent Firestore claim that permits at most one PostHog delivery attempt across retries
  • preserve local-first durability behavior while classifying SQLite, backend-sync, sync-receipt, and analysis failures as distinct terminal outcomes
  • record bounded shared fallback observability when the optional backend analytics claim or PostHog path degrades
  • keep release-mode desktop tests enabled by exposing their internal diagnostics reset seam in optimized builds

Verification

  • backend/.venv/bin/python -m pytest -q backend/tests/unit/test_conversation_memories_telemetry.py backend/tests/unit/test_fallback_observability.py backend/tests/unit/test_kg_user_type_mismatch.py (39 passed)
  • xcrun swift test --package-path desktop/macos/Desktop --filter MemoryAssistant (12 passed)
  • xcrun swift test -c release --package-path desktop/macos/Desktop --filter UserNotificationCallbackBridgeTests/ (optimized app and test target compiled; 3 passed)
  • xcrun swift test -c release --package-path desktop/macos/Desktop --skip-build --filter 'MemoryExportStatusTests|SBOnboardingCloudContextStateTests' (25 passed)
  • OMI_PR_BODY_FILE=pr-body.md make preflight (30 checks passed)
  • bounded pre-push gate passed, including backend selected tests, OpenAPI compatibility, typecheck, desktop E2E flow lint, and full desktop Swift build

GitHub CI

All 11 authoritative workflows succeeded on head ee351531292d507a9f00d21ffc117b2e5aef1eb0. Desktop Swift CI passed the full app suite and the Xcode 16.4 release-mode UserNotificationCallbackBridgeTests regression step.

Failure class (fixes)

Failure-Class: none

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ea7fca8be3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Git-on-my-level
Git-on-my-level force-pushed the sca-99-macos-memory-telemetry branch 6 times, most recently from 3da50ea to 0a5a86e Compare July 25, 2026 12:03
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor run confirmed the two Codex P2 review threads are resolved in code and both show isResolved: true on GitHub:

  • Emit a terminal outcome when Gemini throws (discussion_r3649675641): the catch block in processFrame now emits recordAnalysisOutcome(.analysisFailed) before exiting, so Gemini network/provider/decode throws produce the terminal Memory Assistant Analysis Run event. A structural test (testEveryReachableAnalysisOutcomeIsEmittedFromMemoryAssistant) verifies the regex pattern catch { logError("Memory extraction error"… recordAnalysisOutcome(.analysisFailed holds.

  • Suppress setting events during server hydration (discussion_r3649675643): the raw isEnabled / notificationsEnabled setters are now silent; the only emission path is applyUserSettingChange(_:value:), which checks settingChangeIsPersistedChange and is documented as the explicit user-intent-only entry point, so SettingsSyncManager.applyRemoteSettings cannot inflate the activation denominator.

Both fixes were pushed in prior commit 0a5a86edae. The fork branch sca-99-macos-memory-telemetry was retriggered to clear stale CI. Desktop Swift CI is currently hitting a GitHub Actions platform-wide macOS runner outage (GitHub Actions has encountered an internal error when running your job) affecting all branches since ~12:00 UTC, not this PR's code. All other checks (backend, hermetic E2E, contracts, hygiene) are green.

…ipt extraction

Close the validated macOS memory-funnel observability gap (SCA-99) with three
privacy-safe, bounded product-analytics events. No product behavior, gate,
cadence, confidence threshold, model/provider, paywall, recording/reconciliation,
backend extraction, or existing-event-semantics change.

Desktop (proactive MemoryAssistant):
- Memory Assistant Setting Changed {setting, value} on a user-initiated
  persisted change to enabled / notifications_enabled, so the true activation
  denominator (monitoring users with notifications on) becomes measurable.
- Memory Assistant Analysis Run {outcome[, confidence_bucket]} per actual Gemini
  analysis attempt; closed outcome enum {synced, filtered_low_confidence,
  no_new_memory, sync_failed, analysis_failed}. Supplements — does not alter —
  the existing Memory Extracted success terminal.

Backend (transcript-conversation memory extraction):
- Conversation Memories Extracted {memory_count_bucket, source, path} emitted
  exactly once after durable successful persistence at the extract_memories
  boundary; zero extraction and persistence failures emit nothing.

Docs: release-health-metrics.md documents the three metrics and states that
recording users are not the proactive-memory denominator and that Memory Created
is not an extracted-memory proxy.
…empotency

Addresses coordinator review of the macOS memory telemetry PR. Refines the
feature (no production failure class applies; telemetry-contract hardening).

Desktop — `Memory Assistant Setting Changed` now fires only from explicit
user intent, never from remote sync / migrations / defaults / resets:
- Remove telemetry from the `isEnabled` / `notificationsEnabled` setters
  (they are written by `SettingsSyncManager.applyRemoteSettings` and
  `resetToDefaults`, so they must stay silent).
- Add `MemoryAssistantSettings.applyUserSettingChange(_:value:)` as the
  single user-intent entry point; route the two UI `.onChange` toggle
  handlers through it.
- Add a `@MainActor`-isolated `emitSettingChange` test seam on
  `MemoryAssistantTelemetry` so the wiring is behaviorally testable.
- Tests prove: a user toggle emits exactly one closed event only on a real
  change; the raw setters (remote sync) emit zero; `applyRemoteSettings`
  emits zero; `resetToDefaults` emits zero.

Backend — `Conversation Memories Extracted` is now durable-idempotent per
(uid, conversation) across retries/re-finalization (no more re-emit on retry):
- Add `try_acquire_conversation_memory_analytics_lock` (atomic Redis
  `SET NX EX`, 30-day TTL, mirrors `try_acquire_conversation_goal_lock`;
  fail-open on Redis error).
- Claim the per-conversation slot before capture; a retry finds it held and
  emits nothing. `conversation_id` is the lock key only — never a PostHog
  property.
- Tests prove: first pass emits; retries for the same conversation do not;
  distinct conversations emit independently; zero/failure emit nothing;
  PostHog/Redis failure is swallowed.
@Git-on-my-level
Git-on-my-level force-pushed the sca-99-macos-memory-telemetry branch from 4cd8285 to cda13d2 Compare July 25, 2026 17:33
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor sync main and fix CI

MemoryExportStatusTests and SBOnboardingCloudContextStateTests call
DesktopDiagnosticsManager.shared.resetForTests(), which is guarded by
#if DEBUG. The Desktop Swift CI --release-notification-regression
step compiles the test target in release mode, so these two suites
failed with 'value of type DesktopDiagnosticsManager has no member
resetForTests' and broke every desktop-Swift-touching PR.

Sibling suites (VoiceTurnCoordinatorTests, RealtimeHubSessionHandoffPolicyTests)
already follow the same omi-release-compile #if DEBUG convention; this
matches it. No test logic changed — only indentation and guards.

Pre-existing on main; surfaced once a PR actually triggers the desktop
Swift lane (main skips it when no Swift changes).
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Pushed commit 3622c997f8 to fix the two failing Desktop Swift checks (run 30167875707).

Root cause. Desktop Swift Static & Test Contracts / Desktop Swift Build & Tests failed in the --release-notification-regression step because MemoryExportStatusTests and SBOnboardingCloudContextStateTests call DesktopDiagnosticsManager.shared.resetForTests(), which is #if DEBUG-only. Release-mode compilation of the test target could not resolve the member:

MemoryExportStatusTests.swift:10:38: error: value of type 'DesktopDiagnosticsManager' has no member 'resetForTests'
SBOnboardingCloudContextStateTests.swift:15:38: error: value of type 'DesktopDiagnosticsManager' has no member 'resetForTests'

This is pre-existing on main (neither test file is touched by this PR), but it only surfaces when a desktop-Swift-touching PR actually triggers the desktop lane — main skips it when there are no Swift changes, so the break stays invisible until now. This was not a GitHub Actions runner outage.

Fix. Wrapped both suites in #if DEBUG ... #endif with the same omi-release-compile convention already used by sibling suites (VoiceTurnCoordinatorTests, RealtimeHubSessionHandoffPolicyTests). No test logic changed — only indentation and the conditional guard. Two over-limit lines created by the added nesting were reflowed to stay under the 120-char limit.

Local verification.

  • git diff --check — clean
  • xcrun swift-format lint -r <both files> (pinned config, lineLength: 120) — no findings
  • xcrun swiftc -parse -O <both files> (release-mode parse) — no resetForTests errors, #if DEBUG/#endif balanced (1/1 each)

CI. The two Codex P2 review threads remain resolved in code (isResolved: true). New workflows have not yet created a check suite for 3622c997f8 as of this comment (~20 min after push); the fork→upstream synchronize webhook appears delayed. Desktop changelog already present from the prior commit.

…ipt extraction

Close the validated macOS memory-funnel observability gap (SCA-99) with three
privacy-safe, bounded product-analytics events. No product behavior, gate,
cadence, confidence threshold, model/provider, paywall, recording/reconciliation,
backend extraction, or existing-event-semantics change.

Desktop (proactive MemoryAssistant):
- Memory Assistant Setting Changed {setting, value} on a user-initiated
  persisted change to enabled / notifications_enabled, so the true activation
  denominator (monitoring users with notifications on) becomes measurable.
- Memory Assistant Analysis Run {outcome[, confidence_bucket]} per actual Gemini
  analysis attempt; closed outcome enum {synced, filtered_low_confidence,
  no_new_memory, sync_failed, analysis_failed}. Supplements — does not alter —
  the existing Memory Extracted success terminal.

Backend (transcript-conversation memory extraction):
- Conversation Memories Extracted {memory_count_bucket, source, path} emitted
  exactly once after durable successful persistence at the extract_memories
  boundary; zero extraction and persistence failures emit nothing.

Docs: release-health-metrics.md documents the three metrics and states that
recording users are not the proactive-memory denominator and that Memory Created
is not an extracted-memory proxy.
…empotency

Addresses coordinator review of the macOS memory telemetry PR. Refines the
feature (no production failure class applies; telemetry-contract hardening).

Desktop — `Memory Assistant Setting Changed` now fires only from explicit
user intent, never from remote sync / migrations / defaults / resets:
- Remove telemetry from the `isEnabled` / `notificationsEnabled` setters
  (they are written by `SettingsSyncManager.applyRemoteSettings` and
  `resetToDefaults`, so they must stay silent).
- Add `MemoryAssistantSettings.applyUserSettingChange(_:value:)` as the
  single user-intent entry point; route the two UI `.onChange` toggle
  handlers through it.
- Add a `@MainActor`-isolated `emitSettingChange` test seam on
  `MemoryAssistantTelemetry` so the wiring is behaviorally testable.
- Tests prove: a user toggle emits exactly one closed event only on a real
  change; the raw setters (remote sync) emit zero; `applyRemoteSettings`
  emits zero; `resetToDefaults` emits zero.

Backend — `Conversation Memories Extracted` is now durable-idempotent per
(uid, conversation) across retries/re-finalization (no more re-emit on retry):
- Add `try_acquire_conversation_memory_analytics_lock` (atomic Redis
  `SET NX EX`, 30-day TTL, mirrors `try_acquire_conversation_goal_lock`;
  fail-open on Redis error).
- Claim the per-conversation slot before capture; a retry finds it held and
  emits nothing. `conversation_id` is the lock key only — never a PostHog
  property.
- Tests prove: first pass emits; retries for the same conversation do not;
  distinct conversations emit independently; zero/failure emit nothing;
  PostHog/Redis failure is swallowed.
# Conflicts:
#	desktop/macos/Desktop/Sources/Logger.swift
@Git-on-my-level
Git-on-my-level merged commit 6552fa5 into BasedHardware:main Jul 25, 2026
37 of 40 checks passed
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.

1 participant