Skip to content

Addressing PR comments#145

Open
Claude wants to merge 17 commits intomainfrom
claude/improve-deploy-time-error-classification
Open

Addressing PR comments#145
Claude wants to merge 17 commits intomainfrom
claude/improve-deploy-time-error-classification

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Mar 17, 2026


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Claude Claude AI assigned Claude and ewega Mar 17, 2026
@Claude Claude AI linked an issue Mar 17, 2026 that may be closed by this pull request
8 tasks
Claude AI and others added 2 commits March 17, 2026 00:45
Co-authored-by: ewega <26189114+ewega@users.noreply.github.com>
Co-authored-by: ewega <26189114+ewega@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Improve deploy-time error classification and bounded recovery Add deploy-time error classification and bounded port fallback recovery Mar 17, 2026
@Claude Claude AI requested a review from ewega March 17, 2026 00:48
@ewega ewega marked this pull request as ready for review March 17, 2026 01:27
Copilot AI review requested due to automatic review settings March 17, 2026 01:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves gh devlake deploy resilience by introducing deploy-time error classification (focused on Docker port conflicts) and adding bounded recovery paths for both local and Azure deployments.

Changes:

  • Added DeployError classification helpers for Docker Compose failures, including port extraction and conflicting container detection.
  • Implemented a bounded local deploy recovery: on detected port conflict, rewrite compose ports to an alternate bundle and retry once.
  • Normalized Azure deploy recovery messaging for login, stopped MySQL servers, and soft-deleted Key Vault conflicts; updated deployment docs accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
docs/deploy.md Documents local port fallback behavior and Azure bounded recovery messaging.
cmd/deploy_local.go Adds bounded port-fallback retry logic and compose port rewriting for local deploys.
cmd/deploy_local_test.go Adds tests for compose port rewriting behavior and error cases.
cmd/deploy_errors.go Introduces Docker Compose error classification, port extraction, and port-owner discovery.
cmd/deploy_errors_test.go Adds unit tests for port extraction and Docker Compose error classification patterns.
cmd/deploy_azure.go Updates Azure recovery output to a consistent detection → recovery → outcome format.
Comments suppressed due to low confidence (3)

docs/deploy.md:74

  • The documented port-conflict patterns list omits bind for, but classifyDockerComposeError treats bind for as one of the recognized patterns. Please align the docs with the actual classifier so users know all the strings that trigger the recovery path.
- **Port conflicts**: When deploying with official or fork images, the CLI detects port conflicts (patterns: `port is already allocated`, `ports are not available`, `address already in use`, `failed programming external connectivity`) and automatically retries with alternate ports (`8085/3004/4004`). Recovery is bounded to a single retry.
- **Custom deployments**: Port conflicts in custom deployments require manual resolution — the CLI will identify the conflicting container and suggest remediation commands.

docs/deploy.md:76

  • The local section claims “State checkpointing” saves deployment state early for mid-flight cleanup, but deploy local doesn’t appear to write .devlake-local.json at all (cleanup falls back to docker-compose.yml when no state exists). Please clarify what state is checkpointed for local deploys, or update the implementation/docs so the claim matches actual behavior.
- **State checkpointing**: Deployment state is saved early to enable cleanup even when deployment fails mid-flight.

cmd/deploy_local.go:200

  • With port fallback, backendURL can now be http://localhost:8085, but the later user-facing summary still prints Config UI/Grafana URLs using the default ports (4000/3002). That will mislead users after a successful fallback because the compose file ports are rewritten to 4004/3004. Consider deriving the full endpoint bundle from the selected backend port (8080→{3002,4000}, 8085→{3004,4004}) and printing the matching URLs.
		// Allow alternate port bundle for official/fork (not custom)
		allowPortFallback := deployLocalSource != "custom"

		backendURL, err := startLocalContainers(absDir, buildImages, allowPortFallback, services...)
		if err != nil {
			return err
		}
		cfgURL = backendURL

docs/deploy.md Outdated
| Config UI | http://localhost:4000 or http://localhost:4004 | — |
| Grafana | http://localhost:3002 or http://localhost:3004 | admin / admin |

**Port Fallback**: When deploying with `--source official` or `--source fork`, the CLI automatically recovers from port conflicts by retrying with alternate ports (`8085/3004/4004`). Custom deployments require manual port conflict resolution.
Comment on lines +179 to +197
// isValidPort checks if a string looks like a valid port number (all digits, 1-65535).
func isValidPort(s string) bool {
if len(s) < 1 || len(s) > 5 {
return false
}
for _, ch := range s {
if ch < '0' || ch > '9' {
return false
}
}
// Basic range check (ports are 1-65535)
if len(s) == 5 {
// Quick check: if > 65535, invalid
if s > "65535" {
return false
}
}
return true
}
Comment on lines +468 to +479
fmt.Println()
fmt.Printf("🔧 Port conflict detected on default ports (8080/3002/4000)\n")
if deployErr.Port != "" {
fmt.Printf(" Port %s is in use", deployErr.Port)
if deployErr.Container != "" {
fmt.Printf(" by container: %s", deployErr.Container)
}
fmt.Println()
}
fmt.Println()
fmt.Println("🔄 Retrying with alternate ports (8085/3004/4004)...")

Comment on lines +541 to +565
// Port mapping patterns:
// - "8080:8080" -> "8085:8080" (external:internal)
// - "3002:3002" -> "3004:3002"
// - "4000:4000" -> "4004:4000"
portMappings := map[string]string{
"8080:8080": "8085:8080",
"- 8080:8080": "- 8085:8080",
"\"8080:8080\"": "\"8085:8080\"",
"'8080:8080'": "'8085:8080'",

"3002:3002": "3004:3002",
"- 3002:3002": "- 3004:3002",
"\"3002:3002\"": "\"3004:3002\"",
"'3002:3002'": "'3004:3002'",

"4000:4000": "4004:4000",
"- 4000:4000": "- 4004:4000",
"\"4000:4000\"": "\"4004:4000\"",
"'4000:4000'": "'4004:4000'",
}

modified := content
for old, new := range portMappings {
modified = strings.ReplaceAll(modified, old, new)
}
Comment on lines +252 to +256
fmt.Println()
if de.Port != "" {
fmt.Printf("❌ Port conflict detected: port %s is already in use.\n", de.Port)
} else {
fmt.Println("❌ Port conflict detected: a required port is already in use.")
@ewega
Copy link
Contributor

ewega commented Mar 17, 2026

@claude[agent] Please address the actionable findings from the fresh Copilot review on this PR:

  1. In cmd/deploy_errors.go, fix isValidPort so it only accepts ports in the inclusive range 1..65535; reject 0/00000 and avoid misleading docker ps --filter publish=0 diagnostics.
  2. In cmd/deploy_local.go, harden rewriteComposePorts so it rewrites only the exact intended host-port mappings; it must not mutate unrelated custom ports like 18080:8080 -> 18085:8080. Please add/adjust tests for this case.
  3. In cmd/deploy_local.go, after successful alternate-port fallback, print the matching endpoint bundle in the final success summary/manual guidance instead of always showing the default Config UI/Grafana ports.
  4. In docs/deploy.md, either document the local --source/related flags that are referenced later or reword that section so it does not point users at undocumented flags. Also align the documented port-conflict trigger patterns with the classifier (include bind for if that remains part of detection).
  5. Update the emoji-prefixed step lines called out in cmd/deploy_local.go and cmd/deploy_errors.go so they include the leading newline in the same print call per .github/instructions/terminal-output.instructions.md.

Please push a follow-up commit and keep checks green.

@ewega
Copy link
Contributor

ewega commented Mar 17, 2026

@claude[agent] please address the actionable review feedback on this PR:

  1. In isValidPort, enforce the documented valid range 1..65535 so 0 / 00000 are rejected before conflict lookup runs.
  2. In rewriteComposePorts, avoid raw substring replacement that can mutate unrelated host ports like 18080:8080 -> 18085:8080. Rewrite only the exact intended host-port mappings (regex with boundaries or structured YAML rewrite is fine).
  3. When local deploy succeeds on the fallback bundle (8085/3004/4004), make the final user-facing endpoint summary print the matching Config UI and Grafana URLs instead of the default 4000/3002.
  4. Align docs/deploy.md with the implementation: if the local docs reference --source / related flags, make sure those flags are actually documented; include all recognized port-conflict patterns (including bind for if that is intentional); and remove or correct the local state checkpointing claim if local deploy does not actually persist that state.
  5. While touching the reviewed areas, please also make the emoji-prefixed step lines follow the terminal output convention of including the leading newline in the same print call at the cited locations.

After pushing the fixes, I’ll re-run the review/check pass.

…RLs, docs, and terminal output

Co-authored-by: ewega <26189114+ewega@users.noreply.github.com>
@Claude
Copy link
Contributor Author

Claude AI commented Mar 17, 2026

@claude[agent] Please address the actionable findings from the fresh Copilot review on this PR:

  1. In cmd/deploy_errors.go, fix isValidPort so it only accepts ports in the inclusive range 1..65535; r...

All findings addressed in e358254:

  1. Port validation: isValidPort now properly validates 1-65535 range, rejects 0/00000/65536
  2. Port rewriting safety: Uses regex with boundaries (?m)(^\s*-\s*)["']?8080:8080["']? to avoid rewriting custom ports like 18080:8080
  3. Dynamic endpoint URLs: Added inferCompanionURLs() that detects backend port (8080 vs 8085) and shows matching Grafana/Config UI URLs in success summary
  4. Documentation: Added --source, --repo-url, --start flags to table; included "bind for" in error patterns list
  5. Terminal output: Fixed emoji-prefixed steps to include leading \n in same print call per terminal-output.instructions.md

All tests pass, checks green.

@Claude Claude AI changed the title Add deploy-time error classification and bounded port fallback recovery Addressing PR comments Mar 17, 2026
@ewega ewega requested a review from Copilot March 17, 2026 01:42
@ewega
Copy link
Contributor

ewega commented Mar 17, 2026

@copilot review the latest updates on this PR, especially the fixes for port validation, exact compose-port rewriting, fallback endpoint reporting, and deploy docs alignment.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates gh devlake local and Azure deployment UX/documentation to reflect bounded recovery behaviors (port fallback locally; login/MySQL/Key Vault recovery on Azure) and adds test coverage for the new deployment error classification and compose port rewriting.

Changes:

  • Add local deploy port-fallback support (single retry) by rewriting compose ports and detecting which backend port is healthy.
  • Introduce Docker Compose error classification + port-owner detection helpers, with accompanying unit tests.
  • Update deployment docs to document new flags and resilience behaviors for local and Azure deployments.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/deploy.md Documents new local flags, port fallback behavior, and bounded recovery behavior for local/Azure deploy flows.
cmd/deploy_local.go Implements bounded local port fallback, companion URL inference, and compose port rewriting.
cmd/deploy_local_test.go Adds tests for compose port rewriting behavior across multiple compose port syntaxes.
cmd/deploy_errors.go Adds Docker Compose error classification, port extraction, and port-owner lookup helpers.
cmd/deploy_errors_test.go Adds unit tests for port extraction + compose error classification patterns.
cmd/deploy_azure.go Adjusts Azure deploy output to clearly surface bounded recovery steps for login/MySQL/Key Vault.
Comments suppressed due to low confidence (1)

cmd/deploy_local.go:497

  • This sub-item print includes a leading blank line (\n ...), which introduces extra vertical spacing within the recovery block and breaks the “sub-items stay tight under their parent” rule. Consider removing the leading \n here and rely on the surrounding step banners for spacing.
	fmt.Println("\n   Starting containers with alternate ports...")
	err = dockerpkg.ComposeUp(absDir, build, services...)

Comment on lines +502 to +503
fmt.Println()
fmt.Println("❌ Alternate ports are also in use.")
Comment on lines +481 to +490
// Rewrite port mappings in docker-compose.yml or docker-compose-dev.yml
composePath := filepath.Join(absDir, "docker-compose.yml")
if _, err := os.Stat(composePath); os.IsNotExist(err) {
composePath = filepath.Join(absDir, "docker-compose-dev.yml")
}

if err := rewriteComposePorts(composePath); err != nil {
fmt.Printf(" ⚠️ Could not rewrite ports: %v\n", err)
printDockerPortConflictError(deployErr)
return "", fmt.Errorf("port conflict and failed to apply alternate ports: %w", err)
modified := content

// Port mapping patterns with regex boundaries
// Match: "- 8080:8080" or "- "8080:8080"" or "- '8080:8080'" at start of list item
@ewega
Copy link
Contributor

ewega commented Mar 17, 2026

@claude[agent] Fresh Copilot follow-up review landed with one substantive fix request plus one output-consistency follow-up. Please address these before the next review pass:

  1. In cmd/deploy_local.go, make the bounded port-fallback path detect when the compose file is already on the alternate bundle (or when the initial conflict is already on the alternate ports) and skip rewrite in that case. Right now it can try to rewrite an already-rewritten compose file, fail with no port mappings found, and miss the correct remediation path of simply reporting that the alternate ports are occupied.
  2. In the same recovery block, make the ❌ Alternate ports are also in use. step follow the terminal output rule by including the leading newline in the same print call (Copilot flagged this at lines 496/503).
  3. Optional cleanup while you are there: fix the extra quote in the nearby port-mapping comment example.

Please push the follow-up commit, then I’ll trigger another Copilot review/check pass.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates local/azure deployment UX and documentation, primarily by formalizing port-conflict detection/recovery and improving endpoint/health reporting guidance across the CLI docs.

Changes:

  • Add docker-compose port-conflict classification + user-friendly remediation output, with bounded retry to an alternate local port bundle.
  • Infer and print companion service URLs (Grafana/Config UI) based on compose configuration, plus expanded test coverage for port rewrite/bundle detection and error parsing.
  • Refresh docs/README to reflect deploy local defaults (--start=true), alternate port bundle support, and resilience behaviors.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docs/status.md Documents companion URL inference and status output for alternate localhost bundle.
docs/state-files.md Updates discovery chain to include localhost:8085 and clarifies state-file behavior.
docs/deploy.md Rewrites deploy local/deploy azure docs to reflect current flags, defaults, endpoints, and bounded recovery behaviors.
README.md Updates quick-start endpoint guidance for default + alternate local port bundles.
cmd/deploy_local.go Implements port-conflict classification, bounded port fallback via compose rewrite, and companion URL inference via compose parsing.
cmd/deploy_local_test.go Adds unit tests for compose port rewriting, bundle detection, compose parsing fallbacks, and deploy local command help/flags.
cmd/deploy_errors.go Introduces docker-compose error classification, port extraction, container/compose ownership detection, and standardized conflict messaging.
cmd/deploy_errors_test.go Adds tests for port extraction and compose-error classification patterns.
cmd/deploy_azure.go Improves bounded recovery messaging for Azure login/MySQL/Key Vault soft-delete scenarios.
Comments suppressed due to low confidence (1)

cmd/deploy_local.go:569

  • waitAndDetectBackendURL always tries to parse ports from docker-compose.yml. If the deployment is using a different compose filename (e.g., docker-compose-dev.yml), port extraction will silently fail and the readiness probe may miss the actual backend port. Consider passing the resolved compose path into this function (or doing the same filename fallback here) so readiness checks are aligned with the compose file that was started/re-written.
func waitAndDetectBackendURL(dir string) (string, error) {
	composePath := filepath.Join(dir, "docker-compose.yml")

	// Try to extract the actual backend port from the compose file
	ports := extractServicePorts(composePath, "devlake")

fmt.Println(" Config UI: http://localhost:4000")
fmt.Println(" Grafana: http://localhost:3002 (admin/admin)")
// Infer companion URLs based on compose file ports
composePath := filepath.Join(absDir, "docker-compose.yml")
@ewega
Copy link
Contributor

ewega commented Mar 17, 2026

@claude[agent] Please address the remaining actionable review feedback on this PR before merge:

  1. Fix isValidPort in cmd/deploy_errors.go so it enforces the documented range 1..65535 and does not accept 0 or zero-padded zero values.
  2. Fix waitAndDetectBackendURL in cmd/deploy_local.go so it does not hardcode docker-compose.yml when the active compose file may have a different name in custom mode. Keep backend-port detection aligned with the compose file actually used.
  3. Reconcile docs/deploy.md with the current --start=true default and --source behavior. The docs still mix “manual compose up” language with “auto-start by default” language and should describe source-specific behavior consistently.
  4. If straightforward, also clean up any remaining terminal-output spacing issues caused by leading \n on indented sub-items so sub-items stay tight under their parent.

Please push the fixes to this PR branch and keep the existing scope unchanged.

- Add findComposeFile() helper to detect docker-compose.yml vs docker-compose-dev.yml
- Update waitAndDetectBackendURL, inferCompanionURLs, and startLocalContainers to use findComposeFile()
- Fix docs/deploy.md to consistently describe auto-start behavior across all sources
- Clarify custom source accepts docker-compose-dev.yml

Co-authored-by: ewega <26189114+ewega@users.noreply.github.com>
@Claude
Copy link
Contributor Author

Claude AI commented Mar 17, 2026

@claude[agent] Please address the remaining actionable review feedback on this PR before merge:

  1. Fix isValidPort in cmd/deploy_errors.go so it enforces the documented range 1..65535 and does ...

All four items addressed in 11ef152:

  1. isValidPort validation: Already correct - rejects port 0 and zero-padded values (tests pass).

  2. Compose file detection: Added findComposeFile() helper that checks for docker-compose.yml first, then docker-compose-dev.yml. Updated waitAndDetectBackendURL, inferCompanionURLs, and startLocalContainers to use it instead of hardcoding docker-compose.yml.

  3. Docs consistency: Updated docs/deploy.md "What It Does" section to list "Starts containers (unless --start=false)" as the final step for all three sources. Removed redundant note. Custom source now explicitly mentions docker-compose-dev.yml support.

  4. Terminal output spacing: Already fixed in ce9a0f5 - removed leading \n from all nextSteps strings.

All tests pass (go test ./..., go build ./..., go vet ./...).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates local/azure deployment UX and documentation, primarily to clarify default startup behavior and add resilient handling of local port conflicts (single retry onto an alternate port bundle).

Changes:

  • Add bounded local port-fallback (8080/3002/4000 → 8085/3004/4004) with compose rewriting + improved port-conflict classification.
  • Infer/print companion service URLs (Grafana/Config UI) based on the compose configuration and/or backend URL.
  • Refresh docs/README for the new port bundle behavior and add targeted unit tests for the new helpers.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/status.md Documents companion URL inference and alternate-bundle behavior for status.
docs/state-files.md Updates discovery chain to include localhost 8085.
docs/deploy.md Updates deploy local docs for --start, --source, and port-fallback resilience; updates Azure resilience notes.
cmd/deploy_local_test.go Adds tests for compose port rewriting, port bundle detection, and URL inference fallback.
cmd/deploy_local.go Implements bounded port fallback, compose port rewrite helpers, and companion URL inference for printed endpoints.
cmd/deploy_errors_test.go Adds unit tests for docker compose error classification and port extraction.
cmd/deploy_errors.go Introduces docker compose error classification + friendly port-conflict remediation output.
cmd/deploy_azure.go Improves bounded-recovery messaging (login/MySQL/Key Vault soft-delete).
README.md Updates quick start endpoint guidance to reflect port bundles and fallback.

docs/status.md Outdated
| ❌ | Connection refused or timeout |

Grafana is checked at `/api/health`. Backend and Config UI are checked at their root URL.
Grafana is checked at `/api/health`. Backend and Config UI are checked at their root URL. When auto-discovery lands on `http://localhost:8080`, companion URLs infer to `http://localhost:3002` and `http://localhost:4000`. When it lands on `http://localhost:8085`, companion URLs infer to `http://localhost:3004` and `http://localhost:4004`.
// Not a port conflict or unknown error - print general cleanup and fail
fmt.Println("\n💡 To clean up partial artifacts:")
fmt.Println(" gh devlake cleanup --local --force")
return "", err
@ewega
Copy link
Contributor

ewega commented Mar 22, 2026

@claude[agent] apply changes based on the comments in this thread

- Update docs/status.md to correctly document Backend health check at /ping
- Wrap non-port-conflict docker compose errors with context for consistency

Co-authored-by: ewega <26189114+ewega@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DevExpGbb/gh-devlake/sessions/de3f03b9-067f-4f4b-9e01-1b211ae5100c
@Claude
Copy link
Contributor Author

Claude AI commented Mar 22, 2026

@claude[agent] apply changes based on the comments in this thread

Both review items addressed in 0df339b:

  1. Status docs health check paths: Updated docs/status.md to correctly document that Backend is checked at /ping (not root URL), matching the implementation in cmd/status.go:320-321.

  2. Error wrapping consistency: Wrapped non-port-conflict docker compose errors with context (fmt.Errorf("docker compose up failed: %w", err)) for consistency with other error paths in startLocalContainers.

All tests pass.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates local/azure deployment behavior and documentation to reflect recent PR feedback, including bounded recovery paths and more accurate service URL/port handling across commands.

Changes:

  • Add port-conflict classification + user-friendly remediation output, with bounded auto-fallback to the alternate local port bundle for official/fork deploys.
  • Infer Grafana/Config UI URLs from the active compose file (with fallback heuristics) and expand test coverage for port rewriting/bundle detection.
  • Refresh docs/README to reflect /ping health checks, localhost discovery on 8080/8085, and the port-fallback behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docs/status.md Clarifies health-check endpoints and documents companion URL inference for 8080 vs 8085 discovery.
docs/state-files.md Updates discovery chain documentation to include localhost 8085.
docs/deploy.md Rewrites deploy documentation to match --start default behavior and describes bounded recovery behaviors (local + Azure).
cmd/deploy_local_test.go Adds tests for compose port rewriting, port bundle detection, compose-port extraction fallback, and command help/flags.
cmd/deploy_local.go Implements bounded port-fallback flow, compose-based companion URL inference, and compose-port extraction via docker compose config.
cmd/deploy_errors_test.go Adds unit tests for docker compose error classification and port extraction edge cases.
cmd/deploy_errors.go Introduces docker compose error classification, port extraction, port-owner detection, and friendly conflict output.
cmd/deploy_azure.go Adjusts output to explicitly label bounded recovery actions (login, MySQL start, Key Vault purge).
README.md Updates local endpoint guidance to reflect printed bundle + one-time port fallback behavior.

Comment on lines +649 to +654
// composeFileHasDefaultPorts checks if a compose file contains the default port bundle (8080/3002/4000).
// Returns true only for the default bundle, and false for alternate or other custom port mappings.
func composeFileHasDefaultPorts(composePath string) bool {
return detectPortBundle(composePath) == portBundleDefault
}

Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

composeFileHasDefaultPorts is introduced here but is never called anywhere in the repo. Keeping unused helpers in cmd/deploy_local.go makes the deploy flow harder to follow; consider removing it or using it in the port-fallback decision logic so the intent is clear.

Suggested change
// composeFileHasDefaultPorts checks if a compose file contains the default port bundle (8080/3002/4000).
// Returns true only for the default bundle, and false for alternate or other custom port mappings.
func composeFileHasDefaultPorts(composePath string) bool {
return detectPortBundle(composePath) == portBundleDefault
}

Copilot uses AI. Check for mistakes.
@ewega
Copy link
Contributor

ewega commented Mar 24, 2026

@claude[agent] please address fixes in this comment #145 (review)

The function was never called; detectPortBundle is used directly instead.

Co-authored-by: ewega <26189114+ewega@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DevExpGbb/gh-devlake/sessions/661889e8-068e-46dc-88b3-7a2106030ce9
@Claude
Copy link
Contributor Author

Claude AI commented Mar 24, 2026

@claude[agent] please address fixes in this comment #145 (review)

Removed unused composeFileHasDefaultPorts helper in c517bca. The function was never called; detectPortBundle is used directly on line 484 instead.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

cmd/deploy_local.go:568

  • findComposeFile can return docker-compose-dev.yml, but startLocalContainers ultimately runs docker compose up via internal/docker.ComposeUp, which doesn’t pass -f and therefore won’t use docker-compose-dev.yml. This makes custom deployments that only provide docker-compose-dev.yml fail, despite being accepted earlier. Consider either (1) ensuring a docker-compose.yml exists (copy/rename dev → yml) before calling ComposeUp, or (2) extending the docker helper to accept an explicit compose file path and always using the result of findComposeFile.
// findComposeFile returns the path to the active docker compose file in the given directory.
// Checks for docker-compose.yml first, then docker-compose-dev.yml.
func findComposeFile(dir string) string {
	composePath := filepath.Join(dir, "docker-compose.yml")
	if _, err := os.Stat(composePath); err == nil {
		return composePath
	}
	return filepath.Join(dir, "docker-compose-dev.yml")
}

fmt.Println("\n💡 To clean up partial artifacts:")
fmt.Println(" gh devlake cleanup --local --force")
return "", err
nextSteps := " Edit your docker-compose.yml to use different host ports, or stop the conflicting container."
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The remediation text hard-codes docker-compose.yml, but findComposeFile (and the earlier custom-mode validation) allow docker-compose-dev.yml too. To avoid sending users to the wrong file, consider referencing the detected compose file path (or saying “your compose file”) here.

This issue also appears on line 560 of the same file.

Suggested change
nextSteps := " Edit your docker-compose.yml to use different host ports, or stop the conflicting container."
nextSteps := " Edit your compose file to use different host ports, or stop the conflicting container."

Copilot uses AI. Check for mistakes.
docs/status.md Outdated
| ❌ | Connection refused or timeout |

Grafana is checked at `/api/health`. Backend and Config UI are checked at their root URL.
Backend is checked at `/ping`, Grafana at `/api/health`, and Config UI at its root URL. When auto-discovery lands on `http://localhost:8080`, companion URLs infer to `http://localhost:3002` and `http://localhost:4000`. When it lands on `http://localhost:8085`, companion URLs infer to `http://localhost:3004` and `http://localhost:4004`.
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The sentence listing inferred companion URLs doesn’t indicate which URL is Grafana vs Config UI, which can be confusing (it just lists two URLs per bundle). Consider explicitly labeling them (e.g., “Grafana → …, Config UI → …”) for both the 8080 and 8085 cases.

Suggested change
Backend is checked at `/ping`, Grafana at `/api/health`, and Config UI at its root URL. When auto-discovery lands on `http://localhost:8080`, companion URLs infer to `http://localhost:3002` and `http://localhost:4000`. When it lands on `http://localhost:8085`, companion URLs infer to `http://localhost:3004` and `http://localhost:4004`.
Backend is checked at `/ping`, Grafana at `/api/health`, and Config UI at its root URL. When auto-discovery lands on `http://localhost:8080`, companion URLs infer to Grafana → `http://localhost:3002`, Config UI → `http://localhost:4000`. When it lands on `http://localhost:8085`, companion URLs infer to Grafana → `http://localhost:3004`, Config UI → `http://localhost:4004`.

Copilot uses AI. Check for mistakes.
docs/deploy.md Outdated
5. Starts containers (unless `--start=false`)

**custom**:
1. Uses the existing `docker-compose.yml` (or `docker-compose-dev.yml`) in the target directory
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This section states that --source custom can use docker-compose-dev.yml, but the deploy code starts containers via docker compose up in the directory without selecting a compose file (no -f docker-compose-dev.yml). If the directory only contains docker-compose-dev.yml, deploy local will fail. Either document that custom requires docker-compose.yml, or update the implementation to use the detected compose file (e.g., pass -f or copy/rename dev → docker-compose.yml).

Suggested change
1. Uses the existing `docker-compose.yml` (or `docker-compose-dev.yml`) in the target directory
1. Uses the existing `docker-compose.yml` in the target directory (if you only have `docker-compose-dev.yml`, rename it to `docker-compose.yml` or start containers manually with `docker compose -f docker-compose-dev.yml up -d`)

Copilot uses AI. Check for mistakes.
@ewega
Copy link
Contributor

ewega commented Mar 25, 2026

@claude[agent] apply changes based on the comments in this thread

- Use generic "compose file" instead of hardcoded "docker-compose.yml" in error messages
- Add explicit Grafana/Config UI labels to status docs URL mappings
- Clarify that custom mode requires docker-compose.yml (not docker-compose-dev.yml)

Agent-Logs-Url: https://github.com/DevExpGbb/gh-devlake/sessions/5b89b918-ab13-4890-82b6-7f25c5e85ae2

Co-authored-by: ewega <26189114+ewega@users.noreply.github.com>
@Claude
Copy link
Contributor Author

Claude AI commented Mar 25, 2026

@claude[agent] apply changes based on the comments in this thread

All three review items addressed in afdb558:

  1. Generic compose file reference: Changed hardcoded "docker-compose.yml" to "compose file" in port conflict remediation text (line 511).

  2. Explicit URL labels: Added Grafana/Config UI labels to status.md companion URL mappings (e.g., "Grafana → http://localhost:3002, Config UI → http://localhost:4000").

  3. Custom mode compose file clarification: Updated docs/deploy.md to clarify that custom mode requires docker-compose.yml (not docker-compose-dev.yml). Added note with workaround for users who only have the dev variant.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Comment on lines +1 to +2
package cmd

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This file appears to have Windows CRLF line endings (line 1 shows a trailing \r in searches). Please convert to LF to match the repository’s standard line endings and avoid cross-platform issues.

Copilot uses AI. Check for mistakes.
func printDockerPortConflictError(de *DeployError, customHeader string, nextSteps string) {
// Print header
if customHeader != "" {
fmt.Println(customHeader)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

When customHeader is provided, it’s printed verbatim. To keep terminal output spacing consistent (blank line before emoji-prefixed steps), consider normalizing customHeader inside this function (e.g., prefixing a newline if missing) rather than relying on all callers to include \n correctly.

Suggested change
fmt.Println(customHeader)
normalizedHeader := customHeader
if !strings.HasPrefix(normalizedHeader, "\n") {
normalizedHeader = "\n" + normalizedHeader
}
fmt.Println(normalizedHeader)

Copilot uses AI. Check for mistakes.
Comment on lines +685 to +688
if err := os.WriteFile(composePath, []byte(modified), 0644); err != nil {
return fmt.Errorf("writing compose file: %w", err)
}

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

rewriteComposePorts overwrites the user’s compose file in-place. Since this runs as part of an automated recovery path, consider writing a backup (e.g., docker-compose.yml.bak) and/or doing an atomic write (temp file + rename) so users can easily revert and to reduce risk of partial writes if the process is interrupted.

Suggested change
if err := os.WriteFile(composePath, []byte(modified), 0644); err != nil {
return fmt.Errorf("writing compose file: %w", err)
}
// Create a backup of the original compose file so users can revert if needed.
backupPath := composePath + ".bak"
if _, statErr := os.Stat(backupPath); os.IsNotExist(statErr) {
if err := os.WriteFile(backupPath, data, 0644); err != nil {
return fmt.Errorf("creating compose backup %s: %w", backupPath, err)
}
}
// Write updated content atomically via temp file + rename to avoid partial writes.
dir := filepath.Dir(composePath)
tmpFile, err := os.CreateTemp(dir, ".compose-*.tmp")
if err != nil {
return fmt.Errorf("creating temp compose file: %w", err)
}
// Ensure temp file is removed on failure paths.
defer os.Remove(tmpFile.Name())
if _, err := tmpFile.Write([]byte(modified)); err != nil {
tmpFile.Close()
return fmt.Errorf("writing temp compose file: %w", err)
}
if err := tmpFile.Close(); err != nil {
return fmt.Errorf("closing temp compose file: %w", err)
}
if err := os.Rename(tmpFile.Name(), composePath); err != nil {
return fmt.Errorf("replacing compose file atomically: %w", err)
}

Copilot uses AI. Check for mistakes.
docs/deploy.md Outdated
Comment on lines 71 to 72
**Port Fallback**: When deploying with `--source official` or `--source fork`, the CLI automatically recovers from port conflicts by retrying with alternate ports (`8085/3004/4004`). Custom deployments require manual port conflict resolution.

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The doc mentions port fallback, but it doesn’t note that the CLI rewrites docker-compose.yml port mappings on disk as part of the recovery. Please document that side effect (what gets rewritten, and how to revert) so users aren’t surprised when their compose file changes.

Suggested change
**Port Fallback**: When deploying with `--source official` or `--source fork`, the CLI automatically recovers from port conflicts by retrying with alternate ports (`8085/3004/4004`). Custom deployments require manual port conflict resolution.
**Port Fallback**: When deploying with `--source official` or `--source fork`, the CLI automatically recovers from port conflicts by retrying with alternate ports (`8085/3004/4004`). As part of this recovery, it updates the port mappings in `docker-compose.yml` on disk so that future `docker compose up` runs use the fallback ports. Custom deployments (`--source custom`) are not modified automatically and require manual port conflict resolution.
To revert fallback changes, edit `docker-compose.yml` and restore your preferred host ports (for example, change the mapped ports back to `8080/3002/4000` if they were adjusted), or revert the file via version control / re-run the deployment in a clean directory.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
package cmd

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This file appears to have Windows CRLF line endings (e.g., lines show trailing \r in searches). The repo is predominantly LF; please convert this file to LF to avoid noisy diffs and potential tooling issues on Unix environments.

Copilot uses AI. Check for mistakes.
@ewega
Copy link
Contributor

ewega commented Mar 25, 2026

@claude[agent] please address comments in this thread: #145 (review)

- Convert deploy_errors.go and deploy_errors_test.go from CRLF to LF
- Normalize customHeader in printDockerPortConflictError for consistent spacing
- Add backup (.bak) and atomic write (temp+rename) to rewriteComposePorts
- Document port rewrite side effect and backup file in deploy.md

Agent-Logs-Url: https://github.com/DevExpGbb/gh-devlake/sessions/cbca78e8-02a6-4a80-b698-12d2fb258ca9

Co-authored-by: ewega <26189114+ewega@users.noreply.github.com>
@Claude
Copy link
Contributor Author

Claude AI commented Mar 25, 2026

@claude[agent] please address comments in this thread: #145 (review)

All five review items addressed in 78c70a3:

  1. CRLF to LF conversion: Converted both cmd/deploy_errors.go and cmd/deploy_errors_test.go from CRLF to LF line endings.

  2. Header normalization: Added logic in printDockerPortConflictError to normalize customHeader by prepending \n if missing, ensuring consistent spacing.

  3. Backup and atomic write: Updated rewriteComposePorts to create a backup at docker-compose.yml.bak (if it doesn't exist) and use atomic writes (temp file + rename) to avoid partial writes on interruption.

  4. Documentation: Updated docs/deploy.md to document that port fallback rewrites docker-compose.yml on disk, creates a backup, and explains how to revert changes.

All tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve deploy-time error classification and bounded recovery

4 participants