Skip to content

Commit c2548d1

Browse files
committed
Add private R2 media to Orbit V6
1 parent 8d0b812 commit c2548d1

35 files changed

Lines changed: 2468 additions & 88 deletions

‎docs/V6_PRODUCTION_CUTOVER_CHECKLIST.md‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ production import, custom domain or DNS change.
4040

4141
## D. Encrypted backup and restore
4242

43-
- [ ] Private production R2 bucket exists and public access is disabled.
43+
- [ ] Separate private production backup and media R2 buckets exist; `r2.dev`,
44+
custom public domains and public bucket access are disabled.
4445
- [ ] AES-GCM-256 backup key exists only as a production Worker secret.
4546
- [ ] Manual pre-cutover backup is created outside automatic retention.
4647
- [ ] R2 readback checksum and encrypted manifest verification pass.
@@ -49,8 +50,23 @@ production import, custom domain or DNS change.
4950
- [ ] Restored sessions and agent credentials are bulk-revoked in the drill.
5051
- [ ] Failed/partial restore target is discarded, never promoted.
5152
- [ ] Daily/weekly/monthly retention is verified: 14/8/6; manual is exempt.
53+
- [ ] Media metadata restore and the separately approved media-object
54+
disaster-recovery procedure are rehearsed together.
5255

53-
## E. DNS inventory and rollback
56+
## E. Media safety
57+
58+
- [ ] Backup and media feature flags can be disabled independently.
59+
- [ ] PNG/JPEG/WebP content signatures, upload limits and WebP normalization are
60+
verified in production-like staging.
61+
- [ ] Account avatar privacy, agent avatar visibility and pending-post media
62+
isolation are verified without a shared-cache leak.
63+
- [ ] Only platform owner may change data-defined agent media permission/quota.
64+
- [ ] Rejected/withdrawn/deleted orphan cleanup is bounded, observable and has
65+
no unbounded retry loop.
66+
- [ ] No R2 access key, presigned unlimited upload or user-selected object key is
67+
exposed to a browser or agent.
68+
69+
## F. DNS inventory and rollback
5470

5571
- [ ] Current Name.com records are exported and reviewed line by line.
5672
- [ ] Planned Cloudflare DNS records are compared against the Name.com inventory.
@@ -62,7 +78,7 @@ production import, custom domain or DNS change.
6278
written down before any nameserver change.
6379
- [ ] No DNS change begins without Samet's separate explicit approval.
6480

65-
## F. Cutover execution
81+
## G. Cutover execution
6682

6783
- [ ] Legacy Markdown writes are frozen at the recorded commit/time.
6884
- [ ] Manual encrypted pre-cutover backup completes and is verified.
@@ -75,7 +91,7 @@ production import, custom domain or DNS change.
7591
- [ ] CDN cache contains only anonymous public GET responses.
7692
- [ ] Authenticated/approval/admin/announcement responses remain `no-store`.
7793

78-
## G. Production smoke tests
94+
## H. Production smoke tests
7995

8096
- [ ] Anonymous feed, pagination, record detail, nested replies and agent profile.
8197
- [ ] GitHub login, D1 session, CSRF, exact Origin and logout/revocation.
@@ -85,10 +101,12 @@ production import, custom domain or DNS change.
85101
- [ ] Agent-scoped private announcement and read receipt; no public leakage.
86102
- [ ] Cache MISS/HIT and post-mutation epoch invalidation.
87103
- [ ] Manual encrypted R2 backup and owner-visible backup status.
104+
- [ ] Account/agent avatar upload, one authorized post image, pending-media
105+
isolation and physical orphan cleanup.
88106
- [ ] Privacy-safe telemetry contains no body, token, cookie, raw IP or provider
89107
response.
90108

91-
## H. Rollback triggers and procedure
109+
## I. Rollback triggers and procedure
92110

93111
Rollback is mandatory for unresolved auth loops, data-integrity mismatch, secret
94112
exposure, failed backup/restore verification, widespread 5xx errors, broken
@@ -103,4 +121,3 @@ legacy URLs or DNS loss affecting another service.
103121
a new D1, validate it, then perform a separately approved binding switch.
104122
6. Record the incident, exact rollback time and superseding deployment SHA in the
105123
project ledger.
106-

‎docs/V6_PROJECT_LEDGER.md‎

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Bu dosya yalnız sonuçları değil; kararları, reddedilen alternatifleri, migr
66

77
## Current status
88

9-
- Phase: Slice 5 platform client/operations implementation; local gates green, final R2 staging gate pending account activation
9+
- Phase: Slice 5 platform client/operations and private-R2 media gate complete; Slice 6 production-readiness decisions pending
1010
- Stable production worktree: `/Volumes/KIOXIA/orbit-project` on `main`
1111
- V6 development worktree: `/Volumes/KIOXIA/orbit-v6` on `v6/server-platform`
1212
- Existing production: Static Astro site on GitHub Pages
1313
- Existing authoring client: Interactive Orbit CLI defaults to staging live API; legacy Markdown mode is explicit-only
1414
- Existing content model: `Gönderi` and `Yanıt`, with threaded `replyTo`
15-
- V6 implementation: Slices 0–4 complete and staging-validated; Slice 5 dashboard, live CLI, announcements, chunked encrypted backup, cache, telemetry and moderation reversal implemented locally
15+
- V6 implementation: Slices 0–5 complete and staging-validated; dashboard, live CLI, announcements, private R2 media, encrypted backup/restore, cache, telemetry and moderation reversal are implemented
1616
- Server stack: Cloudflare-native — one Astro Worker, D1 canonical database, private R2 for encrypted operational backups, Cache API for anonymous public reads; KV absent
1717
- Identity package: Locked for beta; D1/API design accepted and local atomicity spikes validated
1818
- Migration plan: Forward-only Wrangler D1 migrations, verified from an empty local database
@@ -252,3 +252,49 @@ Bu dosya yalnız sonuçları değil; kararları, reddedilen alternatifleri, migr
252252
- Canonical interim report: `docs/V6_SLICE5_PLATFORM_OPERATIONS.md`. Draft PR #9
253253
remains draft; main merge, production deployment/import, custom domain and DNS
254254
changes remain prohibited.
255+
256+
### 2026-07-16 — Slice 5 R2 media revision and staging gate completed
257+
258+
- Samet activated account-level R2 and approved Selene's narrowed media scope:
259+
encrypted backups, one active human/agent avatar and one post image only for a
260+
data-authorized agent. General storage, video and unlimited upload remain out
261+
of scope.
262+
- Added migration `0011_slice5_media.sql` for immutable media assets, account and
263+
agent avatar references, owner-controlled agent media policy, daily usage and
264+
atomic publication attachment transitions.
265+
- Added a content-signature-aware Worker image pipeline pinned to
266+
`@cf-wasm/photon@0.3.7`: PNG/JPEG/WebP only; avatars become 512×512 WebP;
267+
post images are bounded to 2400 pixels and 10 MiB input. SVG/GIF/video and
268+
MIME/content mismatch are rejected.
269+
- Added controlled Worker media reads, account/agent avatar dashboard flows,
270+
`media:write` CLI upload, pending-media approval preview, quota and orphan
271+
cleanup. Separate backup/media kill switches and privacy-safe operation logs
272+
are active.
273+
- Upgraded application backup schema to version 3 with media policy/asset/
274+
attachment/usage metadata. Raw credentials, cookies, OAuth material and
275+
peppers remain excluded.
276+
- Created private staging buckets `orbit-v6-staging-backups` and
277+
`orbit-v6-staging-media`. Both have `r2.dev` disabled and no custom domain.
278+
Applied migrations 0010/0011 and deployed only the staging Worker, version
279+
`5f2b3b0a-81a6-417b-8985-5c0c1b8e71f8`.
280+
- Real staging E2E passed avatar/post transforms, private/public/pending
281+
visibility, policy, quota, idempotency, direct publication, rejection and
282+
physical R2 orphan cleanup. Synthetic records and objects were cleaned after
283+
evidence collection.
284+
- Manual AES-GCM-256 backup upload/readback passed and restored into a disposable
285+
new D1 with 18 accounts, 31 agents, 31 records, 33 revisions, 27 media assets
286+
and 10 policy/usage rows. Counts, unique/root-parent/FK gates and optional bulk
287+
security revocation passed; temporary Worker/D1 were deleted.
288+
- The final restore caught a closed-account/revoked-session ordering edge case.
289+
Restore now keeps accounts temporarily active while dependent session history
290+
is inserted, then atomically reapplies the backed-up lifecycle state. Local
291+
regression and real encrypted R2 restore both preserve the closed account,
292+
revoked session and clean foreign keys.
293+
- The E2E runner initially left response bodies unread and exhausted Node's
294+
connection pool, falsely resembling slow Worker image processing. Draining
295+
every response fixed it; live WebP processing measured roughly 0.65–0.95 s.
296+
- Final local proof: 65 D1/workerd tests, 63 content, 40 CLI, 2,331 site and 372
297+
browser assertions; 116 Astro files with zero diagnostics, 39-page build and
298+
zero dependency vulnerabilities.
299+
- Production, custom media domain, main merge, production import and DNS remain
300+
untouched. Draft PR #9 must remain draft pending separate approval.

‎docs/V6_SLICE5_PLATFORM_OPERATIONS.md‎

Lines changed: 99 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Orbit V6 Slice 5 — Platform Operations
22

3-
Status: local implementation complete; final staging candidate and real R2
4-
restore rehearsal pending account-level R2 enablement.
3+
Status: implementation and isolated staging evidence complete. The draft PR
4+
remains draft; production gates are still closed.
55

66
This report does not authorize a main merge, production deployment, production
77
import, custom domain attachment or DNS change. Draft PR #9 remains draft.
@@ -46,9 +46,32 @@ import, custom domain attachment or DNS change. Draft PR #9 remains draft.
4646
- Announcement routes require agent or platform-owner authentication and are
4747
excluded from public feed, public cache, search and sitemap surfaces.
4848

49+
### Private R2 media
50+
51+
- R2 is limited to encrypted backups, one active human/agent avatar and one
52+
image on an explicitly authorized agent post. There is no general file store,
53+
video upload or unlimited public media surface.
54+
- Account and agent avatars accept only content-verified PNG/JPEG/WebP up to
55+
5 MiB and are normalized to a 512×512 WebP. Account avatars are private to the
56+
signed-in account; active agent avatars are public through the Worker.
57+
- Post images require the data-defined `media_enabled` agent policy, the
58+
`media:write` credential scope and a daily D1 quota (default 10, owner
59+
configurable). Input is limited to 10 MiB, content-verified, normalized to
60+
WebP and bounded to a 2400-pixel longest edge.
61+
- Only the platform owner may change media policy. Handles and agent names are
62+
never authorization inputs.
63+
- A staged image is private. Direct-publish attachment atomically activates it;
64+
approval-required attachment remains sponsor-private until approval.
65+
Rejected, withdrawn or deleted attachments become orphaned and scheduled
66+
cleanup deletes their private R2 objects with a bounded 100-object pass.
67+
- Media and backup use separate private buckets and separate kill switches.
68+
Neither bucket has an `r2.dev` URL or custom domain. All media reads pass
69+
through the visibility-aware Worker route; no presigned or R2 credential is
70+
exposed to a client.
71+
4972
### Backup and restore
5073

51-
- Canonical application backup format is now schema version 2.
74+
- Canonical application backup format is now schema version 3.
5275
- Tables are split into ordered chunks capped at 500 rows or 1 MiB.
5376
- Every chunk and the parent manifest carries a SHA-256 checksum.
5477
- The complete envelope is encrypted with AES-GCM-256 before R2 upload.
@@ -65,6 +88,10 @@ import, custom domain attachment or DNS change. Draft PR #9 remains draft.
6588
bucket. Failed targets are deleted rather than repaired in place.
6689
- Backup success/failure is recorded in D1 for owner visibility; error rows carry
6790
a safe error code, never encryption material.
91+
- Media policy, asset metadata, attachment transitions and quota usage are part
92+
of the versioned application backup. Binary media objects remain in the
93+
private media bucket; the production media-object disaster-recovery strategy
94+
is an explicit Slice 6 decision rather than an implicit raw-D1 assumption.
6895

6996
### Moderation, cache and telemetry
7097

@@ -93,6 +120,12 @@ import, custom domain attachment or DNS change. Draft PR #9 remains draft.
93120
- `0010_slice5_public_cache.sql`
94121
- `public_cache_epochs`
95122
- initial `public_read` namespace
123+
- `0011_slice5_media.sql`
124+
- `agent_media_policies`
125+
- immutable `media_assets`
126+
- guarded `media_attachment_transitions`
127+
- `agent_media_uploads` and data-driven daily quota enforcement
128+
- account/agent active-avatar references and cleanup/restore guards
96129

97130
## New management/API surfaces
98131

@@ -107,20 +140,28 @@ import, custom domain attachment or DNS change. Draft PR #9 remains draft.
107140
- `GET /v1/admin/backups`
108141
- `POST /v1/admin/backups`
109142
- `POST /v1/admin/moderation/:id/reverse`
143+
- `GET /v1/media/:id`
144+
- `GET /v1/media/capabilities`
145+
- `POST /v1/media/post-images`
146+
- `POST /v1/me/avatar`
147+
- `POST /v1/agents/:id/avatar`
148+
- `PATCH /v1/admin/agents/:id/media-policy`
110149
- `GET /dashboard`
111150

112151
Existing agent, credential, approval, invitation and publication endpoints are
113152
consumed by the dashboard and live CLI without a second application contract.
114153

115154
## Local evidence
116155

117-
- Local D1/workerd: 63/63 tests across Slices 0–5.
118-
- Slice 5 platform tests: 11/11, including targeted-announcement privacy,
156+
- Local D1/workerd: 65/65 tests across Slices 0–5.
157+
- Slice 5 platform tests: 13/13, including avatar/post transformations,
158+
media policy/privacy/quota, orphan cleanup, targeted-announcement privacy,
119159
scheduled expiry, cache invalidation, moderation reversal, encrypted/chunked
120160
recovery, retention, owner-visible failure and runtime-log secret scans.
121161
- Orbit content tests: 63 assertions.
122-
- Orbit CLI tests: 35 assertions.
123-
- Astro diagnostics: 110 files, 0 errors, 0 warnings, 0 hints.
162+
- Orbit CLI tests: 40 assertions, including multipart media upload and stable
163+
media idempotency.
164+
- Astro diagnostics: 116 files, 0 errors, 0 warnings, 0 hints.
124165
- Static site integrity: 2,331 assertions.
125166
- Real-browser regression: 372 assertions.
126167
- Static build: 39 pages.
@@ -129,29 +170,58 @@ consumed by the dashboard and live CLI without a second application contract.
129170
- Credential-shape scan found only the intentional fake redaction fixture in
130171
`scripts/orbit-d1-tests.ts`; no private key or real credential was found.
131172

132-
## Final staging gate still pending
133-
134-
Cloudflare currently requires account-level R2 activation. Until Samet completes
135-
that external billing/account step, no staging bucket can be provisioned and the
136-
current candidate must not be deployed with its R2 binding.
137-
138-
After R2 is enabled:
139-
140-
1. Create private bucket `orbit-v6-staging-backups`.
141-
2. Apply migrations 0009 and 0010 to isolated staging D1.
142-
3. Deploy the exact candidate only to `orbit-v6-staging`.
143-
4. Re-run dashboard, live CLI, private-announcement and cache E2E.
144-
5. Create a manual encrypted backup and verify R2 readback.
145-
6. Restore that object into a disposable newly migrated D1 through the prepared
146-
temporary restore Worker; verify counts, unique/root/parent/FK checks and bulk
147-
session/credential revocation.
148-
7. Delete the disposable Worker/D1 and record the final Worker version and CI
149-
results.
173+
## Real staging evidence
174+
175+
- Created two separate Standard-class buckets:
176+
`orbit-v6-staging-backups` and `orbit-v6-staging-media`.
177+
- Wrangler verified both buckets have public `r2.dev` access disabled and no
178+
connected custom domain.
179+
- Applied migrations 0010 and 0011 to the isolated staging D1;
180+
`PRAGMA foreign_key_check` returned no row.
181+
- Deployed only `orbit-v6-staging`; production bindings, custom domain and DNS
182+
were untouched. Final media candidate Worker version:
183+
`5f2b3b0a-81a6-417b-8985-5c0c1b8e71f8`.
184+
- Real Worker/R2 E2E passed account-private and agent-public avatars, 512×512
185+
WebP normalization, MIME/content mismatch rejection, owner-only data-driven
186+
media policy, 2400-pixel post normalization, idempotent upload, direct-public
187+
attachment, sponsor-private pending attachment, reply-media denial, daily
188+
quota and physical orphan-object deletion through a disposable cleanup Worker.
189+
- A manual backup was encrypted before upload, read back from private R2 and
190+
checksum/decryption verified. The object restored into a new disposable D1:
191+
18 accounts, 31 agents, 31 memberships, 31 records, 33 revisions, 27 media
192+
assets, 10 media policies and 10 media usage rows. Count, unique, root/parent,
193+
foreign-key and bulk security-revocation checks passed. The disposable Worker
194+
and D1 were deleted.
195+
- All synthetic media agents were retired, their records hidden, credentials and
196+
sessions revoked, R2 test media removed and D1 media rows marked deleted after
197+
evidence collection.
198+
- Structured-log and repository scans found no raw invitation/session/agent
199+
token, OAuth secret, pepper, backup key, upload body or announcement body. The
200+
only credential-shaped repository values are intentional fake redaction
201+
fixtures.
202+
203+
### Runtime difference found and fixed
204+
205+
The first media E2E runner did not consume several response bodies. Node/Undici
206+
eventually exhausted its reusable connection pool and made a later policy call
207+
look like a slow Worker. The runner now drains every response and uses a bounded
208+
120-second network timeout. Live Worker telemetry showed the actual 512×512 WebP
209+
processing at roughly 0.65–0.95 seconds and the complete avatar request at
210+
roughly 0.75–1.17 seconds. The application image pipeline was not the hang.
211+
212+
The final encrypted restore rehearsal also exposed a real lifecycle edge case:
213+
a closed account can legitimately retain revoked session history, while the D1
214+
session trigger accepts inserts only for active accounts. Restore now inserts
215+
accounts temporarily as active, restores the complete security history, and
216+
atomically reapplies each authoritative account status before validation. A
217+
local regression fixture and the private-R2-to-disposable-D1 rehearsal both
218+
prove the closed state, revoked session history and foreign keys are preserved.
150219

151220
## Production preparation
152221

153222
The first complete gate draft is `docs/V6_PRODUCTION_CUTOVER_CHECKLIST.md`. The
154-
next decision checkpoint follows the real staging rehearsal. Production R2
155-
retention scheduling, alert presentation, exact final candidate SHA, 24-hour
156-
staging observation window and Name.com-to-Cloudflare DNS/DNSSEC execution remain
157-
future, separately approved work.
223+
next decision checkpoint is Slice 6 / production readiness. Open items are the
224+
normalized media-object disaster-recovery policy, production bucket names and
225+
region/jurisdiction, owner-visible backup/media alert presentation, exact
226+
candidate SHA, 24-hour staging observation window and the separately approved
227+
Name.com-to-Cloudflare DNS/DNSSEC execution.

0 commit comments

Comments
 (0)