Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion build/Targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ let private runLocalContainer _ =
let image = $"elastic/docs-builder:%s{tag}"
exec { run "docker" ["docker"; "run"; image; "--help"] }

let private runDotnetWithRegistryPushRetry (args: string list) =
let maxAttempts = 3
let rec attempt number =
match exec {
validExitCode (fun _ -> true)
exit_code_of "dotnet" args
} with
| 0 -> ()
| _ when number < maxAttempts ->
printfn "Container registry push failed (attempt %d/%d); retrying..." number maxAttempts
attempt (number + 1)
| _ ->
exec { run "dotnet" args }
attempt 1
Comment on lines +110 to +123

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Logic error: performs 4 attempts instead of 3.

The retry logic executes the command 4 times when all attempts fail, not 3. When attempt 3 fails, the guard 3 < maxAttempts is false, so it falls through to line 122 and runs the command a 4th time. The PR description states "up to three times" but this implementation runs once more than intended.

🔧 Proposed fix
 let private runDotnetWithRegistryPushRetry (args: string list) =
     let maxAttempts = 3
     let rec attempt number =
-        match exec {
+        let exitCode = exec {
             validExitCode (fun _ -> true)
             exit_code_of "dotnet" args
-        } with
+        }
+        match exitCode with
         | 0 -> ()
         | _ when number < maxAttempts ->
             printfn "Container registry push failed (attempt %d/%d); retrying..." number maxAttempts
             attempt (number + 1)
         | _ ->
-            exec { run "dotnet" args }
+            failwithf "Container registry push failed after %d attempts with exit code %d" maxAttempts exitCode
     attempt 1
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@build/Targets.fs` around lines 110 - 123, The retry loop in
runDotnetWithRegistryPushRetry currently causes one extra run; change the
recursion to start with attempt 0 (call attempt 0) and update the guard to "when
number < maxAttempts - 1" so that you only retry while number < maxAttempts-1,
and update the printfn to display (number + 1) as the current attempt; keep the
final branch as exec { run "dotnet" args } so the command is executed at most
maxAttempts times.


let private publishContainers _ =

let createImage projectPath containerName =
Expand All @@ -132,7 +147,10 @@ let private publishContainers _ =
"-p"; "ContainerUser=1001:1001";
]
| _ -> []
exec { run "dotnet" (args @ registry) }
let dotnetArgs = args @ registry
match registry with
| [] -> exec { run "dotnet" dotnetArgs }
| _ -> runDotnetWithRegistryPushRetry dotnetArgs
createImage "src/tooling/docs-builder/docs-builder.csproj" "docs-builder"
createImage "src/api/Elastic.Documentation.Mcp.Remote/Elastic.Documentation.Mcp.Remote.csproj" "docs-builder-mcp"
createImage "src/api/Elastic.Documentation.Api/Elastic.Documentation.Api.csproj" "docs-builder-api"
Expand Down
Loading