Repository navigation
fix(v2): keep connector timestamps honest without a reload (TASK-131) - #1728
Conversation
lilyshen0722
left a comment
There was a problem hiding this comment.
UX-GATE: PASS @ 6b2444c — read the full diff, not a fixture: no CSS file touched, no className added or changed, no label string changed. Every edit is relativeTime(x) → relativeTime(x, now) plus the shared 60s clock and the visibility re-read, so the Signal copy is identical and only the number moves. Note, not a blocker: the pending-code countdown (codeExpiresInMinutes), the used-recently pulse and claimIsStale still read Date.now() directly; they re-evaluate on the same tick because the component re-renders, so the screen stays honest — they just are not on the shared clock, which matters only for fake-timer tests.
lilyshen0722
left a comment
There was a problem hiding this comment.
Gate at 6b2444c8c93604662864225818f538ceeb7cc022: passes, nothing blocking. One same-class gap is worth a line, plus one pre-existing note.
Baseline: V2ConnectorTools.test.tsx + V2ConnectorsPage.test.tsx 54/54. Each mutation changes one line (git diff --numstat 1+1-):
- no interval in
useRelativeNow: 2 red; default tick 60s → 600s: 1 red - Connectors page visibility listener removed: 1 red; Tools listener removed: 1 red. Each surface is pinned on its own.
- age math ignoring
now(either file): 54/54 green. These are equivalent mutants, not gaps: the tick re-renders the component, soDate.now()at render already equalsnow. - reload on any visibility change (not only
visible): green. That costs one harmless extra fetch on hide, which is fine unpinned.
load() never flips a loading flag, so a tab return refreshes in place with no spinner flash.
Same-class gap: notYet doesn't tick. notYet (V2ConnectorTools.tsx:290) calls isDead(grant), and so isExpired(grant) with its default Date.now(), inside a useMemo keyed on [catalog, grants, q, segment], with no now. When the last live grant expires while the page sits open, grantedCount (computed at render) drops on the next tick, but the tool doesn't move back under "not yet" until a reload or a tab return. The count and the list disagree until then. Fix: isDead(grant, now) there, with now in the deps. (This is from reading the code; I didn't build a fake-timer test for it. The deps list is the evidence.)
Pre-existing, not this PR (de5fc4d8, #1669): !(grants || []).some((grant) => !isDead(grant)) never references entry, so any one live grant hides every catalog entry from "not yet". The comment says "no live grant on it". It's inert today with a single tools-list entry and breaks when the second tool ships.
Docstring nit: "this is the same clock, shared". V2PodsSidebar still runs its own setInterval (:227), so this is the same cadence, not a shared clock.
lilyshen0722
left a comment
There was a problem hiding this comment.
Re-gate at 34bd8911a672417b28feb62384782612cf4a8981: passes; the gap is fixed and pinned.
Since 6b2444c8: V2ConnectorTools.tsx, useRelativeNow.ts and a new test. The two suites are 55/55.
nowdropped fromnotYet's deps → 1 red. This is the load-bearing change, and it's pinned.isDead(grant)withoutnowinsidenotYet, ingrantedCount, or insideisDeaditself → 55/55 green each. These are equivalent mutants, not gaps: withnowin the deps the memo recomputes on every tick, andgrantedCountis render-time, so the defaultDate.now()already equalsnowat those call sites. Passingnowexplicitly is still the right reading of the code, and leavingload()on the default is correct for the reason you gave.
The #1669 .some that ignores entry is still there (pre-existing, inert with one tools-list entry). It's worth its own row before the second tool ships.
34bd891 to
9ba19c1
Compare
lilyshen0722
left a comment
There was a problem hiding this comment.
UX-GATE: PASS @ 9ba19c1 — re-pin after rebase. Not rebase-only versus the head I gated (6b2444c): the branch carries one further commit (9ba19c1) that threads the render now into isDead so an expiring grant drops out of grantedCount and back into Not yet on the same tick, plus a test and a comment reword. Read from the interdiff: still no copy, className, or CSS delta; it closes the count-vs-list disagreement I called non-blocking last time. Gated from the full diff, no fixture.
9ba19c1 to
c88f3f9
Compare
c88f3f9 to
b9851df
Compare
b9851df to
39c8951
Compare
39c8951 to
38602d6
Compare
The Connectors surface renders relative ages ("since 5m ago", "Slack
answered 5m ago", "granted 1h ago") that are computed from `Date.now()`
while React renders. Both surfaces read once on mount and never
re-render on their own, so the age a page first draws is the age it
keeps showing until a manual reload — even though the label is supposed
to be a live fact.
Two halves, both needed:
- A shared 60s clock (`useRelativeNow`) so relative ages advance in
place. This mirrors the clock `V2PodsSidebar` already runs; it is
rendering only and never reads the server.
- A `visibilitychange -> visible` re-read on `V2ConnectorsPage` and
`V2ConnectorTools`, the same pattern `V2PodBoard` uses for the focus
panel, so a tab that was in the background comes back to the server's
state rather than to whatever it loaded hours ago.
`relativeTime` takes `now` with a `Date.now()` default, so existing
callers and tests are unchanged.
Proof: a fake-clock test on each surface drives a 5m/1h age forward and
then dispatches `visibilitychange`. Removing the interval goes red
(1/40) and removing the visibility listener goes red (1/40), so the
test pins the re-render, not just the presence of code. Focused suites
40/40 and 14/14; eslint clean; `tsc` unchanged apart from the
pre-existing missing `@dicebear/*` modules (not installed in this
checkout, unrelated).
Known limit, stated rather than hidden: integrations have no socket
invalidation, so a second client's change to a *visible* tab still waits
for the next tab return or reload. Adding a push would mean a new
user-scoped event; not bundled here.
Sprint Review's same-class gap from the 6b2444c gate: `notYet` calls `isDead`, which falls through to `isExpired` with its default `Date.now()`, inside a memo keyed on `[catalog, grants, q, segment]`. When the last live grant expired while the page sat open, the header count (computed at render) dropped on the next tick, but the row stayed under "Granted" until a reload — the count and the list disagreed. `now` is now threaded into every `isDead` that decides what a render shows (`notYet`, `grantedCount`, `renderRow`, `renderAside`) and into the memo's deps. The read path in `load()` keeps the default: there the question is what is live at the moment of the read, which is a fresh `Date.now()`. Also the docstring nit from the same gate: `V2PodsSidebar` runs its own interval, so this is the same cadence, not one shared clock. Proof: a new fake-clock test — grant live for one more minute, tick two minutes with no reload — asserts the header and the list agree (`0 granted · 1 more` and a `not granted` row). Removing `now` from the memo deps goes 1 red; leaving the deps and dropping the `now` argument stays green, i.e. under a real clock the argument is an equivalent mutant and the deps entry is what this test pins — same shape Sprint Review measured for the age math. 55/55 across both suites, eslint clean, tsc clean apart from the repo's uninstalled `@dicebear/*`.
38602d6 to
1d01d4d
Compare
lilyshen0722
left a comment
There was a problem hiding this comment.
UX-GATE: PASS @ 1d01d4d — re-pin after sixth rebase. Patch-id of origin/main..1d01d4d is byte-identical to the 38602d6 patch I gated (4b98589d…): shared 60s render clock, visibility re-read, isDead(grant, now) threaded through the Not-yet predicate and the granted count. No copy, className, or CSS delta. Gated from the diff, no fixture.
What
The Connectors surface (
/v2/connectorsrows and the Tools grant rows) renders relative ages —since 5m ago,added 1h ago,Slack answered 5m ago,granted 1h ago, the trail'swhen. All of them are computed fromDate.now()while React renders.Both components read once on mount and then never re-render on their own, so the age the page first drew is the age it keeps showing forever. That is the report behind TASK-131: a visible last-update timestamp that only moves when you reload.
Sam's report was made while viewing the Connectors surface, and the Sharpen notes ask for the cause to be split: missing source-data invalidation vs. relative-time rendering. Reading the code, it is both, and neither is covered today:
V2PodsSidebaralready runs a 60s clock; the connector pages do not).hasPending). Otherwise the data is whatever was loaded on mount.Changes
frontend/src/v2/hooks/useRelativeNow.ts(new): a shared 60s clock. Rendering-only; it never reads the server.V2ConnectorsPage/V2ConnectorTools: takenowfrom that clock, pass it intorelativeTime, and re-read onvisibilitychange -> visible— the same freshness patternV2PodBoardalready uses for the focus panel.relativeTimegainsnowwith aDate.now()default, so existing callers and tests are untouched.Proof
added 5m ago→added 7m agoon the tick, thenvisibilitychangetriggers a re-readV2ConnectorsPage.test.tsxgranted 1h ago→granted 2h agoon the tick, thenvisibilitychangetriggers a re-readV2ConnectorTools.test.tsxFocused:
V2ConnectorsPage.test.tsx40/40,V2ConnectorTools.test.tsx14/14.eslintclean on all five files.tsc --noEmitreports only the pre-existing missing@dicebear/*modules (node_modules/@dicebearis absent in this checkout) — no error in touched files. The full-suite run fails 32 suites/2 tests on that same missing dependency, unrelated to this diff.Known limit (not hidden)
Integrations have no socket invalidation today, so a change made by a second client to a visible tab still waits for the next tab-return or reload. Closing that needs a new user-scoped event on the integration/installation write paths. This PR does not add a poll for it, because the Sharpen notes ask for a generic timer only after reproduction, and the tick here is rendering-only.
Verification requested
nowplumbing did not change any label's wording.