From 78df95d853fa98962af6640d738b5cf9f2aeebd8 Mon Sep 17 00:00:00 2001 From: "dam-application[bot]" <280654635+dam-application[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 13:12:52 +0000 Subject: [PATCH] fix: an item with work pushed past its merged pull requests is not done (6.16.2) Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 11 ++++++++++- VERSION | 2 +- app/src/developer/run-state.ts | 15 +++++++++++--- app/src/factory/git.ts | 14 +++++++++++++ app/test/run-state.test.ts | 36 ++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c9136..5895b6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.** @@ -34,7 +44,6 @@ nothing changes. **Upgrade:** optional, in the direct session — add `- prune: ` to `work/CONFIG.md`. - ## 6.15.2 — 2026-11-05 **A demo shows the change for real, or there is none.** A demo Environment diff --git a/VERSION b/VERSION index 954ea49..cd8864f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.16.1 +6.16.2 diff --git a/app/src/developer/run-state.ts b/app/src/developer/run-state.ts index eb2b657..fa4f7c3 100644 --- a/app/src/developer/run-state.ts +++ b/app/src/developer/run-state.ts @@ -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 { + /** + * 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 { 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 } @@ -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, { diff --git a/app/src/factory/git.ts b/app/src/factory/git.ts index c6ad23c..18b9732 100644 --- a/app/src/factory/git.ts +++ b/app/src/factory/git.ts @@ -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\//, ""); diff --git a/app/test/run-state.test.ts b/app/test/run-state.test.ts index ff8a0bd..8f82053 100644 --- a/app/test/run-state.test.ts +++ b/app/test/run-state.test.ts @@ -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);