Skip to content

fix(desktop): context-buckets mode must not silence the focus suggestion assistant - #11554

Closed
kodjima33 wants to merge 1 commit into
mainfrom
kodjima33/buckets-starve-suggestions
Closed

kodjima33 wants to merge 1 commit into
mainfrom
kodjima33/buckets-starve-suggestions

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

What

The context_buckets rollout silently killed focus (suggestion) nudges for everyone in the flag cohort — and the flag was at 100% of all users. Nik's last delivered focus nudge before the fix: Aug 12 23:06; nothing after, with zero errors logged anywhere. Insights/memories/tasks kept working, which is exactly the signature: focus is the only assistant whose pipeline starts from a context switch.

Three defects, one per commit hunk:

  1. Coordinator starved the assistants. The buckets path of AssistantCoordinator.checkContextSwitch fired onContextSwitch only on assistants["task-extraction"]. SuggestionAssistant.analyze returns nil before any logging when no switch ever armed its dwell anchor. Now a shared fireContextSwitchOnAllAssistants fires on every registered assistant in buckets mode and out of it — awaited, and outside the bucket-persistence do/catch.
  2. SuggestionAssistant.isEnabled was hard-gated on !ContextBucketsFeature.isEnabled — the context director was supposed to replace live suggestions and delivered almost nothing. The gate is removed; replacing the assistant must be an explicit evidenced change, not a rollout side effect.
  3. Context tracking died with the bucket DB. lastTrackedApp was only assigned inside the do blocks, so any bucket-visit write failure left tracking unprimed and every assistant starved. Tracking now updates regardless of persistence health. (Found by the new regression test failing in the hermetic test host, where the bucket store throws.)

Live mitigation already shipped separately: the PostHog flag (id 817239) was disabled at 02:00; this PR makes re-enabling it safe.

Product invariants

None matched (scripts/pr-preflight --suggest: no invariant IDs emitted for these paths).

Failure-Class: none

Verification

  • New deterministic regression test testBucketsModeDispatchesContextSwitchToEveryAssistant (spy assistant hears switches with buckets forced on; no wall-clock sleeps — dispatch is awaited, registration visibility via bounded Task.yield()); AssistantCoordinatorTests 4/4 green; check_desktop_test_quality.py at/below baseline (16 waits, unchanged).
  • Live on omi-ankara built from this branch with OMI_FORCE_CONTEXT_BUCKETS=1 (real signed-in account):
    • probe_suggestion_nudge pre-fix returned {"outcome": "disabled"}; post-fix it ran the full pipeline — {commitments: 3, goals: 5, confidence: 80, outcome: filtered_low_confidence} (honest below-bar refusal).
    • Organic proof: the running bundle logged real Suggestion: skipped (skippedDwell) app=Warp / below bar [80% < 85%] lines from the user's own app switches with buckets ON — the exact signature absent all day on broken builds.
  • Fleet evidence of the outage: PostHog fleet gate outcomes continued (other users mostly weren't on builds with the buckets code yet); the affected machine logged zero Suggestion: lines across every app instance from Aug 13 02:59 (first build carrying the rollout) until the flag was disabled.

Review in cubic

…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)

@cubic-dev-ai cubic-dev-ai 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.

3 issues found across 4 files

Confidence score: 4/5

  • In desktop/macos/Desktop/Sources/ProactiveAssistants/Core/AssistantCoordinator.swift, fireContextSwitchOnAllAssistants now awaits each onContextSwitch serially within checkContextSwitch, which can make the default path wait on assistant work and risk delayed context handling if any assistant is slow — dispatch these callbacks asynchronously (or in parallel) so the caller is not blocked.
  • In desktop/macos/Desktop/Tests/AssistantCoordinatorTests.swift, the buckets-enabled test hits real shared singletons and persistence paths, so test outcomes can depend on global state and become flaky or mask regressions — isolate with injected fakes/mocks or explicit singleton reset/cleanup.
  • In desktop/macos/changelog/unreleased/20260814-buckets-context-switch-starvation.json, the entry emphasizes implementation details over user-visible behavior, which can confuse release notes quality and consistency — rewrite the fragment around the user impact/outcome.
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's second half describes implementation mechanics ("every assistant hears context switches again, not just the task assistant") rather than the user-visible outcome. Desktop changelog fragments must describe behavior from the user's perspective (per `changelog/README.md` and this repo's convention).</violation>
</file>

<file name="desktop/macos/Desktop/Tests/AssistantCoordinatorTests.swift">

<violation number="1" location="desktop/macos/Desktop/Tests/AssistantCoordinatorTests.swift:68">
P3: This test is not hermetic: checkContextSwitch with bucketsEnabled runs the real bucket persistence path against the shared singletons (ContextVisitCoordinator/ContextBucketStore, ContextProactivityEngine with the live ProactiveLaneClient, ContextBucketRollupWriter), so it can write to the real bucket DB and trigger backend/rollup Tasks when persistence succeeds, and it leaves AssistantCoordinator.shared.lastTrackedApp permanently set to "SpyTargetApp". That contradicts the PR's "hermetic" claim and risks non-deterministic side effects and cross-test contamination. Currently it is the only test touching the coordinator, but consider isolating the coordinator (fresh instance or a reset hook that clears lastTrackedApp/lastTrackedWindowTitle) instead of mutating the shared singletons.</violation>
</file>

<file name="desktop/macos/Desktop/Sources/ProactiveAssistants/Core/AssistantCoordinator.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/ProactiveAssistants/Core/AssistantCoordinator.swift:199">
P2: `fireContextSwitchOnAllAssistants` awaits each assistant's `onContextSwitch` serially inside `checkContextSwitch`, changing the previous fire-and-forget `Task {}` dispatch. In the flag-off (default) path the caller now blocks for the sum of every assistant's handler instead of returning immediately, and in buckets mode this serial await runs while `contextTransitionQueue` is still held in-flight (between `begin` and the `defer`'d `finish`), so a slow assistant delays every subsequent context transition. Keep the per-assistant dispatch concurrent (non-blocking) while still awaiting completion only where the test needs determinism.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

}
lastTrackedApp = newApp
lastTrackedWindowTitle = newWindowTitle
await fireContextSwitchOnAllAssistants(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: fireContextSwitchOnAllAssistants awaits each assistant's onContextSwitch serially inside checkContextSwitch, changing the previous fire-and-forget Task {} dispatch. In the flag-off (default) path the caller now blocks for the sum of every assistant's handler instead of returning immediately, and in buckets mode this serial await runs while contextTransitionQueue is still held in-flight (between begin and the defer'd finish), so a slow assistant delays every subsequent context transition. Keep the per-assistant dispatch concurrent (non-blocking) while still awaiting completion only where the test needs determinism.

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 199:

<comment>`fireContextSwitchOnAllAssistants` awaits each assistant's `onContextSwitch` serially inside `checkContextSwitch`, changing the previous fire-and-forget `Task {}` dispatch. In the flag-off (default) path the caller now blocks for the sum of every assistant's handler instead of returning immediately, and in buckets mode this serial await runs while `contextTransitionQueue` is still held in-flight (between `begin` and the `defer`'d `finish`), so a slow assistant delays every subsequent context transition. Keep the per-assistant dispatch concurrent (non-blocking) while still awaiting completion only where the test needs determinism.</comment>

<file context>
@@ -181,69 +188,70 @@ class AssistantCoordinator {
         }
+        lastTrackedApp = newApp
+        lastTrackedWindowTitle = newWindowTitle
+        await fireContextSwitchOnAllAssistants(
+          departingFrame: departingFrame, newApp: newApp, newWindowTitle: newWindowTitle)
         return true
</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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The changelog's second half describes implementation mechanics ("every assistant hears context switches again, not just the task assistant") rather than the user-visible outcome. Desktop changelog fragments must describe behavior from the user's perspective (per changelog/README.md and this repo's convention).

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's second half describes implementation mechanics ("every assistant hears context switches again, not just the task assistant") rather than the user-visible outcome. Desktop changelog fragments must describe behavior from the user's perspective (per `changelog/README.md` and this repo's convention).</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>


// First call primes the tracked context; the second is a real switch. The dispatch is
// awaited inside checkContextSwitch, so by the time it returns the spy has heard it.
_ = await AssistantCoordinator.shared.checkContextSwitch(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: This test is not hermetic: checkContextSwitch with bucketsEnabled runs the real bucket persistence path against the shared singletons (ContextVisitCoordinator/ContextBucketStore, ContextProactivityEngine with the live ProactiveLaneClient, ContextBucketRollupWriter), so it can write to the real bucket DB and trigger backend/rollup Tasks when persistence succeeds, and it leaves AssistantCoordinator.shared.lastTrackedApp permanently set to "SpyTargetApp". That contradicts the PR's "hermetic" claim and risks non-deterministic side effects and cross-test contamination. Currently it is the only test touching the coordinator, but consider isolating the coordinator (fresh instance or a reset hook that clears lastTrackedApp/lastTrackedWindowTitle) instead of mutating the shared singletons.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Tests/AssistantCoordinatorTests.swift, line 68:

<comment>This test is not hermetic: checkContextSwitch with bucketsEnabled runs the real bucket persistence path against the shared singletons (ContextVisitCoordinator/ContextBucketStore, ContextProactivityEngine with the live ProactiveLaneClient, ContextBucketRollupWriter), so it can write to the real bucket DB and trigger backend/rollup Tasks when persistence succeeds, and it leaves AssistantCoordinator.shared.lastTrackedApp permanently set to "SpyTargetApp". That contradicts the PR's "hermetic" claim and risks non-deterministic side effects and cross-test contamination. Currently it is the only test touching the coordinator, but consider isolating the coordinator (fresh instance or a reset hook that clears lastTrackedApp/lastTrackedWindowTitle) instead of mutating the shared singletons.</comment>

<file context>
@@ -46,4 +46,59 @@ final class AssistantCoordinatorTests: XCTestCase {
+
+    // First call primes the tracked context; the second is a real switch. The dispatch is
+    // awaited inside checkContextSwitch, so by the time it returns the spy has heard it.
+    _ = await AssistantCoordinator.shared.checkContextSwitch(
+      newApp: "SpyBaselineApp", newWindowTitle: "baseline", bucketsEnabled: true)
+    _ = await AssistantCoordinator.shared.checkContextSwitch(
</file context>

@kodjima33

Copy link
Copy Markdown
Collaborator Author

Superseded by #11562, which contains these commits rebased plus the Maximum pacing work verified in the 10-trial live marathon.

@kodjima33 kodjima33 closed this Aug 14, 2026
@kodjima33
kodjima33 deleted the kodjima33/buckets-starve-suggestions branch August 14, 2026 10:25
@github-actions

Copy link
Copy Markdown
Contributor

Hey @kodjima33 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

kodjima33 added a commit that referenced this pull request Aug 14, 2026
…cus-nudge cadence (+ context-buckets starvation fix) (#11562)

## 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).

`SuggestionPacing` is the single surface where Maximum may differ:
- dwell 4s (30s elsewhere), settle 2s (6s), cooldown capped 20s (180s),
confidence bar capped 0.65, dedup memory 0 (10 — the user asked to be
nagged repeatedly), daily evaluation budget 600 (40)
- context re-arms after an eligible evaluation (calm levels stay
one-shot per arrival)
- fresh context waives leftover cooldown (same-context repeats stay
paced; anchor-vs-lastEvaluation ordering makes this safe)
- capture: full frame every base heartbeat (no preview-similarity
skip/backoff), and the idle window extends to 300s — including inside
`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/cooldown` now delegate to
`SuggestionPacing`.

## Product invariants

None matched (`scripts/pr-preflight --suggest`).

Failure-Class: none

## Verification

- Pinned-value tests: `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
#11553 expectations (10s→4s, 30s→20s) cite Nik's explicit spec: "receive
a notification almost immediately in <10 seconds… every <30 seconds".
- **Live 10-trial marathon** (omi-ankara from this branch, real
signed-in account, real TikTok feed window frontmost, Maximum): first
delivery per trial = 1.1, 7.2, 7.2, 2.1, 2.0, 1.0, 3.2, 7.3, 6.1, 1.1 s
— **10/10 under 10s**. Inter-delivery gaps while the feed stayed open:
27/28 under 30s (5–26s), one 49s gap from a single below-bar evaluation.
Up to 4 deliveries per 65s hold.
- `.cross-review-verify.png`: live floating-bar nudge card ("Suggested
by Omi …") captured seconds after delivery on this build.
- Earlier iterations' failures that shaped the design are in the commit
messages (one-shot context consume, preview-similarity starvation,
cooldown carry-over, trigger idle bypass).

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


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/11562?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
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