Skip to content

fix(app,backend): BigText chat-answer notifications + chat deep-link - #13173

Merged
kodjima33 merged 4 commits into
BasedHardware:mainfrom
apoorvdarshan:cursor/fix-4375-chat-answer-bigtext-8d4b
Sep 11, 2026
Merged

kodjima33 merged 4 commits into
BasedHardware:mainfrom
apoorvdarshan:cursor/fix-4375-chat-answer-bigtext-8d4b

Conversation

@apoorvdarshan

@apoorvdarshan apoorvdarshan commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Fixes #4375. Click-to-talk / chat-answer notifications were truncated in the Android shade and tapping them opened the app without navigating to the chat. This PR delivers chat answers as client-displayed FCM (data-only on Android + APNS alert on iOS) so Flutter can render BigText locally with a navigate_to payload.

Supersedes #13065 (dirty merge base + CHANGES_REQUESTED). Clean branch cut from current BasedHardware/omi main.

Integration vs #13065 review

  1. Rebased on current main — keeps send_chat_message_notification_async + _chat_message_notification; both sync and async chat paths use the client-displayed sender.
  2. Reuses NotificationUtil.navigateToFromFcmData / handleNavigateTo — no cold-start navigator race (bug: Tapping Omi response notifications doesn't navigate to the correct conversation #5126).
  3. Single FCM background handler — chat-answer BigText is patched into main.dart's _firebaseMessagingBackgroundHandler; no fcm_background_handler.dart dual registration.
  4. Extends backend/utils/notifications.py — send_client_displayed_notification / _async share APNS topic, failure codes, and token pruning (no parallel chat_answer_notifications.py).
  5. Cubic issues — background path invokes ChatAnswerNotificationHandler; initial-message navigation stays on NotificationUtil; unit tests use testing.import_isolation as on main.

Review follow-up (CHANGES_REQUESTED → 5789f10)

  1. FCM 4KB payload — dropped duplicated payload['body']; answer travels once via data['text']. APNS/webpush still receive display_body for system alerts.
  2. Foreground / speaking — FCM early branch gates on !OmiVoicePlaybackService.instance.isSpeaking; handler only creates a shade notification when !isAppInForeground (merge-handler pattern).

Product notes left for maintainer review (same as #13065): data-only Android drops system-tray fallback when the client handler cannot run; wakeUpScreen is not enabled (matches merge/important handlers).

Product invariants affected

  • INV-DATA-1 — touched app/lib/main.dart only to add the chat-answer branch in the existing FCM background handler. Preserves existing production-family routing / Firebase authority; no data-plane or API-base change.

How it was verified

# Backend unit (client-displayed shape + no body duplication)
cd backend && source .venv/bin/activate
ENCRYPTION_SECRET=test PYTHONPATH=. python -m pytest \
  tests/unit/test_chat_answer_client_displayed_notification.py -q --tb=short
# → 5 passed

Device BigText / tap-to-chat could not be exercised in this Linux Cloud VM (no Android SDK / physical device). Flutter unit file app/test/unit/chat_answer_notification_handler_test.dart is included for CI Mobile App Checks.

Tests

  • backend/tests/unit/test_chat_answer_client_displayed_notification.py — data-only Android message, APNS alert, push_type=chat_answer, sync + async senders, no duplicated body, long-answer under 4KB
  • app/test/unit/chat_answer_notification_handler_test.dart — isChatAnswerData predicate cases
  • Stub updates so suites that load real utils.chat still import the new notification APIs

Failure class (fixes)

Failure-Class: none

Fixes BasedHardware#4375. Chat answers use a client-displayed FCM path (data-only on
Android, APNS alert on iOS) so Flutter can render BigText locally with a
navigate_to payload. Extends utils/notifications.py instead of a parallel
module; keeps async send_chat_message_notification_async wired; patches
main.dart's single background handler (no dual registration); reuses
NotificationUtil for cold-start taps.

Failure-Class: none

Co-authored-by: Apoorv Darshan <[email protected]>

@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.

All reported issues were addressed across 10 files

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

Re-trigger cubic

Comment thread backend/utils/notifications.py Resolved

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the clean rebase - this integrates far better than #13065: one background entrypoint in main.dart's _firebaseMessagingBackgroundHandler (no second registration), tap routing reuses NotificationUtil.navigateToFromFcmData/handleNavigateTo so cold-start taps survive the navigator race, and the client-displayed sender shares APNS topic, failure codes, and token pruning with the existing send_notification paths. I also verified the foreground path still emits ServerMessage before the early return, so in-app consumers are unaffected, and the legacy compat branch (notification_type == 'plugin' + /chat/ route) in isChatAnswerData keeps old-format pushes working.

Two issues block merge for me, both in this PR's core surface:

  1. backend/utils/notifications.py - send_client_displayed_notification and its _async twin set payload['body'] = body on top of the data['text'] field that NotificationMessage.get_message_as_dict already carries, so the full answer travels twice in the data payload. FCM caps data payloads at 4KB and rejects the entire message when it's exceeded, so long answers (roughly 2k+ chars) will make the push fail silently - the notification disappears entirely instead of expanding as BigText. That's a regression versus the current single-copy path and it hits exactly the long-answer case this PR is fixing. ChatAnswerNotificationHandler._resolveBody already falls back to data['text'], so dropping (or bounding) the duplicated body keeps behavior while halving the payload.

  2. app/lib/services/notifications/chat_answer_notification_handler.dart - handle() creates the notification unconditionally; isAppInForeground is only used in the debug log, unlike the sibling handlers (MergeNotificationHandler.handleMergeCompleted, ImportantConversationNotificationHandler) which only display when the app is backgrounded. Two visible consequences: (a) on Android foreground, the early branch in notification_service_fcm.dart runs before the !OmiVoicePlaybackService.instance.isSpeaking guard, so a shade notification now pops while Omi is speaking the answer aloud; (b) on iOS foreground, listenForMessages previously showed nothing (_shouldShowForegroundNotificationOnFCMMessageReceived() is Android-only) and now presents a local banner while the user is inside the app. If foreground display is intended for chat answers, please gate the foreground call site on the speaking state (mirroring the legacy branch just below it) and make the isAppInForeground semantics explicit; otherwise display only when !isAppInForeground like the merge/important handlers.

The rest checks out, verified against the diff:

  • app/lib/main.dart - the new else-if branch in _firebaseMessagingBackgroundHandler matches the existing handler chain, and the comment correctly warns against re-registering a second background handler.
  • app/lib/services/notifications/notification_service_fcm.dart - the legacy _showForegroundNotification path now selects NotificationLayout.BigText for /chat/ routes and threads the payload through; taps flow through the existing awesome-notifications action path (_handleAppLinkOrDeepLink polls for the navigator, so terminated-state taps work).
  • backend/utils/chat.py - both send_chat_message_notification and send_chat_message_notification_async use the client-displayed sender; no stale references to the removed send_notification import; call sites unchanged.
  • backend/utils/notifications.py - _build_apns_config's new alert branch sets apns-push-type: alert / priority 10 / topic correctly; _build_message(client_displayed=True) omits the top-level notification and the Android notification config while webpush keeps title/body with the HTTPS-link guard intact.
  • Tests - chat_answer_notification_handler_test.dart covers the matcher including legacy-plugin and negative cases; test_chat_answer_client_displayed_notification.py asserts the message shape (no top-level notification, push_type, APNS alert) for both senders; the three stub updates (test_chat_stream_error_fallback.py, test_desktop_transcribe.py, test_sync_silent_failure.py) only mock the new symbols on the already-stubbed utils.notifications module - no production behavior masked.

Also noting the tradeoff you flagged in the description: data-only Android delivery means no system-tray fallback if the background isolate can't run (Doze / aggressive OEM killers), and wakeUpScreen stays off. Reasonable call, but it's a notification-reliability product decision that needs explicit maintainer sign-off alongside merge review.

Requesting changes on items 1 and 2; happy to re-review. Human maintainer sign-off needed for the data-only fallback tradeoff, which the PR description itself defers.


AI-generated maintainer feedback on behalf of the Omi maintainers. Leaving for human maintainer sign-off on the data-only Android delivery tradeoff noted above.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

Drop duplicated payload['body'] from client-displayed chat pushes so the
answer travels once via data['text']; keep APNS/webpush display_body.
Match merge-handler foreground semantics and suppress shade while speaking.

Failure-Class: none

Co-authored-by: Apoorv Darshan <[email protected]>
@apoorvdarshan

Copy link
Copy Markdown
Collaborator Author

Addressed both CHANGES_REQUESTED items in 5789f10:

  1. FCM 4KB duplication — send_client_displayed_notification / _async no longer set payload['body']. Answer stays in data['text'] only; APNS alert still uses display_body. Tests updated + added a long-answer regression.
  2. Foreground / speaking gating — speaking guard at the FCM call site; handler only shows the shade when backgrounded (merge-handler semantics).

Ready for re-review.

— Apoorv

Run dart format --line-length 120 on changed Dart files so the
Formatting CI job passes (notification_service_fcm.dart was the
reported failure; main.dart, chat_answer_notification_handler.dart,
and chat_answer_notification_handler_test.dart were also reformatted).

Verification: dart format --line-length 120 --set-exit-if-changed --output=none (4 files, 0 changed)

Co-authored-by: Apoorv Darshan <[email protected]>
@apoorvdarshan

Copy link
Copy Markdown
Collaborator Author

Formatting fixed — ran dart format --line-length 120 on the four changed Dart files (notification_service_fcm.dart was the CI failure; also main.dart, chat_answer_notification_handler.dart, chat_answer_notification_handler_test.dart). New head: 48e33c6c13.

CI Formatting runs flutter pub get before dart format, which resolves
app/analysis_options.yaml (formatter.page_width: 120) and applies the
Dart 3.7+ formatter. The prior fix ran without pub resolution and
reformatted authMethod / ChangeNotifierProxyProvider4 differently than
CI expects.

Verification (after cd app && flutter pub get):
  dart format --line-length 120 --set-exit-if-changed --output=none (4 dart files, 0 changed)
  scripts/backend-python-format --check (6 py files, unchanged)

Co-authored-by: Apoorv Darshan <[email protected]>
@apoorvdarshan

Copy link
Copy Markdown
Collaborator Author

Formatting fix (take 2): CI runs flutter pub get before dart format, which fully resolves app/analysis_options.yaml (formatter.page_width: 120) and uses the Dart 3.7+ formatter. The prior format commit ran without resolved packages and reformatted main.dart differently than CI expects.

Re-ran after cd app && flutter pub get; only main.dart needed adjustment (reverted authMethod / ChangeNotifierProxyProvider4 wrapping to CI-expected layout).

New head: 60633dfb0c

@Git-on-my-level
Git-on-my-level dismissed their stale review September 11, 2026 05:46

Both concerns from this review are resolved on the current head (5789f10 / 60633df): send_client_displayed_notification no longer duplicates the answer in payload['body'] (single copy via data['text']; APNS alert keeps display_body), and the chat-answer shade path is now gated on !OmiVoicePlaybackService.instance.isSpeaking with display only when backgrounded (merge-handler semantics).

@Git-on-my-level

Copy link
Copy Markdown
Member

Both items from the earlier changes-requested review are verified fixed on 60633df — thanks for the quick turnaround and the clean fix commit.

  1. FCM payload duplication — send_client_displayed_notification / _async no longer set payload['body']; the answer travels once via data['text'] (filled from the body arg only when text is absent), and display_body now feeds only the APNS alert and webpush notification. test_chat_answer_client_displayed_notification.py asserts 'body' not in msg.data on both senders plus the text-fill fallback. One small accuracy note: your reply mentions a 2500-char size-cap test, but I don't see it in the test file at this head — the not-in-data assertions are what carry the regression guard, so this is a nit rather than a blocker. If you do add the size test, asserting the serialized data stays under FCM's 4KB for a long answer would be the right shape.

  2. Foreground/speaking gating — notification_service_fcm.dart's early branch now requires !OmiVoicePlaybackService.instance.isSpeaking, and ChatAnswerNotificationHandler.handle early-returns while foregrounded (merge-handler semantics), with the background entrypoint in main.dart passing isAppInForeground: false. Net behavior: foreground answers are consumed in-app via ServerMessage; the BigText shade entry appears only when backgrounded — consistent with MergeNotificationHandler / ImportantConversationNotificationHandler.

Everything else still checks out on this head:

  • backend/utils/notifications.py — _build_message(client_displayed=True) omits the top-level notification and the Android notification config (data-only), _build_apns_config's alert branch sets apns-push-type: alert / priority 10 / topic correctly, and webpush keeps title/body with the HTTPS-link guard intact (relative /chat/ routes correctly excluded). Token pruning and permanent-failure handling stay shared with the legacy senders via _send_to_user / _collect_send_results.
  • backend/utils/chat.py — both the sync and streaming chat paths use the client-displayed sender; no bare send_notification references remain, and _chat_message_notification still sets navigate_to=/chat/{app_id} so the deep-link payload survives.
  • app/lib/main.dart — the new else-if sits after the type-keyed handlers (chat answers carry type='text', so no routing conflict) and keeps the single background registration the comment warns about.
  • app/lib/services/notifications/chat_answer_notification_handler.dart — nice detail: notificationId derives from (messageId ?? body).hashCode, so repeated deliveries replace the shade entry instead of stacking, unlike the Random() id in the legacy foreground path.
  • app/test/unit/chat_answer_notification_handler_test.dart — covers the matcher both ways (new push_type, legacy notification_type=plugin + /chat/ route, and two negatives).
  • test_chat_stream_error_fallback.py, test_desktop_transcribe.py, test_sync_silent_failure.py — the stub updates only mock the new symbols on already-stubbed utils.notifications modules; no production behavior masked.
  • Tap routing: Android taps on the local BigText notification flow through the awesome-notifications action stream → _handleAppLinkOrDeepLink with the navigate_to payload; FCM-delivered taps route via navigateToFromFcmData; both terminate in the matching chat.

Left for human maintainer sign-off (unchanged from the prior review, and deliberately outside this PR's scope): data-only Android delivery drops the system-tray fallback when the client handler can't run (Doze / aggressive OEM killers), and wakeUpScreen stays off. That's a notification-reliability product call the PR description itself defers — it needs a maintainer decision alongside merge review, not a code change here.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added needs-maintainer-review Needs a human maintainer to sign off before merge positive-signal Automation verified a genuine fix/quality contribution labels Sep 11, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fix confirmed real (Fixes #4375, BigText chat notifications). Prior CHANGES_REQUESTED (FCM 4KB payload duplication, missing foreground/speaking gate) addressed in follow-up commit 5789f10 and dismissed; cubic confirms all issues addressed. CI green, tests added. 4/5 confidence (only scoped-diff line count exceeds threshold).

@kodjima33
kodjima33 merged commit 6b36701 into BasedHardware:main Sep 11, 2026
41 of 42 checks passed
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Sep 11, 2026
… boundary ratchet

BasedHardware#13173 added `send_client_displayed_notification` and its async twin to
`utils/notifications.py`, and moved `utils/chat.py` off `send_notification`
onto them. Both new functions reach `_send_to_user{,_async}` directly, so
they are transport entry points like the ones already listed — but the
scanner did not know the names, so after merging main `chat.py` read as 0
direct calls and the checker demanded the baseline drop it.

That would have recorded a reduction that never happened and left two
unguarded ways to own transport. Adding the names restores `chat.py: 2`,
so the baseline is unchanged and the ratchet still holds at 20.

Failure-Class: none
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Sep 14, 2026
The boundary ratchet guarded a hand-written list of seven names — two private, five public — and
utils/notifications.py has thirteen public functions that call an FCM
primitive directly. The other eight — send_action_item_data_message, the
action-item update/deletion/batch-deletion messages,
send_apple_reminders_sync_push{,_async}, send_important_conversation_message
and send_merge_completed_message — were bypasses a new producer could use
without tripping the check, and twelve existing call sites already did.

The recorded 20 was exact only for the subset. Against the module's real
surface the tree has 32 direct calls across 18 files.

Two properties make this worth fixing before merge rather than after. The
baseline must exactly match observed counts and may never grow per file, so
once it is on main, widening the guard means migrating every newly visible
call site in the same PR or weakening the check. And the list has already
drifted once: the first entry point added after it (BasedHardware#13173) went unguarded
until a merge happened to surface it.

So the list is gone. The checker reads the transport module and treats as an
entry point every public function whose own body calls _send_to_user,
_send_to_user_async or _send_messages. A sender added tomorrow is guarded the
day it lands, with no edit here. The baseline is regenerated at the honest 32;
there is no baseline on main yet, so this is the one moment that costs nothing.

Direct callers only, and that limit is stated in the checker and pinned by a
test: a wrapper delivering through another public function
(send_credit_limit_notification -> send_notification) is not itself counted.
A missing or unparseable transport module raises rather than deriving an empty
list that would pass as zero calls.

Mutation-checked: restoring a fixed list fails the new derivation test, and
the real tree's ratchet rejects a baseline that no longer matches; a fresh
producer calling send_merge_completed_message — previously unguarded — is now
counted and rejected.

Failure-Class: none

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Click to talk notifications don't show full text and won't take me to the chat with that answer

4 participants