Repository navigation
refactor(backend): centralize app notification dispatch - #12409
undivisible merged 7 commits into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Reviewed file-by-file against the #9518 dispatch-owner plan — this is a strong, well-scoped first slice. Findings below; nothing blocking from my side, but a couple of decisions deserve a human maintainer. Verified sound
For the maintainer
Labeled by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
@undivisible @kodjima33 green and mergeable, reviewed two days ago with nothing blocking. The review flagged three things as needing a human rather than more code: the new boundary ratchet triggers on |
kodjima33
left a comment
There was a problem hiding this comment.
Clean consolidation of notification dispatch with a shrink-only ratchet guard, but it's an explicit refactor (not a bug fix), so approve-only per policy.
|
Answering the one item from the review that was addressed to me rather than to a maintainer — the v1 chat-message ordering. I had left it implicit; here it is checked against both trees. Confirmed: the contract is preserved. A rate-limited v1 request writes no chat message, before or after.
This head: Both return 429 ahead of the write, so suppression skips the chat message on both. That is the behaviour you described, and yes — it is the intended contract. A quota rejection should not leave a chat row implying the notification went out. The one real difference is that No code change from this, so I am not pushing to an approved and clean head. The three items you routed to a maintainer — repo-wide ratchet triggers, the one-time quota-key reset, and v1 transport failures now returning 200 with a logged Also carrying forward, for whoever picks up the next #9518 slice: the daily proactive caps in |
kodjima33
left a comment
There was a problem hiding this comment.
Solid, well-tested backend refactor (dispatcher consolidation) from a trusted contributor, but it's a refactor not a bug fix, so per policy it stays approve-only rather than an auto-merge.
…on-dispatch # Conflicts: # .github/checks-manifest.yaml
|
Conflict resolved on 0645100. Merge of current main only — no change to this diff. The conflict was in Verified by parsing rather than by eye, since a manifest that looks merged and has silently dropped an entry is exactly the failure this file cannot afford: 175 entries here against main's 173, the two added are this PR's, none dropped, no duplicate ids. The ratchet still holds against the moved base, which was the thing worth checking — main advanced 1208 commits, and a new direct transport caller landing there would have shown up as growth: Same count as the approved head, so main added no new bypass while this sat. Verification on the merged head: boundary ratchet held at 20 against Scope is unchanged: The three items routed to a maintainer are unchanged by this merge and still need a yes rather than a change: the boundary ratchet triggering on |
|
Re-verified at the new head Merge resolution is lossless. The manifest at head is exactly the parsed union of both parents' entries — 175 checks, no duplicates, nothing dropped from either side, both Ratchet still holds on the merged tree. Ran Tests re-run green at head with the repo venv: scanner self-tests 5/5; Nothing new blocks from my side. One mechanical item: @kodjima33's approvals are attached to the pre-merge tree (they predate Thanks @aryanorastar — verifying the manifest merge by parsing rather than by eye was exactly the right instinct for that file. by AI on behalf of David — re-approval of the head SHA by a maintainer is the remaining step; the substantive items above need a yes, not a change. |
… point The conflict was `.github/checks-manifest.yaml` for the second time in three days, and both times for the same mechanical reason: main inserts new checks just below the SDK block at the top of `checks:`, which is exactly where this branch's two entries sit. Last merge it was go-device-sdk-tests; this one is typescript-device-sdk-tests. Resolved as the union again, but the two notification-dispatch entries now go at the end of the list instead of the head, so the next check main adds does not collide with them. Order carries no meaning here -- run_checks validates by id and rejects duplicates, and nothing depends on position -- so this costs nothing and stops a conflict that would otherwise recur on every new check. Verified by parsing rather than by eye: 179 entries against main's 177, the two added are this PR's, none dropped, no duplicate ids. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Conflict resolved on acb844e — same file as three days ago, and this time I also removed the reason it keeps happening. Why it recurred. Both conflicts are the same mechanical shape, not a disagreement: main inserts new checks just below the SDK block at the top of So the two Verified by parsing rather than by eye, same as last time: 179 entries against main's 177, the two added are this PR's, none dropped, no duplicate ids. The ratchet held again on a base that moved another 171 commits: Still the same count as the approved head, so no new direct transport caller has landed on main in the two weeks this has been open — which is the whole point of a shrink-only boundary on a staged migration. Verification on the merged head: ratchet held at 20 against The three items routed to a maintainer are untouched by this merge and still need a yes rather than a change: the boundary ratchet triggering on |
|
The two red backend checks on What fails: The Why it isn't this PR. The file is not in this diff — Reproduced on clean main. I checked out Root cause — corrected. My first read of this blamed
So the assertion held for exactly two half-lives and then flipped: Nothing changed in the code on Sep 11 — the clock crossed the band floor. After that instant the test fails permanently, on every backend PR, on main included. Fixed on main. This PR's own surface is unaffected and still green on the head: boundary ratchet held at 20 against |
|
Verified the CI triage and it holds up. All four red checks trace to causes outside this diff: shard 3/4 fails on Also independently confirmed the merge resolution at acb844e is net-exactly the twelve PR files against merged main, with the checks-manifest union lossless. Still leaving the three previously flagged decisions with a human maintainer before merge: the new dispatch-boundary ratchet runs on every future backend PR; the Redis key namespace change resets in-flight integration quotas once at deploy; and v1 now mirrors v2's 200-on-transport-failure contract. The code side looks in good shape. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
… 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
|
Merged current main on The backend red is gone. The merge exposed a hole in this PR's own ratchet, and it would have failed open. #13173 added Taking that at face value would have recorded a reduction that never happened and left two unguarded ways to own transport. So I added the two names to Checked it rather than assuming: with the names added, a fresh file calling The desktop red on I first read that as a cold SwiftPM cache and was wrong — green runs log the same Exit 143 is the harness watchdog's SIGTERM at the 1500s per-invocation ceiling. Every other invocation in that run exited 0 in 16-94s, the machine was otherwise idle for 23 minutes, and the two halved re-runs of that same batch passed in 56s and 48s. So ~1500s of the 2414s is a single batch of 100 suites hanging in one SwiftPM process and then being killed — not build cost, and nothing this diff can reach. This push re-runs the lane. Verified on the new head: boundary ratchet 20 with the baseline untouched, its 6 tests pass, |
|
Delta-verified at Delta since the last reviewed head ( The only PR-authored change is Re-verified at this head in a clean container: ratchet exit 0 ("20 legacy direct calls (ratchet held)"), scanner self-tests 6/6, and the four touched unit files green ( New finding: the ratchet guards 7 of the 16 public transport entry points, and the baseline locks that in at merge
The part that makes this a now-or-never decision: Three reasonable resolutions — maintainer's call, not necessarily more code:
The production slice itself is unaffected and still looks good. @kodjima33's approvals sit on by AI on behalf of David — the ratchet-coverage choice above needs a maintainer decision before merge. |
…on-dispatch # Conflicts: # .github/checks-manifest.yaml
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]>
|
Took option 1, plus the change that stops it recurring, on The finding holds, with one count to correct. Why derive rather than extend the list. Extending it would have been the one-commit fix you described, and it would drift again — it already had: the first entry point added after the list was written (#13173) went unguarded until a merge surfaced it, which is what Stated limit, pinned rather than implied. Direct callers only. A public wrapper that delivers through another public function ( Verified:
The manifest conflict recurred at the tail this time — main now appends there too, so the relocation three days ago only moved the collision. The two entries now sit mid-list after PR description updated to the derived guard and the 32 count, including the direct-callers-only limit. The earlier maintainer items — the ratchet running on every backend PR, the one-time |
|
Delta-verified at What changed since the last reviewed head ( One PR-authored commit: Independently verified in a clean clone of this head
The production slice is unchanged since prior reviews and still checks out, including Still open before merge — the same three maintainer yes/no decisions from earlier in the thread, unchanged by this commit: (1) the ratchet triggers on by AI on behalf of David — the ratchet-coverage fix is verified; the three queued decisions above need a maintainer ruling before merge. |
kodjima33
left a comment
There was a problem hiding this comment.
Solid refactor (centralizes notification dispatch, atomic Redis reservation, AST ratchet guard) with good test coverage, but it's explicitly a refactor — confidence gate requires a bug/issue fix to merge, so approve-only.
|
@Git-on-my-level need human response — kodjima approved d8f7700 as approve-only. The three items from the earlier review are unchanged and still need a yes or no, not more code:
I am not merging on the GitHub APPROVED state. If any of those is a no, say which one and I will cut or close. |
|
Maintainer ruling on the three open items — this is the yes/no the thread has been waiting on:
Merge follows. Nice work — the delta-review trail on this one is genuinely excellent. |
What changed and why
Starts the backend notification-owner convergence requested by #9518 with a reviewable first production slice.
NotificationIntentand oneNotificationDispatcherthat returns explicitdispatched,suppressed, orfailedoutcomes./v1/integrations/notificationand/v2/integrations/{app_id}/notification) onto that owner.utils/notifications.py— every public function whose own body calls an FCM primitive — rather than hand-listed, so a sender added later is guarded the day it lands. The remaining 32 legacy direct calls across 18 files are recorded exactly; additions, alias escapes, hidden baseline growth, and stale baselines fail. Later refactor(backend): converge notification sending onto one dispatch owner (typed intents, single policy point) #9518 slices can only move this number down. Direct callers only: a wrapper delivering through another public function (send_credit_limit_notification→send_notification) is not itself counted.This deliberately does not claim full closure of #9518. Other producer families, preference/quiet-hour policy, deduplication, cron, and the final zero baseline remain separate reviewable migrations.
Behavior and compatibility
429behavior.plugin_id) and app/main-chat navigation payloads are preserved.Product invariants affected
None. This preserves the existing integration-notification contract while consolidating its backend owner.
How it was verified
backend/.venv/bin/python -m pytest -q backend/tests/unit/test_notification_dispatch.py backend/tests/unit/test_app_notification_plugin_id.py— 9 passed.backend/.venv/bin/python -m pytest -q backend/tests/unit/test_integration_notification_validation.py— 1 passed.python3 .github/scripts/test_check_notification_dispatch_boundary.py— 5 mutation/ratchet tests passed.python3 .github/scripts/check_notification_dispatch_boundary.py --base origin/main— 32 legacy direct calls, ratchet held.python3 .github/scripts/test_run_checks.py— 47 manifest contract tests passed.git diff --checkpassed.Tests
backend/tests/unit/test_notification_dispatch.pycovers the shared contract and its error paths: full quota then suppression, app/user bucket isolation, UTC-hour expiry, direct-policy bypass, typed payload attribution/navigation, content-safe failure observability, and async transport delivery..github/scripts/test_check_notification_dispatch_boundary.pyproves the guard resolves direct aliases and module-qualified calls, detects function escapes, rejects baseline-assisted growth, and accepts only exact downward ratchets.Failure class (fixes)
Failure-Class: FC-split-mutation-authority
New guards
#9518 documents the live split authority: notification policy and low-level delivery are owned across routers and utility modules. The AST ratchet complements the shared dispatcher because Python cannot make a transport import private across packages; it turns the staged migration into an enforceable monotonic boundary rather than an honor-system convention.
Part of #9518.