Skip to content

fix(v2): keep connector timestamps honest without a reload (TASK-131) - #1728

Merged
lilyshen0722 merged 2 commits into
mainfrom
fix/task-131-relative-now
Sep 18, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
fix/task-131-relative-now

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

What

The Connectors surface (/v2/connectors rows and the Tools grant rows) renders relative ages — since 5m ago, added 1h ago, Slack answered 5m ago, granted 1h ago, the trail's when. All of them are computed from Date.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:

  • Rendering: no clock, so the text never recomputes (V2PodsSidebar already runs a 60s clock; the connector pages do not).
  • Source: no socket, no focus/visibility re-read, and the 3s poll only runs while a connection is pending (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: take now from that clock, pass it into relativeTime, and re-read on visibilitychange -> visible — the same freshness pattern V2PodBoard already uses for the focus panel.
  • relativeTime gains now with a Date.now() default, so existing callers and tests are untouched.

Proof

Assertion Result
Connectors row age advances added 5m ago → added 7m ago on the tick, then visibilitychange triggers a re-read PASS V2ConnectorsPage.test.tsx
Grant age advances granted 1h ago → granted 2h ago on the tick, then visibilitychange triggers a re-read PASS V2ConnectorTools.test.tsx
Remove the interval → the age test goes red 1/40 red
Remove the visibility listener → the age test goes red 1/40 red

Focused: V2ConnectorsPage.test.tsx 40/40, V2ConnectorTools.test.tsx 14/14. eslint clean on all five files. tsc --noEmit reports only the pre-existing missing @dicebear/* modules (node_modules/@dicebear is 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

  • @ux-lead: Signal copy unchanged (only the number moves); no layout/CSS delta.
  • @sprint-review: mutation pass on both guards; confirm the now plumbing did not change any label's wording.

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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, so Date.now() at render already equals now.
  • 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 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

  • now dropped from notYet's deps → 1 red. This is the load-bearing change, and it's pinned.
  • isDead(grant) without now inside notYet, in grantedCount, or inside isDead itself → 55/55 green each. These are equivalent mutants, not gaps: with now in the deps the memo recomputes on every tick, and grantedCount is render-time, so the default Date.now() already equals now at those call sites. Passing now explicitly is still the right reading of the code, and leaving load() 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.

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@samxu01
samxu01 force-pushed the fix/task-131-relative-now branch from 9ba19c1 to c88f3f9 Compare September 18, 2026 08:24

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

UX-GATE: PASS @ c88f3f9 — re-pin after second rebase. Patch-id of origin/main..c88f3f9 is byte-identical to the 9ba19c1 patch I gated; no copy/CSS delta. Gated from the diff, no fixture.

@samxu01
samxu01 force-pushed the fix/task-131-relative-now branch from c88f3f9 to b9851df Compare September 18, 2026 09:04

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

UX-GATE: PASS @ b9851df — re-pin after third rebase. Patch-id of origin/main..b9851df is byte-identical to the c88f3f9 patch I gated; no copy/CSS delta. Gated from the diff, no fixture.

@samxu01
samxu01 force-pushed the fix/task-131-relative-now branch from b9851df to 39c8951 Compare September 18, 2026 09:44

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

UX-GATE: PASS @ 39c8951 — re-pin after fourth rebase. Patch-id of origin/main..39c8951 is byte-identical to the b9851df patch I gated; no copy/CSS delta. Gated from the diff, no fixture.

@samxu01
samxu01 force-pushed the fix/task-131-relative-now branch from 39c8951 to 38602d6 Compare September 18, 2026 10:24

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

UX-GATE: PASS @ 38602d6 — re-pin after fifth rebase. Patch-id of origin/main..38602d6 is byte-identical to the 39c8951 patch I gated; no copy/CSS delta. Gated from the diff, no fixture.

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/*`.
@samxu01
samxu01 force-pushed the fix/task-131-relative-now branch from 38602d6 to 1d01d4d Compare September 18, 2026 11:04

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

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