Skip to content

Commit 78dbfbd

Browse files
PiquelChipsclaude
andcommitted
feat: add targets, policy and the landing queue
Changes could be made and annotated, but nothing moved a target past `init`. The landing queue now lands them: `origin land` rebases a change and the changes below it onto the target's tip with a path-level three-way merge, checks the statements `policy.toml` requires against the policy in force (promoting results whose input digest still matches), and appends an acceptance signed by the target's authority, one per change. Only checked claims count as evidence, a promotion as its original's issuer. Conflicts issue `core.conflict`, and landings without evidence wait in a durable, enumerable queue until they're retried; a stack that waits is kept whole. Divergent changes, those abandoned by their creator and revisions with unresolved conflicts are refused, and only the authority lands. A landing on `policy` is governed by the acceptance before it, never by the policy it lands (`Policy::governing`). `policy.toml` gains its full schema: nodes, groups, per-target authority and requirements, retention and path rules, validated so a policy landing can never lock `policy` up. Targets fork with `origin target new` and land on each other with `origin land --from`. Their merge base comes from both histories (`ancestry.rs`): the best common ancestors, merged recursively when there are several, and any change under a path the bases disagree on conflicts. Conflicts are explicit state. A merge (`converge` now merges every head's files) writes both versions of a conflicted text file between markers, and a `core.conflict` lists each conflicted path with what was written there. A path stays unresolved until a revision changes it or `origin resolve` accepts it, every revision-producing operation carries unresolved paths forward, and the statements are published before their revision, so nothing finds the revision without them. Markers are only an editing aid; nothing scans files for them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c1a0b8c commit 78dbfbd

22 files changed

Lines changed: 4695 additions & 119 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ to a hot path (hashing, storage, snapshots, transfer) should come with a
2727
benchmark, and its numbers in the pull request.
2828

2929
- `just bench`: the divan micro-benchmarks (encoding, store writes,
30-
snapshots, input digests and promotion).
30+
snapshots, input digests and promotion, landing).
3131
- `just bench-git`: times origin against git on a 20,000-file tree with
3232
hyperfine, and rewrites `docs/benchmarks.md`.
3333

‎README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,43 @@ origin evolog <change> # every revision of a change
2121
origin edit <change> # switch the working copy to another change
2222
origin abandon --reason "Too slow" # give a change up, keeping it for others to see
2323
origin converge <change> # end a change's divergence
24+
origin resolve <path>... # accept conflicted files as they are
2425
origin index rebuild # rebuild the record index from the store
2526

2627
origin annotate @ ci.test --pass --inputs src Cargo.toml # a statement about a revision
2728
origin statements [<rev>] # the statements about a revision
2829
origin promote [<rev>] # carry results over from revisions with the same inputs
2930
origin gc # drop expired payloads (policy.toml) and pack objects
31+
32+
origin land [<change>] [--onto <target>] # land a change and the ones below it
33+
origin land --from <target> --onto <target> # land a target's tip on another
34+
origin land --status # the landings waiting for evidence or a conflict fix
35+
origin targets # every target, its tip, authority and requirements
36+
origin target new <name> --from <target>
37+
origin new [description] --on <target> # start a change on a target's tip
3038
```
3139

40+
Landing rebases a change onto the target's tip, file by file, checks the
41+
statements `policy.toml` requires (promoting results whose inputs didn't
42+
change), and appends an acceptance signed by your node, which must be the
43+
target's authority. A landing that conflicts or lacks evidence waits: issue
44+
the statements, or a new revision, and run `origin land` again. Policy is a
45+
target too: edit it with `origin new --on policy`, then `origin land`.
46+
3247
Changes are named by a unique prefix of their id, or `@` for the working
3348
copy's. A revision is `@`, a change (for its head), or a unique prefix of
3449
the revision's id. Your name and node key live in `~/.config/origin` (or
3550
`$ORIGIN_CONFIG_DIR`): set `user = "<name>"` in its `config.toml` if `$USER`
3651
isn't the name you want. See [the design](docs/design.md) for the model.
3752

53+
`converge` merges the files of a change's heads. A text file two heads
54+
changed holds both versions between conflict markers (`<<<<<<<`, `=======`,
55+
`>>>>>>>`), and a binary one keeps one side. A `core.conflict` statement
56+
records which files conflict and what the merge wrote there, and the change
57+
doesn't land while they're unchanged: edit them, or accept a file as it is
58+
with `origin resolve <path>`. `status` lists those left, and every new
59+
revision, `describe` included, keeps them.
60+
3861
## Development
3962

4063
```sh

‎apps/origin-src/Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ tempfile.workspace = true
3737
name = "annotations"
3838
harness = false
3939

40+
[[bench]]
41+
name = "land"
42+
harness = false
43+
4044
[[bench]]
4145
name = "snapshot"
4246
harness = false

‎apps/origin-src/benches/annotations.rs‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,22 @@ fn promotions_cached(bencher: Bencher<'_, '_>) {
180180
let (_dir, store, target) = promotion_store();
181181
let issuer: Principal = "node:queue".parse().unwrap();
182182
let mut annotations = Annotations::open(&store).unwrap();
183-
assert_eq!(annotations.promotions(target, &issuer).unwrap().len(), 9);
183+
assert_eq!(
184+
annotations
185+
.promotions(RecordId::Revision(target), &issuer)
186+
.unwrap()
187+
.len(),
188+
9
189+
);
184190
let index = Index::open(&store).unwrap();
185191
bencher
186192
.counter(ItemsCount::new(STATEMENTS))
187193
.with_inputs(|| Annotations::new(&store, index.clone()))
188-
.bench_local_refs(|annotations| annotations.promotions(target, &issuer).unwrap());
194+
.bench_local_refs(|annotations| {
195+
annotations
196+
.promotions(RecordId::Revision(target), &issuer)
197+
.unwrap()
198+
});
189199
}
190200

191201
/// The first search, which computes and remembers the digest of each of
@@ -202,5 +212,9 @@ fn promotions_uncached(bencher: Bencher<'_, '_>) {
202212
fs::remove_file(&log).unwrap();
203213
Annotations::open(&store).unwrap()
204214
})
205-
.bench_local_refs(|annotations| annotations.promotions(target, &issuer).unwrap());
215+
.bench_local_refs(|annotations| {
216+
annotations
217+
.promotions(RecordId::Revision(target), &issuer)
218+
.unwrap()
219+
});
206220
}

‎apps/origin-src/benches/land.rs‎

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
//! The landing queue: the latency of one landing, made on the target's tip
2+
//! or rebased onto it, with and without a requirement, of a target landing
3+
//! another after long histories, and the throughput of several proposers
4+
//! landing different changes on one target at once. Run on a real disk:
5+
//! syncs are most of the cost.
6+
7+
use std::thread;
8+
9+
use divan::Bencher;
10+
use divan::counter::ItemsCount;
11+
use origin_platform::Native;
12+
use origin_shared::{
13+
AcceptanceId, Base, ChangeId, EncodedObject, EntryKind, EntryName, Kind, NodeKey,
14+
PrincipalName, Record, RecordId, Revision, Statement, TargetName, Tree, TreeEntry, Verdict,
15+
};
16+
use origin_src::annotations::Annotations;
17+
use origin_src::queue::{Landing, Queue};
18+
use origin_src::store::Store;
19+
20+
fn main() {
21+
divan::main();
22+
}
23+
24+
/// A repository whose `policy` and `main` the node `queue` orders.
25+
struct Repo {
26+
_dir: tempfile::TempDir,
27+
store: Store,
28+
key: NodeKey,
29+
}
30+
31+
impl Repo {
32+
/// A repository where landing on `main` requires `require`, a TOML
33+
/// array.
34+
fn new(require: &str) -> Self {
35+
let dir = tempfile::tempdir().unwrap();
36+
let store = Store::new(dir.path().join(".origin"), Native::default());
37+
store.init().unwrap();
38+
let repo = Self {
39+
_dir: dir,
40+
store,
41+
key: NodeKey::from_bytes(&[7; 32]),
42+
};
43+
let policy = format!(
44+
"[nodes]\nqueue = \"{}\"\n[groups]\nrunners = [\"node:ci\"]\n\
45+
[targets.policy]\nauthority = \"node:queue\"\n\
46+
[targets.feature]\nauthority = \"node:queue\"\n\
47+
[targets.main]\nauthority = \"node:queue\"\nrequire = {require}\n",
48+
repo.key.public()
49+
);
50+
repo.queue().init(&policy).unwrap();
51+
repo
52+
}
53+
54+
fn queue(&self) -> Queue<'_> {
55+
Queue::new(&self.store, &self.key, PrincipalName::new("queue").unwrap())
56+
}
57+
58+
fn tip(&self) -> AcceptanceId {
59+
self.tip_of(&TargetName::MAIN)
60+
}
61+
62+
fn tip_of(&self, target: &TargetName) -> AcceptanceId {
63+
self.store.head(target).unwrap().unwrap().acceptance
64+
}
65+
66+
/// Writes a change made on `base`, a tip of `main`, adding the file
67+
/// `file-<n>`.
68+
fn change(&self, n: usize, base: AcceptanceId) -> ChangeId {
69+
let mut tree: Tree = self
70+
.store
71+
.get(self.store.get(base).unwrap().body().state)
72+
.unwrap();
73+
let content = EncodedObject::blob(format!("fn f{n}() {{}}\n").as_bytes());
74+
tree.insert(
75+
EntryName::new(format!("file-{n}")).unwrap(),
76+
TreeEntry {
77+
kind: EntryKind::File,
78+
id: content.id(),
79+
},
80+
);
81+
let tree = tree.encode();
82+
let mut id = [0; 16];
83+
id[..8].copy_from_slice(&(n as u64).to_le_bytes());
84+
let change = ChangeId::from_bytes(id);
85+
let revision = Revision {
86+
change,
87+
predecessors: Vec::new(),
88+
base: Base::Acceptance(base),
89+
deps: Vec::new(),
90+
snapshot: tree.id().into(),
91+
description: EncodedObject::blob(b"").id().into(),
92+
author: "user:bench".parse().unwrap(),
93+
}
94+
.encode();
95+
let description = EncodedObject::blob(b"");
96+
self.store.write_all(&[content, tree, description]).unwrap();
97+
self.store.write_all(&[revision]).unwrap();
98+
change
99+
}
100+
101+
fn land(&self, change: ChangeId) {
102+
self.land_on(change, &TargetName::MAIN);
103+
}
104+
105+
fn land_on(&self, change: ChangeId, onto: &TargetName) {
106+
let landings = self.queue().land_change(change, onto).unwrap();
107+
assert!(
108+
matches!(landings[..], [Landing::Landed { .. }]),
109+
"{landings:?}"
110+
);
111+
}
112+
}
113+
114+
/// One landing of a change made on the tip: no rebase, no requirement.
115+
#[divan::bench(sample_count = 50)]
116+
fn land_on_tip(bencher: Bencher<'_, '_>) {
117+
let repo = Repo::new("[]");
118+
let mut n = 0;
119+
bencher
120+
.with_inputs(|| {
121+
n += 1;
122+
repo.change(n, repo.tip())
123+
})
124+
.bench_local_values(|change| repo.land(change));
125+
}
126+
127+
/// One landing of a change made on an older tip, which the queue rebases
128+
/// into a new revision.
129+
#[divan::bench(sample_count = 50)]
130+
fn land_rebased(bencher: Bencher<'_, '_>) {
131+
let repo = Repo::new("[]");
132+
let first = repo.tip();
133+
let mut n = 0;
134+
bencher
135+
.with_inputs(|| {
136+
n += 1;
137+
repo.change(n, first)
138+
})
139+
.bench_local_values(|change| repo.land(change));
140+
}
141+
142+
/// One landing of a change made on the tip, with the `ci.test` result
143+
/// `main` requires.
144+
#[divan::bench(sample_count = 50)]
145+
fn land_with_requirement(bencher: Bencher<'_, '_>) {
146+
let repo = Repo::new(r#"[{ kind = "ci.test", verdict = "pass", issuer = "group:runners" }]"#);
147+
let mut n = 0;
148+
bencher
149+
.with_inputs(|| {
150+
n += 1;
151+
let change = repo.change(n, repo.tip());
152+
let annotations = Annotations::open(&repo.store).unwrap();
153+
let head = annotations.index().heads(change)[0];
154+
let result = Statement {
155+
subject: RecordId::Revision(head),
156+
kind: Kind::new("ci.test").unwrap(),
157+
verdict: Some(Verdict::Pass),
158+
issuer: "node:ci".parse().unwrap(),
159+
inputs: None,
160+
payload: None,
161+
supersedes: None,
162+
promoted_from: None,
163+
};
164+
annotations.issue(&result, None).unwrap();
165+
change
166+
})
167+
.bench_local_values(|change| repo.land(change));
168+
}
169+
170+
/// How many changes each target lands before they merge.
171+
const HISTORY: usize = 1_000;
172+
173+
/// Landing the tip of `feature` on `main` once each landed `HISTORY`
174+
/// changes since `feature` forked, after `feature` lands one more: the
175+
/// merge base reads both histories whole.
176+
#[divan::bench(sample_count = 20, sample_size = 1)]
177+
fn land_target_after_long_histories(bencher: Bencher<'_, '_>) {
178+
let repo = Repo::new("[]");
179+
let feature = TargetName::new("feature").unwrap();
180+
repo.queue()
181+
.create_target(&feature, &TargetName::MAIN)
182+
.unwrap();
183+
for n in 0..HISTORY {
184+
repo.land(repo.change(n, repo.tip()));
185+
let change = repo.change(HISTORY + n, repo.tip_of(&feature));
186+
repo.land_on(change, &feature);
187+
}
188+
let mut n = 2 * HISTORY;
189+
bencher
190+
.with_inputs(|| {
191+
n += 1;
192+
let change = repo.change(n, repo.tip_of(&feature));
193+
repo.land_on(change, &feature);
194+
})
195+
.bench_local_values(|()| {
196+
let landing = repo
197+
.queue()
198+
.land_target(&feature, &TargetName::MAIN)
199+
.unwrap();
200+
assert!(matches!(landing, Landing::Landed { .. }), "{landing:?}");
201+
});
202+
}
203+
204+
/// How many changes each proposer lands.
205+
const EACH: usize = 8;
206+
207+
/// `proposers` threads landing `EACH` changes each on `main` at once, all
208+
/// made on its first tip, so all but the first are rebased. Threads lock
209+
/// the queue as processes do: the lock belongs to the open file.
210+
#[divan::bench(args = [1, 2, 4, 8], sample_count = 5, sample_size = 1)]
211+
fn concurrent_proposers(bencher: Bencher<'_, '_>, proposers: usize) {
212+
bencher
213+
.counter(ItemsCount::new(proposers * EACH))
214+
.with_inputs(|| {
215+
let repo = Repo::new("[]");
216+
let first = repo.tip();
217+
let changes: Vec<_> = (0..proposers * EACH)
218+
.map(|n| repo.change(n, first))
219+
.collect();
220+
(repo, changes)
221+
})
222+
.bench_local_values(|(repo, changes)| {
223+
thread::scope(|scope| {
224+
for changes in changes.chunks(EACH) {
225+
let repo = &repo;
226+
scope.spawn(move || {
227+
for &change in changes {
228+
repo.land(change);
229+
}
230+
});
231+
}
232+
});
233+
(repo, changes)
234+
});
235+
}

0 commit comments

Comments
 (0)