Commit Graph
2409 Commits
Author SHA1 Message Date
thePR0M3TH3ANandClaude Opus 4.8 dd3fbfdae6 refactor(blocks): route block-list sub through SubscriptionManager (P4)
kind-10000/30002 block-list live subscription now goes through L1 (dedup +
reconnect re-issue), handle closed on teardown; relaySubscriptionService kept as
manager-less fallback. user-blocks + dm-block-filter suites pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 16:10:26 -04:00
thePR0M3TH3ANandClaude Opus 4.8 09d0e045e8 refactor(lists): route follows + hashtag-prefs subs through SubscriptionManager (P4)
The two feed-driving list subscriptions (kind-30000 follows, kind-30015/30005
hashtag prefs) now go through the L1 SubscriptionManager instead of the global
relaySubscriptionService singleton: centralized dedup + reconnect re-issue (the
lists self-heal after a relay drop). Handles are stored and closed on teardown;
relaySubscriptionService is retained as the manager-less fallback.

Verified: subscriptions-manager/-feed + hashtag-preferences suites pass (32);
flaky multi-relay harness still all-PASS; pool-access lint clean.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 16:08:54 -04:00
thePR0M3TH3ANandClaude Opus 4.8 ee9c2700e7 refactor(watch-history): route relay fetches through SubscriptionManager (P4)
watchHistory.fetch now reads via the L1 SubscriptionManager (deduped +
health-gated) instead of pool.list directly: a new getSubscriptionManager dep
is threaded from the client, and both fetches (index + chunks) go through a
listEvents() helper. Raw pool.list is retained only as a fallback for
environments without a manager (tests/mocks), so the file stays grandfathered.

Verified: watch-history unit test passes; wh-repro cold resolve returns 10
items with 2 decrypts (routing intact end-to-end).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 16:01:29 -04:00
thePR0M3TH3ANandClaude Opus 4.8 dde0c35477 refactor(views): batch kind-30079 view counts via SubscriptionManager (P3)
Replaces the per-card view-count transport (each card: list + NIP-45 COUNT +
live sub, × relays — the ~880 REQ/s storm) with ONE shared batched kind-30079
subscription + ONE backfill list() over all visible cards, bucketed back to
per-pointer state by #a. Re-enables the VideoListView circuit-breaker.

Grid counts are convergent/approximate (cheap, persists via the existing view
cache); the watch page opts into an exact NIP-45 COUNT for its single pointer
(modalCoordinator passes { exact: true }) — accurate where it matters, one
request, no storm. Legacy per-pointer path retained for SubscriptionManager-less
environments (tests/mocks).

Verified: nip07-heat steady-idle with views on; flaky multi-relay harness still
all-PASS; new cheat-resistant batching+bucketing test. (Pre-existing
view-counter publish-session-tag failure is unrelated — fails at baseline.)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 15:49:50 -04:00
thePR0M3TH3ANandClaude Opus 4.8 25d3e83c46 refactor(moderation): batch kind-1984 report subs via SubscriptionManager (P2)
Replaces the per-video live report subscription (one pool.sub per visible
video × ~20 relays, re-fired on every reconnect — the ~1000 REQ/s storm) with
ONE batched SubscriptionManager subscription over the whole active id set,
updated in place as the set changes. Backfill fetches history only for
newly-added ids (one batched list()). Unchanged sets are a no-op (dedup guard).

MODERATION_REPORT_SUBS_ENABLED flipped back on. Trusted-mute subs were already
batched-by-author, so the relay cap + contact-loop fix already tamed them.

Legacy per-id path retained only for SubscriptionManager-less environments
(unit tests / mock clients). All 39 moderation tests pass; new cheat-resistant
batching test added; nip07-heat shows reports no longer storm (steady idle).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 15:04:40 -04:00
thePR0M3TH3ANandClaude Opus 4.8 2509c4d950 refactor(feed): route the video feed through the SubscriptionManager (P1 pilot)
subscribeVideos now goes through the L1 SubscriptionManager instead of calling
pool.sub directly: health-gated relay resolution (healthy-or-default fallback
preserved), centralized dedup, and registration for reconnect re-issue. The
buffer + .unsub() contract are unchanged. The client's manager uses its own
RelaySubscriptionService instance (isolated from the global singleton).

Verified: subscribeVideos relay-fallback + client + nostr-service suites pass;
ux-harness renders the grid (first card ~1.1s); steady-state REQ/ext idle.
(Pre-existing nostr-delete-flow failure confirmed unrelated — fails at the
pre-session baseline too.)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 10:19:36 -04:00
thePR0M3TH3ANandClaude Opus 4.8 1fb6b86b7f feat(relay): add SubscriptionManager (L1) + direct-pool-access lint guard
P1 foundation of the data-flow refactor (docs/architecture-refactor.md):

- js/nostr/subscriptionManager.js: the single chokepoint for relay reads.
  Builds on relaySubscriptionService (dedup by key) and adds: health-gated
  default relays, deduped one-shot list() with timeout, and a reconnect
  registry that re-issues active subs centrally (instead of every subsystem
  re-subscribing on reconnect — the storm amplifier). Callers pass batched
  filters (one REQ for many ids), never per-item.
- Export RelaySubscriptionService class for test isolation.
- scripts/check-direct-pool-access.mjs + lint:pool-access: fail on NEW direct
  pool.sub/list usage; 12 grandfathered files listed as migration targets
  (allowlist may only shrink).

Nothing rewired yet — additive. Pilot (video feed) and per-subsystem
migration follow. Cheat-resistant tests included.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 10:11:43 -04:00
thePR0M3TH3ANandClaude Opus 4.8 70aab38470 perf(relay): cap the subscribe/read relay set (interim RelayHealth)
A user's NIP-65 list can carry ~20 relays, most dead. Subscribing on all of
them is the dominant REQ-storm amplifier: every subsystem fans every query
across all relays and re-fires on each flaky-relay reconnect. Cap the
read/subscribe set to a bounded core (6), prioritizing the bundled known-good
defaults; WRITES still fan out to the full set so publish reach is unaffected.
Interim until RelayHealth ranks by liveness (docs/architecture-refactor.md P1).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 10:03:00 -04:00
thePR0M3TH3ANandClaude Opus 4.8 35c4e68cde chore(perf): add nip-07/relay diagnostic harnesses + dev REQ monitor
Headless Playwright probes that reproduce the real login path via a fake
window.nostr extension (which loginWithNsec bypasses) and measure
steady-state extension-call and relay-REQ rates:
- nip07-heat.mjs, req-capture.mjs, ws-lifecycle.mjs, loopc-capture.mjs, etc.

Plus js/devReqMonitor.js: a localhost-only WebSocket REQ-rate monitor that
warns in-console when relay traffic spikes, naming the storming kinds — used
to capture the real-environment storm the mock-relay harness could not see.
Removable once the refactor lands.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 09:52:41 -04:00
thePR0M3TH3ANandClaude Opus 4.8 a3b205bfa1 fix(login-perf): kill relay REQ storms and feedback loops
Real-environment console logs revealed nip-07 login pegging the CPU and
starving encrypted-list decryption via relay REQ storms (~1000 REQ/s):

- moderationService.rebuildTrustedContacts emitted "contacts"
  unconditionally, forming an emit->fetch->emit loop (~1600 kind-3 REQ/s).
  Now emits only on actual change. Regression test added.
- Per-video live report (kind 1984) and view-count (kind 30079)
  subscriptions fan out O(videos x relays) and re-fire on every flaky-relay
  reconnect. Circuit-broken behind flags until batched (see refactor plan).
- onVideosShouldRefresh now coalesces forced reloads (2s leading-edge
  throttle) so list-change signals can't drive a reload loop.
- nip-07 queue reserves one foreground slot; DM decryption demoted to LOW
  so background DM backfill can't starve feed-driving lists. Test added.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 09:52:33 -04:00
thePR0M3TH3ANandClaude Opus 4.8 2553072770 fix(dm): keep explicit hints + self-fallback in legacy decrypt ordering
The legacy-DM perf reorder regressed tests/nostr/dmDecryptorPreference:

1. preferLegacy short-circuited BEFORE the explicit-hint ranking, so a kind-4
   event tagged ["encrypted","nip44"] would still try nip04 first. Explicit
   hints now win; preferLegacy only flips the *no-hint* default.
2. The "skip the actor's own key" optimization dropped self even when it was the
   ONLY candidate (note-to-self DMs), leaving zero candidates -> ok:false. Self
   is now deferred to last and attempted as a fallback instead of dropped.

Spec correction (per Dark Factory rules): for a kind-4 DM with no hints, nip04
is now the preferred default (protocol-correct + avoids a wasted serialized
nip-07 round-trip). Rewrote the preference test to assert: nip04-first default,
explicit nip44 hint wins, nip04->nip44 fallback, and note-to-self decrypts.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-13 18:48:09 -04:00
thePR0M3TH3ANandClaude Opus 4.8 915b77b740 fix(watch-history): stop infinite feed-refresh loop pegging the CPU
updateFingerprintCache (and the fingerprint getter) emitted "fingerprint"
unconditionally on every load. The For You feed subscribes to that event and
re-runs refreshFeed -> loadLatest -> updateFingerprintCache -> emit, so once the
For You feed was active the app entered an infinite loop: a full feed rebuild
plus a watch-history reload (with extension decrypts) every ~400ms. That pegged
the CPU (fans maxing) and starved every other load — videos, hashtags, subs,
DMs and watch history all failed to appear.

Emit "fingerprint" only when the fingerprint actually changes. The first real
resolution emits once (triggering a single refresh); the follow-up load produces
the same fingerprint and emits nothing, so the loop settles immediately.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-13 07:57:04 -04:00
thePR0M3TH3AN 9dddda0326 Revert "perf(watch-history): decrypt only recent months on load (cap cold cost)"
This reverts commit b5ad582b6c.
2026-06-12 21:21:16 -04:00
thePR0M3TH3ANandClaude Opus 4.8 b5ad582b6c perf(watch-history): decrypt only recent months on load (cap cold cost)
Root cause of the ~20s watch-history load: history is bucketed by month (one
encrypted snapshot event per month) and the fetch decrypted EVERY month via the
serialized nip-07 extension — ~1 slow call per month, so accounts with years of
history paid dozens of back-to-back extension decrypts on every load.

Cap the load to the most recent RECENT_MONTHS_DECRYPT_LIMIT (6) months by default
— enough for the feed's watched-video suppression and the initial view. Callers
that need the full history (the explicit History view) pass recentMonthsLimit: 0,
threaded loadLatest -> scheduleWatchHistoryRefresh -> resolveWatchHistory ->
resolve -> fetch.

Harness (fresh-context wh-repro): 600 items / 18 months goes from 18 nip-07
decrypt calls to 6. Watch-history tests green. Bumps the watchHistory.js
file-size baseline for the added logic.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 21:11:40 -04:00
thePR0M3TH3ANandClaude Opus 4.8 3d0564feea fix(auth): stop eagerly preloading watch history on login
The eager watch-history preload (0c8a17e3) — even deferred after the critical
lists — saturated the serialized nip-07 extension with ~150+ chunk decrypts for
~18s after login. If the profile modal was opened in that window, its hashtag /
subscription / DM loads competed for the extension and failed/timed out, and DMs
felt broken.

Revert to lazy loading: watch history loads when the For You feed or History view
is opened, keeping login light so the critical lists and the modal work. Re-add
an eager preload only after the cold-load decrypt cost is reduced (task #14).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 20:32:03 -04:00
thePR0M3TH3ANandClaude Opus 4.8 ed90ddc2bb perf(feed): trust relays for the public feed (drop off-thread verification)
Per decision: the off-thread signature-verification worker added feed latency
(the worker can hang loading nostr-tools, costing up to its timeout on the first
batch) and fragility (it could blank the feed) for little benefit on a PUBLIC
video feed. Default the VideoEventBuffer verifier to trust-all (the relay pool
already does not verify), so feed events commit immediately. Verification is now
opt-in via the verifyEvents option (the worker client remains for that).

Security note: a malicious relay could serve events with forged authorship for
the read feed; verify on sensitive actions instead. Reversible.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 20:30:46 -04:00
thePR0M3TH3ANandClaude Opus 4.8 5a45ec7bf5 fix(auth): defer watch-history preload so it doesn't starve the critical lists
Regression from the eager watch-history preload (0c8a17e3): it fired BEFORE the
blocks/subscriptions/hashtags list sync. The nip-07 extension serializes all
decrypt calls, and a cold watch history is ~150+ chunk decrypts — so those
queued ahead of the small critical lists, which then timed out ("hashtags not
working / subscriptions super slow") while watch history slowly drained the
extension (~20s).

Move the preload to AFTER Promise.all(parallelListTasks) so the small, critical
lists decrypt first, then watch history warms in the background. Still
non-blocking; still emits "fingerprint" for the For You re-run.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 20:06:57 -04:00
thePR0M3TH3ANandClaude Opus 4.8 39aa81fb23 perf(dm): coalesce concurrent decrypts of the same DM event
Multiple subscribers (history list + notifications) decrypt the same DM event
at once; before the in-memory cache fills, each hit the serialized nip-07
extension, multiplying round-trips per message. Cache the in-flight decrypt
promise by event id so concurrent callers share one decrypt.

Harness: cold-load extension decrypt calls drop from ~50-60 to exactly 20 for 20
DMs (1 per message); warm reload stays 0 via the persisted cache. Combined with
the earlier ordering/sequential and persist-cache fixes, legacy DM decryption
went from ~241 extension calls (20 DMs) to 20 cold / 0 warm.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 19:56:36 -04:00
thePR0M3TH3ANandClaude Opus 4.8 8171fcb347 perf(dm): persist decrypted DM results so reloads skip the extension
Consolidates the persisted-plaintext-decrypt-cache pattern (already used by watch
history) into a shared factory, persistedPlaintextCache.js, and adds a DM cache
on top of it. watchHistoryDecryptCache now delegates to the factory (same public
API; tests unchanged).

decryptDirectMessageEvent now also consults/writes a persisted cache keyed by the
immutable DM event id (JSON of the decrypt result; flushed once per
listDirectMessages batch; cleared on logout alongside the in-memory cache). DM
events never change, so a reload re-decrypts only messages it has not seen and
skips the (serialized, slow) nip-07 extension for the rest.

Harness (dm-repro, now cold/warm): 20 DMs -> COLD nip04.decrypt 50, WARM 0 —
reloads cost zero extension decrypt calls. Also excludes the actor's own key from
NIP-04 remote candidates (decrypting against self is always wasted). DM unit +
integration and watch-history cache tests green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 19:55:07 -04:00
thePR0M3TH3ANandClaude Opus 4.8 bbf8d10473 fix(dm): stop the per-message extension decrypt storm in legacy DMs
The DM-repro harness (fake nip-07 extension) showed legacy DM history made ~12
extension decrypt round-trips PER message (20 DMs -> 241 calls: nip44.decrypt
121 + nip04.decrypt 120). At a real ~100ms extension latency that's ~24s, which
is why DM history "looked broken" — it was just catastrophically slow.

Two causes in decryptLegacyDm:
- It raced EVERY (decryptor x remote-pubkey) combination in parallel. That looked
  like a latency win, but the nip-07 extension serializes calls, so racing N
  combinations just queued N slow round-trips per message.
- orderDecryptors ranked nip44 first (by candidate priority), so every kind-4
  (always NIP-04) message burned a failing nip44 extension call first.

Fix: order nip04 first for legacy DMs (preferLegacy) and try candidates
SEQUENTIALLY, stopping at the first success. With the right scheme and remote
party tried first, it's ~1-3 calls/message instead of ~12. Harness after: 20 DMs
-> 60 calls, zero nip44 attempts (was 241). DM unit + integration tests green.

Adds scripts/perf/dm-repro.mjs (seeds kind-4 DMs, logs in via the fake extension,
calls listDirectMessages, reports decrypted count + extension call counts).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 19:43:49 -04:00
thePR0M3TH3ANandClaude Opus 4.8 7e3cdb4174 fix(nostr): make feed signature verification fail-open and non-hanging
The UX harness (fake nip-07 extension) revealed that the off-thread verification
could blank the feed: if nostr-tools is slow/unable to load inside the verify
worker, the worker hangs, each batch waits the full 10s timeout, and the
main-thread fallback could return an empty set (fail-closed) — dropping every
event so no videos ever render, silently (devLogger is suppressed in prod).

Harden it so verification can never stall or blank the read feed:
- Worker timeout 10s -> 2.5s, and disable the worker for the session after one
  timeout/error so we never pay the timeout on every batch.
- Bound the main-thread nostr-tools wait (Promise.race ~2s) so a slow/failed
  load can't hang the fallback.
- Fail OPEN when the verifier is genuinely unavailable: pass events through
  unverified rather than dropping them (the pool already does not verify, so this
  does not regress the prior posture). Real verification still runs whenever
  nostr-tools is available.

Adds a regression test (hung worker -> resolves via fallback, worker disabled).
Also updates the harness to seed mode:"live" videos + a NIP-65 relay list for
mock-relay isolation.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 15:52:40 -04:00
thePR0M3TH3ANandClaude Opus 4.8 8c4412a562 perf(watch-history): cache decrypted chunk plaintext by event id
Watch history is ~150 separately encrypted chunk events; decrypting each one is
a serialized round-trip to the nip-07 extension (the key lives in the extension
and cannot be cached locally), so a full re-decrypt cost many seconds on EVERY
load. Chunk events are addressable/replaceable: an unchanged chunk keeps its
event id while a modified chunk republishes under a new id.

Add a persisted cache (watchHistoryDecryptCache.js) keyed by chunk event id. The
fetch path checks it before calling the extension and stores successful
decryptions, so reloads decrypt only the chunk(s) that actually changed
(typically one) and skip the extension for the rest — across sessions. Bounded
to 400 entries; cleared on logout alongside the conversation-key cache. The
cached plaintext is no more sensitive than the watch-history items already
persisted by the manager.

Adds watchHistoryDecryptCache.test.mjs (round-trip, persistence/re-hydrate,
bounds, clear).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 15:07:18 -04:00
thePR0M3TH3ANandClaude Opus 4.8 122d806ad2 perf(feed): don't block fresh load on remote admin-list fetch
loadVideos awaited ensureAccessControlReady -> waitForReady -> _performRefresh
-> loadAdminState, which awaits a remote admin-list fetch. On a cold load that
waits for relays to connect (~5s) plus the fetch, stalling the feed ~10s before
any video renders. The cached admin state IS hydrated synchronously at
construction, but with markLoaded:false, so waitForReady blocked on a full
remote refresh even when a usable cache existed ("refresh fixes it").

ensureAccessControlReady now blocks only on a first-ever cold load WITH whitelist
mode (where showing non-whitelisted content before the whitelist arrives would be
wrong). In every other case — admin state hydrated from the localStorage cache,
already loaded, or blacklist-only mode — it kicks the refresh off in the
background (ensureReady) and renders immediately; the reactive
onWhitelist/onBlacklistChange handlers re-filter the grid once fresh lists land.

Adds accessControl.isHydrated() and a branching test
(nostr-service-access-control-ready.test.mjs).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 14:31:38 -04:00
thePR0M3TH3ANandClaude Opus 4.8 0c8a17e3cf perf(watch-history): eagerly preload on login (was lazy until For You/history tab)
Watch history was never loaded as part of the login cascade — it only loaded
when the For You feed refreshed or the history tab was opened. So on login (and
on other feeds) watched-video suppression and watch-history tags did nothing
until the user navigated there.

Kick off a non-blocking watchHistoryService.loadLatest() during the login
list-sync (deliberately NOT in parallelListTasks, so the feed never waits for
it). loadLatest schedules the background refresh, which emits "fingerprint" and
the For You feed re-runs (feedCoordinator) to apply suppression once resolved.
Deduped against the feed's own loadLatest via the in-flight refresh promise.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 14:18:09 -04:00
thePR0M3TH3ANandClaude Opus 4.8 9b12a282af perf(watch-history): show persisted history instantly on reload
After a page reload the in-memory caches (service fingerprintCache and the
client watch-history cache) are empty, so loadLatest's non-blocking path returned
[] and the For You feed suppressed nothing until the slow background network
refresh (~150 encrypted chunk events over 2 sequential relay round-trips) landed.

Return the best available items immediately via getCachedSnapshotItems, which
falls back to the persisted localStorage snapshot. Reloads now suppress watched
videos right away using the last-known history, while the background refresh
still runs and corrects it (firing "fingerprint" to re-run the feed). Persisted
items were previously valid, so there is no correctness risk.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 13:47:27 -04:00
thePR0M3TH3ANandClaude Opus 4.8 52ceb4f211 perf(watch-history): load in background; re-run For You when it resolves
The For You feed awaited watchHistoryService.loadLatest() before rendering, and
loadLatest blocked on the full ~1500-item watch-history fetch on a cold load even
with allowStale:true (the `!allowStale || !hasCachedItems` guard awaited whenever
there was no cache). So the main feed froze behind the entire watch-history
resolution, and nothing re-ran the feed once history finished loading — watched
videos were never suppressed and watch-history tags never applied until a manual
refresh.

- watchHistoryService.loadLatest: allowStale callers now NEVER block. On a cold
  load the refresh is kicked off in the background and the call returns
  immediately with whatever is available (cached items, else the local queue).
- feedCoordinator.subscribeWatchHistoryFeedRefresh: subscribes to the
  "fingerprint" event and, when the For You feed is active, debounced-re-runs it
  so newly-resolved watched videos are suppressed and tags applied. Wired in at
  bootstrap alongside feed registration.

The re-run reads the now-fresh cache (no further refresh scheduled), so there is
no loop. Adds feedCoordinatorWatchHistoryRefresh.test.mjs (debounced single
refresh while active; no refresh when inactive; idempotent subscription).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 11:44:01 -04:00
thePR0M3TH3ANandClaude Opus 4.8 874897b933 perf(nostr): verify event signatures off the main thread
Profiling the live app showed the single biggest CPU cost was the relay pool
verifying every incoming event's schnorr signature synchronously on the main
thread: ~1.2s of secp256k1 work ([email protected] 855ms) during feed load and tab
switches, dropping to ~16ms when skipped. The pool was constructed as
`new SimplePool()` with no options, so nostr-tools used its default verifying
verifyEvent; the `verifyEvent: () => true` that looked like it disabled this
only existed on a mock tools object and was never wired to the real pool.

Move verification off the main thread instead of dropping it:
- Construct the pool with `verifyEvent: () => true` so it never blocks.
- Add signatureVerifyWorker (+ client) that verifies event batches in a Web
  Worker and returns the valid ids; falls back to main-thread verification only
  when Workers are unavailable (never silently trusts).
- VideoEventBuffer verifies each batch via the worker before committing, and
  drops events that fail (fails closed). The verifier is injectable so tests can
  virtualize the worker; subscribeVideos passes it through and returns the flush
  promise from EOSE so commits are awaitable.

Tests: new signatureVerifyWorkerClient.test.mjs (worker protocol + drop-invalid
+ empty/no-id handling); videoEventBuffer.test.mjs and client.test.mjs adapted
to the async, verified commit path with a passthrough verifier.

Note: tests/nostr-delete-flow.test.mjs has a PRE-EXISTING failure on
`should not trigger subscription callbacks` (fails on clean unstable, and is a
standalone script not run by the unit-test runner); its edits here only adapt it
to the now-async flush.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 11:16:25 -04:00
thePR0M3TH3ANandClaude Opus 4.8 3f19294a8e fix(admin-lists): force full fetch so persisted lastSeen can't hide current list
fetchLatestListEvent fetched admin lists via fetchListIncrementally without an
explicit `since`, so it relied on the persisted per-relay lastSeen. Admin lists
are replaceable events with a single current version whose created_at does not
advance, so once lastSeen == that created_at, every later load queries
since=lastSeen+1 and the relay returns nothing — perpetually hiding the current
list and dropping admin lists whenever the local cache is absent.

Pass since: 0 to force a full fetch of the (tiny) current event each time. Other
list callers anchor an explicit since to their own cached state; admin lists
have no comparable per-list timestamp, so always re-fetching current is both
correct and cheap.

Adds tests/nostr/relayBatchFetcherReplaceable.test.mjs documenting the
replaceable-event since-gate at the fetcher boundary: relying on persisted
lastSeen hides the current event; since: 0 returns it.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 09:44:36 -04:00
thePR0M3TH3ANandClaude Opus 4.8 818fe16254 fix(feed): fall back to default relays in subscribeVideos on cold start
subscribeVideos called pool.sub(getHealthyRelays(this.relays)) with no
empty-relay fallback, unlike the fetch paths in the same file. On a cold first
load the 5s relay connect probe can time out, marking every relay unreachable;
init() only warns and schedules a background reconnect (it does not throw), so
boot proceeds and the feed subscribes to ZERO relays. The background reconnect
later succeeds but nothing re-issues the subscription, so the feed stays empty
until the user refreshes (when the SWR cache renders) — the reported
"notes don't load on first visit / need a refresh" symptom.

Fall back to DEFAULT_RELAY_URLS when no relays are healthy, mirroring the
established pattern. Because the fallback bypasses the unreachable cooldown, the
subscription retries those relays directly and self-heals instead of staying
dead until refresh.

Adds tests/nostr/subscribeVideosRelayFallback.test.mjs: empty healthy set =>
default relays (never zero), populated healthy set => uses those relays.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 09:41:17 -04:00
thePR0M3TH3ANandClaude Opus 4.8 8850eb962a perf(watch-history): memoize NIP-44 conversation key across chunk decrypts
Watch history is stored as up to ~150 separately NIP-44-encrypted chunk
events. Each chunk built a fresh cipher suite whose conversation-key cache
lived only in its own closure, so the ECDH conversation key (~12ms each in
the bundle) was re-derived once per chunk — multiplied across actor-candidate
and scheme-fallback retries this synchronously blocked the main thread for up
to ~20s after login/profile open (the reported freeze + fan spin-up).

Memoize the derived key by (scheme, privateKey, target) at module scope so it
is computed once per load and reused. Cleared on logout/identity change next
to clearDecryptionSchemeCache so a derived shared secret never outlives its
session. On the 150-chunk path this drops decrypt time ~1955ms -> ~182ms.

Adds tests/nostr/watchHistoryConversationKeyCache.test.js covering: 150 chunks
=> one derivation, distinct identities derive independently (no cross-identity
reuse), and cache-clear forces re-derivation.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-12 09:41:06 -04:00
thePR0M3TH3AN 414a20c1b6 test: harden harness polling and fix dm signer key usage 2026-03-04 12:25:23 -05:00
google-labs-jules[bot]andPR0M3TH3AN a6d11914b1 chore(ai): document js/historyView.js
Added public API JSDoc blocks to `js/historyView.js`.
Created standalone architectural and execution overview `docs/historyView-overview.md`.
Completed required docs-code-investigator daily scheduling execution.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-03-02 19:51:49 +00:00
google-labs-jules[bot]andPR0M3TH3AN f7712f51a9 fix: initialize video modal share popover with correct arguments
- Update `js/ui/components/VideoModal.js` to correctly initialize the modal share popover using the `createPopover(trigger, renderFn, options)` signature instead of a single config object.
- Fix the flaky e2e test `tests/e2e/search-and-filter.spec.ts` by increasing the test timeout from 15s to 30s to allow more time for feed items to be retrieved from the network.
- Update `tests/e2e/video-modal-share-bug.spec.ts` to attach an `#uiOverlay` wrapper element for the popover so the DOM doesn't crash on tests.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-03-01 20:49:41 +00:00
google-labs-jules[bot]andPR0M3TH3AN f255bdd9bc chore(torch): execute daily agent run for ci-health-agent
- Resolve scheduler context and preflight exclusions
- Select `ci-health-agent` from roster using round-robin logic
- Acquire distributed lock for execution window
- Perform necessary repository check fixes (linting and tests)
- Publish successful completion lock event
- Write final `task-logs` event record
- Output execution summary

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-28 19:48:57 +00:00
thePR0M3TH3AN 444b39da6c Merge branch 'unstable' into agents/daily/test-audit-agent-nostr-tools-v2-11614128753134538673 2026-02-26 23:31:26 -05:00
google-labs-jules[bot]andPR0M3TH3AN 96f630a738 Fix nostr-tools v2 compatibility and test quality issues
- js/nostr/nip46Client.js: Convert hex keys to Uint8Array before calling nip44.v2 functions. Remove .bind() from getConversationKey getters to fix context issues.
- js/ui/components/RevertModal.js: Remove duplicate imports and variable declarations causing SyntaxErrors.
- tests/compliance/nip04_44_compliance.test.mjs: Update test setup to mock nostr-tools.utils and pass byte keys.
- tests/nostr/dm-direct-message-flow.test.mjs: Update setupDmScenario to pass byte keys to getPublicKey and finalizeEvent.
- tests/nostr/nip46Client.test.js: Update tests to handle byte vs hex keys correctly for nostr-tools v2.
- tests/minimal-webtorrent.test.mjs: Add explicit assertions.
- tests/ui/components/debug_hashtag_strip_helper.test.mjs: Add explicit assertions.
- artifacts/test-audit-report.md: Add audit report.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 03:43:14 +00:00
thePR0M3TH3AN 34b0b03ad0 Merge branch 'unstable' into agents/daily/torch-garbage-collection-agent-2026-02-26-15639715828522871125 2026-02-26 21:42:21 -05:00
thePR0M3TH3AN 8d6e32be27 Merge branch 'unstable' into agents/daily/style-agent-1740615175-12694853261144843326 2026-02-26 21:40:23 -05:00
thePR0M3TH3AN 9448624753 Merge branch 'unstable' into agents/daily/todo-triage-agent-13829754158937187173 2026-02-26 21:38:12 -05:00
google-labs-jules[bot]andPR0M3TH3AN 5c2ba17459 chore: garbage collection and maintenance fixes
Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 02:32:53 +00:00
google-labs-jules[bot]andPR0M3TH3AN a649c341e0 I have updated the nostr-tools usage and resolved the UI bugs. Here are the details of the changes:
- Updated `js/nostr/adapters/nsecAdapter.js` to ensure private keys are `Uint8Array` bytes before passing to `getPublicKey`, fixing compatibility with `nostr-tools` v2.
- Updated `tests/nostr/nip46Client.test.js` to use byte arrays for keys in crypto operations.
- Implemented missing `setupModalMorePopover`, `setupModalSharePopover`, and `refreshModalMoreMenuPanel` in `VideoModal.js`.
- Fixed a bug in `VideoModal.js` where `setCommentComposerState` was overriding `CommentsController` send button logic; it now delegates to the controller if available.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 02:14:29 +00:00
google-labs-jules[bot]andPR0M3TH3AN 089556acd1 chore(todo-triage): daily scan and minor fixes
- Ran `todo-triage-agent` scan (0 actionable items found).
- Fixed inline style lint error in `tests/ui/components/DeleteModal.test.mjs`.
- Fixed duplicate import syntax error in `js/ui/components/RevertModal.js`.
- Initialized `modalNavScrollHandler` in `VideoModal` constructor to improve test stability.
- Updated scheduler memory.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 02:14:06 +00:00
google-labs-jules[bot]andPR0M3TH3AN bf076578e9 fix(ci): resolve nostr-tools v2 compatibility and VideoModal regressions
- Fix `nostr-tools` v2 compatibility:
  - Update `js/nostr/adapters/nsecAdapter.js` to convert hex private keys to `Uint8Array` before passing to `getPublicKey`.
  - Update `js/nostr/nip46Client.js` to ensure keys are bytes for `getPublicKey`.
  - Update `tests/nostr/nip46Client.test.js` and `tests/nostr-private-key-signer.test.mjs` to use `Uint8Array` for keys.
- Fix `VideoModal` regressions:
  - Add missing delegation methods (`setCommentsVisibility`, `clearComments`, `resetCommentComposer`, `setCommentStatus`, `setCommentComposerState`, `appendComment`, `renderComments`, `setCommentSectionCallbacks`, `hideCommentsDisabledMessage`, `showCommentsDisabledMessage`, `updateCommentCharCount`, `updateCommentSubmitState`) to `js/ui/components/VideoModal.js`.
  - Expose getters for `commentsList`, `commentsComposer`, etc., in `VideoModal.js` to support tests.
  - Implement `setCallbacks` in `js/ui/components/video-modal/commentsController.js` and ensure robust initialization when DOM elements are missing.
  - Fix `open()` and `updateSourceAvailability()` in `VideoModal.js` to correctly re-enable Share, Embed, and Copy Magnet buttons.
- Fix `DeleteModal` tests to comply with linting rules (avoid direct `.style` assignment).

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 02:08:58 +00:00
google-labs-jules[bot]andPR0M3TH3AN 7427961a69 fix(ci): resolve various test failures and nostr-tools v2 compatibility
- Fix duplicate imports/declarations in `js/ui/components/RevertModal.js`
- Update `js/nostr/nip46Client.js` to pass `Uint8Array` keys to `getConversationKey` for compatibility with `nostr-tools` v2
- Fix NIP-46 compliance tests by using correct key types and improved mocks
- Implement missing methods in `js/ui/components/VideoModal.js` (`handleCopyRequest`, `setCommentsVisibility`, etc.) to fix runtime crashes in tests
- Ensure `VideoModal` stores comment composer state locally to support external controller updates in tests
- Update DM integration tests to use `Uint8Array` keys for `nostr-tools` helpers
- Fix linting issue in `tests/ui/components/DeleteModal.test.mjs` using `Object.defineProperty`

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 01:52:00 +00:00
google-labs-jules[bot]andPR0M3TH3AN 6a7dbf8c7d fix(ui): restore missing methods in VideoModal.js to prevent initialization crash
- Restore missing handlers (`handleCopyRequest`, `handleShareRequest`, `handleEmbedRequest`, `handleCreatorNavigation`, `handleModalMoreButtonClick`, `handleReactionClick`) and setup methods (`setupModalMorePopover`, `setupModalSharePopover`, `bindVideoEvents`, `detachVideoEvents`, `bindActionButtons`, `updateSourceAvailability`, `updateSourceToggleState`, `attachAmbientGlow`, `teardownAmbientGlow`, `refreshModalMoreMenuPanel`).
- Fixes `TypeError: Cannot read properties of undefined (reading 'bind')` in `VideoModal` constructor which caused E2E test timeouts and unit test failures.
- Implement methods using standard patterns and available imports (`popoverEngine`, `videoMenuRenderers`, `ambientBackground`).

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 01:31:28 +00:00
google-labs-jules[bot]andPR0M3TH3AN 5aac1b2d21 fix(ci): address multiple test and build failures
- Fixed duplicate import and variable declaration in `js/ui/components/RevertModal.js` which caused syntax errors.
- Fixed missing method implementations in `js/ui/components/VideoModal.js` which caused `bind` errors during initialization.
- Fixed NIP-46 compliance tests by updating mocks to match `nostr-tools` v2 structure.
- Updated `js/nostr/nip46Client.js` to ensure keys are passed as `Uint8Array` to `nostr-tools` helpers, maintaining compatibility with legacy hex strings.
- Updated `tests/nostr/dm-direct-message-flow.test.mjs` to use `Uint8Array` keys, fixing "expected Uint8Array" errors.
- Maintained the previous lint fix for `tests/ui/components/DeleteModal.test.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 01:15:53 +00:00
google-labs-jules[bot]andPR0M3TH3AN 51128c1d33 fix(ci): address linting errors and nostr-tools v2 compatibility
- Fix `SyntaxError` in `js/ui/components/RevertModal.js` by removing duplicate variable declaration.
- Update `js/nostr/nip46Client.js` to support hex string private keys with `nostr-tools` v2 `nip44` operations by converting to `Uint8Array`.
- Update `tests/nostr/dm-direct-message-flow.test.mjs` and `tests/compliance/nip04_44_compliance.test.mjs` to pass `Uint8Array` keys where required.
- Fix linting error in `tests/ui/components/DeleteModal.test.mjs` by avoiding direct `.style` assignment in mock.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 00:32:11 +00:00
thePR0M3TH3AN 98e1181783 Merge branch 'unstable' into security-fix-qrcode-innerhtml-16143867429725848701 2026-02-26 14:42:34 -05:00
thePR0M3TH3AN d050156d69 Merge pull request #2720 from PR0M3TH3AN/perf-watch-history-parallel-18111087127374532903
⚡ Optimize watch history publishing with Promise.all
2026-02-26 14:41:05 -05:00
thePR0M3TH3AN 11250f681b Merge pull request #2716 from PR0M3TH3AN/refactor-app-extract-dtag-value-657233878683899686
Refactor extractDTagValue in js/app.js
2026-02-26 14:38:13 -05:00