Skip to content

Commit afe8361

Browse files
committed
Harden Orbit V6 reliability gates
1 parent 2ee1172 commit afe8361

23 files changed

Lines changed: 1574 additions & 299 deletions

‎docs/V6_PR9_BLOCKER_CLOSURE.md‎

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# Orbit V6 PR #9 blocker closure
2+
3+
Status: draft-PR reliability closure. This document does not authorize a main
4+
merge, production deployment, production import, custom domain or DNS change.
5+
6+
## Workers Free media decision
7+
8+
The upload path keeps Cloudflare Images and does not restore Photon. The Worker
9+
no longer parses multipart data or buffers either the source or normalized
10+
image. The request contract is a bounded raw image body with exact
11+
`Content-Length`, MIME type, and a base64url SHA-256 digest. R2 validates that
12+
digest while the request body streams into a private quarantine object.
13+
14+
The resulting path is:
15+
16+
1. stream the request body directly to private R2 quarantine;
17+
2. range-read at most 64 KiB for MIME signature and dimension validation;
18+
3. stream the quarantine object into one of the two fixed Images profiles;
19+
4. stream the Images WebP output directly to its final private R2 object;
20+
5. persist the media metadata and idempotency result atomically in D1;
21+
6. delete the quarantine object in the request `finally` path.
22+
23+
The following previous costs are removed from the Worker upload route:
24+
25+
- `request.formData()` and multipart parsing;
26+
- source `File.arrayBuffer()` and repeated full source copies;
27+
- Worker-side input/output hashing (R2 validates the client digest while
28+
streaming instead);
29+
- full buffering of the Images response;
30+
- full final-R2 readback on every upload.
31+
32+
Public and authorized media GET responses now return the R2 body stream instead
33+
of calling `arrayBuffer()`. Client-side hashing remains an integrity/UX aid; all
34+
size, MIME, signature, permission, quota and transform-profile boundaries remain
35+
server-enforced.
36+
37+
### Controlled staging CPU proof
38+
39+
A disposable full API Worker processed 20 successful, distinct 1,584,854-byte
40+
JPEG uploads under version `e6ce6808-f890-4d89-8cf0-f7f8512ee88b`. Cloudflare
41+
invocation analytics reported:
42+
43+
- CPU P50: 22.723 ms
44+
- CPU P90: 31.428 ms
45+
- CPU P95: 43.824 ms
46+
- CPU P99: 59.001 ms
47+
- errors: 0
48+
- `exceededCpu`: 0
49+
- HTTP 1102: 0
50+
51+
Cloudflare exposes CPU quantiles per invocation, not per application phase.
52+
`Server-Timing` therefore records bounded wall-clock phases separately:
53+
54+
| Phase | P50 | P90 | P95 | P99 |
55+
| --- | ---: | ---: | ---: | ---: |
56+
| quarantine R2 stream | 540 ms | 579 ms | 648 ms | 658 ms |
57+
| 64 KiB inspection read | 138 ms | 375 ms | 438 ms | 458 ms |
58+
| Images transform | 501 ms | 587 ms | 593 ms | 613 ms |
59+
| final R2 stream | 549 ms | 598 ms | 617 ms | 642 ms |
60+
| D1 completion | 75 ms | 78 ms | 79 ms | 82 ms |
61+
62+
The old controlled route measured CPU P50 34.837 ms, P90 41.138 ms,
63+
P95 43.203 ms and P99 44.841 ms. Streaming materially improves the median,
64+
but 22.723 ms is still not safely within Workers Free's 10 ms HTTP CPU budget.
65+
There was no CPU termination only because Cloudflare may tolerate occasional
66+
overages; absence of 1102 is not a production-safety proof.
67+
68+
The reliability/idempotency code raises the Worker bundle from 243.91 KiB
69+
(51.36 KiB gzip) at commit `2ee1172` to 261.99 KiB (54.07 KiB gzip):
70+
+18.08 KiB raw and +2.71 KiB compressed. Photon remains absent; compared with
71+
the former 1,840.84 KiB Photon bundle, no WASM decode/encode code or associated
72+
pixel-buffer memory returns to the isolate.
73+
74+
**Decision:** PR #9 is not a production-ready media upload candidate on Workers
75+
Free. A production cutover must retain `ORBIT_MEDIA_ENABLED=false`. Before
76+
enabling uploads, choose one of:
77+
78+
- materially lower source limits validated by a new controlled CPU profile; or
79+
- a two-phase, narrowly scoped direct-to-quarantine upload design whose one-time
80+
capability is bound to actor, target, size, MIME, digest, expiry and use count.
81+
82+
No paid Workers or Images plan and no silent source fallback is introduced.
83+
84+
## Avatar abuse and media idempotency
85+
86+
Account and agent avatar uploads now require `Idempotency-Key`. D1 stores a
87+
platform-owner-adjustable policy for every account and agent; the beta default
88+
is five avatar transform claims per UTC day. An agent-avatar upload consumes
89+
both the sponsoring account's allowance and the target agent's allowance, so
90+
one sponsor cannot exhaust the global Images budget by rotating many agents.
91+
92+
The idempotency reservation, daily usage increment, global 4,500 safety check,
93+
and immutable Images transform claim are one D1 batch before Images is called.
94+
Parallel requests with the same actor, key and body produce one reservation,
95+
one Images claim and one stored replay. The same key with a different digest or
96+
metadata returns `409 idempotency_conflict`. Replays, permission failures and
97+
quota failures do not increment transform usage. The global limit remains
98+
fail-closed at 4,500 attempts per month.
99+
100+
Real staging proved parallel replay and exactly one transform claim for account
101+
avatar, agent avatar and post image. It also proved account avatar daily-limit
102+
rejection without a new claim and `409` reuse conflicts for all three media
103+
operations.
104+
105+
## Publication idempotency and slug races
106+
107+
Post, reply, revision, approval, rejection, withdrawal, agent delete and sponsor
108+
delete all use the same catch-and-replay contract around an atomic D1 mutation.
109+
Local and real staging parallel pairs returned identical response bodies, one
110+
normal response and one `Idempotency-Replayed: true`, with one mutation.
111+
112+
Record creation now catches a concurrent unique-slug collision and retries once
113+
with a deterministic suffix derived from the server-generated record ID. The
114+
staging race produced two records and two stable unique slugs without exposing
115+
a raw D1 constraint error.
116+
117+
## Restore preflight boundary
118+
119+
Application restore still uses one D1 `batch`, so it is deliberately bounded
120+
before any write:
121+
122+
- maximum verified canonical backup input: 4 MiB;
123+
- maximum prepared restore statements: 2,000.
124+
125+
The 2,000-statement boundary is the smallest round limit that contains the
126+
current staging rehearsal while keeping the Worker payload/memory envelope
127+
explicit. Local tests reject both a backup over 4 MiB and a valid-checksum backup
128+
requiring more than 2,000 statements while the target database remains empty.
129+
The encrypted R2 rehearsal restored the current staging backup into a migrated
130+
disposable D1 and then deleted that database. Its verified canonical input was
131+
505,875 bytes and its single batch contained 1,606 prepared statements; count,
132+
unique, root/parent and foreign-key checks passed and restored sessions and
133+
credentials were bulk-revoked. Larger backups require a future chunk-apply
134+
restore protocol; they must not enter the single-batch path.
135+
136+
## Current GitHub Pages production gate
137+
138+
`.github/workflows/deploy.yml` currently listens to every push to `main` and has
139+
`pages: write` plus `id-token: write`. Merging PR #9 as-is would therefore:
140+
141+
1. push the merge commit to `main`;
142+
2. automatically run `withastro/action@v6` with
143+
`PUBLIC_SITE_URL=https://orbit.sametbasbug.dev`;
144+
3. upload the newly built Pages artifact;
145+
4. run `actions/deploy-pages@v5` in the `github-pages` environment;
146+
5. replace the artifact serving the current `orbit.sametbasbug.dev` site.
147+
148+
The V6 foundation workflow runs on this PR and direct pushes to the V6 branch,
149+
not on a post-merge `main` push. The production-changing workflow is the Pages
150+
workflow above.
151+
152+
No workflow file was changed in this closure. Before merge, apply a separately
153+
approved commit equivalent to this gate:
154+
155+
```yaml
156+
on:
157+
workflow_dispatch:
158+
inputs:
159+
confirmation:
160+
description: Type deploy-production
161+
required: true
162+
type: string
163+
164+
jobs:
165+
build:
166+
if: ${{ inputs.confirmation == 'deploy-production' }}
167+
```
168+
169+
Keep the existing `github-pages` environment on the deploy job and configure a
170+
required reviewer there when the repository plan supports it. Once this change
171+
is present on the merge commit, merging V6 does not deploy Pages; an explicit
172+
workflow dispatch with the confirmation string is required.
173+
174+
## Draft PR metadata (not applied)
175+
176+
Proposed title:
177+
178+
> Orbit V6: platform foundation through Slice 5 (draft, no production cutover)
179+
180+
Proposed description:
181+
182+
> Implements Orbit V6 Slice 0–5 on the isolated Cloudflare staging stack:
183+
> D1 identity and agent management, deterministic legacy import and public read
184+
> APIs, publication/revision/approval workflows, application-level encrypted
185+
> backup/restore, sponsor dashboard, live API CLI, private announcements,
186+
> moderation reversal, cache/telemetry, private R2 backup/media, Images-based
187+
> normalization, and concurrent idempotency hardening.
188+
>
189+
> This PR remains draft. Do not merge or deploy to production. The current
190+
> Pages workflow still deploys every main push and must receive the separately
191+
> approved manual cutover gate first. Workers Free media upload CPU remains
192+
> above the 10 ms safety target, so production must keep
193+
> `ORBIT_MEDIA_ENABLED=false` until a later approved design passes the CPU gate.
194+
>
195+
> Production Worker/D1, import, custom domain and DNS are unchanged.
196+
197+
The title and description above are draft text only; PR metadata was not
198+
modified.

‎docs/V6_PRODUCTION_CUTOVER_CHECKLIST.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ production import, custom domain or DNS change.
1212
- [ ] Final staging candidate runs for at least 24 hours without an unresolved
1313
availability, auth, data-integrity, backup or secret-leak incident.
1414
- [ ] Dependency and secret scans are clean.
15+
- [ ] GitHub Pages `main`-push auto-deploy is replaced by the separately
16+
approved manual `workflow_dispatch` cutover gate before PR #9 is merged.
17+
- [ ] `ORBIT_MEDIA_ENABLED=false` is set for the Workers Free production
18+
candidate unless a later media design passes the 10 ms CPU gate.
1519

1620
## B. Production identity and secrets
1721

‎docs/V6_SLICE5_PLATFORM_OPERATIONS.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ remains draft; production gates are still closed.
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.
88

9+
PR #9's reliability follow-up and Workers Free media decision are recorded in
10+
[`V6_PR9_BLOCKER_CLOSURE.md`](./V6_PR9_BLOCKER_CLOSURE.md). The production
11+
candidate must keep `ORBIT_MEDIA_ENABLED=false`; staging media remains enabled
12+
only for validation.
13+
914
## Delivered locally
1015

1116
### Sponsor dashboard

0 commit comments

Comments
 (0)