OXYGENHUB
◆ v0.9.7 oxygenhub / docs / diffusion.md
13.2 KiB · Markdown · last changed Diffusion reconciler: every 10 minutes the pin index is checked and mended 19 days ago renderedsource blame history raw
1
# Diffusion: upstream changes reach their consumers
2
3
Status: D1 is built, with auto-land (2026-10-14); D2–D5 are designed.
4
What is built, what comes next and in what order, with ecosystems and
5
OSV alerts, is in [diffusion-roadmap.md]diffusion-roadmap.md.
6
The name **Diffusion** was confirmed by Andy on 2026-10-12: changes
7
diffuse from an upstream into the repositories that pin it.
8
9
## 1. The problem
10
11
R* API is a subrepo of Metal Gear, Metal Gear 2, Super Mario Land and
12
others. When it changes, each consumer should take the change, test it,
13
and propose it when it works, with no one opening proposals by hand.
14
Renovate and Dependabot do this for package manifests; Diffusion does it
15
for Oxygen pins, as part of Oxygen, and goes further than they can.
16
17
## 2. Why Oxygen can do better
18
19
- **The dependency graph is exact.** An Oxygen pin names a repository id
20
  and a state, and is a verifiable object (spec §7.8). The hub already
21
  reads every pin in a state to give jobs their subrepos. Nothing is
22
  scanned or guessed.
23
- **A pin is a set of changes, and independent changes commute.** A
24
  consumer can take an upstream state minus one change and whatever is
25
  built on it (§6). Git tools can only pin one commit: all or nothing.
26
- **Bumps never need rebasing.** The pin change commutes with the
27
  consumer's own work; only a consumer moving the same pin itself
28
  conflicts, as an ordinary replace conflict.
29
- **Everything is signed.** The bump, the upstream changes and the CI
30
  receipts are signed objects, so a consumer can check what it takes, even
31
  from another hub.
32
33
## 3. The approaches compared
34
35
| Approach | Strength | Weakness |
36
|---|---|---|
37
| Bump proposals (Renovate, Dependabot) | Consumers stay in charge; auditable; works across hubs | Reactive: breakage is found after upstream ships |
38
| Monorepo at head (Google) | Upstream cannot land what breaks a consumer | Takes control from consumers; upstream sees all code; one hub only |
39
| Upstream-driven migrations (large-scale changes, codemods) | Handles breaking changes, not just detects them | Needs tooling per change |
40
| Consumer-gated promotion (contract testing) | Prevents breakage | Needs consumers' tests to run upstream |
41
42
Diffusion is bump proposals as the base, with consumer checks on upstream
43
proposals (§7), partial pins (§6) and repair (§8) on top.
44
45
## 4. D1: follow and propose
46
47
### 4.1 The reverse pin index
48
49
When a push moves a repository's default bookmark, the hub records each
50
Oxygen pin in the new state: consumer, path, the upstream repository id
51
and the pinned heads (`diffusion_pins`). That answers "who consumes R*
52
API, at which state" at once. An upstream repository's page shows its
53
consumers on this hub ("Diffuses to"); the API gives
54
`GET /repos/{owner}/{name}/consumers`, and `GET /repos/{owner}/{name}/diffusion`
55
gives both directions with their pills (#153).
56
57
Keeping it right (oxygenhub#210). Each write records the state it indexed
58
(`diffusion_indexed`); a failed write is logged with the step that failed
59
and tried once more, and a state whose pins cannot be read leaves the
60
index as it was. Every ten minutes a reconciler compares each followed
61
bookmark with the state it was indexed at and re-indexes where they
62
differ; in the same pass, a consumer whose pin is not its upstream's
63
newest passing state, with no bump open or in draft, is caught up as if it
64
had just turned Diffusion on. A bump a person closed counts as a "no": it
65
is not opened again until the upstream moves. Repairs are logged
66
(`diffusion: reconciled: …`).
67
68
### 4.2 Turning it on
69
70
A consumer follows a subrepo when, in order of precedence:
71
72
1. its `.oxymodules` entry says so, beside the existing `url` and
73
   `bookmark` keys:
74
75
   ```toml
76
   [rstar-api]
77
   url = "https://oxygenhub.io/doomsdayone/rstar-api"
78
   bookmark = "main"
79
   follow = "green"   # off | green | any
80
   land = "propose"   # propose | auto
81
   target = "develop" # optional: the bookmark to bump (default: learned, §4.3)
82
   ```
83
84
2. else its repository setting (Settings › Subrepos), so an
85
   administrator can turn it on without a commit;
86
3. else the hub's default (`[diffusion] follow` in hub.toml, `off`).
87
88
`green` waits for the upstream state's required checks to pass; `any`
89
follows every move. An upstream with no checks at all is **unverified**
90
(amber): it never turns green, so its moves bump green followers too, and
91
the proposal is labelled `upstream unverified` with a note saying only the
92
consumer's pipeline tested it (decided by Andy, 2026-10-13). A passing run
93
of the upstream later clears it.
94
95
**Landing by itself** (built 2026-10-14, oxygenhub#174; Andy chose
96
"opt-in, per repository" after rstar-api's first green/green): `land =
97
auto` in the entry, else the repository's Settings › Diffusion › Landing
98
(`PUT …/diffusion {"land": "auto"}`), off by default. The hub lands a bump
99
itself, as the `diffusion` account, when both halves are green: the exact
100
upstream state the bump pins passed its own run, and the consumer's
101
newest run on the bump bookmark passed on the bump as it is now. Never
102
for amber: an upstream with no checks always waits for a person. It lands
103
through the web's own path (`land_as`), signed by the hub's own key, so
104
the consumer's required checks, approvals and trust policy decide as for
105
anyone; a policy that does not let the hub's key move the bookmark keeps
106
the bump waiting, and the proposal's timeline says why, once. It is tried
107
when the bump's run passes, when the upstream's run passes under a bump
108
already made, and when the setting is turned to `auto`. The timeline
109
records "landed (Diffusion, both halves green)".
110
111
### 4.3 The bump
112
113
**Which bookmark of the consumer** (decided 2026-10-12): the bookmark its
114
work lands on. The hub learns it per consumer from where the
115
consumer's proposals land (the most common target of those landed in the
116
last 90 days), falling back to the default bookmark; a `target` key in
117
the consumer's `.oxymodules` entry overrides it. The pin index (§4.1)
118
records pins on that bookmark as well as the default. So a game whose
119
default is `main` but whose work lands on `develop` is bumped on
120
`develop`, with no setup, and follows if its workflow changes.
121
122
When an upstream's followed bookmark reaches a new state S (and, for
123
`green`, S's required checks pass), for each consumer that follows it:
124
125
- **Skip** when the consumer's pin already holds S, or when S does not
126
  hold everything the current pin does (upstream moved backwards or was
127
  rewritten). Consumers only move forward.
128
- **Build** one change on the target bookmark's heads that replaces the
129
  pin's blob with a pin of S. The hub signs it with its delegate key, as
130
  it signs wiki edits, authored by the hub's `diffusion` account.
131
- **Place** it on the bookmark `diffusion/<path>`: the target's heads
132
  plus the change. One bookmark per consumer and subrepo, moved in
133
  place when upstream moves again, so there is never a pile of bumps.
134
- **Propose** it, once: a proposal from `diffusion/<path>` to the target
135
  bookmark, labelled `dependencies`, kept up to date as the bookmark
136
  moves. Its CI runs on the projected state like any proposal's.
137
138
A trust policy that does not admit the hub's key still gets the
139
proposal; it is landed from a client, as today.
140
141
### 4.4 What the proposal says
142
143
- The upstream, the old pin and the new state.
144
- **The exact changelog:** every upstream change in S and not in the old
145
  pin, with its author, whether it is signed, and the issues it closes or
146
  refers to.
147
- Its checks, as for any proposal. A red bump stays open, with the
148
  failing check; D2 then says which upstream change broke it.
149
150
### 4.5 Seeing it (#150)
151
152
A repository's **Diffusion** tab lists who pins it (Used by) and what it
153
pins (Follows), each with a status Andy chose on 2026-10-13: **green**
154
(the upstream was checked and the consumer's run on the bump passed),
155
**amber** (the run passed but the upstream has no checks), **red** (the run
156
failed), **grey** (running), **up to date**. The overview shows the same in
157
brief; Admin › Diffusion shows the whole hub.
158
159
It is drawn as a two-half pill, like a capsule (Andy, 2026-10-13): the
160
left half is the upstream (**checked**, **untested**, **failing**,
161
**testing**), the right half the consumer (**passes**, **fails**,
162
**testing**, **waiting**, **up to date**), each coloured on its own, so a
163
game that passes on an untested upstream reads [untested │ passes] rather
164
than a single amber that hides the pass.
165
166
## 5. Across hubs
167
168
Each hub only ever writes to its own repositories. What one hub tells
169
another is a hint; the consumer's hub fetches and verifies the facts.
170
171
- **Polling always works.** The consumer's hub has the upstream URL in
172
  `.oxymodules`; it asks for the followed bookmark every few minutes. An
173
  upstream kept in a Strata bucket with no hub is polled by reading its
174
  bookmark record.
175
- **Subscribing makes it prompt.** The consumer's hub asks the upstream's
176
  hub to notify it when the bookmark moves. Notes are signed with the
177
  upstream hub's key and carry only "repository *id* moved to state *S*";
178
  the consumer fetches and verifies. A forged note causes a fetch, nothing
179
  more; a lost one is caught by the next poll.
180
- **Private upstreams** are read with a read-only credential the
181
  consumer's owner stores as a secret on the consumer's hub.
182
- **"Green" across hubs** is evidence the consumer checks: a Flow receipt
183
  for S, signed by a runner the upstream hub vouches for. The consumer's
184
  policy names the upstream hub keys it accepts, and may also require
185
  every upstream change to be signed by the upstream's maintainers, which
186
  holds even if the upstream hub is compromised.
187
- **Consumer checks across hubs (§7)** are opt-in on both sides; the
188
  consumer's hub runs them on its own runners and returns only a signed
189
  summary, or nothing.
190
191
## 6. D2: partial pins and the culprit
192
193
A pin is a state: any set of changes closed under dependencies. So a
194
consumer can pin "upstream S, minus change X and everything built on X":
195
its heads are the maximal changes of `closure(S) − ({X} ∪ dependents(X))`,
196
well-formed by construction.
197
198
When a bump of N upstream changes fails:
199
200
1. Flow searches for the culprit by testing subsets of the N changes (a
201
   delta-debugging search over independent changes, bounded in runs).
202
2. The bump proposal then pins everything except the culprit and its
203
   dependents, and says which change is held back and why, with the
204
   failure.
205
3. The consumer gets the rest at once; the held-back change comes with a
206
   later bump, once upstream fixes it.
207
208
`oxy submodule` and checkout take such pins as they are (a pin is heads);
209
`oxy submodule status` names the changes a partial pin leaves out.
210
211
## 7. D3: consumers test upstream proposals
212
213
A proposal on R* API can run each consumer's pipeline with its pin swapped
214
for the proposal's projected state, committing nothing to the consumer
215
(the claim already carries subrepo pins; the run overrides one). Each
216
consumer's result appears on the upstream proposal as a check,
217
`consumers/<owner>/<name>`, with a summary: "Metal Gear ✔, Super Mario
218
Land ✘ (test X)". The person changing the API sees what breaks before it
219
lands, which is the monorepo's main strength without taking consumers'
220
control. An upstream may make consumer checks required.
221
222
## 8. D4: repair
223
224
- **Migrations with the change.** An upstream change that alters the API
225
  may carry a migration (a script, or instructions for an agent) under
226
  `.diffusion/migrations/`. A bump spanning it runs the migration in the
227
  consumer and adds the result as a separate change on the bump proposal.
228
- **An agent's fix.** When a bump is red, a scoped agent key (an agent
229
  home with `changes` scope on that consumer, never `refs`) may add a fix
230
  as a separate change to the proposal, for the consumer's owner to
231
  review. The bump and the fix stay separate changes, so either can be
232
  dropped.
233
234
## 9. D5: reach
235
236
- **Auto-land** (`land = "auto"`): a green bump lands itself when the
237
  consumer's trust policy and required checks allow it, and every
238
  upstream change is signed by keys the policy trusts.
239
- **Chains:** landing a bump moves the consumer's default bookmark, which
240
  may be followed in turn.
241
- **Grouping and quiet hours:** several upstreams' bumps in one proposal;
242
  no bumps outside set hours.
243
- **Cross-hub** polling and subscriptions (§5).
244
- **Channels:** with Cylinder, a consumer follows `rstar-api:stable`, a
245
  signed channel whose moves are gated by consumer checks (§7).
246
247
## 10. Order
248
249
| Step | What |
250
|---|---|
251
| D1 | The reverse pin index and Used by; turning it on; the signed bump on `diffusion/<path>`, moved in place; the proposal with the changelog |
252
| D2 | Partial pins; the culprit search |
253
| D3 | Consumer checks on upstream proposals |
254
| D4 | Migrations and agent fixes |
255
| D5 | Auto-land, chains, grouping, cross-hub, channels |
256
257
D2 is what no other tool can do; D3 is worth the most.
258
259
The full order, with the work that makes Diffusion safe to rely on
260
first and the ecosystem adapters and OSV alerts beside it, is in
261
[diffusion-roadmap.md]diffusion-roadmap.md §4.
262
263
## 11. Open questions
264
265
- **Who may turn it on** for a consumer: its owner and administrators, or
266
  also the upstream's maintainers (by offering, which the consumer
267
  accepts)?
268
- **Bot identity:** a `diffusion` account per hub, or the upstream
269
  pusher's name with the hub as delegate?
270
- **Cost limits** for the culprit search and consumer checks: runs per
271
  bump, per upstream proposal, per day.