Commit Graph
6322 Commits
Author SHA1 Message Date
thePR0M3TH3ANandClaude Opus 4.8 200e5cec80 test(storage): assert credentials never persist in plaintext at rest
Pre-launch credential-security regression: scans the ENTIRE serialized account
record (meta + encrypted blob) for the secret/access-key strings and asserts
they never appear in plaintext, that listConnections() doesn't expose them, that
they round-trip while unlocked, and that they're unreachable once locked. The
prior check only compared the cipher field to JSON.stringify(payload), which
wouldn't catch a secret leaking into plaintext meta.

Audit conclusion: credential storage is sound — envelope encryption (AES-GCM-256
payload, fresh per-encrypt IV; master key encrypted to-self via the Nostr signer,
NIP-44 preferred / NIP-04 fallback), in-memory master key cleared on logout, no
secret logging, legacy plaintext migrated then cleared.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-17 05:35:02 -04:00
thePR0M3TH3ANandClaude Opus 4.8 c2228f3f4f docs(todo): R2 system follow-up backlog
Captures remaining R2 work after the upload audit + object-cleanup increments:
credential-security review, bucket/custom-domain provisioning audit, CDN purge
integration, and follow-ups to the cleanup work (generic-S3 cleanup, all-versions
delete cleanup, edit thumbnail cleanup). Plus the Vercel production-branch parking
lot item.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 22:21:32 -04:00
thePR0M3TH3ANandClaude Opus 4.8 33c701aae8 feat(r2): clean up the superseded object when a video's URL is replaced on edit
Editing a video with a newly-uploaded file produced a new content-addressed
object and orphaned the old one. editModalController.handleSubmit now removes the
old object (best-effort) when the hosted URL was genuinely replaced — guarded so
it only fires when both old and new URLs are present and different (so clearing
the URL, which may still be referenced by a magnet web-seed, never deletes it),
and it deliberately leaves thumbnails alone (the new note may still point at
them). Reuses R2Service.deleteVideoStorage (owned-objects-only, never throws).

Documented the cleanup contract in AGENTS.md §4a.

Test: tests/ui/edit-modal-storage-cleanup.test.mjs (3). Full suite green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 22:19:01 -04:00
thePR0M3TH3ANandClaude Opus 4.8 95b51b6e61 feat(r2): delete the underlying storage objects when a video is deleted
Deleting a video removed the Nostr note but left the actual file (plus its
thumbnail and .torrent) publicly downloadable at its R2/S3 URL forever — a
privacy gap and ongoing storage cost. Now the delete flow also removes the
backing objects, best-effort.

- collectVideoStorageKeys() (storagePointer.js): pure helper that derives the
  object keys (video + sibling .torrent + thumbnail) from a note, ONLY for URLs
  under the owner's bucket base — external/3rd-party URLs are never returned.
- R2Service.deleteVideoStorage(): resolves the owner's connection, and deletes
  those keys. Skips cleanly when storage is locked / no creds / no owned
  objects, and never throws (failures are recorded, not propagated) so storage
  cleanup can't block note deletion. R2Service class now exported for testing.
- app.handleDeleteModalConfirm: calls it after handleFullDeleteVideo succeeds.

Tests: tests/storage-key-collection.test.mjs (4),
tests/services/r2-delete-video-storage.test.mjs (4). Full suite green.

Note: superseded versions orphaned by past edits aren't retroactively cleaned;
edit-time cleanup (next) prevents new orphans going forward.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 22:09:57 -04:00
thePR0M3TH3ANandClaude Opus 4.8 96302a59f3 chore: remove dev Agent Dashboard sidebar link + view constant
Follow-up to c79120ba (which only captured the file deletion): removes the
sidebar nav link and the unused DEV_DASHBOARD view constant. No dangling refs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:36:27 -04:00
thePR0M3TH3ANandClaude Opus 4.8 43c843dbae build(vercel): no-cache headers for HTML + service worker
Adds Cache-Control: no-cache,must-revalidate for the entry HTML (/ , *.html)
and sw.min.js so Vercel-served domains (and any CDN/browser in front) always
revalidate the shell and pick up new deploys, mirroring netlify.toml. Hashed
JS/CSS keep far-future caching via their content-hashed filenames.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:35:58 -04:00
thePR0M3TH3ANandClaude Opus 4.8 c79120ba04 chore: remove dead dev 'Agent Dashboard' view (embedded external TORCH)
Drops views/dev/agent-dashboard.html (iframed the external TORCH dashboard,
now defunct), its sidebar nav link, and the unused DEV_DASHBOARD view constant.
No dangling references; build green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:35:58 -04:00
thePR0M3TH3ANandClaude Opus 4.8 ac1dcff184 fix(publish): flag + log unconfirmed (optimistic) relay publishes
publishEventToRelay optimistically reports success when a relay handle exposes
no ok/failed event and isn't thenable (legacy 'seen'-only relays). That made an
UNCONFIRMED publish indistinguishable from a real ack, so a note could show
'Published' with nothing actually stored. The result now carries optimistic:true
for that path (callers can distinguish it from a confirmed ack) and logs a
dev.warn. Behavior is otherwise unchanged (still treated as success for legacy
relays). Publish audit #3.

Test: tests/nostr-publish-optimistic.test.mjs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:28:27 -04:00
thePR0M3TH3ANandClaude Opus 4.8 3d6ffe997b fix(upload): surface thumbnail/.torrent upload failures to the user
These optional-asset uploads are non-fatal, but failures were warn-only — the
user got a silently-missing thumbnail or torrent with no signal. Both upload
services now emit a 'warning' status at the point of failure and append a note
to the final 'Published' status (downgraded to warning variant) listing what
failed. Cloudflare-upload audit #5.

Test: tests/services/s3-upload-optional-asset-failures.test.mjs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:19:27 -04:00
thePR0M3TH3ANandClaude Opus 4.8 04ae0ec4e6 fix(upload): fail fast on 0-byte files in multipartUpload
A 0-byte file produced a multipart upload with zero parts, which S3/R2 reject
with a cryptic CompleteMultipartUpload error. Guard file.size === 0 up front
with a clear message, before any S3 request is issued. Cloudflare-upload #4.

Test: tests/multipart-empty-file-guard.test.mjs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:15:17 -04:00
thePR0M3TH3ANandClaude Opus 4.8 6b603cc21c fix(upload): surface an 'Analyzing' status during pre-upload file hashing
Computing the torrent info-hash (and the content-hash fallback) reads the entire
file before the upload starts and before any progress is emitted, so on
multi-GB videos there was a long silent pause that looked like a freeze. Both
upload services now emit an 'Analyzing video…' status when a full-file hash is
required (i.e. no valid info-hash was pre-supplied). Cloudflare-upload audit #2.

Test: tests/services/s3-upload-analyzing-status.test.mjs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:14:21 -04:00
thePR0M3TH3ANandClaude Opus 4.8 c1ae810776 chore: remove TORCH subsystem (no longer used)
Removes the TORCH task-locking/scheduler-memory subsystem in full:
- delete torch/ (4900+ files), torch-config.json, and tracked .scheduler-memory/
- drop torch:* npm scripts and the torch-lock dependency; regenerate
  package-lock.json (only torch-lock removed)
- strip the dead "TORCH Memory Integration" / "Task Claiming Protocol (TORCH)"
  sections from AGENTS.md and CLAUDE.md (agent coordination is now PR-based) and
  the torch/TORCH.md doc-table row
- drop the stale `torch` ignore entries from check-hex / check-inline-styles /
  check-design-tokens

Build + touched lints pass. Note: views/dev/agent-dashboard.html still embeds
the external TORCH dashboard URL — left in place (separate dev-tools view).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:11:26 -04:00
thePR0M3TH3ANandClaude Opus 4.8 1d7808809e build(vercel): pin npm install command (avoid pnpm auto-detect)
Both package-lock.json and pnpm-lock.yaml are present, so Vercel auto-selected
pnpm, whose install failed on the new bitvid-unstable/bitvid-beta projects (the
existing bitvid project only worked via a dashboard install-command override).
Pinning installCommand makes every project/branch build with npm regardless of
dashboard settings.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:01:00 -04:00
thePR0M3TH3ANandClaude Opus 4.8 134f60dfd3 chore: gitignore .vercel CLI link directory
Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 19:50:55 -04:00
thePR0M3TH3ANandClaude Opus 4.8 4c5465eb35 build: auto-stamp service worker cache version with the build hash
The SW cache key (bitvid-sw-YYYY-MM-DD) and the informational meta in
index.html/embed.html were hand-bumped, so client caches only invalidated when
someone remembered to change the date — stale app shells (and stale footer
versions) persisted across deploys.

build-dist now stamps the dist artifacts with `bitvid-sw-<buildDate>-<hash8>`
(same content hash shown in the footer), so every content change yields a new
cache name and the SW's activate step drops the old cache automatically. Only
the dist output is rewritten — the committed (minified) sw.min.js source is left
as-is, so the sw-compat guard and tests that reference the source value are
unaffected. Build verified: all three dist files share one stamped version,
dist/sw.min.js still parses, verify:dist:deploy-artifact passes.

Also confirmed `npm run build` is reproducible (same inputs => same hash), so
deploys are deterministic.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 19:42:47 -04:00
thePR0M3TH3ANandClaude Opus 4.8 066d98febb fix(upload): content-address storage keys to stop URL-first overwrites
buildR2Key fell back to a static "uploads" namespace (and "video" slug) when
no torrent info-hash was available, so two distinct URL-first uploads sharing a
filename produced the SAME R2/S3 key — the second silently overwrote the first
object while the first video note still pointed at that URL (data loss).
WebTorrent uploads were already safe because the info-hash namespaces the key.

Add computeStorageContentHash(file) in js/r2.js: when no info-hash is present it
derives a deterministic content-based namespace — full SHA-256 of the bytes for
files ≤512 MB (idempotent: re-uploading the same file reuses the key), and a
SHA-256 fingerprint over name/size/mtime + sampled head/tail bytes above that,
so we never buffer a multi-GB video in memory. Wired into BOTH upload paths
(r2Service + s3UploadService) via a new storageIdentifier kept separate from the
info-hash, so magnet generation is unchanged.

Test: tests/storage-key-collision.test.mjs (distinct same-named uploads get
distinct keys; same content is idempotent; large-file fingerprint path samples
edges without buffering and stays deterministic). Full unit suite green.

test_integrity_note:
  change_type: ["new_tests"]
  scenarios:
    - id: SCN-upload-key-no-collision
      given: "a URL-first upload with no torrent info-hash"
      when: "the storage key is derived (computeStorageContentHash -> buildR2Key)"
      then: "distinct same-named files get distinct keys, same content is idempotent, and no key uses the colliding 'uploads' namespace"
  observable_outcomes:
    - "returned key strings for real Blob/File content and a fake >512MB file"
  determinism_controls:
    - "fixed byte content; fake large file with stubbed slice() and fixed lastModified"
  anti_cheat_rationale:
    prevents:
      - "hard-coded return value"
      - "over-mocking internal logic"
  relaxation:
    did_relax_any_assertion: false

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 16:56:12 -04:00
thePR0M3TH3ANandClaude Opus 4.8 0d6af82b30 docs(agents): capture NIP-07 reliability + upload-path lessons
- AGENTS.md §4a: Cloudflare/S3 upload-path gotchas from the 2026-06-16 audit
  (r2Service/s3UploadService duplication, buildR2Key collision = data loss,
  whole-file hash before upload, optimistic publish success, silent partial
  failures / empty-file guard).
- AGENTS.md §17 (new, appended so existing section numbers/cross-refs stay
  valid): NIP-07 Signer Reliability & Encrypted-List Loading — raw-probe
  diagnostic + the resilience invariants (relay cap, circuit breaker, no
  transient-error swallowing, decrypt budget, lazy modal population) and the
  deterministic fake-signer + mock-relay test harness.
- CLAUDE.md: matching condensed "NIP-07 Signer Reliability (hard-won)"
  subsection under Nostr Integration, cross-linking AGENTS.md §17 and
  KNOWN_BUGS #0.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 16:36:35 -04:00
thePR0M3TH3ANandClaude Opus 4.8 8022942464 docs: record nip-07 list-decrypt + post-login freeze resolution
- README "Login with Nostr": recommend a well-maintained NIP-07 signer
  (nos2x/Alby) and add a troubleshooting note for the locked/asleep-signer
  case (unlock/reload + refresh), since a flaky extension was the root cause
  of the encrypted-list load failures.
- KNOWN_BUGS #0: mark RESOLVED (2026-06-16) — confirmed in real env after the
  user switched to nos2x; DMs/watch-history/lists decrypt in ms with no
  timeouts. Documented the DM decrypt-resilience + receiver fixes and the
  post-login profile-panel freeze fix (defer panel rendering to selectPane).
  Recorded the remaining low-priority follow-ups (liveness-ranked relays,
  opt-in queue concurrency, optional DM double-decrypt routing).
- Retitle the section "## Open" → "## Tracked" so resolved entries (#0/#1/#2)
  aren't mislabeled as open; status is now per-entry.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 16:23:17 -04:00
thePR0M3TH3ANandClaude Opus 4.8 a1a8f6cda6 perf(profile): defer profile-panel rendering until the modal opens
Post-login the site froze for ~10-15s and the profile panel wouldn't open.
Cause: profileModalController.handleAuthLogin eagerly rendered EVERY profile
panel at login (twice) — friends list + per-contact avatar fetches,
subscriptions, blocks, relays, wallet, hashtags, storage — into a CLOSED
modal. With a responsive signer (nos2x) making decryption instant, that all
fired in one main-thread burst right after login. The block- and
subscription-"change" listeners and the moderation "contacts" listener also
re-rendered their panels unconditionally as that data loaded, compounding it.

selectPane() already lazily populates each pane when it's shown, so the eager
pass was redundant. Changes:
- handleAuthLogin: only run the full panel population when the modal is
  already open (e.g. account switch with it visible); otherwise rely on
  open()/selectPane. Kept the cheap DM-identity setup eager.
- Gate the userBlocks "change", subscriptions "change", and moderation
  "contacts" re-renders on isProfileModalOpen() so they don't paint into a
  closed modal during the post-login data burst.
- Add a "friends" case to selectPane() (the only pane without a lazy-populate
  trigger) so it still populates on open now that login doesn't.
- Add isProfileModalOpen() + populateOpenProfilePanels() helpers.

All panes remain covered (account is static; admin refreshes independently).
Full build + unit suite green. KNOWN_BUGS #0 (post-login freeze).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 16:06:26 -04:00
thePR0M3TH3ANandClaude Opus 4.8 4f7ef08935 fix(feed): render the grid after the disclaimer is dismissed (logged-out)
KNOWN_BUGS #1: logged out, the video grid stayed empty after dismissing the
disclaimer until a manual page refresh.

Reproduced deterministically with scripts/perf/disclaimer-grid.mjs (fresh
context, real relays) once it actually waits for and dismisses the
disclaimer: post-dismiss card timeline was 0,0,0,… and only a reload
yielded 132 cards.

Root cause: bootstrapInterface (js/index.js) opens the disclaimer — which
makes the background inert via staticModalAccessibility — and THEN awaits
handleHashChange(), which loads the feed view and renders into that
inert/hidden background, so the initial grid mount/render is dropped.
Dismissing the disclaimer never re-triggered a render.

Fix: disclaimer.js hide() now dispatches a `bitvid:disclaimer-dismissed`
event; index.js listens once and calls application.loadVideos(true) so the
feed re-renders into the now-interactive background. Only fires when a shown
disclaimer is dismissed, so returning visitors (who never see it) get no
redundant reload.

Harness after fix: post-dismiss timeline 132,132,… immediately. Full build
+ unit suite green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 15:40:06 -04:00
thePR0M3TH3ANandClaude Opus 4.8 bf30233649 fix(dm): route Actions calls to the correct controller (open conversation, etc.)
The controller→Actions split left a batch of method calls in
ProfileDirectMessageActions pointing at `this` (the Actions instance)
instead of the object that actually defines them. Opening a conversation
threw "this.setFocusedDmConversation is not a function"; the same latent
bug also broke DM send-error messaging, read receipts, settings publish,
and the whole attachment flow (generate/render/reset/upload) — the user
just hadn't exercised them yet.

Route each to its real receiver:
- DM-controller methods → this.controller.*:
  handleDmSettingsPublish, describeDirectMessageSendError,
  maybePublishReadReceipt, setFocusedDmConversation
- main-controller methods → this.mainController.*:
  generateAttachmentId, renderAttachmentQueue, resetAttachmentQueue,
  uploadAttachmentQueue, clearProfileMessages

(Builds on the earlier handleDmConversationSelect delegation fix.) A static
sweep confirms every remaining `this.*` call in Actions resolves to an
Actions method or an explicit controller/mainController/helper receiver.

Test: tests/dm-conversation-select.test.mjs (cheat-resistant — drives the
real handleDmConversationSelect with stub receivers; would throw on the old
wrong-receiver code). DM unit + integration suites green; full build OK.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 15:07:14 -04:00
thePR0M3TH3ANandClaude Opus 4.8 7951fd0f09 fix(dm): can't open conversations + "helpers unavailable" on a working signer
After switching to a responsive signer (nos2x), two DM-specific bugs surfaced.

1. Clicking a conversation in the list threw
   "this.controller.handleDmConversationSelect is not a function"
   (ProfileDirectMessageRenderer onSelectConversation). The method exists on
   ProfileDirectMessageActions and the controller delegates ~15 sibling Actions
   methods — but the handleDmConversationSelect delegation was missing. Add it.

2. Loading a conversation's messages threw "DM decryption helpers are
   unavailable" even though the signer decrypts blocks/subscriptions/hashtags
   fine. buildDmDecryptContext gated decryptor registration on (a) the dynamic
   `capabilities` getter (which probes window.nostr and false-negatives on lazy
   injection / nos2x's module shape) and (b) the permission-probe result. The
   list services already learned to register by METHOD EXISTENCE and validate at
   call time; align the DM path to do the same so a present, working signer
   never yields zero decryptors. The permission probe still runs.

Tests: tests/dm-decrypt-context.test.mjs (cheat-resistant — a signer whose
capabilities getter reports false and whose permission probe returns ok:false
must still register nip04+nip44 decryptors). Full unit + dm:unit + dm:integration
suites green. KNOWN_BUGS #0.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 14:52:11 -04:00
thePR0M3TH3ANandClaude Opus 4.8 8f39b2c479 feat(signer): surface an actionable notice when the signer goes unresponsive
A raw window.nostr probe in the user's browser (getPublicKey → nip04.encrypt
→ nip04.decrypt, bypassing ALL of bitvid) HUNG forever, with the extension's
own console showing `ObjectMultiplex - orphaned data for "background-liveness"`
+ `malformed chunk` + listener-leak warnings. That is the NIP-07 extension's
content-script ↔ background-service-worker channel being dead (classic MV3
worker death) — an extension/environment failure, not a bitvid bug. No client
change can force an unresponsive signer to answer; the fix is to reload/unlock
the extension.

What bitvid CAN do is stop failing silently. Add js/utils/signerHealthNotice.js:
after a few consecutive list-decrypt timeouts while the signer reports itself
present, emit ONE rate-limited, actionable user notice ("your signer isn't
responding to decryption — unlock/reload the extension and refresh") instead of
the silent 15-minute retry loop. Reset on any decrypt success so a transient
blip doesn't warn. Wired into blocks, hashtags, and subscriptions.

Also documents the definitive root-cause + all resilience increments in
KNOWN_BUGS #0. Test: tests/signer-health-notice.test.mjs (threshold, rate-limit,
success-reset). Full unit suite green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 14:18:46 -04:00
thePR0M3TH3ANandClaude Opus 4.8 f3bac3066d perf(nip07): don't kill slow signers during the permission handshake
On a cold login / permission cache-miss, requestEnablePermissions probes
several permission-payload variants before the no-arg prompt. The specific
(silent) variants were capped at 3s "to fail fast" — but real extensions
REJECT an unsupported payload shape almost immediately (and a fast
rejection already falls through to the next variant), so the 3s cap added
no real safety. What it DID do: kill a slow-but-responsive signer
mid-grant, forcing all 3 specific variants to time out (3s each) before the
prompt variant finally succeeded — ~25s of dead time before signer-ready.

Raise the specific-variant timeout to 20s (SPECIFIC_VARIANT_TIMEOUT_MS).
The bound now only matters for a variant that genuinely HANGS; unsupported
shapes still reject fast, and a slow signer can actually answer the first
supported variant.

Channel-sim at 16s/call: enable extension calls 4 → 1, signer-ready
~42s → ~33s, lists-sync ~58s → ~50s; healthy login unchanged (~1.6s),
all lists still decrypt. Full unit suite green (pre-existing Node
localStorage failures unrelated). KNOWN_BUGS #0.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 13:04:34 -04:00
thePR0M3TH3ANandClaude Opus 4.8 38c9c52c0a fix(lists): give slow signers room to decrypt (raise timeout budget)
Real-env console: signerStatus "present" but every block/hashtag decrypt
timed out at the 15s service budget, forever, retrying every ~15s for
15+ minutes — lists never loaded.

Reproduced deterministically with the channel-sim harness (latency
override): with per-call latency BELOW the service budget all lists load;
the instant it crosses the budget every list fails (NO) and retries
forever. A nip-07 decrypt is a postMessage round-trip to the extension's
single-threaded, possibly-sleeping service worker — under cold-login load
real extensions take 15-25s to answer even though the crypto is instant.
The earlier 6s per-call timeout was killing those in-progress decrypts.

Raise the budget across blocks/hashtags/subscriptions so a slow-but-
responsive signer completes instead of timing out:
- service-level DECRYPT_TIMEOUT_MS 15s → 30s
- per-call nip-07 decrypt timeout 6s → 25s interactive / ~10-12s background
- backoff cap 30s → 60s so a persistently dead signer settles into an
  occasional heartbeat instead of pinning the extension every ~15s

Harness: at 16s/call (previously NO across the board) blocks +
subscriptions + hashtags now all decrypt (0 timeouts); healthy mode
unchanged (signer-ready ~1.2s). Full unit suite green. KNOWN_BUGS #0.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 11:18:00 -04:00
thePR0M3TH3ANandClaude Opus 4.8 0db4f0a603 perf(subscriptions): cut redundant cold-login list fetches
Two redundancies were inflating the login REQ burst (kind 30000=19 storm in
the real-env console — the cause of the slow hashtags, KNOWN_BUGS #0),
isolated with the channel-sim harness's REQ-signature + timing capture:

1. Duplicate trigger: ProfileModalController.handleAuthLogin called
   subscriptions.loadSubscriptions() AND userBlocks.loadBlocks() DIRECTLY at
   login, on top of the auth coordinator's gated list loads — a second,
   ungated relay round-trip for each. Route them through ensureLoaded()
   instead so they coalesce with the coordinator's in-flight load. Harness:
   subscriptions updateFromRelays now fires ONCE at login instead of 3×
   (≈3× fewer kind-30000 fetches in prod, where each is multiplied by the
   relay set).

2. Fetch/decrypt coupling: a decrypt retry re-ran the full relay fetch even
   though only signer availability had changed. Cache the fetched ciphertext
   (_pendingDecryptEvent) and have scheduleDecryptRetry re-decrypt it via a
   cachedDecryptEvent fast-path in updateFromRelays — no redundant relay
   query per retry.

Validated: MODE=overload (channel drops) still decrypts blocks +
subscriptions + hashtags (DMs OK); full unit suite green; subscription loop
+ aggregation tests still pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 10:26:26 -04:00
thePR0M3TH3ANandClaude Opus 4.8 10ea4f6a22 fix(subscriptions): guard the subscription-list refresh loop
The live subscription-list subscription (kind 30000) delivers our OWN list
event back through handleSubscriptionListEvent, which called updateFromRelays
on EVERY event. updateFromRelays re-fetches the list, the relay echoes the
same event through the live sub, and the handler fires again — a
self-sustaining loop that floods the cold-login burst with redundant
kind-30000 REQs (the kind 30000=19 storm in the real-env console,
KNOWN_BUGS #0). Same shape as the contact-list emit→fetch→emit loop fixed
earlier.

Add an emit-on-change guard: skip the refresh when the event is one we've
already acted on (by id — matters during the pre-decrypt login window where
subsEventCreatedAt isn't set yet) or is not newer than what we've applied.
A genuinely newer list event still refreshes exactly once.

Also extend the channel-sim harness to capture per-filter REQ signatures and
kind-30000 REQ timing, which is how this loop was isolated.

Test: tests/subscriptions-manager.test.mjs — echo of the same event id does
not re-refresh; an older event is ignored; a newer event refreshes once.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 09:53:52 -04:00
thePR0M3TH3ANandClaude Opus 4.8 1f07538c66 test(harness): extend nip07 channel-sim to all list systems
Grow the deterministic channel-simulation harness from blocks-only to a
two-session, multi-list rig so every cold-login decrypt path can be
validated locally:

- Session 1 logs in programmatically (loginWithNsec, same key the fake
  extension uses) on a HEALTHY channel and publishes the user's real
  encrypted lists via the services (block list + subscription list +
  hashtag interest) through new testHarness.seedTestLists().
- Session 2 logs in via the NIP-07 path under the target channel MODE and
  reports, per list, whether it decrypted — plus signer-ready time, the
  login REQ burst (per kind), decrypt timeouts, breaker activity, and a DM
  load probe.

testHarness: expose subscriptions + hashtag load state on getAppState().lists
and add seedTestLists() (resolves the actor from nostrClient.pubkey, which —
unlike the registry getActiveSigner() — is populated for a NIP-07 login).
Verdict is mirrored to a report file and uses process.exitCode so results
survive stdout buffering when piped/backgrounded.

Validation:
  MODE=healthy  → blocks/subscriptions/hashtags all decrypt, DMs OK.
  MODE=overload → 26 injected channel drops, ALL THREE lists still recover
                  via the transient-retry fix (db0fc079), DMs OK.
The harness exits non-zero if a list that should load doesn't, so it can
gate CI. Confirms the burst is still ~60 REQ frames at login (kind 30000
dominant) — the next target. KNOWN_BUGS #0.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 09:17:47 -04:00
thePR0M3TH3ANandClaude Opus 4.8 db0fc07989 fix(nostr): retry list decrypt on transient channel failure (not give up)
Built a deterministic NIP-07 channel-simulation harness
(scripts/perf/nip07-channel-sim.mjs) that reproduces the real cold-login
failure locally with a fake extension whose message channel drops under
concurrent load (MODE=overload), recovers (MODE=slow), or stays dead. It
seeds a real encrypted block list and reports whether it decrypts.

The harness pinned the actual root cause that the relay/breaker/timeout
work hadn't fixed: when the channel briefly drops during the login burst,
the per-scheme decrypt probe (Promise.any) rejects with
"message channel closed" — and every list service SWALLOWED that and
treated it as "the user has no blocks / no subs / no hashtags", or routed
it to a give-up branch. Either way: no retry, so the list stayed empty
until a full page refresh, even though the channel recovered seconds later.

Fix: classify transient failures (channel-death messages, breaker fast-fail
code, our own decrypt-timeout) and route them to the existing keep-stale +
scheduleDecryptRetry path instead of swallowing/abandoning:
- userBlocks: re-throw a transient sub-error out of the Promise.any probe
  (was silently returning [] = "no blocks"); route it (and channel/breaker
  errors) through the retry branch.
- hashtagPreferencesService + subscriptions: broaden the retry condition
  from the timeout code only to any transient error, recursing into the
  nested Promise.any AggregateError causes.

Harness verdict (MODE=overload, 16 channel drops): block list
BLOCK LIST DECRYPTED NO -> YES after the fix; signer-ready ~1.9s.
Adds getAppState().lists observability to the test harness. Full unit
suite green. KNOWN_BUGS #0.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-15 09:58:31 -04:00
thePR0M3TH3ANandClaude Opus 4.8 265b7813f2 fix(nostr): unblock the signer handshake (priority + decrypt timeouts)
Real-env console (2026-06-15) showed [signer-ready] taking ~48s and every
list decrypt timing out before AND after it. Root mechanism: a priority
inversion on the 2-slot NIP-07 request queue.

- List decrypts run at NIP07_PRIORITY.HIGH; the readiness gate's
  permission/enable handshake ran at NORMAL. So a flood of HIGH-priority
  decrypts jumped ahead of the gate and starved it — the channel never got
  warmed, so the decrypts kept failing. Fix: add NIP07_PRIORITY.CRITICAL
  (above HIGH) and run the permission/enable handshake at CRITICAL so it
  always wins queue ordering.
- Login-time decrypt timeouts were 12-15s even though a healthy
  nip04/nip44 decrypt is local crypto (~1s); the long window was only to
  tolerate a first-grant prompt, which the gate already pre-grants. A 15s
  timeout just monopolizes one of the two queue slots on a doomed call,
  blocking the gate for 15s at a time. Cut blocks/hashtags/subscriptions
  login decrypt timeouts to 6s so slots cycle ~2.5x faster (and the circuit
  breaker trips in ~18s instead of ~45s). Service-level 15s wrappers stay
  as a backstop (now strictly longer than the nip07 layer).

Part of KNOWN_BUGS #0 ("cut the burst, then add a safety net"). Full unit
suite green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-15 09:24:21 -04:00
thePR0M3TH3ANandClaude Opus 4.8 ff1afa1175 fix(nostr): count 'message channel closed' toward the circuit breaker
Real-env console (2026-06-15) showed the breaker never opening even as
decrypts failed for minutes. Cause: the breaker treated every non-timeout
error as "channel alive" and RESET the timeout streak — but
"message channel closed before a response was received" is the exact
dead-channel signal, and it rejects as a (fast) non-timeout error. So each
such rejection reset the counter and the circuit could never open.

Classify channel-death messages (message channel closed / could not
establish connection / receiving end does not exist / extension context
invalidated / connection lost) as channel failures that count TOWARD
opening the circuit, instead of as responsive failures that reset it.
Genuine extension responses (user rejection, permission denied, etc.)
still reset the streak.

Test: extends nip07-channel-breaker with a synchronous channel-closed op
asserting consecutive channel-death errors open the circuit and then
fast-fail (no waits).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-15 09:11:40 -04:00
thePR0M3TH3ANandClaude Opus 4.8 ab57f8d596 fix(nostr): circuit-break the dead nip-07 signer channel
Real-env console (2026-06-15) showed that once the extension's message
port drops under the post-login burst ("message channel closed"), EVERY
subsequent decrypt call hangs to its full ~15s timeout. Each list service
(blocks, hashtags, subscriptions, watch history) independently retries on
that timeout, so the app sits in a permanent loop of 15s-blocking
extension calls — pinning the CPU ("fans at max") and never recovering
until a manual page refresh.

Add a shared circuit breaker at the runNip07WithRetry chokepoint:
- After CIRCUIT_TIMEOUT_THRESHOLD (3) consecutive timeouts the circuit
  OPENS; further calls fail fast with code "nip07-channel-unresponsive"
  (no multi-second hang), so the retry loops become cheap and the CPU
  settles.
- While open, a single probe per CIRCUIT_PROBE_INTERVAL_MS is allowed
  through; one success CLOSES the circuit and normal decryption resumes —
  no page refresh required.
- Responsive failures (extension answered with an error) reset the
  timeout streak — only genuine channel hangs open the circuit.
- Interactive permission prompts bypass the breaker entirely: a user
  taking their time at the extension UI can neither trip it nor be
  blocked by it, and such a prompt can itself heal the channel.

Increment 2 of the "cut the login burst, then add a safety net" work for
KNOWN_BUGS #0. Test: tests/nostr/nip07-channel-breaker.test.mjs
(cheat-resistant — drives the real queue with hanging/responsive/success
ops; asserts open-after-threshold, fast-fail, probe-recovery, responsive
errors don't open, and bypass is never fast-failed). Full unit suite green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-15 08:49:05 -04:00
thePR0M3TH3ANandClaude Opus 4.8 71cd04b215 perf(login): stop eagerly loading DM history at login
Real-env console (cold nip-07 login) showed list decryption failing en
masse: blocks/hashtags/subscriptions fetched fine (relay cap working —
every sub now fans out to exactly 8 relays) but decryption timed out for
minutes with "message channel closed", only recovering on a page refresh.

Root cause: the single-threaded nip-07 extension channel is overwhelmed
during the post-login handshake. One contributor is the eager DM load —
loadDirectMessages({ limit: 50, initialLoad: true }) ran at login and
fired a burst of decrypts that competed with the feed-driving lists
(blocks/subscriptions/hashtags) for the same channel. DMs are lower
priority (the user isn't viewing Messages at login) and already load
lazily when the Messages tab opens.

Defer the eager DM load; report dms state as "deferred". The lightweight
unread-indicator refresh still runs so the badge stays accurate. First
increment of the "cut the login burst" work (KNOWN_BUGS #0).

Test: tests/app/login-defers-dms.test.mjs (cheat-resistant — asserts
loadDirectMessages is never called at login, dms state is "deferred", and
the unread indicator still runs).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 23:16:40 -04:00
thePR0M3TH3ANandClaude Opus 4.8 55bd181867 fix(nostr): bound read/subscribe relay set to stop cold-login REQ storm
On cold login the app opened WebSockets to a user's full NIP-65 read set
(in prod often ~20 relays, most dead). The flood of failing connections
churned the main thread and starved the nip-07 extension's postMessage
round-trips, so encrypted lists (blocks, subscriptions, hashtags) were
fetched but timed out during decryption ("message channel closed",
"Decryption timed out").

Bound every read/subscribe path to MAX_SUBSCRIBE_RELAYS=8 via a shared,
test-aware capReadRelays helper, applied at the chokepoints:
- client.js applyRelayPreferences (this.relays / this.readRelays)
- relayBatchFetcher.js fetchListIncrementally (blocks, subs, hashtags)
Writes stay uncapped (publish reach preserved).

capReadRelays is user-relays-first (a user's own relays are where their
data authoritatively lives, and small fast-path limits would otherwise
crowd them out — the regression that reverted the first attempt) while
reserving RESERVED_DEFAULT_RELAY_SLOTS=2 for reliable default aggregators
so the "~20 personal relays, all dead" case still reaches a live relay.
Under test the reserved core resolves to the test-relay override, keeping
harnesses isolated.

Tests: new relay-subscribe-cap coverage (bounded + reserved-defaults +
writes-uncapped); spec-corrected user-blocks, subscriptions-manager and
nostr/client fetch tests to bounded (not exact) relay fan-out while
keeping all behavioral/security assertions (per-relay coverage, correct
decrypt, block hydration, dedup) intact. See TEST_INTEGRITY.md and
KNOWN_BUGS #0/#4. Full unit + dm:unit suites green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 22:51:36 -04:00
thePR0M3TH3ANandClaude Opus 4.8 49b7645f80 fix(decrypt): bump hashtag+subscription decrypt timeout 6s->15s; document lists-decrypt root cause
Real-env console shows the encrypted lists are FETCHED but DECRYPTION fails on
cold login: hashtags time out at 6s, blocks report signerStatus 'missing', DMs
throw 'helpers unavailable'. Root cause: a relay-connection storm to the user's
~20 dead NIP-65 relays (subsystems use uncapped relayManager read+write) starves
the nip-07 extension. Bumping the decrypt timeout to 15s (matching blocks) is a
partial mitigation for hashtags/subscriptions. The proper fix (bound reads to a
liveness-ranked healthy core incl. defaults + DM decrypt retry) is documented in
KNOWN_BUGS #0 — a first capReadRelays attempt was reverted because capping block
reads broke the security-critical user-blocks integration test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 22:12:21 -04:00
thePR0M3TH3ANandClaude Opus 4.8 c0a8636678 feat(feed): make For You inclusive + ranked by your lists (G1-G5)
The For You feed was chronological, hashtag-interest-EXCLUSIVE, and ignored
follows entirely (docs/feed-algo-audit.md). Now it is inclusive + ranked:

- createForYouScorerStage scores each video: follows-boost (author you follow)
  + interest/watch-topic affinity (cosine vs your interests+watch-history vector)
  + freshness - disinterest penalty. Reuses Explore's vector/similarity helpers.
- createForYouScoreSorter ranks by that score (muted last, recency tiebreak).
- For You pipeline: interests now BOOST not exclude (enforceInterests:false);
  scorer added; chronological sorter replaced. Never empty (falls back to
  recency when you have no follows/interests/history).
- buildForYouFeedRuntime now feeds subscriptionAuthors + watchHistoryTagCounts.

Watched/blocked/muted are still removed (suppression/blacklist/moderation
stages unchanged). Cheat-resistant tests (older boosted items only win via the
boost). Grid renders end-to-end (~1.3s). Weight tuning is a follow-up.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 16:57:05 -04:00
thePR0M3TH3AN 44bf88cf88 docs: audit For You feed algo <-> lists wiring (read-only, gaps + fix order)
Traced registerForYouFeed/buildForYouFeedRuntime + feedEngine. Confirms hashtag
prefs, blocks, watch-history suppression, and moderation DO drive For You. Gaps:
G1 follows have zero effect on For You; G2 chronological not relevance-ranked;
G3 interest filter is binary/exclusive; G4 watch-topic affinity unused; G5 no
blending. No code changed.
2026-06-14 16:43:49 -04:00
thePR0M3TH3ANandClaude Opus 4.8 9c3ee01755 fix(feed): reload only when the block set changes (P5; KNOWN_BUGS #2)
handleBlocksLoaded reloaded the feed on every 'blocks-loaded' signal — but a
forced reload re-fetches the lists, which re-emit 'blocks-loaded', a
self-sustaining loop. Now it computes a signature of the block set and reloads
only on actual change (emit-on-change — the P5 principle). handleRelaysLoaded
only touches relay UI; hashtag prefs already dedup by signature.

Cheat-resistant regression test added. Bumped authSessionCoordinator file-size
baseline. Logged 2 pre-existing app test failures (fail at pre-session baseline)
in KNOWN_BUGS. Marks KNOWN_BUGS #2 resolved.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 16:25:42 -04:00
thePR0M3TH3AN 4a3fe06a03 chore: bump userBlocks file-size baseline; flaky-harness tolerate dead-relay connect delay
userBlocks grew (P4 handle teardown) — bump baseline. flaky-relays grid-render
timeout 15s->30s so dead-relay connect timeouts don't cause a false-negative
(ux-harness with a healthy relay renders in ~1.2s; the harness now reliably
passes 4/4).
2026-06-14 16:18:46 -04:00
thePR0M3TH3AN e528a17975 docs: mark P4 (lists via L1) complete 2026-06-14 16:15:31 -04:00
thePR0M3TH3ANandClaude Opus 4.8 d693bf55aa refactor(profiles): batch profile fetch through SubscriptionManager (P4)
performProfileFetch now issues ONE deduped, health-gated list() across all
relays via the L1 SubscriptionManager (the pool merges per-relay results),
replacing the manual per-relay fan-out. Newest-per-author selection unchanged;
legacy per-relay path retained as the manager-less fallback.

Spec correction: tests/app-batch-fetch-profiles.test.mjs asserted one query
PER relay (implementation detail); updated to assert one BATCHED query across
all relays. All behavioral assertions (cached hydration, newest profile
rendered, failing relay tolerated) unchanged; added a relays-targeting
assertion. Documented in TEST_INTEGRITY.md (SCN-profiles-batched).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 16:15:06 -04:00
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
thePR0M3TH3AN 5c494b8961 chore(lint): bump watchHistory.js file-size baseline (P4 listEvents helper) 2026-06-14 16:05:02 -04:00
thePR0M3TH3AN 7a9b421f18 docs: P4 in progress (watch-history routed); note multi-line lint gap 2026-06-14 16:02:35 -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 b0c00ebc99 fix(lint): catch bare pool.sub/list calls in chokepoint guard (KNOWN_BUG #3)
The guard only matched member access (.pool.sub); bare local-variable calls
(pool.sub/pool.list) slipped through. Broadened the regex and re-baselined the
allowlist — true scope is 22 files (10 were hidden), e.g. viewEvents.js,
relayBatchFetcher.js, watchHistory.js, commentEvents.js. The L1 chokepoint is
now actually enforced; the allowlist only shrinks as P4 migrates subsystems.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 15:57:34 -04:00
thePR0M3TH3AN 89d224226c docs: add KNOWN_BUGS.md (deferred defects); mark P3 complete 2026-06-14 15:51:20 -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 1ac03c49e9 test(perf): flaky multi-relay harness (verification-fidelity fix)
Stands up several mock relays — some alive (seeded), some dead (unreachable
ports) — points the app at all of them, logs in via the fake nip-07 extension,
and asserts the refactor invariants under reconnect churn:
  1. grid renders from alive relays
  2. subscribes on <= the capped core (not all configured relays)
  3. no steady-state REQ storm despite dead relays (was 1000+/s)
  4. report subs are batched (one kind-1984 filter with many #e, no per-id)

All four PASS on the current build. This is the realism the single perfect mock
relay lacked — the reason earlier 'fixed' verdicts didn't hold in production.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-14 15:19:05 -04:00