Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Applying the kit never touches an agent already created from it, so an instance
crosses a version only when its operator walks it through these steps, in the
direct session.

## 6.16.2 — 2026-11-10

**An item with work pushed past its merged pull requests is not done.** `start`
releases an item whose recorded pull requests are all merged or closed only
when the branch it starts on holds nothing the default branch lacks. An issue
planned as several pull requests keeps its next one's work on a branch of its
own, and `start` now takes a slot for it there instead of releasing the item.

**Upgrade:** nothing.

## 6.16.1 — 2026-11-10

**A run asks for review with the reviewer's own label, and never creates one.**
Expand All @@ -34,7 +44,6 @@ nothing changes.

**Upgrade:** optional, in the direct session — add `- prune: <command>` to
`work/CONFIG.md`.

## 6.15.2 — 2026-11-05

**A demo shows the change for real, or there is none.** A demo Environment
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.16.1
6.16.2
15 changes: 12 additions & 3 deletions app/src/developer/run-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,19 @@ class RunState {
return this.itemKey(item, "pr").split(/\s+/).filter(Boolean);
}

/** Every pull request on the item's record is merged or closed; one unread is not. */
async allDone(item: string): Promise<boolean> {
/**
* Every pull request on the item's record is merged or closed, and the
* branch the run starts on holds nothing the default branch lacks; one
* unread is not. An issue planned as several pull requests keeps its later
* work on a branch of its own before that pull request is opened, and that
* work is not done because the earlier ones merged.
*/
async allDone(item: string, branch: string): Promise<boolean> {
const refs = this.prsOf(item).flatMap((a) => parsePrRef(a, this.kit.slug) ?? []);
if (refs.length === 0) return false;
const co = this.kit.checkout;
for (const ref of [this.kit.git.defaultBranch(co), branch]) this.kit.git.run(co, ["fetch", "-q", "origin", ref]);
if (this.kit.git.remoteAhead(co, branch)) return false;
for (const ref of refs) {
const view = (await this.deps.github.prView(this.kit.host, ref.slug, ref.number, "state")) as
| { state?: string }
Expand Down Expand Up @@ -220,7 +229,7 @@ class RunState {
// an item whose pull requests all merged or closed only needs its release
// — labels, a comment, finish released — and no worktree: it takes no
// slot, so a full house never holds it back (docs/babysit.md → Merged)
if (!this.mySlot() && (await this.allDone(item))) {
if (!this.mySlot() && (await this.allDone(item, branch))) {
this.resume(item, "-", "releasing");
this.logLine("resumed", this.kit.me, item, "-", this.prsOf(item).join(","), this.now(), "cause=released");
this.writeItem(item, {
Expand Down
14 changes: 14 additions & 0 deletions app/src/factory/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ export class Git {
this.run(dir, ["switch", "-q", "--detach", ...onto]);
}

/**
* Whether a branch on origin holds work the default branch lacks: merging it
* into the default branch would change something. A branch whose pull
* request merged by squash, or that never moved, holds nothing new. A branch
* that is not on origin holds nothing to lose here.
*/
remoteAhead(co: string, branch: string): boolean {
const ref = `origin/${branch}`;
if (!this.hasRef(co, ref)) return false;
const dflt = `origin/${this.defaultBranch(co)}`;
const merged = this.line(co, ["merge-tree", "--write-tree", dflt, ref]);
return merged === "" || merged !== this.line(co, ["rev-parse", `${dflt}^{tree}`]);
}

/** The default branch: origin/HEAD, else what the remote says, else main. */
defaultBranch(co: string): string {
const head = this.line(co, ["rev-parse", "--abbrev-ref", "origin/HEAD"]).replace(/^origin\//, "");
Expand Down
36 changes: 36 additions & 0 deletions app/test/run-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,42 @@ test("a parked item whose pull request merged is released with every slot busy",
);
}));

test("an item whose recorded pull request merged, with more work pushed on its branch, takes a slot", () =>
inSandbox(async (s) => {
world(s);
s.originCheckout();
s.github.on(PULL, PULL21);
s.github.prViews = [view("OPEN", "REVIEW_REQUIRED", "MERGEABLE", GREEN)];
await as(s, "sess-a", "start", "7", "feat/7");
await as(s, "sess-a", "park", "21");
s.github.prViews = [view("MERGED", "APPROVED", "UNKNOWN", GREEN)];
const part2 = join(s.home, "part2");
s.git(["clone", "-q", join(s.home, "widgets.git"), part2]);
s.git(["checkout", "-q", "-b", "feat/7-part2"], part2);
writeFileSync(join(part2, "part2.txt"), "the second pull request\n");
s.git(["add", "-A"], part2);
s.git(["-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "part 2"], part2);
s.git(["push", "-q", "origin", "feat/7-part2"], part2);
const r = await as(s, "sess-a", "start", "7", "feat/7-part2");
assert.equal(r.rc, 0, r.err);
assert.doesNotMatch(r.out, /no slot needed/);
assert.equal(s.slot(1), "feat/7-part2", "the slot is on the branch with the work");
}));

test("an item whose recorded pull request merged, on a branch with nothing new, needs no slot", () =>
inSandbox(async (s) => {
world(s);
s.originCheckout();
s.github.on(PULL, PULL21);
s.github.prViews = [view("OPEN", "REVIEW_REQUIRED", "MERGEABLE", GREEN)];
await as(s, "sess-a", "start", "7", "feat/7");
await as(s, "sess-a", "park", "21");
s.github.prViews = [view("MERGED", "APPROVED", "UNKNOWN", GREEN)];
const r = await as(s, "sess-a", "start", "7");
assert.equal(r.rc, 0, r.err);
assert.match(r.out, /no slot needed/);
}));

test("wait refuses while the exclusive lock is held", () =>
inSandbox(async (s) => {
world(s);
Expand Down
Loading