Skip to content

refactor: read notification approval row state through one selector - #31070

Merged
bolichen97 merged 1 commit into
mainfrom
fix/20618-approval-row-phase
Nov 6, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/20618-approval-row-phase

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The notifications feed, the detail panel and the approval frame handlers all learn whether an approval row can still be decided from one shared answer, so they cannot disagree.

An approval row in the notifications feed is in one of three places: it can still be decided, it is retired (a decide was refused, or failed after its request ended), or its decision landed and only the clean-up DELETE failed. That answer is spread over two per-row marks in the notifications slice, retiredApprovals and dismissFailed. The slice, NotificationFeed and NotificationDetailPanel each read the marks directly, in three different spellings (Object.hasOwn, ?.[ts], === 'decided'). A reader that checks one mark and forgets the other treats a settled row as live, or a live row as settled.

Why it matters

Any new surface that shows approval rows (the chat cards and other approval surfaces #16481 planned) would have to copy that two-mark check by hand, and one missed half shows Approve/Reject on a row that can no longer be decided, or drops a live row when a frame ends an older request under the same id.

Not a goal

  • No behaviour change: every rendered state, notice, focus move and unread count stays as on main.
  • Not changing how the marks are stored or written. The existing approval tests read and seed retiredApprovals, approvalDecisions and dismissFailed directly, and the issue requires them to pass unmodified.
  • Not folding row.acked into the phase: it is the read flag every notification carries, read by every badge and banner, not approval state.
  • Not moving approvalDecisions (a decision in flight) behind the selector: only the reducers that write it read it.

What changed (motivation → approach → change)

Every place that asks "can this approval row still be decided?" now asks one function instead of two maps.

website/src/store/notificationsSlice.ts gains rowPhase(notifications, ts). It reads both marks at once and returns one record: phase (live, retired or decided), endedFailure (the reason a retired row quotes, or null) and dismissFailed (a DELETE after a landed decision failed). An idle row and a row with a decision in flight are both live: nothing outside the reducers tells them apart. Every reader goes through it:

Reader Asks
liveApprovalRows (used by the approval frame handlers and the chat page) phase === 'live'
the unread-broadcast guard and the refetch merge phase !== 'live'
approvalDecisionSettled and decideApprovalRow's ended check phase, endedFailure
components/notifications/NotificationFeed.tsx rows and focus rescue phase, endedFailure, dismissFailed
components/notifications/NotificationDetailPanel.tsx phase, endedFailure, dismissFailed

The marks keep their storage and every writer; the private isSettledApprovalRow helper and the feed's hasRetired helpers are gone because nothing needs them. The kind check that lets a cron note with a failed DELETE keep its read toggle stays in the feed and the panel, exactly as before. The panel selects rowPhase with shallowEqual, and the feed selects the marks through the slice's approvalMarks with shallowEqual, so neither re-renders more often than on main and a mark added to rowPhase later reaches the feed without touching it.

Backwards compatibility

Compatible: no state shape, action, existing export or rendered output changes; rowPhase, approvalMarks and ApprovalRowPhase are new exports.

Removes nothing: only private helpers inside the slice and the feed are deleted, and each of their callers now reads rowPhase.

Tests

  • website/src/store/notificationsSlice.rowPhase.test.ts (new): a table over every phase (no mark, as in state rehydrated without the maps; a mark on another row only; refused; failed after the request ended, with and without a reason; decided with a failed DELETE; retired with a failed DELETE), plus a row with a decision in flight staying live.
  • Unmodified and passing: src/test/notificationsSlice.test.ts, src/test/NotificationFeed.retiredApproval.test.tsx, src/test/NotificationDetailPanel.approvalRefusal.test.tsx, src/store/notificationsSlice.refetchIdentity.test.ts, the other NotificationFeed.* and NotificationDetailPanel.* specs, UseWebSocketCoverage.test.tsx and the NotificationsPage.* and notificationSheet.* specs.
  • Determinism: the new spec is pure reducer calls with no timers, network or render; 10 of 10 runs passed with --sequence.shuffle (seeds 1001-1010).

Manual verification

N/A — unit coverage sufficient: behaviour is unchanged, and the slice, feed and panel specs that pin each phase's rendering pass without edits.

Screenshots / video

Why no screenshot: internal refactor of how the feed and the detail panel read approval state; every rendered state is unchanged and pinned by the existing specs.

Related Issues

Closes #20618

Sibling sweep

N/A — refactor, no defect fixed.

Pattern harvest

N/A — refactor, no defect fixed.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

An approval row in the notifications feed is live, retired, or decided
with a failed DELETE, and that is spread over two per-row marks in the
notifications slice. The slice, the feed and the detail panel each read
the marks directly, in three spellings, so a new reader could check one
mark and miss the other.

Add rowPhase(notifications, ts), which reads both marks at once, and route
every reader through it: liveApprovalRows, the unread guard, the fetch
merge, the decide settle, decideApprovalRow's ended check, the feed and
the detail panel. The marks keep their storage and every writer; the
existing tests read and seed that shape and pass unmodified. Behaviour is
unchanged.

Closes #20618
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 6, 2026 04:28
@bolichen97
bolichen97 requested a review from Zedmor November 6, 2026 04:28
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of e36f5edd726728f7d21793e9aa4a0d907d1d4f66 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns. Every non-writer read of the two marks now goes through rowPhase, and the derived booleans match main's logic.

[DESIGN-REVIEWED] e36f5ed

Description read

[DESCRIPTION-READ] 0c807d884dc1f984a5d98c8015d988b1f939cf95e63e0c29a6007fbd69da7550

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of e36f5edd726728f7d21793e9aa4a0d907d1d4f66 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. This refactor changes how the feed and the detail panel read approval-row state. It adds or changes no labels, controls, copy or rendered states, so the missing blind read leaves no gap to fill.

[UX-REVIEWED] e36f5ed

Description read

[DESCRIPTION-READ] d39f884be6def98c86f1c9c7938d91617987797ebe89cd6b6dee69a82e78f5b6

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed e36f5edd726728f7d21793e9aa4a0d907d1d4f66 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] e36f5ed

Verdict parsed from the review's SHA-scoped output markers for commit e36f5edd726728f7d21793e9aa4a0d907d1d4f66.

False positive or not applicable? A repository writer can comment:
/ai-review override fable e36f5edd726728f7d21793e9aa4a0d907d1d4f66 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of e36f5edd726728f7d21793e9aa4a0d907d1d4f66 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Pure consolidation: every reader of retiredApprovals and dismissFailed outside the writers now goes through rowPhase. A grep of non-test website/src finds no reader left that bypasses it.

What this change ships

Inventory (5 items) — 5 justified

Intent: let every approval surface ask one place whether a notification row can still be decided, so the surfaces cannot disagree. This is an ADDITION (refactor, closes #20618).

  1. One shared answer for whether a row is live, retired or decided-but-not-deleted, read by the slice reducers, liveApprovalRows and the decide thunk — justified
  2. The feed subscribes to just the two approval marks through approvalMarks with shallowEqual — justified
  3. The private isSettledApprovalRow, hasRetired, NO_RETIRED and NO_DISMISS_FAILED helpers are deleted — justified
  4. The detail panel reads the phase, ended-failure reason and failed-DELETE flag from the shared answer instead of two separate selectors — justified
  5. A new table spec pins every phase, including a row with a decision in flight staying live — justified

[FIRST-PRINCIPLES-REVIEWED] e36f5ed

Description read

[DESCRIPTION-READ] cd3953cd2e6b9807ba017753f42a67f5116e85c91dea40109928a3202a414749

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of e36f5edd726728f7d21793e9aa4a0d907d1d4f66 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e36f5ed

False positive or not applicable? A repository writer can comment:
/ai-review override gpt e36f5edd726728f7d21793e9aa4a0d907d1d4f66 false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 04:43
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 merged commit d74ea47 into main Nov 6, 2026
97 checks passed
@bolichen97
bolichen97 deleted the fix/20618-approval-row-phase branch November 6, 2026 06:01
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 6, 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.

refactor(notifications): one per-row phase record for approval rows

2 participants