Skip to content

Cache Discord media locally - #6

Merged
Peyton-Spencer merged 1 commit into
feat/unified-inboxfrom
feat/discord-media-cache
Aug 30, 2026
Merged

Cache Discord media locally#6
Peyton-Spencer merged 1 commit into
feat/unified-inboxfrom
feat/discord-media-cache

Conversation

@Peyton-Spencer

@Peyton-Spencer Peyton-Spencer commented Aug 29, 2026

Copy link
Copy Markdown

Summary

Cache Discord images locally while their signed CDN URLs are still valid, then render them through T3's existing signed local asset route. This is stacked directly on #5.

Changes

  • validate Discord CDN hosts, redirects, response types, image signatures, and a 25 MiB size limit
  • deduplicate downloads and store them atomically under deterministic local attachment ids
  • clean only discord-* cache files after 30 days or above a 1 GiB LRU budget
  • prefer signed local asset URLs in Inbox and show an exact-message Discord fallback for expired media
  • store no Discord token, cookie, or browser credential

Recovery finding

Opening an exact Discord message produced a fresh signed URL transiently, but Discrawl v0.13.3's full wiretap later overwrote it with an older duplicate and a targeted fetch still returned HTTP 404. This PR therefore does not automate accessibility or hidden Discord navigation; expired media uses an explicit exact-message fallback until Discrawl can deterministically preserve the newest attachment URL.

Test plan

  • pnpm --filter t3 typecheck
  • pnpm --filter @t3tools/web typecheck
  • pnpm --filter t3 exec vp test run src/channels/DiscordMediaCache.test.ts src/channels/DiscrawlAdapter.test.ts
  • pnpm --filter @t3tools/web build
  • pnpm exec vp check (0 errors; 19 pre-existing warnings)

Note

Add local Discord media cache to Discrawl channel adapter

  • Introduces DiscordMediaCache in DiscordMediaCache.ts to download and store Discord image attachments on the local filesystem with host, expiry, type, signature, and size (<= 25 MiB) validation, atomic writes, deduplicated in-flight fetches, and a periodic sweeper that removes files older than 30 days and trims total cache to <= 1 GiB.
  • Wires the cache into makeDiscrawlAdapter via ChannelRegistry.ts and DiscrawlAdapter.ts; listed messages now include cachedAttachmentId and cacheState on attachments when caching is enabled.
  • Updates InboxPage.tsx with DiscordAttachment, CachedDiscordAttachment, DiscordImage, and DiscordAttachmentButton components that render locally cached assets via useAssetUrl, show an open-in-Discord button for expired links, and fall back to remote URLs otherwise.
  • Extends ChannelAttachment in channels.ts with optional cachedAttachmentId and cacheState fields.
  • Risk: DiscordMediaCache writes to config.attachmentsDir; incorrect config or a full disk will cause cache failures to surface as unavailable attachments rather than errors. Sweeper deletes any discord--prefixed files in the attachments directory older than 30 days, so existing files matching that pattern will be removed.

Macroscope summarized 2e710d1.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Aug 29, 2026
@github-actions

github-actions Bot commented Aug 29, 2026

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 13.3 KiB 15.1 KiB
Codex Thread snapshot wire 6.9 KiB 7.3 KiB
Codex Live turn WebSocket wire 6.4 KiB 7.8 KiB
Codex Live turn WebSocket decoded 55.6 KiB 66.4 KiB
Codex Live turn messages 11 21
Claude Total thread wire 13.4 KiB 15.1 KiB
Claude Thread snapshot wire 6.9 KiB 7.3 KiB
Claude Live turn WebSocket wire 6.5 KiB 7.8 KiB
Claude Live turn WebSocket decoded 56.4 KiB 66.4 KiB
Claude Live turn messages 11 21

Baseline: unavailable · PR result: 2e710d1 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 109.4 KiB
  • Claude decoded thread snapshot: 110.1 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@Peyton-Spencer
Peyton-Spencer force-pushed the feat/discord-media-cache branch from 5ee6fe7 to 2e710d1 Compare August 29, 2026 04:46
@Peyton-Spencer
Peyton-Spencer marked this pull request as ready for review August 30, 2026 18:50
@Peyton-Spencer
Peyton-Spencer merged commit 747ebe9 into feat/unified-inbox Aug 30, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant