Repository navigation
feat(desktop): Maximum notification level delivers the <10s / <30s focus-nudge cadence (+ context-buckets starvation fix) - #11562
Conversation
There was a problem hiding this comment.
6 issues found across 9 files
Confidence score: 3/5
- In
desktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift, Maximum mode can still inherit an uncapped persisted heartbeat (including battery scaling), allowing nudge gaps to drift past expected limits and making suggestions feel intermittently silent—apply the same cap logic to Maximum’s heartbeat path. - In
desktop/macos/Desktop/Sources/ProactiveAssistants/Assistants/Suggestions/SuggestionAssistant.swift(probeEvaluateAndDeliver), using a stale Balanced cache to evaluate Maximum probes can misclassify valid deliveries as filtered, which suppresses user-visible suggestions—refresh the delivery level before threshold/dedup checks (or pass the currentgateState.2). - In
desktop/macos/Desktop/Sources/ProactiveAssistants/Core/AssistantCoordinator.swift(fireContextSwitchOnAllAssistants), awaiting each assistant sequentially on the main actor can stall context-switch propagation and delay downstream assistant updates under load—restore concurrent dispatch or move work off the main-actor bottleneck. - In
desktop/macos/changelog/unreleased/20260814-buckets-context-switch-starvation.json,desktop/macos/Desktop/Tests/SuggestionAssistantTests.swift, anddesktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift(captureFrame()), remaining issues are low severity but worth cleanup to reduce confusion and drift (user-facing changelog wording, 20s vs 30s test doc mismatch, repeated frequency-level reads)—tighten these for consistency and easier future debugging.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="desktop/macos/changelog/unreleased/20260814-buckets-context-switch-starvation.json">
<violation number="1" location="desktop/macos/changelog/unreleased/20260814-buckets-context-switch-starvation.json:2">
P3: The changelog line starts user-facing (“focus suggestions going silent”) but then describes implementation details (“every assistant hears context switches again, not just the task assistant”) that add no user-visible meaning. Keep the fragment to the outcome users experience so release notes stay user-facing.</violation>
</file>
<file name="desktop/macos/Desktop/Sources/ProactiveAssistants/Assistants/Suggestions/SuggestionAssistant.swift">
<violation number="1" location="desktop/macos/Desktop/Sources/ProactiveAssistants/Assistants/Suggestions/SuggestionAssistant.swift:520">
P2: `probeEvaluateAndDeliver` can report a Maximum probe as filtered because this line uses the stale Balanced cache. Refresh the delivery level before applying the threshold and dedup policy, or pass `gateState.2` explicitly into `resolveDelivery`.</violation>
</file>
<file name="desktop/macos/Desktop/Tests/SuggestionAssistantTests.swift">
<violation number="1" location="desktop/macos/Desktop/Tests/SuggestionAssistantTests.swift:97">
P3: The doc comment above this test still says "Maximum caps the between-nudge cooldown at 30 s", but the test now asserts a 20 s cap. Update the comment to 20 s so the pinned behavior and its documentation don't contradict.</violation>
</file>
<file name="desktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift">
<violation number="1" location="desktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift:890">
P2: When Maximum runs with a persisted capture interval above 10 seconds, this flag still uses the unchanged heartbeat interval, so repeated nudges can exceed 30 seconds. Cap Maximum's heartbeat, including the battery multiplier, before this trigger runs.</violation>
<violation number="2" location="desktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift:890">
P3: captureFrame() reads NotificationService.currentFrequencyLevel() three separate times per capture tick (idle gate, forceHeartbeatCapture, idleThresholdOverride). Hoist it into one local so the idle gate and the capture-trigger override always use the same value and avoid redundant UserDefaults reads at the 1 Hz poll rate.</violation>
</file>
<file name="desktop/macos/Desktop/Sources/ProactiveAssistants/Core/AssistantCoordinator.swift">
<violation number="1" location="desktop/macos/Desktop/Sources/ProactiveAssistants/Core/AssistantCoordinator.swift:247">
P2: fireContextSwitchOnAllAssistants awaits every assistant's onContextSwitch sequentially on the main actor from checkContextSwitch, whereas the prior code dispatched onContextSwitch fire-and-forget inside `Task { }` and returned immediately. The plugin awaits checkContextSwitch in the capture loop (before trackFrame), so each app/window switch now blocks the main actor for the full sequential run of every assistant. Dispatch the switches concurrently (e.g. `TaskGroup` / `async let`) — or, if the awaited ordering is only needed for the spy test, keep a Task-based dispatch in production and have the test await the result differently.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| let threshold = SuggestionPacing.minConfidence( | ||
| base: await minConfidence, frequencyLevel: cachedFrequencyLevel) |
There was a problem hiding this comment.
P2: probeEvaluateAndDeliver can report a Maximum probe as filtered because this line uses the stale Balanced cache. Refresh the delivery level before applying the threshold and dedup policy, or pass gateState.2 explicitly into resolveDelivery.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/ProactiveAssistants/Assistants/Suggestions/SuggestionAssistant.swift, line 520:
<comment>`probeEvaluateAndDeliver` can report a Maximum probe as filtered because this line uses the stale Balanced cache. Refresh the delivery level before applying the threshold and dedup policy, or pass `gateState.2` explicitly into `resolveDelivery`.</comment>
<file context>
@@ -512,7 +517,8 @@ actor SuggestionAssistant: ProactiveAssistant {
let telemetryIdentity = SuggestionAssistantTelemetry.NotificationIdentity(result.telemetryIdentity)
let ownerID = RuntimeOwnerIdentity.currentOwnerId()
- let threshold = await minConfidence
+ let threshold = SuggestionPacing.minConfidence(
+ base: await minConfidence, frequencyLevel: cachedFrequencyLevel)
</file context>
| let threshold = SuggestionPacing.minConfidence( | |
| base: await minConfidence, frequencyLevel: cachedFrequencyLevel) | |
| let deliveryFrequencyLevel = await MainActor.run { NotificationService.currentFrequencyLevel() } | |
| cachedFrequencyLevel = deliveryFrequencyLevel | |
| let threshold = SuggestionPacing.minConfidence( | |
| base: await minConfidence, frequencyLevel: deliveryFrequencyLevel) |
| idleSeconds: idleSeconds, | ||
| now: now | ||
| now: now, | ||
| forceHeartbeatCapture: SuggestionPacing.forcesHeartbeatCapture( |
There was a problem hiding this comment.
P2: When Maximum runs with a persisted capture interval above 10 seconds, this flag still uses the unchanged heartbeat interval, so repeated nudges can exceed 30 seconds. Cap Maximum's heartbeat, including the battery multiplier, before this trigger runs.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift, line 890:
<comment>When Maximum runs with a persisted capture interval above 10 seconds, this flag still uses the unchanged heartbeat interval, so repeated nudges can exceed 30 seconds. Cap Maximum's heartbeat, including the battery multiplier, before this trigger runs.</comment>
<file context>
@@ -879,7 +886,12 @@ public class ProactiveAssistantsPlugin: NSObject {
idleSeconds: idleSeconds,
- now: now
+ now: now,
+ forceHeartbeatCapture: SuggestionPacing.forcesHeartbeatCapture(
+ frequencyLevel: NotificationService.currentFrequencyLevel()),
+ idleThresholdOverride: SuggestionPacing.captureIdleThreshold(
</file context>
| newWindowTitle: String? | ||
| ) async { | ||
| for (_, assistant) in assistants { | ||
| await assistant.onContextSwitch( |
There was a problem hiding this comment.
P2: fireContextSwitchOnAllAssistants awaits every assistant's onContextSwitch sequentially on the main actor from checkContextSwitch, whereas the prior code dispatched onContextSwitch fire-and-forget inside Task { } and returned immediately. The plugin awaits checkContextSwitch in the capture loop (before trackFrame), so each app/window switch now blocks the main actor for the full sequential run of every assistant. Dispatch the switches concurrently (e.g. TaskGroup / async let) — or, if the awaited ordering is only needed for the spy test, keep a Task-based dispatch in production and have the test await the result differently.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/ProactiveAssistants/Core/AssistantCoordinator.swift, line 247:
<comment>fireContextSwitchOnAllAssistants awaits every assistant's onContextSwitch sequentially on the main actor from checkContextSwitch, whereas the prior code dispatched onContextSwitch fire-and-forget inside `Task { }` and returned immediately. The plugin awaits checkContextSwitch in the capture loop (before trackFrame), so each app/window switch now blocks the main actor for the full sequential run of every assistant. Dispatch the switches concurrently (e.g. `TaskGroup` / `async let`) — or, if the awaited ordering is only needed for the spy test, keep a Task-based dispatch in production and have the test await the result differently.</comment>
<file context>
@@ -181,69 +188,70 @@ class AssistantCoordinator {
+ newWindowTitle: String?
+ ) async {
+ for (_, assistant) in assistants {
+ await assistant.onContextSwitch(
+ departingFrame: departingFrame,
+ newApp: newApp,
</file context>
| @@ -0,0 +1,3 @@ | |||
| { | |||
| "change": "Fixed focus suggestions going silent when the context-buckets rollout was enabled: every assistant hears context switches again, not just the task assistant" | |||
There was a problem hiding this comment.
P3: The changelog line starts user-facing (“focus suggestions going silent”) but then describes implementation details (“every assistant hears context switches again, not just the task assistant”) that add no user-visible meaning. Keep the fragment to the outcome users experience so release notes stay user-facing.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/changelog/unreleased/20260814-buckets-context-switch-starvation.json, line 2:
<comment>The changelog line starts user-facing (“focus suggestions going silent”) but then describes implementation details (“every assistant hears context switches again, not just the task assistant”) that add no user-visible meaning. Keep the fragment to the outcome users experience so release notes stay user-facing.</comment>
<file context>
@@ -0,0 +1,3 @@
+{
+ "change": "Fixed focus suggestions going silent when the context-buckets rollout was enabled: every assistant hears context switches again, not just the task assistant"
+}
</file context>
| func testCooldownCapsAtThirtySecondsOnlyAtMaximumLevel() { | ||
| XCTAssertEqual(SuggestionGatePolicy.cooldown(base: 180, frequencyLevel: 5), 30) | ||
| func testCooldownCapsAtTwentySecondsOnlyAtMaximumLevel() { | ||
| XCTAssertEqual(SuggestionGatePolicy.cooldown(base: 180, frequencyLevel: 5), 20) |
There was a problem hiding this comment.
P3: The doc comment above this test still says "Maximum caps the between-nudge cooldown at 30 s", but the test now asserts a 20 s cap. Update the comment to 20 s so the pinned behavior and its documentation don't contradict.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Tests/SuggestionAssistantTests.swift, line 97:
<comment>The doc comment above this test still says "Maximum caps the between-nudge cooldown at 30 s", but the test now asserts a 20 s cap. Update the comment to 20 s so the pinned behavior and its documentation don't contradict.</comment>
<file context>
@@ -82,19 +82,19 @@ final class SuggestionGatePolicyTests: XCTestCase {
- func testCooldownCapsAtThirtySecondsOnlyAtMaximumLevel() {
- XCTAssertEqual(SuggestionGatePolicy.cooldown(base: 180, frequencyLevel: 5), 30)
+ func testCooldownCapsAtTwentySecondsOnlyAtMaximumLevel() {
+ XCTAssertEqual(SuggestionGatePolicy.cooldown(base: 180, frequencyLevel: 5), 20)
XCTAssertEqual(SuggestionGatePolicy.cooldown(base: 20, frequencyLevel: 5), 20)
XCTAssertEqual(SuggestionGatePolicy.cooldown(base: 180, frequencyLevel: 4), 180)
</file context>
| idleSeconds: idleSeconds, | ||
| now: now | ||
| now: now, | ||
| forceHeartbeatCapture: SuggestionPacing.forcesHeartbeatCapture( |
There was a problem hiding this comment.
P3: captureFrame() reads NotificationService.currentFrequencyLevel() three separate times per capture tick (idle gate, forceHeartbeatCapture, idleThresholdOverride). Hoist it into one local so the idle gate and the capture-trigger override always use the same value and avoid redundant UserDefaults reads at the 1 Hz poll rate.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift, line 890:
<comment>captureFrame() reads NotificationService.currentFrequencyLevel() three separate times per capture tick (idle gate, forceHeartbeatCapture, idleThresholdOverride). Hoist it into one local so the idle gate and the capture-trigger override always use the same value and avoid redundant UserDefaults reads at the 1 Hz poll rate.</comment>
<file context>
@@ -879,7 +886,12 @@ public class ProactiveAssistantsPlugin: NSObject {
idleSeconds: idleSeconds,
- now: now
+ now: now,
+ forceHeartbeatCapture: SuggestionPacing.forcesHeartbeatCapture(
+ frequencyLevel: NotificationService.currentFrequencyLevel()),
+ idleThresholdOverride: SuggestionPacing.captureIdleThreshold(
</file context>
…ion assistant The context_buckets rollout starved focus nudges three ways: the coordinator's buckets path fired onContextSwitch only on the task assistant (Suggestion's dwell anchor never armed, analyze() silently no-oped), SuggestionAssistant.isEnabled was hard-gated on !ContextBucketsFeature.isEnabled (the director was supposed to replace it and delivered almost nothing), and context tracking died whenever a bucket-visit write failed because lastTrackedApp was only set inside the do blocks. With the flag at 100% of all users, focus notifications stopped fleet-wide with no error logged (Aug 13-14 2026; mitigated live by disabling the flag). - checkContextSwitch fires onContextSwitch on ALL assistants in buckets mode, awaited, outside the bucket-persistence do/catch - SuggestionAssistant.isEnabled = user setting only; replacing the assistant must be an explicit evidenced change, not a rollout side effect - lastTrackedApp/lastTrackedWindowTitle update regardless of bucket-DB health - deterministic regression test: spy assistant hears switches with buckets on (caught the tracking-dies-with-DB bug by failing before the third fix)
… demos At frequency level 5 only: dwell 4s (was 30s), settle 2s (was 6s), cooldown capped at 20s (was 180s), confidence bar capped at 0.75, dedup memory 2 (was 10) so a small task set rotates instead of starving cadence, and the paid evaluation budget rises to 600/day to cover the faster cadence the user explicitly opted into. Levels 0-4 keep every long-standing value byte-for-byte (pinned by SuggestionPacingTests). SuggestionPacing is the single surface where the two regimes may differ.
… of stillness Passive feed/video watching produces no keyboard or mouse input, so the 60s idle gate froze both focus nudges and Rewind capture exactly when the Maximum user asked to be nudged. Level 5 extends the idle window to 300s; levels 0-4 keep the 60s gate (pinned in SuggestionPacingTests).
…h evaluation Calm levels evaluate once per context arrival by design; that one-shot consume made 'stay on the feed, keep nudging' impossible at any pacing. Maximum keeps the context armed so the same feed re-evaluates every cooldown interval; cooldown and the daily budget still bound spend. Levels 0-4 unchanged (pinned in SuggestionPacingTests).
…he promised cadence Live 10-trial run on a real TikTok feed: first nudge landed in 6-7s, but every repeat was eaten by the duplicate filter (same open commitments produce near-identical nudges) or a 70%-confidence dip. Maximum's contract is a steady stream — repeat-suppression defeats it, so dedup memory drops to 0 and the bar caps at 0.65 there. Calm levels keep 10-deep dedup and the configured bar (pinned in SuggestionPacingTests).
Live marathon showed delivery gaps of 39-64s on a mostly-static feed page: the same-context preview-similarity skip and heartbeat backoff starve the evaluation cadence Maximum promises. At level 5 the trigger captures a real frame every base heartbeat; calm levels keep the cost-saving preview path (pinned in SuggestionPacingTests).
…ext, and the capture trigger honors the level-aware idle window Live marathon on a real TikTok feed (v6, 10 trials): repeat gaps were 18-26s across the board, but two first-nudge times (12.3s, 31.8s) missed the <10s bar — both were cooldown carry-over from a nudge delivered in the previous context moments earlier. At Maximum, an anchor newer than the last evaluation now clears the cooldown baseline; same-context repeats keep the anchor older, so their pacing is untouched, and the daily budget still bounds spend. Also fixes the reviewer-caught idle bypass: ProactiveCaptureTrigger's internal 60s idle check now takes the level-aware override, with a behavioral test proving Maximum at 120s stillness still reaches a heartbeat capture while Balanced skips.
c352919 to
cb022d9
Compare
What
Nik's demo spec for the Maximum notification level: open TikTok/X → focus nudge in <10 seconds; keep the feed open → another nudge under every half minute, indefinitely. This PR makes level 5 deliver that, verified with 10 consecutive live trials on a real TikTok feed, while every calmer level stays byte-identical (test-pinned).
Stacked on the context-buckets starvation fix (supersedes #11554 — same commits included; that PR will be closed on merge).
SuggestionPacingis the single surface where Maximum may differ:ProactiveCaptureTrigger's own idle check (reviewer-caught bypass, now with a behavioral test at idleSeconds=120)Merged #11553's 10s-dwell/30s-cooldown values are superseded by this newer spec; its hide/re-hide and no-snooze-gate behavior is preserved.
SuggestionGatePolicy.requiredDwell/cooldownnow delegate toSuggestionPacing.Product invariants
None matched (
scripts/pr-preflight --suggest).Failure-Class: none
Verification
SuggestionPacingTests(Maximum values + every calm level's 30/6/180/0.85/10/40 asserted level-by-level; caps never raise user-configured values; idle-override behavioral test; heartbeat/re-arm/waiver policy tests). Focused suites green; changed fix(desktop): Hide-for-2h keeps notifications; Maximum level nudges in ~10s with 30s repeats; unsilence suggestions from the buckets flag #11553 expectations (10s→4s, 30s→20s) cite Nik's explicit spec: "receive a notification almost immediately in <10 seconds… every <30 seconds"..cross-review-verify.png: live floating-bar nudge card ("Suggested by Omi …") captured seconds after delivery on this build.Line-Count-Exception: desktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift | 1761 -> 1773 | 12 lines wiring the level-aware idle threshold and forced-heartbeat flag into the two capture-gate call sites; the policy itself lives in SuggestionPacing (SuggestionModels.swift), splitting these call sites out would separate a gate check from the loop that owns it