Repository navigation
Conversation
Greptile SummaryThe PR restructures the native macOS watcher around PID-based foreground reconciliation and preserves app/title heartbeats when optional browser enrichment fails.
Confidence Score: 3/5The PR should not merge until the Chrome fallback preserves incognito privacy when browser scripting is unavailable. The new fallback fixes dropped foreground evidence but also sends AX-derived Chrome identity and titles when the failed browser lookup prevents the only incognito check; the Swift test target additionally does not exercise the supported deployment floor. Files Needing Attention: aw_watcher_window/macos.swift, Makefile
|
| Filename | Overview |
|---|---|
| aw_watcher_window/macos.swift | Consolidates foreground reconciliation and improves recovery, but the browser-failure fallback bypasses Chrome incognito blanking. |
| aw_watcher_window/macos_state.swift | Adds small, deterministic helpers for observer rebuild decisions and stale AX callback rejection. |
| tests/macos_state_tests.swift | Covers PID changes, observer repair, and callback ownership for the extracted reconciliation helpers. |
| Makefile | Wires the new Swift source and tests into builds, though the test compiler invocation does not preserve the production macOS 12 target. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Startup, activation, or poll] --> B[Select NSRunningApplication]
B --> C{Tracked PID changed or observer missing?}
C -->|Yes| D[Rebuild AX observer]
C -->|No| E[Reuse observer]
D --> F[Refresh focused AX window]
E --> F
F --> G[Read app and window title]
G --> H{Supported browser?}
H -->|Chrome or Safari| I{Browser context available?}
I -->|Yes| J[Add URL and tab title]
I -->|No| K[Keep AX app and title]
H -->|Firefox| L[Read URL from AX tree]
H -->|Other| M[Keep app and title]
J --> N[Apply privacy filters]
K --> N
L --> N
M --> N
N --> O[Send heartbeat]
Reviews (1): Last reviewed commit: "fix(macos): preserve foreground events w..." | Re-trigger Greptile
| } else { | ||
| log("Failed to read Chrome context; emitting foreground heartbeat without URL") | ||
| } |
There was a problem hiding this comment.
Fallback bypasses incognito blanking
If Chrome automation access is unavailable while Accessibility access remains granted, this fallback sends the AX-derived application and window title even for an incognito window, causing private browsing information to be stored in the currentwindow bucket. Incognito blanking occurs only inside the successful ScriptingBridge branch, with no equivalent guard before sendHeartbeat. How this was verified: The failed optional ScriptingBridge chain was traced to heartbeat delivery while the only incognito check remains inside its successful branch.
Knowledge Base Used:
| fi | ||
|
|
||
| test-swift: | ||
| swiftc aw_watcher_window/macos_state.swift tests/macos_state_tests.swift -o /tmp/aw-watcher-window-macos-state-tests |
There was a problem hiding this comment.
The new state-test command does not use the production helper's macOS 12 target, so it can pass with APIs available only on the runner's newer deployment target and provide false compatibility coverage.
| swiftc aw_watcher_window/macos_state.swift tests/macos_state_tests.swift -o /tmp/aw-watcher-window-macos-state-tests | |
| swiftc -target "$(shell uname -m)-apple-macosx$(MACOSX_DEPLOYMENT_TARGET)" aw_watcher_window/macos_state.swift tests/macos_state_tests.swift -o /tmp/aw-watcher-window-macos-state-tests |
Knowledge Base Used:
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
@TimeToBuildBob build on top of this to resolve conflict and fix Greptile concerns. Make sure to keep attribution. |
|
Rebased onto current master (after #145) and opened #146. Greptile P1: Chrome ScriptingBridge failure now keeps app identity but drops title and URL, since that lookup is the only incognito detector. Greptile P2: Original work stays attributed to hawai-i ( |
Adding macos_state.swift made macos.swift a non-script compilation unit. Top-level assignments (formatter options, encoder strategy, start()) are illegal outside main.swift. Restore the ActivityWatch#141 closure inits and @main wrapper that the rebase dropped. Git-Session-Id: ca3f0209-55b1-58ce-8820-82fb6f5bc8e0
Rebase of ActivityWatch#141 (hawai-i) onto current master after ActivityWatch#145. Keep PID-based foreground reconciliation and emit a heartbeat when Chrome/Safari ScriptingBridge fails, so merging does not extend the previous application across the real browser interval. Preserve ActivityWatch#145 AX safety (axString/axElement) and observer teardown (unregister focused-window notification, track observedApp). Chrome context-failure fallback keeps app identity for tracking but drops title and URL: ScriptingBridge is the only incognito detector (Greptile P1 on ActivityWatch#141). Swift state tests now compile with the macOS 12 deployment target (Greptile P2). Co-Authored-By: hawai-i <32040032+hawai-i@users.noreply.github.com> Git-Session-Id: 9615c06b-2a11-592d-b1ad-299a3433e323
Adding macos_state.swift made macos.swift a non-script compilation unit. Top-level assignments (formatter options, encoder strategy, start()) are illegal outside main.swift. Restore the ActivityWatch#141 closure inits and @main wrapper that the rebase dropped. Git-Session-Id: ca3f0209-55b1-58ce-8820-82fb6f5bc8e0
Rebase of ActivityWatch#141 (hawai-i) onto current master after ActivityWatch#145. Keep PID-based foreground reconciliation and emit a heartbeat when Chrome/Safari ScriptingBridge fails, so merging does not extend the previous application across the real browser interval. Preserve ActivityWatch#145 AX safety (axString/axElement) and observer teardown (unregister focused-window notification, track observedApp). Chrome context-failure fallback keeps app identity for tracking but drops title and URL: ScriptingBridge is the only incognito detector (Greptile P1 on ActivityWatch#141). Swift state tests now compile with the macOS 12 deployment target (Greptile P2). Co-Authored-By: hawai-i <32040032+hawai-i@users.noreply.github.com> Git-Session-Id: 9615c06b-2a11-592d-b1ad-299a3433e323
Adding macos_state.swift made macos.swift a non-script compilation unit. Top-level assignments (formatter options, encoder strategy, start()) are illegal outside main.swift. Restore the ActivityWatch#141 closure inits and @main wrapper that the rebase dropped. Git-Session-Id: ca3f0209-55b1-58ce-8820-82fb6f5bc8e0
|
@TimeToBuildBob Is this still needed? If so, fix it (conflict). |
Rebase of ActivityWatch#141 (hawai-i) onto current master after ActivityWatch#145. Keep PID-based foreground reconciliation and emit a heartbeat when Chrome/Safari ScriptingBridge fails, so merging does not extend the previous application across the real browser interval. Preserve ActivityWatch#145 AX safety (axString/axElement) and observer teardown (unregister focused-window notification, track observedApp). Chrome context-failure fallback keeps app identity for tracking but drops title and URL: ScriptingBridge is the only incognito detector (Greptile P1 on ActivityWatch#141). Swift state tests now compile with the macOS 12 deployment target (Greptile P2). Co-Authored-By: hawai-i <32040032+hawai-i@users.noreply.github.com> Git-Session-Id: 9615c06b-2a11-592d-b1ad-299a3433e323
Adding macos_state.swift made macos.swift a non-script compilation unit. Top-level assignments (formatter options, encoder strategy, start()) are illegal outside main.swift. Restore the ActivityWatch#141 closure inits and @main wrapper that the rebase dropped. Git-Session-Id: ca3f0209-55b1-58ce-8820-82fb6f5bc8e0
|
Yes—the browser-context fallback and PID/observer reconciliation are still needed; #172 fixes startup initialization, not those paths. The maintained replacement is #146 rather than this original branch. I have already resolved that replacement's conflict with current master ( Please use #146 for review/merge. I am leaving this original PR open until the replacement lands, as previously agreed, rather than maintaining two competing versions of the same change. |
* fix(macos): rebase foreground reconciliation onto master Rebase of #141 (hawai-i) onto current master after #145. Keep PID-based foreground reconciliation and emit a heartbeat when Chrome/Safari ScriptingBridge fails, so merging does not extend the previous application across the real browser interval. Preserve #145 AX safety (axString/axElement) and observer teardown (unregister focused-window notification, track observedApp). Chrome context-failure fallback keeps app identity for tracking but drops title and URL: ScriptingBridge is the only incognito detector (Greptile P1 on #141). Swift state tests now compile with the macOS 12 deployment target (Greptile P2). Co-Authored-By: hawai-i <32040032+hawai-i@users.noreply.github.com> Git-Session-Id: 9615c06b-2a11-592d-b1ad-299a3433e323 * fix(macos): restore @main entry so two-file swiftc compiles Adding macos_state.swift made macos.swift a non-script compilation unit. Top-level assignments (formatter options, encoder strategy, start()) are illegal outside main.swift. Restore the #141 closure inits and @main wrapper that the rebase dropped. Git-Session-Id: ca3f0209-55b1-58ce-8820-82fb6f5bc8e0 * fix(macos): drop stale same-window title callbacks and Safari AX titles PID-only AX guards accepted queued title-change events from a previous window of the same app. Bind title callbacks to the focused window. Safari ScriptingBridge failure kept the AX window title, unlike Chrome. Use the same keep-app / drop-title-URL fallback so private pages cannot leak via accessibility when context lookup fails. Git-Session-Id: 9a7625ed-1cac-5d98-b0d9-013b84aae02d * fix(macos): release unused AXObserver when notification add fails rebuildObserver created an AXObserver then returned on AXObserverAddNotification failure without adopting it, leaking the Mach port. Adopt and tear down through the #139 path. Bind foreground identity in the caller so a failed install still emits a heartbeat. Git-Session-Id: 28375f79-1abe-5518-8f8c-75fcc067315a * fix(macos): drop unused AXObserver via ARC and isolate swift tests The add-failure path never installed the observer in the run loop, so tearDownObserver's CFRunLoopRemoveSource was a no-op. Nil the managed reference instead; CFRelease would double-free a Swift-ARC CF type. Write the Swift state-test binary into a mktemp directory so make test does not execute a predictable path in /tmp. Git-Session-Id: 28375f79-1abe-5518-8f8c-75fcc067315a * fix(macos): retry title-change observer after transient AX add failure If AXObserverAddNotification for kAXTitleChangedNotification fails once, keep the focused window but leave registration retryable so the next poll can install it. Poll heartbeats already carry the current AX title; this restores live title-change callbacks after a transient add failure. Git-Session-Id: 2b8b1429-6ecf-575e-b812-491b60c68d9e * fix(macos): preserve app exclusion in reconciled heartbeat path Git-Session-Id: 857984da-6219-579c-b1f4-44a9cc88fa80 --------- Co-authored-by: hawai-i <32040032+hawai-i@users.noreply.github.com>
Summary
Browser URL/title enrichment is optional context, but the macOS Swift watcher currently returns without emitting a foreground heartbeat when some Chrome/Safari ScriptingBridge lookups fail. Heartbeat merging then extends the previous application's event across the real browser interval.
This change:
NSRunningApplicationfrom the workspace notification;Validation
A controlled
Codex → Chrome → Finder → Chrome → Codexsequence was scored against WindowServer's top visible layer-0 owner. Browser context failure was forced at the existing pre-heartbeat failure point in both the before and fixed test builds.A normal companion build also retained same-title Chrome
page-a → page-bURL changes.Automated Swift state tests cover:
make build-swift,make test-swift, a real PyInstaller 6.11 package build,mypy, andgit diff --checkpassed. The packaged arm64 helper preserves the macOS 12.0 minimum. The borrowed local Python environment reported 61 passing tests and two macOS config-path failures that reproduce unchanged on the base commit.Related work
ActivityWatch/activitywatch#1411 grants the responsible outer app Apple Events permission, which lets browser context acquisition succeed. This PR is logically independent: foreground truth must still be emitted when optional context is unavailable.
This also corrects the mismatched title-notification cleanup and observer teardown discussed in #139, but this PR does not claim a separate multi-day leak validation.