Skip to content

OpenConceptLab/ocl_online#845 | Ask for account notices again at each page load and return - #123

Open
paynejd wants to merge 5 commits into
mainfrom
OpenConceptLab/ocl_online-845-notices-refresh
Open

paynejd wants to merge 5 commits into
mainfrom
OpenConceptLab/ocl_online-845-notices-refresh

Conversation

@paynejd

@paynejd paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member

Linked Issue

Advances OpenConceptLab/ocl_online#845

What this changes

While a person has account notices, TBv3 asks for them again at each page load and each time they come back to the page. Until now it asked once and kept the answer until the tab was closed, so a notice stayed after what it was about had changed somewhere else: in another tab, or on another site.

  • With no notices, it asks at most once an hour, so for nearly everyone a page load asks nothing more.
  • A stored notice shows at once, and is replaced when the new answer arrives.
  • A failed request changes nothing that's shown.
  • An answer is kept only for the person it was asked for.

Nothing anyone sees changes otherwise: the same notices, in the same place. The API doesn't change.

How it was checked

npm test passes (358) and ESLint is clean. In a browser, against a local API:

Before Now
What the notice is about changes, then a reload The notice stays Gone in about a second
The same, then back to the tab The notice stays Gone at once
Another reload, with no notices No request No request
Another language The notice stays until it's translated The same
The API fails The notice goes The notice stays

Reviews

Three Codex passes, a simplification review and a last check are in the comments, with the answers. Every P1 is fixed. The two P2s left open need a second person to sign in over the first in the same browser.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qVzyaMUV7QSvivXit7

paynejd and others added 5 commits December 3, 2026 01:00
… page load and return

While a person has account notices, they're asked for again at each page
load and each return to the page, so a notice goes once what it's about has
changed, even in another tab or site. With none, at most once an hour. A
failed request changes nothing that's shown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVzyaMUV7QSvivXit7
…hange is announced

Otherwise, with none stored and the request after the change failing, the
next page load wouldn't ask for up to an hour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVzyaMUV7QSvivXit7
…ed request, and an answer is only for who asked

A change that's announced drops a stored "none" only. An answer that arrives
once another tab has signed in as someone else is ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVzyaMUV7QSvivXit7
…slation is asked for

What's shown is kept with whose it is, so another person's never shows, and
a change of language doesn't clear it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVzyaMUV7QSvivXit7
…ated another goes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVzyaMUV7QSvivXit7
@paynejd
paynejd requested a review from snyaggarwal December 3, 2026 06:35
@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 1 (codex-cli 0.169.0, commit c252064)

Verdict: findings, 2 findings.

  • F1.1 P1 useNotices.js:83 A failed refresh after a known change leaves the old empty answer eligible to suppress retries.
  • F1.2 P2 useNotices.js:101 A return-triggered request can use one account's credentials and cache its notices under another account's username.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "full",
  "commit": "c25206465",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "F1.1",
      "severity": "P1",
      "tag": null,
      "file": "src/components/common/useNotices.js",
      "line": 83,
      "claim": "A failed refresh after a known change leaves the old empty answer eligible to suppress retries.",
      "scenario": "An account cached an empty answer 10 minutes ago. A successful write triggers a notice refresh, but the request times out. The API recovers and now has a notice. Reloading or returning to the tab skips the request for the remaining 50 minutes, so the notice stays missing.",
      "action": "Invalidate the matching empty cache entry when a change event triggers a refresh. Keep the displayed notices as they are until a successful response arrives.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.2",
      "severity": "P2",
      "tag": null,
      "file": "src/components/common/useNotices.js",
      "line": 101,
      "claim": "A return-triggered request can use one account's credentials and cache its notices under another account's username.",
      "scenario": "An OAuth callback starts with account A's profile still in local storage. The callback installs account B's token before B's profile finishes loading. If the user returns to the tab during that gap, the listener uses A's captured username while APIService sends B's token. If the notices request finishes first, B's notices appear and are cached under A.",
      "action": "Tie notice requests and displayed state to the authenticated session. Wait for the profile associated with the current token, and verify that the session is still current before accepting a response.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Pass 1, both findings answered (commit 197a9c3):

  • F1.1 (P1), fixed. Reproduced in a browser: with "none" stored and the request after a change failing, the next reload didn't ask. The stored answer now goes when a change is announced.
  • F1.2 (P2), accepted. It needs someone to sign in over another person's session without signing out, and to come back to the tab in the moment between the new token and the new profile. Every request the app makes has that gap, on main too. What could be stored under the wrong name is replaced at the next page load, since an answer with notices is always asked about again.

@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 2 (codex-cli 0.169.0, commit 197a9c3)

Verdict: findings, 2 findings.

Earlier: F1.1 regressed, F1.2 unresolved

  • F2.1 P2 useNotices.js:107 The fix restores retries for empty answers but also discards cached notices needed on reload.
  • F2.2 P2 useNotices.js:102 The account mismatch can happen after sign-in has finished in another tab.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "197a9c3df",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "regressed"
    },
    {
      "id": "F1.2",
      "status": "unresolved"
    }
  ],
  "findings": [
    {
      "id": "F2.1",
      "severity": "P2",
      "tag": null,
      "file": "src/components/common/useNotices.js",
      "line": 107,
      "claim": "The fix restores retries for empty answers but also discards cached notices needed on reload.",
      "scenario": "An account has a visible notice. A write triggers a refresh, and the notices endpoint returns 503. The notice stays visible until the person reloads. If the endpoint is still failing, the strip disappears because the change event deleted the last successful answer.",
      "action": "Invalidate only the matching empty cache entry. Keep cached notices available on reload until a successful refresh replaces them.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F2.2",
      "severity": "P2",
      "tag": null,
      "file": "src/components/common/useNotices.js",
      "line": 102,
      "claim": "The account mismatch can happen after sign-in has finished in another tab.",
      "scenario": "Tab 1 is open under A and shows a notice. Tab 2 signs in as B over the existing session and finishes loading B's profile. Tab 1 ignores the token replacement, so returning to it runs the listener captured for A with B's token and caches B's notices under A. If the next request fails, A can see B's notices on signing in again in tab 1.",
      "action": "Update the hook when the authenticated account changes across tabs. Bind requests, cache writes, and displayed notices to the same authenticated session, and discard responses after that session changes.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Pass 2, both findings fixed (commit 0428d94):

  • F2.1 (P2), fixed. Reproduced in a browser. A change that's announced now drops only a stored "none", so a stored notice stays until a new answer arrives.
  • F2.2 (P2, with F1.2), fixed where it's small. An answer is ignored unless the profile on this device is still the one it was asked for, so one person's notices aren't stored under another's name after a sign-in in another tab. What remains is the moment between a new token and its profile, which every request in the app has, on main too.

@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 3 (codex-cli 0.169.0, commit 0428d94)

Verdict: findings, 3 findings.

Earlier: F1.1 resolved, F1.2 unresolved, F2.1 resolved, F2.2 unresolved

  • F3.1 P1 useNotices.js:101 Changing the display language clears an existing notice before its replacement arrives.
  • F3.2 P2 useNotices.js:103 A tab can keep showing the previous account's notice after another tab completes a sign-in.
  • F3.3 P2 limitNoticePayload.test.js:118 The cache test checks the freshness predicate without exercising the display or request behavior it names.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "0428d9464",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "resolved"
    },
    {
      "id": "F1.2",
      "status": "unresolved"
    },
    {
      "id": "F2.1",
      "status": "resolved"
    },
    {
      "id": "F2.2",
      "status": "unresolved"
    }
  ],
  "findings": [
    {
      "id": "F3.1",
      "severity": "P1",
      "tag": null,
      "file": "src/components/common/useNotices.js",
      "line": 101,
      "claim": "Changing the display language clears an existing notice before its replacement arrives.",
      "scenario": "A signed-in user with a visible notice switches from English to Spanish in the user menu. The cache lookup misses because the stored answer is in English, so the strip disappears and the page shifts while the request is pending. If the request returns 503, the strip stays hidden. On the base branch, the strip remains visible while the translation is loading.",
      "action": "Keep the current account's visible notices during a language refresh. Replace them when a matching request succeeds and clear them when the authenticated account changes.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.2",
      "severity": "P2",
      "tag": null,
      "file": "src/components/common/useNotices.js",
      "line": 103,
      "claim": "A tab can keep showing the previous account's notice after another tab completes a sign-in.",
      "scenario": "Tab 1 shows account A's notice. Tab 2 signs in as B over the existing session and finishes loading B's profile. Returning to tab 1 calls the listener captured for A. The request uses B's token, and the new username check discards B's response. Tab 1 keeps showing A's notice until a separate render or reload.",
      "action": "Update the hook when the authenticated session changes. Clear notices from the previous session and fetch for the current account once its profile is available.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.3",
      "severity": "P2",
      "tag": null,
      "file": "src/components/common/__tests__/limitNoticePayload.test.js",
      "line": 118,
      "claim": "The cache test checks the freshness predicate without exercising the display or request behavior it names.",
      "scenario": "If the account hook starts requesting on every reload despite a fresh empty cache, this test still passes because it never observes a request. The account-specific subscription that refreshes a visible notice on return is also outside the test.",
      "action": "Test the account notice flow with a fake clock and request recorder. Assert that a cached notice renders immediately and refreshes on return, and that a fresh empty answer suppresses the request.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Pass 3 (commit 500c620):

  • F3.1 (P1), fixed. Reproduced in a browser: switching the language dropped the notice until the new answer came. What's shown is now kept with whose it is, so it stays until the new language's answer replaces it, and stays if that request fails.
  • F3.2 (P2), accepted. A tab left open while another tab signs in as someone else keeps its own page as it was, notices included, until it's reloaded. That's how the whole app behaves, on main too.
  • F3.3 (P2), accepted. This repo has no tests that render hooks. The rule is tested (isCacheFresh), and the flow was checked in a browser: reload, return, language, a failing API, and another person signing in.

@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Simplification review (a fresh Claude subagent, commit 500c620)

Verdict: findings, 3 findings.

  • S1 yagni limitNoticePayload.js:102 The NO_NOTICES_HOLD constant is used once, by isCacheFresh. The comment above it restates the code.
  • S2 shrink useNotices.js:99 The askUnlessNone helper is called twice, and the second call re-reads the cache. It forces a second readCache just to share a name.
  • S3 dup-test limitNoticePayload.test.js:118 The isCacheFresh({}, now) and isCacheFresh({notices: []}, now) assertions overlap with null and no-timestamp cases: both exercise the 'not an array / no at' path.
findings.json
{
  "reviewer": "claude subagent",
  "perspective": "simplify",
  "mode": "full",
  "commit": "500c620b4",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "S1",
      "severity": null,
      "tag": "yagni",
      "file": "src/components/common/limitNoticePayload.js",
      "line": 102,
      "claim": "The NO_NOTICES_HOLD constant is used once, by isCacheFresh. The comment above it restates the code.",
      "action": "Inline the value as `60 * 60 * 1000` and shorten the comment to one line.",
      "lines_delta": -2,
      "confidence": "low",
      "scenario": null
    },
    {
      "id": "S2",
      "severity": null,
      "tag": "shrink",
      "file": "src/components/common/useNotices.js",
      "line": 99,
      "claim": "The askUnlessNone helper is called twice, and the second call re-reads the cache. It forces a second readCache just to share a name.",
      "action": "Define `const ask = cached => { if(!cached || cached.length) load() }` once outside the effect body, or keep it inline. The current form is fine, so cut only if the cost matters.",
      "lines_delta": -2,
      "confidence": "low",
      "scenario": null
    },
    {
      "id": "S3",
      "severity": null,
      "tag": "dup-test",
      "file": "src/components/common/__tests__/limitNoticePayload.test.js",
      "line": 118,
      "claim": "The `isCacheFresh({}, now)` and `isCacheFresh({notices: []}, now)` assertions overlap with null and no-timestamp cases: both exercise the 'not an array / no at' path.",
      "action": "Drop the `{}` assertion and keep null, no-timestamp and the boundary cases.",
      "lines_delta": -1,
      "confidence": "low",
      "scenario": null
    }
  ]
}

@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Simplification review (commit 6ac75d6): one of three taken.

  • S1, left. The name says what the hour is for.
  • S2, left. The second read is needed: on a return to the page, the stored answer may be a newer one.
  • S3, cut.

@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 0428d94..6ac75d6 (codex-cli 0.169.0, commit 6ac75d6)

Verdict: findings, 1 finding.

  • FC.1 P2 useNotices.js:101 A notice from an earlier sign-in can reappear after the tab switches accounts and then switches back.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "final",
  "commit": "6ac75d643",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "FC.1",
      "severity": "P2",
      "tag": null,
      "file": "src/components/common/useNotices.js",
      "line": 101,
      "claim": "A notice from an earlier sign-in can reappear after the tab switches accounts and then switches back.",
      "scenario": "Account A sees a notice that could not be cached because session storage was full. The same mounted tab renders account B after a sign-in in another tab, but B's notice request returns 503. When the tab renders A again, the old notice immediately reappears and stays if A's refresh also fails, even if the underlying issue was resolved while A was away.",
      "action": "Clear the displayed notice state on every account change when there is no matching cache entry. Preserve the previous display during a language refresh for the same account.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Last check, one P2, accepted:

  • FC.1. It needs a browser whose storage is full, another person signing in and out in a second tab, and two failed requests. What would show is that person's own earlier notice, until the next answer.

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve. Merge any time. It doesn't depend on its sibling PRs, and the ocl_online#856 branch goes on top of it.

Open Core: clean. The hook keeps displaying what GET /capabilities/notices/ sends, and has no wording or rules of its own about what a notice is for. The commits, PR text and comments are neutral too.

How often it asks (page load and return only):

  • AccountNotices is mounted once, in Header at the App level, so navigating inside the app doesn't ask again. Only a full page load does.
  • watchReturns fires once a return (the away flag), with one listener for the whole app.
  • With notices showing, it's one request a page load and one a return. With none, at most one an hour, because isCacheFresh holds a stored "none" for that long.
  • A server without the notices route (404) is stored as "none", so it asks at most once an hour too. Before, it asked once a session.

A failed request now keeps what's shown instead of clearing it. An answer for someone who is no longer signed in on this device is ignored. A change of language keeps the notices until the new language's answer arrives.

The P2s you left open (two people signing in one after the other in the same browser, storage that can't be written) are as described, and are no worse than main. I'm not re-raising them.

CI (Lint and test) is green.

Merge order in its group: on its own, any order relative to OpenConceptLab/oclinfrastructure#52, ocl-ai-assistant#264, ocl_online_api#132 and ocl-analytics-web#9.

This branch has not been deployed

No deployments
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.

2 participants