fix(macos): keep foreground tracking when browser context fails - #146
TimeToBuildBob wants to merge 6 commits into
Conversation
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
|
macos-latest failed at The rebase onto master after #145 dropped the #141 |
|
CI-green and mergeable — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
🤖 AI code reviewSafe to merge — 2 findings disposed (rejected; fixed in 90aad7f)Updated after inline dispositions on finding threads — this is the current state; the verdict below is frozen at review time and is kept as the historical record of that pass. Finding disposition
Needs a look — P2 onlyConfidence 4/5 ℹ️ Consensus was degraded on this run: 2 of 3 passes answered, so findings were filtered at 2-of-2 agreement rather than 2-of-3 — less filtered than usual; 2 of 3 fan-out jobs answered, so the findings above were filtered against less evidence than the threshold assumes. 1 finding ·
|
| commit | score | findings | engine | when |
|---|---|---|---|---|
8ac81d39c2f8 |
4/5 | 2 | llm | 2026-09-16 08:53 UTC |
9424b4f6a054 |
1/5 | 3 | llm | 2026-09-16 12:44 UTC |
Reviewed 90aad7fbb413 · openrouter/deepseek/deepseek-v4-flash-0731 · llm (in-band) engine · 594s · about this reviewer
Maintainer commands
@TimeToBuildBob review (own line) — fresh review · @TimeToBuildBob fix — a worker acts on the findings. Once per comment; 👀 = received.
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
rebuildObserver created an AXObserver then returned on AXObserverAddNotification failure without adopting it, leaking the Mach port. Adopt and tear down through the ActivityWatch#139 path. Bind foreground identity in the caller so a failed install still emits a heartbeat. Git-Session-Id: 28375f79-1abe-5518-8f8c-75fcc067315a
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
|
@greptileai review |
|
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
|
@greptileai review |
Summary
Rebase of #141 (hawai-i) onto current
masterafter #145. Original work is preserved and attributed (Co-Authored-By: hawai-i).Browser URL/title enrichment is optional, but the macOS Swift watcher used to return without a heartbeat when Chrome/Safari ScriptingBridge failed. Heartbeat merging then extended the previous application across the real browser interval.
This keeps #141's PID-based foreground reconciliation:
NSRunningApplicationfrom the workspace notificationConflict with #145
#145 landed on
masterafter #141 opened. The rebase keeps that work:axString/axElementCF type checks (the macOS: native helper crashes when NSHTTPURLResponse is bridged as a window-title string #144NSHTTPURLResponsecrash)observedApp(the [macOS] aw-watcher-window-macos leaks AXObserver/Mach ports, causing high wired memory #139 Mach-port leak)Unsafe
as? String/as! AXUIElementcasts from #141 are not carried forward.Greptile on #141
P1 (incognito): ScriptingBridge is the only Chrome incognito detector. The original fallback sent AX-derived app + title when that lookup failed. The rebase still emits the Chrome app identity (so tracking stays coherent) but drops title and URL. Successful incognito detection still blanks both app and title.
P2 (tests):
make test-swiftnow compiles with-target …-macosx$(MACOSX_DEPLOYMENT_TARGET)(12.0), matching the production helper.Validation
Python tests: 77 passed. mypy clean. Swift helper/tests need Darwin CI (
macos-latest).Related