Skip to content

feat(web): identity-safe caches, relay and asset fixes, notifications, moderation, repository activity, workflow runs - #14

Open
anasfik wants to merge 15 commits into
hardy4yooz:mainfrom
anasfik:fix/repo-cache-isolation-and-missing-assets
Open

anasfik wants to merge 15 commits into
hardy4yooz:mainfrom
anasfik:fix/repo-cache-isolation-and-missing-assets

Conversation

@anasfik

@anasfik anasfik commented Nov 3, 2026 •

Copy link
Copy Markdown

Summary

Fifteen commits on top of upstream main (9718473): two security and asset fixes, five earlier reliability fixes, seven features that fill in missing read-only surfaces, and one follow-up that hardens the workflow run-history gate. The browser stays a client of the existing Relay; this PR adds no server, schema, deployment, or credential changes.

What ships

Cache isolation and asset fallback

  • Repository caches are scoped to identity and Relay. Git clone/fetch storage and query keys now include the signed-in viewer and the configured Relay URL, NIP-98 authorization is bound to the captured viewer namespace, and any non-transport failure fails closed. A denied view shows a localized alert and suppresses private tree, log, README, blob, HTML, and action surfaces instead of serving the previous viewer's data.
  • Missing assets return 404. /app/assets/* was matched by path alone and the catch-all try_files rewrote a missing asset to /app/index.html, so a stale asset URL could be cached for a year as the SPA shell. Assets now go through an existence-checked file_server with a 404 fallback, and npm run check:caddy proves the contract against the container config.
  • Blob downloads work under the shipped CSP. connect-src now allows blob: so client-generated download URLs are not blocked.

Requests and resilience

  • Every NIP-98 request is signed uniquely. Bodyless requests skipped the nonce tag, so two identical signed GETs produced byte-identical events and the Relay replay guard rejected the second. A fresh nonce is emitted for every signed request. The agent-control start timeout also moves from 20s to 35s, which covers the control service's worst case of is-active + start + is-active plus proxy headroom.
  • Relay outages are surfaced, and channel creation requires a live connection. canCreateChannel now tracks the connection state, community-wide management is a separate canManageCommunity role check, and the channel browser, new-DM view, inbox, search, and settings surfaces receive the connection state instead of offering writes that cannot land. The mobile navigation close control takes focus when the drawer opens.
  • Slow profile and presence lookups no longer block chat. Cached messages render before profile hydration, startup presence is detached from the channel gate, HTTP queries are bounded with timeouts, malformed Relay events are rejected, and agent metadata names are reused.
  • Profile names hydrate before messages render. The first usable kind-0 name is parsed instead of letting a blank display_name mask a valid name, malformed or non-object metadata is treated as empty, known and configured names survive newer nameless metadata, channel and message authors hydrate before history becomes visible, and one localized Member/Agent fallback is used across chat, inbox, repos, and agent activity.

Notifications

  • Hidden tabs get inbox notifications. A hidden tab raises at most one notification per channel for mentions, direct messages, thread replies, and needs-action items; the service worker serializes check-and-show so staggered tabs cannot both display the same event. Notification payloads carry a scope derived from the current identity and Relay and no sender, channel, message text, host, or count. Click routing validates the target against the current identity before opening, and falls back to the Inbox rather than guessing. Closed-tab delivery stays unsupported and is recorded in the Roadmap.
  • Enabling notifications arms immediately. Enabling during an inbox reload folded newly arriving events into the seen set and silently suppressed them; both the settings click and the cross-tab re-arm now start armed at the current one-second watermark.

Read-only surfaces

  • Moderation queue for community owners and admins. Reads the Relay's moderator endpoints directly and performs no moderation actions: reports, audit log, and restricted-member rows are display-only. The Relay decides which rows a signed viewer gets, every request is scoped to viewer + Relay, and nothing is persisted — the queue is fetched on demand and held in memory.
  • Repository issues and pull requests. Renders kind 1621 roots, kind 1618 roots, and kinds 1630–1633 as their closing/merging/applying/drafting status events, joined in the browser to already-loaded repository announcements because the Relay does not index #a. The query is a bounded newest window of 200 events and says so; counts and empty states claim absence only when the join is complete, otherwise they report unknown/incomplete. Status events are trusted only from the root author or the repository owner, and the copy states that issue text is Relay-wide rather than governed by repository Git access.
  • Workflow run history. Definitions come from kind 30620 events with no write path; run history is fetched on demand for a single workflow through the existing relay route. Approvals and authoring stay unshipped: the approval reference is a bearer capability and no producer exists yet.

Workflow run-history cleanup

  • The navigation gate survives a bad probe and a late publisher. The probe moved out of BuzzWebApp into a useWorkflowGate hook. It still re-probes on every (re)connect, so a probe that answered on a stale socket recovers on the client's own reconnect instead of hiding the tool for the rest of the session. While the gate is unresolved and the session is connected, one one-shot kind 30620 subscription watches the definition stream and reveals the row on the first definition published mid-session, then tears itself down — no timers, no re-probe loop, nothing left running once the gate is present.
  • Unreadable run rows are reported as information, not failure. The dropped-rows message keeps aria-live="polite" and role="status" but moves off the destructive surface to the muted, ringed surface with an info icon, because the rows that could be read are still shown above it. Browser tests measure ink and icon contrast against the painted background at AA.
  • Test coverage moves to the browser. The unit test that asserted a manual two-probe refinement was deleted: the hook now owns that path, and two Playwright journeys cover it end to end — a dropped socket re-probes and recovers, and a definition published mid-session reveals the tool with exactly one live subscription and one probe.

All new user-facing copy has English and Simplified Chinese values, and the new surfaces were built against the existing navigation, panel, and i18n patterns.

Excluded on purpose

  • Moderation actions, agent-configuration writes, repository/project writes, and workflow approvals/authoring remain out of scope.
  • No branding, copy, or asset changes are included; the diff is feature code, tests, i18n strings, the Caddy file, one package script, and Roadmap updates only.

Verification

Run from web/ on this head (7906f59) with Node 24.14.0 and npm 11.9.0, no retries, no skipped tests, no relaxed assertions:

Gate Result
npm run typecheck tsc --noEmit, exit 0, no diagnostics
npm test 33 files, 209 tests passed (7.0s)
npm run check biome 180 files clean; file-size, i18n, and pubkey-truncation checks pass
npm run build tsc + vite build succeeded (1.69s)
npx playwright test --project=workflows 14 passed (38.3s)
git diff --check clean

npm ci was not rerun for the final commit: node_modules is present and package-lock.json is unchanged by it, which touches only web/src and web/tests. npm run check:caddy and the full npm run test:e2e suite were not rerun on this head — the Caddy config is untouched by this commit. The full suite passed 71 tests on the previous head (3a286c4), one commit behind this tree; that commit changes only the workflow feature and its spec, which the project run above covers.

The unit-test count drops by one (210 → 209) because this cycle deletes the superseded gate-refinement unit test; the behaviour it covered is now asserted in the workflows browser project.

E2E covers the cache-isolation denial journeys, the asset-404 contract, notification dedupe and identity scoping across two tabs, moderation empty/denied/timeout/identity-switch states, repository activity joins and Chinese copy, and workflow definition/run states at 390px and desktop widths. The workflow project additionally covers reconnect recovery, mid-session reveal, and the dropped-rows notice contrast.

npm ci reports 9 dependency advisories (4 moderate, 4 high, 1 critical) in the existing lockfile (vite, vitest, zod, nanoid, seroval, postcss-selector-parser, source-map-js, @tailwindcss/typography). They predate this PR and are untouched here; upgrading them is a separate change.

Limits

  • Open tabs keep running the JavaScript they loaded; this PR adds no auto-update, so a fixed client needs a reload.
  • Identity partitioning prevents reuse of one viewer's cached repository data by another; it is not encryption at rest. Decrypted content remains in browser storage for the identity that created it.
  • The mid-session workflow reveal needs a live connection; a client that never reconnects and never receives a definition stays hidden, which is the honest state for a Relay with no readable definitions.
  • E2E exercises mocked Relay responses, including authenticated ones; the moderation, workflow, and repository-activity panels were not run against a production Relay holding real data.
  • Approvals and authoring are deliberately excluded: no moderation actions, no workflow approvals, no workflow or repository writes.
  • Repository announcements (kind 30618) remain spoofable exactly as before, and Relay ACL gaps are unchanged; this PR does not add trust in announcements or tighten Relay authorization.

Scope Git clone/fetch storage and query keys to the signed-in viewer and configured Relay, bind NIP-98 authorization to the captured viewer namespace, and fail closed on any non-transport failure. Denied views now surface a localized alert and suppress private tree, log, README, blob, HTML and action surfaces.

Add unit coverage for DB naming, signer binding and failure classification, a synthetic smart-HTTP browser fixture for real clone/fetch denial journeys, and pin the Inbox test clock to remove the demo fixture second-boundary race.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
The /app/assets/* immutable Cache-Control header was matched by path alone and the catch-all try_files fallback rewrote a missing asset to /app/index.html, so a stale asset URL could be cached for a year as the SPA shell. Serve assets through an existence-checked file_server with a 404 fallback and add the check:caddy container-backed regression proof.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 3, 2026 13:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the cache-isolation and missing-asset routing changes.

No open issues 🎉

What changed in this PR

This PR addresses two Web-client cache issues: repository data shared across identities and missing assets receiving an immutable-cached SPA shell. Relay and protocol behavior remain unchanged.

Changes:

  • Scope repository caches by viewer and relay, bind Git authorization to the captured viewer, and clear query caches on sign-out.
  • Hide cached repository content after access failures and display localized, accessible error messages.
  • Return 404 for missing assets and add regression coverage for cache isolation, identity-switch races, denial handling, and Caddy routing.
File Description
web/​tests/​e2e/​smoke.spec.ts Fixes the clock for the Inbox test.
web/​tests/​e2e/​p0.spec.ts Tests cache isolation, denial handling, and localized error UI.
web/​tests/​e2e/​git-fixture.ts Adds a synthetic Git transport backed by real fixture repositories.
web/​src/​shared/​i18n/​index.ts Adds English and Chinese repository-access errors.
web/​src/​features/​repos/​use-repos.ts Scopes repository queries by viewer and requires a signer.
web/​src/​features/​repos/​use-repo-refs.ts Scopes refs queries by viewer and requires a signer.
web/​src/​features/​repos/​use-git-browse.ts Scopes browse queries and masks cached results after clone errors.
web/​src/​features/​repos/​ui/​ReposPanel.tsx Makes repository error banners accessible.
web/​src/​features/​repos/​ui/​RepoDetailPage.tsx Adds accessible alert semantics to detail-page errors.
web/​src/​features/​repos/​ui/​RepoBlobViewer.tsx Adds an accessible, styled file-error alert.
web/​src/​features/​repos/​git-client.ts Isolates clone databases, validates signer identity, and restricts offline fallback.
web/​src/​features/​repos/​git-client.test.ts Tests cache namespaces, authorization, and failure classification.
web/​src/​features/​repos/​git-client.nip07-race.test.ts Tests identity changes during signing and rejection before transport.
web/​src/​features/​chat/​ui/​IdentityGate.tsx Clears the query cache before clearing the signer.
web/​scripts/​check-caddy.mjs Adds container-based routing and cache-header checks.
web/​package.json Exposes the check:caddy command.
web/​Caddyfile Separates asset serving from SPA fallback and returns 404 for missing assets.

Review effort: Balanced

…meout

Bodyless NIP-98 requests skipped the nonce tag, so two identical signed
GETs (for example the same Git ref advertisement) produced byte-identical
events and the relay replay guard rejected the second one. Emit a fresh
nonce for every signed request regardless of whether a payload is present.

The agent-control start call aborted after 20s, but the control service can
legitimately spend 25s on is-active, start, and is-active before it answers.
Raise the client timeout to 35s to cover that worst case plus headroom for
an operator proxy in front of the service.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Only visible tabs used to raise a notification, and nothing suppressed a
notification for activity the reader was already looking at. A hidden tab now
raises at most one notification per channel for mentions, direct messages,
thread replies, and needs-action items, and the service worker serializes the
check-and-show so staggered tabs cannot both display the same event.

Each notification carries a scope tag derived from the current identity and
Relay, so a notification raised under one session is never reused after an
identity or Relay change, and the copy stays generic: no sender, channel name,
message text, Relay host, or count reaches the notification store. Cleanup runs
when the scope, the read state, or the inbox contents change.

Click routing validates the pushed target against the current identity before
it opens anything, refuses channels this session did not load, and falls back
to the Inbox rather than guessing a destination.

Closed-tab delivery is still unsupported: there is no push subscription, no
server-side sender, and no Relay-side endpoint, so a notification appears only
while at least one tab is open. The Roadmap records that gap.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Add a community moderation view that reads the Relay's moderator endpoints
directly. The web client performs no moderation actions: reports, the audit
log, and restricted-member rows are display-only.

Access is gated by the Relay. The navigation entry appears for community
owners and admins, and the Relay independently decides which rows are
returned for the signed viewer. Every request is scoped to the viewer and
the configured Relay URL, so responses for one identity or Relay are never
reused for another.

Nothing is persisted locally: the queue is fetched on demand and held in
memory for the duration of the view.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Render repository issues and pull requests from the real Relay event
kinds: kind 1621 (issue root), kind 1618 (pull-request root), and kinds
1630-1633 as the status events that close, merge, apply, or draft them.
The Relay does not index `#a`, so these events are joined in the browser
to the repository announcements that are already loaded.

The query is a bounded newest window of 200 events instead of a full
history scan, and the UI states that window explicitly rather than
presenting it as the complete record. Counts and empty states only claim
absence when the join is complete: a saturated window, or a root naming a
repository with no loaded announcement, yields an unknown count and an
incomplete-state message instead of zero.

Issue and pull-request text is Relay-wide, so this feature does not imply
that repository Git access control applies to it; the copy says so
directly. Status events are trusted only when published by the root
author or the repository owner, because any Relay member with write
access can publish an issue or a pull request.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Enabling notifications during an inbox reload folded the newly arriving
events into the seen set and silently suppressed them, because the enable
paths seeded the arming from the in-flight item list instead of arming at
once. Both the settings enable click and the cross-tab storage re-arm now
use createEnabledArming, which starts already armed at the current
one-second watermark so a load in flight cannot consume fresh events.

A structural test pins both call sites, since the hook has no DOM harness
in this suite.

Limits: the watermark is whole seconds, so eligibility stays strictly
newer than the enable second; events with future timestamps beyond it
still depend on the relay clock matching the browser.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Workflow definitions arrive from kind 30620 events with no write path, and run
history is fetched on demand through the existing relay route for a single
workflow. Approvals and authoring stay unshipped on purpose: the approval
reference is a bearer capability and no producer exists for it yet.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
@anasfik anasfik changed the title fix(web): isolate repository caches by identity and return 404 for missing assets feat(web): identity-safe caches, notifications, moderation, project activity, workflow runs Nov 3, 2026
Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Parse the first usable kind-0 name instead of letting a blank display_name mask a valid name, and treat malformed or non-object metadata as empty. Keep known and configured names when newer metadata has no name, hydrate channel and message authors before history becomes visible, and use one localized Member/Agent fallback across chat, inbox, repos, and agent activity surfaces.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Render cached messages before profile hydration, detach startup presence
from the channel gate, bound HTTP queries, reject malformed relay events,
and reuse agent metadata names.

Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
@anasfik anasfik changed the title feat(web): identity-safe caches, notifications, moderation, project activity, workflow runs feat(web): identity-safe caches, relay and asset fixes, notifications, moderation, repository activity, workflow runs Nov 3, 2026
Signed-off-by: Gwhyyy <anasfik@users.noreply.github.com>
(cherry picked from commit 045e54c)
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