Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(refresh): replan only under the upstream the precheck recorded
garrytand1a2e37f9c4b
diff --git a/src/core/persistence/worktree-refresh.ts b/src/core/persistence/worktree-refresh.tsindex 2e2988115c..d04493969c 100644--- a/src/core/persistence/worktree-refresh.ts+++ b/src/core/persistence/worktree-refresh.ts@@ -171,12 +171,15 @@ const OWN_COMMITS = "gbrain's own commits: writes admitted before the fence that/*** #8828: the drain waits for the writes admitted before the fence, and their commits move HEAD past the precheck's old_head. When* HEAD descends from old_head, every commit in old_head..HEAD is in gbrain's commit ledger, and the upstream ref (which the writer's- * push moves) holds HEAD and the verified target, the fenced refresh takes HEAD as its start and that upstream as its target instead+ * push moves, and which must still be the upstream_ref the precheck recorded) holds HEAD and the verified target, the fenced refresh+ * takes HEAD as its start and that upstream as its target instead* of refusing: the fence defers new writes and the caller's commit lock keeps gbrain's commits out. The row changes only while it is* fenced with no merge started. Null otherwise, and the caller refuses refresh_source_changed as before.*/async function replanOnOwnCommits(engine: BrainEngine, git: Git, root: string, row: WorktreeRefreshRow, head: string): Promise<WorktreeRefreshRow | null> {if (await ancestry(git, root, row.old_head, head) !== true || !await ownCommits(git, root, row.old_head, head)) return null;+ const upstream = await git(['-C', root, 'rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}']);+ if (upstream.code !== 0 || upstream.stdout.trim() !== row.upstream_ref) return null;const target = await revParse(git, root, '@{upstream}');if (!target || (target !== head && !await isAncestor(git, root, head, target)) || !await isAncestor(git, root, row.target_head, target)) return null;const [replanned] = await engine.transaction(async tx => {diff --git a/test/refresh-own-commits-replan-8828.test.ts b/test/refresh-own-commits-replan-8828.test.tsindex 535e260b6f..370436c2b1 100644--- a/test/refresh-own-commits-replan-8828.test.ts+++ b/test/refresh-own-commits-replan-8828.test.ts@@ -105,3 +105,20 @@ test('#8828: one foreign commit among gbrain\'s own published commits still refuexpect(rows).toHaveLength(2);for (const row of rows) expect(row.state).toBe('aborted');}), 180_000);++test('#8828: own published commits under an upstream other than the one the precheck recorded still refuse refresh_source_changed and merge nothing', () => each(async f => {+ f.push('alpha/two.md', page('Alpha two', 'An upstream observation.'));+ const landed: Array<{ own: string; published: string }> = [];+ const refused = await refreshWorktree(f.engine, f.alpha, { hooks: { boundary: async point => {+ if (point !== 'drained') return;+ const n = landed.length + 1;+ landed.push(ownCommitPublished(f, n));+ git(f.root, 'push', '-q', 'origin', `${landed[n - 1]!.published}:refs/heads/other-${n}`);+ git(f.root, 'fetch', '-q', 'origin');+ git(f.root, 'branch', '-q', `--set-upstream-to=origin/other-${n}`);+ } } }).then(() => null, thrown => thrown as { code?: string; message: string });+ expect(refused?.code).toBe('refresh_source_changed');+ expect(landed.length).toBeGreaterThan(0);+ expect(f.head()).toBe(landed[landed.length - 1]!.own);+ for (const row of await f.refreshRows()) expect(row.state).toBe('aborted');+}), 180_000);