feat: orch up starts issue sessions in existing worktrees
build / version (push) Successful in 1m20s
build / build (aarch64-apple-darwin) (push) Successful in 5m55s
build / build (x86_64-unknown-linux-musl) (push) Successful in 4m1s
build / release (push) Successful in 21s

orch up MANIFEST reads an issue manifest (a path, or NAME in manifest_dir,
default <config>/manifests, set in <config>/config.toml) and starts one
detached session per listed worktree, across repos. Each worktree brings its
own machine, profile and .hx/task.md; the task text now reaches the agent.
Sessions live in <state>/issues.db; orch issues shows them grouped by issue.

Also: liveness checks use kill(pid, 0) instead of /proc (broken on macOS),
the same branch name in two repos no longer counts as the same place, and
the merge queue column ticket is renamed to issue (migrated on open).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Johannes KresnerandClaude Opus 5.5 committed 2026-11-16 15:56:58 +01:00
1 parent 440b19180e
commit 20f88d88df
16 files changed
+791 -65

No files matched your search

+56 -7
View File
@@ -30,7 +30,7 @@ create table if not exists commands(
id integer primary key autoincrement, session_id text not null, kind text not null,
payload text not null default '{}', at integer not null, done integer not null default 0);
create table if not exists merge_queue(
ticket integer primary key autoincrement, session_id text not null unique);
issue integer primary key autoincrement, session_id text not null unique);
create table if not exists needs(
id integer primary key autoincrement, session_id text not null, kind text not null,
payload text not null default '{}', created_at integer not null, answer text,
@@ -119,6 +119,15 @@ impl Db {
conn.busy_timeout(std::time::Duration::from_secs(5))?;
conn.pragma_update(None, "journal_mode", "WAL")?;
conn.execute_batch(SCHEMA)?;
// databases from before the rename call the merge queue's number `ticket`
let old: bool = conn.query_row(
"select count(*) > 0 from pragma_table_info('merge_queue') where name = 'ticket'",
[],
|r| r.get(0),
)?;
if old {
conn.execute_batch("alter table merge_queue rename column ticket to issue")?;
}
Ok(Self {
conn,
path: path.to_path_buf(),
@@ -184,14 +193,14 @@ impl Db {
Ok(rows.collect::<rusqlite::Result<_>>()?)
}
/// Joins the merge queue (once) and returns the ticket; lower tickets merge first.
/// Joins the merge queue (once) and returns the issue; lower issues merge first.
pub fn queue_join(&self, session: &str) -> Result<i64> {
self.conn.execute(
"insert or ignore into merge_queue(session_id) values (?1)",
[session],
)?;
Ok(self.conn.query_row(
"select ticket from merge_queue where session_id = ?1",
"select issue from merge_queue where session_id = ?1",
[session],
|r| r.get(0),
)?)
@@ -202,7 +211,7 @@ impl Db {
Ok(self
.conn
.query_row(
"select session_id from merge_queue order by ticket limit 1",
"select session_id from merge_queue order by issue limit 1",
[],
|r| r.get(0),
)
@@ -212,8 +221,8 @@ impl Db {
/// 1 = head of the queue.
pub fn queue_position(&self, session: &str) -> Result<usize> {
let n: i64 = self.conn.query_row(
"select count(*) from merge_queue where ticket <=
(select ticket from merge_queue where session_id = ?1)",
"select count(*) from merge_queue where issue <=
(select issue from merge_queue where session_id = ?1)",
[session],
|r| r.get(0),
)?;
@@ -382,7 +391,11 @@ impl Db {
);
self.set_session(id, &s.state, "suspended")?;
self.set_pid(id, None)?;
self.emit(id, "restart", serde_json::json!({"from": s.status, "state": s.state}))?;
self.emit(
id,
"restart",
serde_json::json!({"from": s.status, "state": s.state}),
)?;
Ok(())
}
@@ -394,6 +407,20 @@ impl Db {
Ok(())
}
/// Every `options` event of a session merged into one object, later keys win (`no_merge`, and for an issue
/// session `issue`, `repo`, `profile` and `task`).
pub fn options(&self, session: &str) -> Result<serde_json::Map<String, Value>> {
let mut m = serde_json::Map::new();
for e in self.events(Some(session), 0)? {
if e.kind == "options"
&& let Value::Object(o) = e.payload
{
m.extend(o);
}
}
Ok(m)
}
/// Append one event; returns its id.
pub fn emit(&self, session: &str, kind: &str, payload: Value) -> Result<i64> {
self.conn.execute(
@@ -558,6 +585,28 @@ mod tests {
(Db::open(&d.join("orch.db")).unwrap(), d)
}
#[test]
fn old_merge_queue_column_is_renamed() {
let d = std::env::temp_dir().join(format!("orch-db-mq-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&d);
std::fs::create_dir_all(&d).unwrap();
let path = d.join("orch.db");
Connection::open(&path)
.unwrap()
.execute_batch(
"create table merge_queue(ticket integer primary key autoincrement, session_id text not null unique);
insert into merge_queue(session_id) values ('s1');",
)
.unwrap();
let db = Db::open(&path).unwrap();
assert_eq!(db.queue_head().unwrap().as_deref(), Some("s1"));
db.queue_join("s2").unwrap();
assert_eq!(db.queue_position("s2").unwrap(), 2);
drop(db);
Db::open(&path).unwrap(); // a second open finds nothing to rename
let _ = std::fs::remove_dir_all(&d);
}
#[test]
fn roundtrip() {
let (db, dir) = temp_db("rt");