Skip to content

Commit 4347d6d

Browse files
anandgupta42claude
andcommitted
fix(learn): do not claim an externally written approved set as an auto-promotion
A `StoreError` from `Store.promote` is a refusal raised before any write, so approved lessons equal to the publish text then came from someone else (for example a pull) and must not be marked as automatically promoted. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent c599e14 commit 4347d6d

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎packages/opencode/src/altimate/learn/auto-promote.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,10 @@ export async function autoPromote(input: AutoPromoteInput): Promise<AutoPromoteR
302302
} catch (error) {
303303
// Store.promote can fail after approved.json was replaced (history, retired reconciliation). Then the
304304
// lessons are live: report the promotion and record its marks rather than claiming it was held.
305+
// A StoreError is a refusal raised before any write, so equal content then came from someone else
306+
// (e.g. a pull) and must not be claimed as this promotion.
305307
const current = await Store.readPromoted(root, name).catch(() => undefined)
306-
const landed = (() => {
308+
const landed = !(error instanceof Store.StoreError) && (() => {
307309
try { return current !== undefined && Lessons.canonical(Lessons.parse(current)) === publishText } catch { return false }
308310
})()
309311
if (landed)

‎packages/opencode/test/altimate/learn/auto-promote.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,25 @@ describe("auto-promote success path", () => {
251251
expect(line).toContain("auto-promoted (previous lessons archived as v1). Undo with `altimate-code learn rollback` (warning: published, but finishing failed")
252252
})
253253

254+
test("an identical approved set written by someone else is not claimed as this promotion", async () => {
255+
await using dir = await tmpdir({ git: true })
256+
await approve(dir.path, [A])
257+
const hash = await stage(dir.path, [A, B])
258+
const promote = spyOn(Store, "promote").mockImplementationOnce(async () => {
259+
// A concurrent pull installs the same lessons, then promote refuses before writing anything.
260+
await Store.writeAtomic(dir.path, Store.paths(dir.path, NAME).approved, await Store.readCandidate(dir.path, NAME) as string)
261+
throw new Store.StoreError("Candidate is identical to the approved lessons; nothing to promote.")
262+
})
263+
let result
264+
try {
265+
result = await autoPromote(input(dir.path, hash))
266+
} finally {
267+
promote.mockRestore()
268+
}
269+
expect(result).toMatchObject({ status: "held" })
270+
expect([...autoPromotedIds(await readAutoPromoteState(dir.path, NAME), await Store.loadApproved(dir.path, NAME))]).toEqual([])
271+
})
272+
254273
test("counter updates on person-approved lessons stay staged instead of going live", async () => {
255274
await using dir = await tmpdir({ git: true })
256275
await approve(dir.path, [A])

0 commit comments

Comments
 (0)