Skip to content

fix(alerts): preserve reenabled push and split alert hooks - #1871

Merged
devswha merged 2 commits into
mainfrom
refactor/use-alerts-split
Oct 25, 2026
Merged

devswha merged 2 commits into
mainfrom
refactor/use-alerts-split

Conversation

@devswha

@devswha devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Change

Turning this device's alerts back on must not let the previous off-state visibility
listener remove its push subscription before React cleans that listener up. Check
the current alerts-on ref before retrying a pending removal.

This follows up on the MINOR items from #1817 in two commits:

  • 5e160436d: fix the re-enable race, add a deterministic regression to the existing
    push hook tests, remove the stale permission comment, and add a user-facing changelog.
  • 6cdd088ca: move existing code into focused notification lifecycle, alert signal,
    and bell modules; keep preference/bookkeeping refs in useAlerts.ts; update consumers.
    The split itself does not change behavior.

The existing Alerts interaction stays as documented in DESIGN.md. This fixes
Ovis's native push retry lifecycle rather than introducing a new UI pattern from
Codex, Claude, Paseo, or T3 Code.

Coordination: #1848 (feat/pane-alert-mute) also edits src/lib/useAlerts.ts.
That branch was not touched. Whichever PR merges second must rebase.

Validation

  • Before the guard, bun test src/lib/push.test.ts --test-name-pattern 'preserves push when visibility'
    failed: expected no DELETE, received a DELETE for the existing native endpoint.
    The test dispatches visibilitychange from a layout effect during re-enable,
    before passive-effect cleanup, and subscribes to the registration response.
    No fixed sleeps are used.
  • With the guard: all 26 push tests pass. After extraction: 79 tests across push,
    notifications, droplet, and alert-turn tests pass. Typecheck passes.
  • Reviewed git diff --color-moved origin/main...HEAD and the second commit's move
    diff. A TypeScript AST comparison confirmed all 13 non-import top-level statements
    from the fix commit remain byte-identical across the four split modules.
  • dori heavy merge-followups -- bun run check fast exited 1. Workflow syntax,
    generated types/themes, typecheck, and build passed. There was no failing test
    assertion in the captured output; the unit-test step was terminated by SIGKILL
    with check: ended processes left running in step process group 917803.
    Source fingerprints were unchanged. The maintainer explicitly asked to proceed
    for this failure while checking whether origin/main has the same problem.
  • Codex review (gpt-6.1-sol, fast tier, xhigh reasoning): no actionable bugs.
    It also passed typecheck and 83 focused tests. No HIGH findings required fixes.
  • Native reviewer unavailable: two attempts to start omo-native-code-reviewer
    were rejected by the harness: depth 2 exceeds maximum depth 1. No native-reviewer
    verdict is claimed.
  • Browser and native-device flows were not exercised. CI results remain pending.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f544ee9 and 0ea4667.

Files selected for processing: 9
  • changelog.d/alerts-reenable-retry.md
  • src/App.tsx
  • src/lib/alertsBell.ts
  • src/lib/push.test.ts
  • src/lib/push.ts
  • src/lib/useAlertSignals.ts
  • src/lib/useAlerts.ts
  • src/lib/useMachineRoster.ts
  • src/lib/useNotifications.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where re-enabling alerts could cause a pending retry to remove the device’s push subscription.
  • Alerts
    • The Alerts menu now reflects alert settings and notification permission, with an indicator when alerts are off.

The change separates alert signal handling, notification state and subscription control, and Alerts menu logic into dedicated modules. It also prevents a native visibility-triggered removal retry from removing the subscription after alerts are re-enabled, with a regression test for endpoint retention.

Changes: Alert lifecycle

Layer / File(s) Summary
Separate alert signal and menu logic
src/lib/useAlerts.ts, src/lib/useAlertSignals.ts, src/lib/alertsBell.ts, src/App.tsx, src/lib/useMachineRoster.ts
Alert signal handlers and Alerts menu logic move into dedicated modules. App and the roster type import use the new module locations.
Notification lifecycle and retry regression
src/lib/useNotifications.ts, src/lib/useAlerts.ts, src/lib/push.test.ts, src/lib/push.ts, changelog.d/alerts-reenable-retry.md
The notification module handles permission state, alert switching, and push subscriptions. Native removal retries check whether alerts remain off. The regression test verifies that re-enabling alerts during a visibility change does not send a DELETE request and retains the endpoint.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

  • devswha/herdr-web-ui issue 1053 concerns re-enabling alerts and a retired push endpoint; this change addresses the related removal retry during re-enablement.

Possibly related PRs

  • devswha/ovis#1769: Splits the combined alert hook into alert preference, notification, signal, and bell units, which this change places in separate modules.
  • devswha/ovis#1880: Changes native subscription removal behavior that the notification lifecycle retries.
  • devswha/ovis#1817: Adds the native push subscription path used by the notification lifecycle.
Merge Risk: Minimal · up to 0ea46

The reviewed retry behavior preserves the push subscription when alerts are re-enabled. No issue identified here needs to be fixed before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 8 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the primary fix and the related alert-hook split. It is concise and specific.
Description check Passed The description includes the required Change and Validation sections. It explains the race condition, resulting behavior, regression coverage, test results, typecheck status, known check failure, and …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes the required Change and Validation sections. It explains the race condition, resulting behavior, regression coverage, test results, typecheck status, known check failure, and untested flows.

Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 8 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: ordering. This PR splits src/lib/useAlerts.ts, which #1848 (shared pane alert mute, an older maintainer PR) also changes. #1848 merges first. Once it is on main, please rebase onto it and carry its mute checks into the split hooks. Those checks make the page alert, the chime and the tab notification skip a muted pane, and check a queued chime again right before it plays. The merge pass reviews this PR on the rebased head.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Understood. #1871 waits for #1848. Once #1848 is on main, it gets rebased onto it, and #1848's mute checks (page alert, chime, tab notification, and the re-check of a queued chime before it plays) move into the split hooks. The rebased head will be posted here.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Code review (omo-native-code-reviewer) at 6cdd088: APPROVE, no CRITICAL/HIGH/MEDIUM findings.

  • The guard closes the race in every ordering it traced: visibility before cleanup (the new test), visibility after the commit (no listener), a retry already in flight (removal and re-registration run in order, so the device ends registered), and the locked state.
  • Deleting only the guard fails the new test with an unexpected DELETE. With the guard, push.test.ts passed 15/15 runs.
  • The split commit is move-only: --color-moved shows only imports and one comment path.
  • Two LOW notes, left as is: the new test's awaited promise relies on bun's default test timeout, as its neighbour does; and a change to locked in that same window is outside this fix, with a removal that fails on auth as the worst case.
    CodeRabbit was rate-limited on this PR, so no CodeRabbit review has run. This review will be redone on the head rebased onto feat(alerts): share one pane mute across alert channels #1848.

devswha added a commit that referenced this pull request Oct 24, 2026
…ck CLI fixture (#1884)

Fixes #1875.

## What failed

`scripts/check.test.ts` › "check CLI teardown" tests timed out in Fast
checks on the self-hosted runners under load: #1871 at 150 s ("bounds
interrupted draining…"), #1848 at 90 s ("removes implicit state…": the
nested check exited 1 after waiting out the fixture's
`CHECK_WAIT_SECONDS=90` for a slot).

## Root cause

Since #1839, `check.ts` `main()` runs `applyHostLimits(process.env)`: a
runner host's `CHECK_HOST_MAX_RUNS` (5 on the P620) overrides
`CHECK_MAX_RUNS`. The fixture builds its nested checks' environment from
`...process.env` and sets `CHECK_MAX_RUNS: "8"` so its throwaway runs
get a slot beside the PC's real runs (#1225). In a runner container the
inherited `CHECK_HOST_MAX_RUNS=5` silently took that back, so they
queued for the host's 5 slots behind its real CI runs.

## Fix (test only)

The fixture drops every `CHECK_HOST_*` name (`HOST_LIMITS`) from the
nested environment, as it already drops `CHECK_DIR` and the GitHub event
variables.

## Proof

- **Deliberate reproduction** on a private `CHECK_LOCK_PORT` with slot 1
held by a stand-in run and `CHECK_HOST_MAX_RUNS=1`: main fails after
90.5 s with `Expected: 0, Received: 1`, as in #1848; this passes in 0.9
s.
- The whole "check CLI teardown" group, 32 runs, 4 at a time, under the
same held slot and host limit: 0 failures.
- `bun run check fast`: passed (6393 pass, 0 fail).
- Reviewed by omo-native-code-reviewer (approve, no blockers: no other
test starts `check.ts` `main()` with a herdr slot and inherits the host
limits). Test-only: no Codex review, per the lane's policy.

Part of the flaky-tests lane.

Co-authored-by: mp <mp@local>
@devswha

devswha commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: #1848 (shared pane mute) is merged (f544ee9), so this PR can rebase onto main now, as agreed. Please push the rebase; the merge pass reviews the delta (it should be the useAlerts split plus #1848's mute handling carried into it) and queues it.

@devswha
devswha force-pushed the refactor/use-alerts-split branch from 6cdd088 to 0ea4667 Compare October 25, 2026 01:44
@devswha

devswha commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main after #1848 (f544ee9) and pushed 0ea4667 (was 6cdd088). The delta is the useAlerts split, with #1848's mute handling carried into it.

The one conflict: src/lib/useAlerts.ts. #1848 added its mute checks to code this PR moves into useAlertSignals.ts. useAlerts.ts keeps this PR's slimmed version, and #1848's four hunks are in src/lib/useAlertSignals.ts, unchanged:

  • Imports: paneAlertsMuted from notifications.ts, currentPaneMutes/subscribePaneMutes from paneMutes.ts, and recheckAlertSounds from alertSound.ts.
  • The chime player: play: (kind, key) checks the pane's mute when the chime's turn comes (and via playAlertSound(kind, wanted) while it waits), and subscribePaneMutes(recheckAlertSounds) is cleaned up with the player.
  • Status alerts: onPaneStatus computes muted once and skips both the droplet+chime and the tab notification for a muted pane.
  • Ended panes: onPaneExited skips the droplet+chime and the ended notification for a muted pane.

None of #1848's mute logic remains in useAlerts.ts, and git diff --stat origin/main..HEAD still lists only this PR's files.

Checks on 0ea4667:

@devswha

devswha commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work report. Overall: PASSED. This is an ordinary client change (a refactor plus a push fix). It is gated by Codex Sol and the code reviewer, plus the merge pass's own checks. It was rebased onto #1848 as agreed.

Lane Verdict Confidence
Codex (gpt-6.1-sol, xhigh) LGTM: no P1, P2 or P3 -
Code review (omo-native-code-reviewer, programming + remove-ai-slops criteria) PASS (CLEAR), 4 LOW -

The split (0ea4667): useAlerts.ts is split into useNotifications.ts, useAlertSignals.ts and alertsBell.ts.

  • The split declarations are AST-identical to the fix commit's useAlerts.ts. Effects, dependency arrays, cleanups and ref-read timing are all unchanged.
  • App.tsx changes only its imports, so hook order is untouched.

#1848's shared mute carried over:

  • useAlertSignals.ts gates every channel: the chime and status notification (:105-111), the ended droplet (:117) and pane-exited (:121).
  • A queued chime is rechecked (:68-70), and the subscribePaneMutes recheck is cleaned up (:73-74).
  • The identifiers appear as often as on main: paneAlertsMuted 7, currentPaneMutes 8, subscribePaneMutes 5, recheckAlertSounds 4.

The push fix (db2c584): when alerts are re-enabled before the retry cleanup, the endpoint is kept and registered once. With the guard at useNotifications.ts:85 removed, the new test fails on an unexpected DELETE.

Tests: 151, 164 and 172 alerts/push/notification/preferences tests passed across the three runs, and 56 conventions tests passed. The typecheck passes and git merge-tree is clean.

LOW follow-ups:

  • A second alertsOnRef in useNotifications.ts:49-50.
  • The comment above read() was dropped.
  • The PR description still names the pre-rebase commits.

@devswha
devswha merged commit a1e4f8b into main Oct 25, 2026
12 checks passed
@devswha
devswha deleted the refactor/use-alerts-split branch October 25, 2026 02:00
@coderabbitai coderabbitai Bot mentioned this pull request Oct 25, 2026
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