@@ -114,7 +114,12 @@ import {
114114 type TargetValidationOptions ,
115115} from "./target-validation.js" ;
116116import { uniqueStrings } from "./validation-command-utils.js" ;
117+ import {
118+ rebaseConflictEditDecision ,
119+ unresolvedRebaseConflictReason ,
120+ } from "./rebase-conflict-policy.js" ;
117121import { validateActivePrAreaCapacity } from "./execute-fix-area-capacity.js" ;
122+ import { issueImplementationTerminalOutcome } from "./issue-implementation-outcome.js" ;
118123import {
119124 repairPauseLabel ,
120125 validateAutonomousFixScope ,
@@ -666,18 +671,26 @@ try {
666671 } ) ;
667672 throw error ;
668673 }
674+ const unresolvedRebaseConflicts = unresolvedRebaseConflictReason ( error ) ;
669675 outcome = {
670- action : "execute_fix" ,
676+ action : unresolvedRebaseConflicts ? "needs_human" : "execute_fix" ,
671677 status : "blocked" ,
672678 repair_strategy : fixArtifact . repair_strategy ,
673679 reason : error . message ,
674- ...( isRetryableCodexFailure ( error ) ? { requeue_required : true } : { } ) ,
680+ ...( unresolvedRebaseConflicts
681+ ? { needs_human : [ unresolvedRebaseConflicts ] }
682+ : isRetryableCodexFailure ( error )
683+ ? { requeue_required : true }
684+ : { } ) ,
675685 } ;
676686 }
677687}
678688
679- report . status = outcome . status ;
689+ report . status = outcome . action === "needs_human" ? "needs_human" : outcome . status ;
680690if ( outcome . reason && ! report . reason ) report . reason = outcome . reason ;
691+ if ( Array . isArray ( outcome . needs_human ) && outcome . needs_human . length > 0 ) {
692+ report . needs_human = uniqueStrings ( [ ...( report . needs_human ?? [ ] ) , ...outcome . needs_human ] ) ;
693+ }
681694report . actions . push ( outcome ) ;
682695writeReport ( report , resultPath ) ;
683696if ( outcome . requeue_required === true ) process . exitCode = 1 ;
@@ -1982,7 +1995,10 @@ function editValidatePrepareMerge({
19821995 repositoryContext,
19831996 reconcileWithBase,
19841997 sourceHead,
1985- rebaseResult,
1998+ rebaseResult :
1999+ rebaseResult ?. status === "conflicts"
2000+ ? { ...rebaseResult , unmerged_paths : unmergedPaths ( targetDir ) }
2001+ : rebaseResult ,
19862002 maxEditAttempts,
19872003 validationCommands : validationPreflight . resolved_commands ?? [ ] ,
19882004 isAutomergeRepair : isAutomergeRepairJob ( ) ,
@@ -2029,37 +2045,49 @@ function editValidatePrepareMerge({
20292045 stderrPath : path . join ( workRoot , `${ mode } -codex-${ attempt } .stderr.log` ) ,
20302046 } ,
20312047 ) ;
2032- if ( ( codexResult . error as JsonValue ) ?. code === "ETIMEDOUT" ) {
2033- throw new Error ( `Codex fix worker timed out after ${ workerTimeoutMs } ms` ) ;
2034- }
2035- if ( codexResult . error ) {
2036- const errorDetail = codexFailureDetail (
2037- codexResult ,
2038- codexResult . error . message || String ( codexResult . error ) ,
2039- ) ;
2040- if ( attempt < maxEditAttempts && isRetryableCodexErrorMessage ( errorDetail ) ) {
2041- previousSummary = compactText ( errorDetail , 360 ) ;
2042- const retryDelayMs = codexRetryDelayMs ( errorDetail , attempt ) ;
2043- logProgress ( "retrying Codex edit pass after transient transport error" , {
2044- mode,
2048+ const timedOut = ( codexResult . error as JsonValue ) ?. code === "ETIMEDOUT" ;
2049+ const errorDetail = timedOut
2050+ ? `Codex fix worker timed out after ${ workerTimeoutMs } ms`
2051+ : codexResult . error
2052+ ? codexFailureDetail ( codexResult , codexResult . error . message || String ( codexResult . error ) )
2053+ : codexResult . status !== 0
2054+ ? codexFailureDetail ( codexResult , "Codex fix worker failed" )
2055+ : "" ;
2056+ const remainingConflicts =
2057+ rebaseResult ?. status === "conflicts" ? unmergedPaths ( targetDir ) : [ ] ;
2058+ // Worker failures keep their transport/terminal classification. Only a completed
2059+ // edit pass that leaves conflicts consumes the bounded conflict-repair budget.
2060+ const conflictDecision = errorDetail
2061+ ? { action : "proceed" as const }
2062+ : rebaseConflictEditDecision ( {
2063+ rebaseStatus : rebaseResult ?. status ,
2064+ unmergedPaths : remainingConflicts ,
20452065 attempt,
2046- max_attempts : maxEditAttempts ,
2047- retry_delay_ms : retryDelayMs ,
2048- } ) ;
2049- updateAutomergeProgressStatus ( {
2050- id : `codex-edit-${ mode } -${ attempt } ` ,
2051- label : `Codex edit ${ attempt } ` ,
2052- status : "retrying" ,
2053- details : "transient Codex transport error" ,
2054- headSha : currentHead ( targetDir ) ,
2066+ maxEditAttempts,
20552067 } ) ;
2056- sleepMs ( retryDelayMs ) ;
2057- continue ;
2058- }
2059- throw new Error ( codexFailureMessage ( "Codex fix worker failed" , errorDetail ) ) ;
2068+ if ( conflictDecision . action !== "proceed" ) {
2069+ previousSummary =
2070+ readTextIfExists ( summaryPath ) . trim ( ) ||
2071+ compactText ( errorDetail , 360 ) ||
2072+ `Rebase conflicts remain unresolved after edit attempt ${ attempt } : ${ remainingConflicts . join ( ", " ) } ` ;
2073+ logProgress ( "rebase conflicts remain after Codex edit pass" , {
2074+ mode,
2075+ attempt,
2076+ max_attempts : maxEditAttempts ,
2077+ unresolved : remainingConflicts ,
2078+ } ) ;
2079+ updateAutomergeProgressStatus ( {
2080+ id : `codex-edit-${ mode } -${ attempt } ` ,
2081+ label : `Codex edit ${ attempt } ` ,
2082+ status : conflictDecision . action === "retry" ? "retrying" : "blocked" ,
2083+ details : `unresolved rebase conflicts: ${ remainingConflicts . join ( ", " ) } ` ,
2084+ headSha : currentHead ( targetDir ) ,
2085+ } ) ;
2086+ if ( conflictDecision . action === "retry" ) continue ;
2087+ throw new Error ( conflictDecision . reason ) ;
20602088 }
2061- if ( codexResult . status !== 0 ) {
2062- const errorDetail = codexFailureDetail ( codexResult , "Codex fix worker failed" ) ;
2089+ if ( timedOut ) throw new Error ( errorDetail ) ;
2090+ if ( codexResult . error || codexResult . status !== 0 ) {
20632091 if ( attempt < maxEditAttempts && isRetryableCodexErrorMessage ( errorDetail ) ) {
20642092 previousSummary = compactText ( errorDetail , 360 ) ;
20652093 const retryDelayMs = codexRetryDelayMs ( errorDetail , attempt ) ;
@@ -3458,25 +3486,6 @@ function issueImplementationPrAction(report: LooseRecord) {
34583486 } ) ;
34593487}
34603488
3461- function issueImplementationTerminalOutcome ( report : LooseRecord ) {
3462- const actionOutcome = [ ...( report . actions ?? [ ] ) ] . reverse ( ) . find ( ( action : JsonValue ) => {
3463- const status = String ( action ?. status ?? "" ) . toLowerCase ( ) ;
3464- if ( ! [ "blocked" , "skipped" , "failed" ] . includes ( status ) ) return false ;
3465- return [ "execute_fix" , "open_fix_pr" , "repair_contributor_branch" ] . includes (
3466- String ( action ?. action ?? "" ) ,
3467- ) ;
3468- } ) ;
3469- if ( actionOutcome ) return actionOutcome ;
3470-
3471- const status = String ( report . status ?? "" ) . toLowerCase ( ) ;
3472- if ( ! [ "blocked" , "skipped" , "failed" ] . includes ( status ) ) return null ;
3473- return {
3474- action : "issue_implementation" ,
3475- status,
3476- reason : report . reason ,
3477- } ;
3478- }
3479-
34803489function issueImplementationTargetIssueNumber ( ) {
34813490 for ( const ref of [
34823491 ...( job . frontmatter . canonical ?? [ ] ) ,
0 commit comments