Skip to content

Refactor startContainers into focused startup and failure helpers#5758

Merged
lpcox merged 2 commits into
mainfrom
copilot/refactor-start-containers-function
Jul 1, 2026
Merged

Refactor startContainers into focused startup and failure helpers#5758
lpcox merged 2 commits into
mainfrom
copilot/refactor-start-containers-function

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

startContainers had grown into a long orchestration method that mixed pre-cleanup, topology-aware bring-up, compose execution, and retry/diagnostic handling. This change splits those phases into named private helpers while preserving the existing startContainers API and startup behavior.

  • What changed

    • Extracted compose-up argument construction and the shared compose-up execution path.
    • Moved topology-mode phased startup (squid-proxy first, onNetworkReady(), then full bring-up) into a dedicated startup helper.
    • Moved retry, per-container failure classification, log dumping, and retry-failure escalation into focused failure-handling helpers.
    • Kept orphaned-container pre-cleanup in startContainers, so the top-level flow is now: cleanup → attempt startup → handle failure/success.
  • Behavior preserved

    • api-proxy and squid startup failures still retry once after docker compose down.
    • cli-proxy startup failures still fail fast without retry.
    • Healthcheck/domain-blockage diagnostics still route through the existing handleHealthcheckError() path.
    • Topology mode still performs the same split bring-up ordering.
  • Why this refactor helps

    • Reduces startContainers to a small orchestration wrapper.
    • Makes the retry/diagnostic path independently navigable and easier to extend for new startup failure cases.
    • Separates the security-sensitive startup phases into explicit units instead of one 100+ line control-flow block.
  • Representative shape

    const composeArgs = getComposeUpArgs(skipPull);
    const runComposeUp = () => runDockerComposeUp(workDir, composeArgs);
    const startupError = await attemptContainerStartup(workDir, composeArgs, skipPull, onNetworkReady);
    
    if (startupError) {
      await handleStartupFailure(startupError, workDir, proxyLogsDir, allowedDomains, runComposeUp);
      return;
    }
    
    logger.success('Containers started successfully');

Copilot AI changed the title [WIP] Refactor startContainers to extract retry and diagnostic phases Refactor startContainers into focused startup and failure helpers Jul 1, 2026
Copilot AI requested a review from lpcox July 1, 2026 18:39
Copilot finished work on behalf of lpcox July 1, 2026 18:39
@lpcox lpcox requested a review from Copilot July 1, 2026 18:56

Copilot AI left a comment

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.

Pull request overview

This PR refactors startContainers in src/container-lifecycle.ts by extracting the Docker Compose argument construction, topology-mode phased bring-up, and retry/diagnostic failure handling into focused private helpers, while preserving the external startContainers API and intended startup behavior.

Changes:

  • Extracted getComposeUpArgs() and runDockerComposeUp() to centralize compose argument construction and execution (including stdout→stderr redirection).
  • Moved topology-mode phased startup (squid-only bring-up → onNetworkReady() → full bring-up) into attemptContainerStartup().
  • Moved first-attempt classification, retry-once behavior (api-proxy/squid), and retry failure escalation into handleStartupFailure() / handleRetryStartupFailure(), including clearer error construction helpers.
Show a summary per file
File Description
src/container-lifecycle.ts Refactors startContainers by extracting compose-up execution, topology startup sequencing, and failure/retry/diagnostic handling into helper functions.
src/container-start.test.ts Adds an assertion ensuring that when the squid-only topology phase fails, the full docker compose up (non---no-deps) is never attempted.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@lpcox lpcox marked this pull request as ready for review July 1, 2026 19:18
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@copilot Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

Smoke test finished. Results: MCP (FAIL), Connectivity (PASS), File (PASS), Bash (PASS). Overall: FAIL.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🚀 Security Guard has started processing this pull request

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

Contribution guidelines check complete for PR #5758. The PR description is clear, changes are in the appropriate src/test files, and the refactor includes a relevant test update; no guideline issues require a comment.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 98.65% 98.67% 📈 +0.02%
Statements 98.53% 98.55% 📈 +0.02%
Functions 99.55% 99.55% ➡️ +0.00%
Branches 94.46% 94.47% 📈 +0.01%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/container-lifecycle.ts 100.0% → 99.1% (-0.91%) 100.0% → 99.1% (-0.87%)
src/workdir-setup.ts 92.7% → 94.5% (+1.82%) 92.7% → 94.5% (+1.82%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

Check Result
API status ✅ PASS
gh check ✅ PASS
File status ✅ PASS

Overall result: PASS

Generated by Smoke Claude for #5758 · 30.1 AIC · ⊞ 3.3K ·
Add label ready-for-aw to run again

@github-actions github-actions Bot mentioned this pull request Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🔥 Smoke Test Results

PR: Refactor startContainers into focused startup and failure helpers
Author: @Copilot | Assignees: @lpcox @Copilot

Test Result
GitHub MCP connectivity
GitHub.com HTTP ✅ 200
File write/read ⚠️ pre-step vars unresolved

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK

✅ GitHub MCP connectivity (merged PR data retrieved)
✅ GitHub.com connectivity (HTTP 200)
✅ File write/read test (I/O working)
✅ Direct BYOK inference (api-proxy → api.githubcopilot.com)

Result: PASS — Running in direct BYOK mode via api-proxy sidecar.

@Copilot @lpcox

🔑 BYOK report filed by Smoke Copilot BYOK
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🔥 Smoke Test: PAT Auth — PASS

Test Result
GitHub MCP connectivity
github.com HTTP ✅ 200
File write/read ⚠️ template vars unresolved

PR: Refactor startContainers into focused startup and failure helpers
Author: @Copilot | Assignees: @lpcox @Copilot
Auth mode: PAT (COPILOT_GITHUB_TOKEN)

🔑 PAT report filed by Smoke Copilot PAT
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke test results:

  • fix: sysroot filter should not drop workspace custom mounts
  • fix: filter split-fs-invisible mounts when sysroot-stage is active (arc-dind)
  • GitHub PR query ✅
  • Browser title check ✅
  • File write/read ✅
  • Build (npm ci && npm run build) ✅
  • Overall: PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Status Summary
1. Module Loading otel.js loads; exports startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled + test helpers. isEnabled() returns true (FileSpanExporter fallback active).
2. Test Suite 59 tests passed, 0 failed across otel.test.js and otel-fanout.test.js. Covers span creation, token attributes, GenAI semconv, ProxyAwareOtlpExporter, FileSpanExporter, and shutdown.
3. Env Var Forwarding src/services/api-proxy-env-config.ts forwards all OTEL env vars: GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, GITHUB_AW_OTEL_TRACE_ID, GITHUB_AW_OTEL_PARENT_SPAN_ID, OTEL_SERVICE_NAME.
4. Token Tracker Integration onUsage callback exists in token-tracker-http.js:324. OTEL hook is wired in upstream-token.jsonUsage calls otel.setTokenAttributes(span, ...) and onSpanEnd calls otel.endSpan(span, statusCode).
5. OTEL Diagnostics No live OTLP endpoint in CI; graceful degradation confirmed — module initialises with FileSpanExporter writing to /var/log/api-proxy/otel.jsonl. No errors on module load.

Result: All 5 scenarios pass. OTEL tracing integration is complete and working correctly.

📡 OTel tracing validated by Smoke OTel Tracing
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Gemini Engine Validation Results:

  • GitHub MCP Testing: ❌ (Tools not found)
  • GitHub.com Connectivity: ❌ (SSL Error 35)
  • File Writing Testing: ✅
  • Bash Tool Testing: ✅
    Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python 3.12.13 3.12.3
Node.js v24.18.0 v22.23.1
Go 1.22.12 1.22.12

Overall: FAILED — Python and Node.js versions differ between host and chroot environments. Go matches.

Tested by Smoke Chroot
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@lpcox @Copilot
MCP Testing PRs:

  • fix: ensure chmod runs even when chown fails in rootless permission repair
  • refactor: split 309-line generateDockerCompose into focused phases ✓
    GitHub.com connectivity ✓
    File I/O test ✓
    Inference BYOK test ✓
    Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)
    Overall: PASS

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx all passed ✅ PASS
Node.js execa all passed ✅ PASS
Node.js p-limit all passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for #5758 · 36.2 AIC · ⊞ 7.8K ·
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Smoke Test Results — FAIL

Check Result
Redis PING ❌ Connection timed out / unreachable
PostgreSQL pg_isready ❌ No response on port 5432
PostgreSQL SELECT 1 ❌ Connection timed out / unreachable

Overall: FAILhost.docker.internal is not reachable and services are not responding on localhost. GitHub Actions service containers do not appear to be running in this environment.

🔌 Service connectivity validated by Smoke Services
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@Copilot @lpcox

  • fix: ensure chmod runs even when chown fails in rootless permission repair ✅
  • refactor: split 309-line generateDockerCompose into focused phases ✅
  • GitHub.com connectivity ✅
  • File write/read ✅
  • BYOK inference path ✅
    Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra
    Overall: PASS

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)
Add label ready-for-aw to run again

@lpcox lpcox merged commit 8d5e21d into main Jul 1, 2026
88 of 91 checks passed
@lpcox lpcox deleted the copilot/refactor-start-containers-function branch July 1, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment