xonecas.io
8447
Co

conveyor / commit f43a892

Code tickets start from the stack: main plus every branch in review

As widget builds start from the trial. Tickets run in parallel as slots allow; one
that finishes later merges what finished before it, since done checks against the
stack. Checks run one at a time, and a passed one joins the stack at once, so two
tickets finishing together still see each other. Landing a ticket lands the ones
it was built on (they move to done). A resumed ticket's agent gets the retry note.

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-10 f43a89205623a41e11c81fd8d8adb98cab96a3b3 parent fdcfa91

6 files changed

DESIGN.md+2−2
@@ -89,11 +89,11 @@ Measured from the rats store in the VM: 2 projects, 314 tickets, 5 MB in total.
8989 | `refine` | throwaway VM, no branch | agent: does discovery and writes scope, acceptance and out-of-scope. Output goes to `scope/` |
9090 | `needs-scope` | store | you add resources, answer or steer. **It always goes back to `refine`**, never straight to `ready` |
9191 | `ready` | store | dispatcher, when a slot and a repo exist. You can still send it back to `refine` |
92-| `running` | ticket VM + branch | agent |
92+| `running` | ticket VM + branch | agent. A code ticket starts from main plus every branch in review (the stack), as a widget build starts from the trial |
9393 | `parked` | VM kept, suspended | you answer; the agent resumes |
9494 | `verify` | ticket VM | conveyor runs the acceptance checks, not the agent |
9595 | `review` | host | you |
96-| `done` | store | the branch merged into main and deleted (Keep, for a widget build). A conflict, or a checkout git won't touch, keeps it in review and says why |
96+| `done` | store | the branch merged into main and deleted (Keep, for a widget build), with the tickets in review it was built on. A conflict, or a checkout git won't touch, keeps it in review and says why |
9797
9898 Only `needs-scope`, `parked`, `deviate` and `review` reach you. Each is a call to action with one line, the agent's recommendation and its attachments.
9999
HANDOFF.md+1−0
@@ -69,3 +69,4 @@ rune (38 s, against 12 s).
6969 | `a1a5277` | Widgets get serde in the app, a secrets store, and failed builds resume their branch |
7070 | `9f8c1e2` | The keychain reaches agents as env vars; `cx.secrets()` lists it |
7171 | `land.rs` | Done from review merges a code ticket's branch into main, as Keep does for widgets |
72+| `stack` | A code ticket starts from main plus every branch in review; landing it lands those too. A retry note reaches the agent |
crates/conveyor/src/agent.rs+46−17
@@ -37,7 +37,9 @@ fn run(p: &Project, id: u32) -> Result<String, String> {
3737 && git config user.name conveyor && git config user.email conveyor@localhost", b"")?;
3838 let (url, git_ssh) = vm.git_remote("/home/sacenox/work");
3939 // A widget build starts from what the user sees: the library with every build on trial.
40- git(&p.path, &git_ssh, &["push", "-q", &url, if p.library { library::BASE } else { "main:main" }])?;
40+ // A code ticket starts from main plus every branch in review: the stack.
41+ let base = if p.library { library::BASE.into() } else { format!("{}:refs/heads/main", stack(p, id)?) };
42+ git(&p.path, &git_ssh, &["push", "-q", &url, &base])?;
4143 // A ticket that ran before (it failed, or was parked) picks up its own branch.
4244 let resumed = git(&p.path, "", &["rev-parse", "-q", "--verify", &branch]).is_ok();
4345 if resumed { git(&p.path, &git_ssh, &["push", "-q", &url, &format!("{branch}:{branch}")])?; }
@@ -46,7 +48,7 @@ fn run(p: &Project, id: u32) -> Result<String, String> {
4648
4749 let local = crate::paths::vm_sock(&name, "verbs");
4850 let remote = format!("/home/{}/.conveyor/{name}-{}.sock", vm::USER, std::process::id());
49- let check = merges_onto(p, &url, &git_ssh, &branch);
51+ let check = merges_onto(p, id, &url, &git_ssh, &branch);
5052 let verbs = Listener::start(&p.slug, id, local.clone(), check).map_err(|e| e.to_string())?;
5153 note("agent working");
5254 let stream = File::create(store::dir(&p.slug, id).join("stream.jsonl")).map_err(|e| e.to_string())?;
@@ -78,27 +80,54 @@ fn run(p: &Project, id: u32) -> Result<String, String> {
7880 })
7981 }
8082
81-/// What `done` checks: the branch still merges onto what it goes on (the trial, or main), which
82-/// may have moved while the agent worked. If not, that goes into the guest as a branch of the
83-/// same name, for the agent to merge.
84-pub(crate) fn merges_onto(p: &Project, url: &str, git_ssh: &str, branch: &str) -> impl Fn() -> Result<(), String> + Send + 'static {
85- let (repo, url, git_ssh, branch) = (p.path.clone(), url.to_owned(), git_ssh.to_owned(), branch.to_owned());
86- let onto = if p.library { "trial" } else { "main" };
83+/// What `done` checks: the branch still merges onto what it goes on (the trial, or the stack),
84+/// which may have moved while the agent worked. If not, that goes into the guest as its branch
85+/// (`trial`, or `main`), for the agent to merge.
86+pub(crate) fn merges_onto(p: &Project, id: u32, url: &str, git_ssh: &str, branch: &str) -> impl Fn() -> Result<(), String> + Send + 'static {
87+ let (p, url, git_ssh, branch) = (p.clone(), url.to_owned(), git_ssh.to_owned(), branch.to_owned());
8788 move || {
88- git(&repo, &git_ssh, &["fetch", "-q", &url, &format!("+{branch}:{branch}")])?;
89- let Err(files) = library::merges(&repo, onto, &branch) else { return Ok(()) };
90- git(&repo, &git_ssh, &["push", "-q", "-f", &url, &format!("{onto}:{onto}")])?;
91- Err(format!("Not done yet: while you worked, the user kept or tried other builds, and your branch conflicts with them in {files}. \
92- Run `git merge {onto}`, resolve it so both changes survive, check it again, commit, then `conveyor done` again."))
89+ // One check at a time, and a passed one counts in the stack at once: two tickets that
90+ // finish together can't both pass without seeing each other.
91+ static ONE: std::sync::Mutex<()> = std::sync::Mutex::new(());
92+ let _one = ONE.lock().unwrap_or_else(|e| e.into_inner());
93+ git(&p.path, &git_ssh, &["fetch", "-q", &url, &format!("+{branch}:{branch}")])?;
94+ let (onto, name) = if p.library { ("trial".into(), "trial") } else { (stack(&p, id)?, "main") };
95+ let Err(files) = library::merges(&p.path, &onto, &branch) else {
96+ store::event(&p.slug, id, json!({"kind": "conveyor", "msg": "done: it merges onto the work in review", "checked": true}));
97+ return Ok(());
98+ };
99+ git(&p.path, &git_ssh, &["push", "-q", "-f", &url, &format!("{onto}:refs/heads/{name}")])?;
100+ Err(format!("Not done yet: while you worked, the user kept or tried other work, and your branch conflicts with it in {files}. \
101+ Run `git merge {name}`, resolve it so both changes survive, check it again, commit, then `conveyor done` again."))
93102 }
94103 }
95104
96-/// For a ticket that ran before: where its work is, and why it stopped.
105+/// A code ticket's stack: main plus the branches of the project's other tickets in review, or
106+/// running with `done` passed.
107+fn stack(p: &Project, id: u32) -> Result<String, String> {
108+ let branches: Vec<String> = store::tickets(&p.slug).iter()
109+ .filter(|t| t.id != id && (t.state == "review" || t.state == "running" && checked(&p.slug, t.id)))
110+ .map(|t| format!("t-{}", t.id)).filter(|b| git(&p.path, "", &["rev-parse", "-q", "--verify", b]).is_ok()).collect();
111+ crate::land::stack(&p.path, &branches)
112+}
113+
114+/// Whether this run of the ticket passed its `done` check.
115+fn checked(project: &str, id: u32) -> bool {
116+ let events = store::events(project, id);
117+ let run = events.iter().rposition(|e| e["kind"] == "state" && e["state"] == "running").unwrap_or(0);
118+ events[run..].iter().any(|e| e["checked"] == true)
119+}
120+
121+/// For a ticket that ran before: where its work is, why it stopped, and the user's note since.
97122 fn stopped(project: &str, id: u32) -> String {
98- let why = store::events(project, id).into_iter().rev()
123+ let events = store::events(project, id);
124+ let why = events.iter().rev()
99125 .find_map(|e| e["msg"].as_str().filter(|_| e["kind"] == "error").or(e["args"]["reason"].as_str().filter(|_| e["verb"] == "block")).map(String::from))
100- .unwrap_or_else(|| "it stopped before finishing".into());
101- format!("\n\nThis ticket ran before. Its work is on your branch (`git log main..`): continue from it. It stopped because:\n\n{why}")
126+ .unwrap_or_else(|| "the user moved it back to ready.".into());
127+ let since = events.iter().rposition(|e| e["kind"] == "reply").map_or(0, |i| i + 1);
128+ let note = events[since..].iter().rev().find(|e| e["kind"] == "conveyor" && e["show"] == true)
129+ .and_then(|e| e["msg"].as_str()).map_or(String::new(), |n| format!("\n\nThe user's note since:\n\n{n}"));
130+ format!("\n\nThis ticket ran before. Its work is on your branch (`git log main..`): continue from it. It stopped because:\n\n{why}{note}")
102131 }
103132
104133 /// Copies the ticket's attached files to ~/ticket/files in the guest. What the prompt says of them.
crates/conveyor/src/land.rs+39−1
@@ -1,7 +1,25 @@
1-//! Lands a code project's finished ticket: its branch merges into main, as Keep does for widgets.
1+//! A code project's branches, as the widget library's trial does it: a ticket starts from main
2+//! plus every branch in review, and landing it merges into main what it was built on too.
23 use crate::{agent::git, library::merges};
34 use std::path::Path;
45
6+/// What a code ticket starts from: main with `branches` (those in review, oldest first) merged
7+/// in, as one commit no branch points to. A branch that conflicts with those before it is left out.
8+pub fn stack(repo: &Path, branches: &[String]) -> Result<String, String> {
9+ let mut head = git(repo, "", &["rev-parse", "main"])?.trim().to_owned();
10+ for b in branches {
11+ if git(repo, "", &["merge-base", "--is-ancestor", b, &head]).is_ok() { continue; }
12+ if git(repo, "", &["merge-base", "--is-ancestor", &head, b]).is_ok() {
13+ head = git(repo, "", &["rev-parse", b])?.trim().to_owned();
14+ continue;
15+ }
16+ let Ok(tree) = git(repo, "", &["merge-tree", "--write-tree", "--no-messages", &head, b]) else { continue };
17+ head = git(repo, "", &["-c", "user.name=conveyor", "-c", "user.email=conveyor@localhost", "commit-tree", tree.trim(),
18+ "-p", &head, "-p", b, "-m", &format!("Merge branch '{b}'")])?.trim().to_owned();
19+ }
20+ Ok(head)
21+}
22+
523 /// Merges `branch` into `repo`'s main and deletes it. Leaves everything as it was, and says
624 /// why, when it conflicts with main or git won't touch the user's checkout.
725 pub fn land(repo: &Path, branch: &str) -> Result<(), String> {
@@ -54,6 +72,26 @@ mod tests {
5472 assert!(repo.join("b").exists() && repo.join("idea.md").exists());
5573 assert!(git(&repo, "", &["rev-parse", "-q", "--verify", "t-1"]).is_err());
5674
75+ // The stack: main, then t-a, then t-b built on t-a (no merge needed), and t-c, which
76+ // conflicts with t-a and is left out. A ticket built on it lands all it was built on.
77+ for (b, from, file, text) in [("t-a", "main", "x", "a\n"), ("t-b", "t-a", "y", "b\n"), ("t-c", "main", "x", "c\n")] {
78+ run(&repo, &["switch", "-qc", b, from]);
79+ commit(&repo, file, text);
80+ }
81+ run(&repo, &["switch", "-q", "main"]);
82+ commit(&repo, "z", "z\n");
83+ let names = |v: &[&str]| v.iter().map(|s| s.to_string()).collect::<Vec<_>>();
84+ let top = stack(&repo, &names(&["t-a", "t-b", "t-c"])).unwrap();
85+ let files = run(&repo, &["ls-tree", "--name-only", &top]);
86+ assert!(files.contains('y') && files.contains('z') && run(&repo, &["show", &format!("{top}:x")]) == "a\n");
87+ run(&repo, &["switch", "-qc", "t-d", &top]);
88+ commit(&repo, "w", "w\n");
89+ run(&repo, &["switch", "-q", "main"]);
90+ land(&repo, "t-d").unwrap();
91+ assert!(git(&repo, "", &["merge-base", "--is-ancestor", "t-b", "main"]).is_ok());
92+ assert_eq!(stack(&repo, &names(&["t-a", "t-b"])).unwrap(), run(&repo, &["rev-parse", "main"]).trim());
93+ run(&repo, &["branch", "-qD", "t-a", "t-b", "t-c"]);
94+
5795 // main moved meanwhile: a real merge.
5896 run(&repo, &["switch", "-qc", "t-2"]);
5997 commit(&repo, "c", "c\n");
crates/conveyor/src/library_tests.rs+1−1
@@ -79,7 +79,7 @@ fn trial_edges() {
7979 assert!(try_out(&p, c, &branch_c).unwrap_err().contains("kept since it started"));
8080 let guest = paths::data().join("guest");
8181 run(&paths::library(), &["clone", "-q", "-b", &branch_c, &paths::library().to_string_lossy(), &guest.to_string_lossy()]);
82- let check = crate::agent::merges_onto(&p, &guest.to_string_lossy(), "", &branch_c);
82+ let check = crate::agent::merges_onto(&p, c, &guest.to_string_lossy(), "", &branch_c);
8383 assert!(check().unwrap_err().contains("widgets/root.rs"));
8484 assert!(git(&guest, "", &[&COMMIT[..], &["merge", "-q", "trial"]].concat()).is_err());
8585 fs::write(guest.join("widgets/root.rs"), format!("{main_root}// b\n// c\n")).unwrap();
crates/conveyor/src/server.rs+8−0
@@ -69,6 +69,14 @@ fn set(project: &str, id: u32, state: &str) -> Result<Value, String> {
6969 if crate::agent::git(&p.path, "", &["rev-parse", "-q", "--verify", &branch]).is_ok() {
7070 crate::land::land(&p.path, &branch).inspect_err(|e| store::event(project, id, json!({"kind": "error", "msg": e})))?;
7171 store::event(project, id, json!({"kind": "conveyor", "msg": format!("merged into main: {branch} is gone")}));
72+ // It was built on the others in review: those it carried in are done too.
73+ for o in store::tickets(project).into_iter().filter(|o| o.state == "review" && o.id != id) {
74+ let b = format!("t-{}", o.id);
75+ if crate::agent::git(&p.path, "", &["merge-base", "--is-ancestor", &b, "main"]).is_err() { continue; }
76+ let _ = crate::agent::git(&p.path, "", &["branch", "-D", &b]);
77+ store::set_state(project, o.id, "done");
78+ store::event(project, o.id, json!({"kind": "conveyor", "msg": format!("merged into main with #{id}: {b} is gone")}));
79+ }
7280 }
7381 }
7482 store::set_state(project, id, state);