ReviewOS

also looking at this

stacks/buddy

fix: report skipped gates as skipped, and honour ai.majorUpgrades.maxAttempts

#1433
Merged glennmichael123 wants to merge fix/gate-neutral into main
9 files +257 -8
src/upgrades/migrate.tsmodified+42-3
Changes to src/upgrades/migrate.ts
@@ -38,6 +38,16 @@ export interface UpgradeOptions {
3838 autoMigrate?: boolean
3939 /** Open as draft below this confidence (default: high) */
4040 draftBelowConfidence?: MigrationConfidence
41 /**
42 * Agent runs allowed before the migration is reported as failed (default: 1).
43 *
44 * Declared on `ai.majorUpgrades` and documented, and the agent ran exactly
45 * once whatever it said. A second attempt is handed the first one's output
46 * so it continues rather than starting over.
47 */
48 maxAttempts?: number
49 /** The agent runner; injectable so attempts can be tested without a model */
50 agent?: typeof runAgent
4151 logger?: Logger
4252}
4353
@@ -116,9 +126,13 @@ export async function attemptMajorUpgrade(options: UpgradeOptions): Promise<Upgr
116126 return { plan, report: renderMigrationReport(plan, undefined, usage), draft: false, status: 'analysis-only' }
117127 }
118128
119 const result = await runAgent(options.ai, {
129 const run = options.agent ?? runAgent
130 const maxAttempts = Math.max(1, Math.floor(options.maxAttempts ?? 1))
131 const task = buildMigrationTask(plan)
132
133 let result = await run(options.ai, {
120134 mode: implementMode,
121 task: buildMigrationTask(plan),
135 task,
122136 context: {
123137 workspace: options.workspace,
124138 baseBranch: options.baseBranch,
@@ -126,11 +140,36 @@ export async function attemptMajorUpgrade(options: UpgradeOptions): Promise<Upgr
126140 },
127141 logger,
128142 })
143 let attempts = 1
144 let applied = result.toolCalls > 0
145
146 // A run that stopped short — out of tool calls, out of time, gave up — is
147 // handed its own output and asked to continue from the workspace as it now
148 // stands. Starting over would redo the work that did land.
149 while (result.stopReason !== 'completed' && attempts < maxAttempts) {
150 attempts++
151 logger.info(`🔧 Migration attempt ${attempts} of ${maxAttempts} (previous run ended: ${result.stopReason})`)
152
153 result = await run(options.ai, {
154 mode: implementMode,
155 task: `${task}\n\nA previous attempt ended (${result.stopReason}) with this output:\n\n${
156 result.output || '(no output)'
157 }\n\nContinue from the workspace as it stands now. Do not redo work that is already done.`,
158 context: {
159 workspace: options.workspace,
160 baseBranch: options.baseBranch,
161 ...(options.branch ? { branch: options.branch } : {}),
162 },
163 logger,
164 })
165 applied = applied || result.toolCalls > 0
166 }
129167
130168 const verified = result.stopReason === 'completed'
131169 const outcome: MigrationOutcome = {
132 applied: result.toolCalls > 0,
170 applied,
133171 verified,
172 attempts,
134173 changedFiles: knownFiles,
135174 unresolved: verified ? [] : plan.changes.filter(change => !change.automatable).map(change => change.action),
136175 ...(verified ? {} : { verificationOutput: result.output }),