OXYGENHUB
# d8d9367878a6 oxygen / docs / stores.md
11.5 KiB · Markdown · last changed Strata: a push lands over what landed meanwhile; oxy gc --remote 1 month ago renderedsource blame history raw
1
# Oxygen Anywhere: stores
2
3
Status: design, 2026-10-03. Nothing here is built yet. Next to implement.
4
5
## 1. What and why
6
7
Today an Oxygen repository lives in `.oxy/` on a disk, and a remote is
8
either another directory or an OxygenHub. This feature makes storage
9
pluggable. Any **store** that can keep write-once objects and update a
10
small reference record by compare-and-swap can hold a complete
11
repository, with no server in between.
12
13
The first stores are **Amazon S3** and **Google Cloud Storage**, built
14
side by side so the code stays portable. Azure Blob and a Git repository
15
used as a plain store follow on the same interface.
16
17
Why Oxygen can do this safely when Git cannot:
18
19
- **Objects never change.** Changes, states, blobs, attestations and
20
  receipts are named by their BLAKE3 hash and written once.
21
- **Only references are mutable.** Bookmarks, tags and the operation
22
  head are small, and object stores now offer compare-and-swap on a
23
  single object.
24
- **Every read is verified.** Objects are re-hashed on read and changes
25
  are signed, so a bucket is untrusted storage. Tampering is detected,
26
  and nobody can forge history, not even the bucket's owner.
27
28
Performance is "good enough" for one engineer today. This work is about
29
where a repository can live, not about speed.
30
31
## 2. What users see
32
33
Storage must be transparent: a bucket behaves like any other remote, with
34
no new concepts to learn.
35
36
```sh
37
oxy remote add backup s3://my-bucket/repos/oxygen
38
oxy push backup
39
oxy clone gs://team-bucket/metalgear
40
oxy pull
41
```
42
43
- **URLs:** `s3://BUCKET/PREFIX` and `gs://BUCKET/PREFIX`. The prefix is
44
  optional, so one bucket can hold many repositories.
45
- **Credentials come from the standard places**, with no oxy-specific
46
  configuration:
47
  - **AWS:** environment variables, `~/.aws` profiles (`AWS_PROFILE`),
48
    SSO, and instance or container roles;
49
  - **Google Cloud:** Application Default Credentials (`gcloud auth
50
    application-default login`), service account files, and workload
51
    identity.
52
  - **Overrides:** optional per-remote settings in the repository's
53
    config (`profile`, `region`, `endpoint`), for example
54
    `oxy remote add backup s3://b/p --profile work`.
55
- **Errors are written for people.** Each one says what to do next, for
56
  example: "no AWS credentials found: run `aws sso login` or set
57
  AWS_PROFILE", or "the bucket exists but this account cannot write to
58
  it (s3:PutObject denied on my-bucket/repos/oxygen)".
59
- **`oxy init --remote s3://…`** creates an empty repository in the
60
  bucket, and `oxy remote check NAME` reports access, latency and
61
  what is stored there.
62
- **Progress, colour and glyphs** follow the CLI style of every other
63
  command.
64
- **Several writers are safe.** Two people pushing to the same bucket at
65
  once is handled the way the operation log handles two processes today
66
  (§5).
67
68
## 3. Architecture
69
70
- **The `Store` trait** (`oxy_core::strata`, built 2026-10-03). It has
71
  two halves:
72
  - **objects**: `has`, `get`, `get_range`, `put_new` (create only),
73
    `list` by prefix, and `delete`;
74
  - **references**: `read_ref() -> (bytes, version)` and
75
    `write_ref(bytes, expected_version) -> Ok | Conflict`. A version is
76
    opaque and compared for equality only. Writing identical bytes may
77
    keep the version, as S3's content-based ETag does; compare-and-swap
78
    guards against losing a *different* record.
79
  - Keys are plain relative paths (`[A-Za-z0-9._-]` segments, no `.` or
80
    `..`), the same rule on every store, so a key can never escape a
81
    directory store.
82
  - Implementations: `LocalStore` (a directory: create-only through a
83
    hard link, references under a lock file beside them, so processes on
84
    one machine can share it), `MemoryStore` (tests), then S3 and GCS in
85
    a crate of their own.
86
  - `strata::conformance(store, prefix)` exercises any store under a
87
    probe prefix and leaves it empty: every implementation runs it in its
88
    tests, and `oxy remote check` runs it against a remote.
89
  - The working repository's own `.oxy/` store is **not** behind the
90
    trait: it is read and written directly, as before, so nothing on the
91
    local path changes or slows. A store is what a remote is kept on.
92
- **The `object_store` crate** (Apache Arrow) for S3 and GCS: one API
93
  for both, mature credential chains, multipart uploads, and conditional
94
  puts. Azure is in the same crate, so it comes nearly free later.
95
- **Push and pull talk to the bucket directly** through the same
96
  negotiation the hub protocol uses: what does the remote have, and what
97
  is missing? The client sends packs, never loose objects.
98
- **A local cache** of fetched objects, which is always correct because
99
  objects never change.
100
- **The working repository stays local.** A bucket is a remote. Running
101
  a repository *from* a bucket (no local `.oxy/`) is out of scope here;
102
  it is what the virtual working copy (§8) is for.
103
104
## 4. Layout in the bucket (as built, 2026-10-03)
105
106
```
107
PREFIX/
108
  oxygen.toml                      format version and repository id, written once by the first push
109
  bundles/<seq>-<hash>.bundle      one per push: changes, signatures, seals, objects, policies
110
                                   (the wire protocol's bundle encoding), written once, named by content
111
  refs                             every bookmark with its heads and attestation, every tag, the policy
112
                                   and its history (the protocol's refs response), moved by compare-and-swap
113
```
114
115
- **Pushing** uploads one bundle, then updates `refs` from the version
116
  it read. A bundle named in `refs` is complete, because the bundle is
117
  written before `refs` moves.
118
- **One `refs` record** so that a push moving several bookmarks is
119
  atomic. Per-reference records would scale to more writers but lose
120
  atomic pushes; one engineer and small teams do not need them.
121
- **Bundles are whole-file transfers.** Each push is one bundle, so a
122
  pull downloads only the bundles it has not seen. Packs with indexes
123
  for range reads, as first planned, are an optimisation for later
124
  (`oxy gc` against a remote merges bundles, and could write a pack).
125
- **The client does what a hub does.** A store cannot run code, so each
126
  client keeps a **mirror**, a bare repository of its own under
127
  `.oxy/remotes/<name>/strata/`, brought level with the store before
128
  every use: the record read, the bundles it has not seen imported (each
129
  object re-hashed), the view set from the record. A push runs the hub's
130
  own checks (`receive_push`: policy, attestations, fast-forward) on the
131
  mirror, uploads the bundle, then moves `refs`. A fetch verifies each
132
  bookmark's attestation under the policy, as for any remote. The
133
  mirror costs a second copy of the objects on disk; sharing them with
134
  the repository's own store is a later optimisation.
135
- **The record moved meanwhile:** the mirror is put back to what the
136
  store says, brought level, and the push's updates are applied over
137
  what landed (up to four times). Two pushes to different bookmarks
138
  both get through; one to the same bookmark is told it is stale, as a
139
  hub says: pull, then push again.
140
- **`oxy gc --remote NAME`** folds every bundle into one holding what
141
  the record reaches, and records the superseded ones in a `gc`
142
  record with the time. They are removed only once seven days have
143
  passed (`--now` ignores that), so a reader that listed them before
144
  the fold can still fetch them; a reader that finds one gone skips it,
145
  since the merged bundle holds the same changes.
146
- **A directory is a store too:** `oxy remote add usb dir:///media/usb/repo`
147
  (`dir://`, since a plain path or `file://` is another repository).
148
  Tests run the whole flow through it with no network.
149
150
## 5. Concurrency: compare-and-swap on `refs`
151
152
| Provider | Create only | Replace only if unchanged |
153
|---|---|---|
154
| S3 | `PutObject` with `If-None-Match: *` | `PutObject` with `If-Match: <ETag>` |
155
| GCS | `ifGenerationMatch=0` | `ifGenerationMatch=<generation>` |
156
157
When a push finds `refs` has moved, it re-reads `refs` and merges by the
158
same rules as the operation log's merge:
159
- a bookmark moved by only one side takes that side's value;
160
- moved differently by both, it keeps both sides' heads, as several
161
  heads;
162
- a tag keeps its first value.
163
164
It then retries the write. Uploading packs needs no locking: two writers
165
uploading the same objects is harmless.
166
167
Before building on it, check each provider's current documentation for
168
conditional writes: S3 added `If-Match` on `PutObject` in 2024, and this
169
design depends on it.
170
171
## 6. Safety
172
173
- **The bucket is untrusted.** Every object is re-hashed on read, as
174
  local reads are now. Signatures and repository policy are checked on
175
  fetch exactly as for a hub remote.
176
- **Bound to one repository.** `oxygen.toml` names the repository id. A
177
  push to a bucket holding a different repository is refused, and so is
178
  a clone that finds packs naming another id.
179
- **Size limits.** The existing 1 GiB object cap, plus limits on index
180
  and `refs` sizes, so a hostile bucket cannot drive huge allocations.
181
- **Garbage collection never deletes in place.** `oxy gc` on a remote
182
  writes the merged pack and moves `refs` first. Packs no longer named
183
  are deleted only after a grace period (default 7 days), so a slow
184
  concurrent reader is never left with a missing pack.
185
- **Least privilege.** The documented IAM and GCS policies need only
186
  Get, Put, List and Delete under the prefix. A read-only key gives a
187
  working clone and pull.
188
- **No secrets in the repository.** Credentials stay in the providers'
189
  own chains or the OS keychain, never in `.oxy/config`.
190
191
## 7. Testing
192
193
- **One conformance suite** that every store must pass, run against
194
  local, S3 and GCS. It covers object round trips, range reads,
195
  create-only refusals, compare-and-swap conflicts, concurrent pushers
196
  merging, an interrupted push leaving the remote valid, gc with a
197
  concurrent reader, and a repository-id mismatch being refused.
198
- **Emulators in CI** (Flow jobs have no network):
199
  - MinIO for S3, if its conditional writes match S3's, otherwise
200
    LocalStack;
201
  - `fake-gcs-server` for GCS.
202
- **Real buckets** (Andy's AWS and GCP accounts) for a nightly or
203
  manual test run. It needs network access, so it runs outside the
204
  isolated tier, with credentials scoped to a test prefix.
205
206
## 8. Order of work
207
208
1. **The `Store` trait in oxy-core**, with the local store moved behind
209
   it and no change in behaviour, so every existing test passes.
210
2. **S3 and GCS stores together**, with the conformance suite and the
211
   emulators.
212
3. **`oxy remote add`, `push`, `pull`, `clone` and `init --remote`**
213
   for bucket URLs, with the friendly errors and `remote check`.
214
4. **`oxy gc` against a bucket**, with the grace period.
215
5. **Documentation:** a user guide page, sample IAM and GCS policies,
216
   and a README section.
217
218
Later, on the same trait:
219
- Azure Blob storage;
220
- a Git repository used as a plain store, so `oxy push` works to
221
  GitHub or GitLab;
222
- the hub attaching a repository from a customer's bucket ("bring your
223
  own storage", see oxygenhub `docs/scaling.md`);
224
- couriers: signed, encrypted bundles shared by email, Slack, Matrix
225
  and the like (a separate design);
226
- a virtual working copy mounted with FUSE (from OxygenFlow's
227
  `flow-casfs`).
228
229
## 9. Open questions
230
231
- Should `oxy clone s3://…` set the bucket as `origin`, or prompt for a
232
  name? Proposed: `origin`, as for any URL.
233
- Does a bucket remote keep its own operation log, or only `refs`?
234
  Proposed: only `refs` at first. The local operation log already
235
  records what each push did.
236
- Should packs be encrypted on the client, so the provider only ever
237
  stores ciphertext, beyond the provider's own encryption? Proposed:
238
  later, as an option. It does not change the layout.