Skip to content

Retry cold-start Claude connection refusals as fresh runs - #52198

Merged
pelikhan merged 4 commits into
mainfrom
copilot/fix-cli-proxy-connection-issues
Aug 12, 2026
Merged

Retry cold-start Claude connection refusals as fresh runs#52198
pelikhan merged 4 commits into
mainfrom
copilot/fix-cli-proxy-connection-issues

Conversation

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Claude Code could exhaust retries after the Anthropic proxy path refused connections, including before the first response. The harness incorrectly treated startup error output as resumable session progress.

  • Retry classification

    • Detect Connection refused and ECONNREFUSED.
    • Distinguish initialization output from completed assistant responses.
  • Recovery behavior

    • Retry pre-response failures as fresh runs using existing exponential backoff.
    • Preserve --continue retries when the session already contains assistant progress.
Cold-start refusal → fresh run with original prompt
Mid-session refusal → resume with --continue
  • Regression coverage
    • Cover both cold-start and mid-session connection-refused paths.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.6 AIC · ⌖ 5.36 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.1 AIC · ⌖ 5.13 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 13.5 AIC · ⌖ 5.2 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Run context: https://github.com/github/gh-aw/actions/runs/31611144406> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 13.2 AIC · ⌖ 5.14 AIC · ⊞ 8.5K ·

Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 22 AIC · ⌖ 5.29 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Run context: https://github.com/github/gh-aw/actions/runs/31616336935> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.9 AIC · ⌖ 5.25 AIC · ⊞ 8.5K ·

Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 21.3 AIC · ⌖ 5.52 AIC · ⊞ 8.5K ·
Comment /souschef to run again


branch update requested from run https://github.com/github/gh-aw/actions/runs/31624023886> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 6.39 AIC · ⌖ 6.6 AIC · ⊞ 8.5K ·

Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix connection failures in Claude Code CLI to Anthropic API Retry cold-start Claude connection refusals as fresh runs Aug 12, 2026
Copilot AI requested a review from pelikhan August 12, 2026 01:43
@pelikhan
pelikhan marked this pull request as ready for review August 12, 2026 01:46
Copilot AI balanced review requested due to automatic review settings August 12, 2026 01:46
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #52198 does not have the 'implementation' label and has 0 new lines of code in business logic directories (threshold: 100).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship.

Generated by Ponytail Reviewer for #52198

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Warning

Firewall blocked 1 domain

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

  • api.individual.githubcopilot.com

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

network:
  allowed:
    - defaults
    - "api.individual.githubcopilot.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions github-actions Bot 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.

The implementation looks correct. hasClaudeSessionProgress reliably guards the fresh-run path, and the !hasSessionProgress gate prevents false-positive restarts when Claude output happens to mention connection refused. Tests cover both the cold-start retry and the post-progress --continue paths.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 23.1 AIC · ⌖ 6.13 AIC · ⊞ 5.4K

@github-actions github-actions Bot mentioned this pull request Aug 12, 2026

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

Adds connection-refusal-aware retry handling to the Claude harness.

Changes:

  • Detects Connection refused and ECONNREFUSED.
  • Chooses fresh or continued retries based on assistant output.
  • Adds cold-start and mid-session regression tests.
Show a summary per file
File Description
actions/setup/js/claude_harness.cjs Implements refusal classification and retry selection.
actions/setup/js/claude_harness.test.cjs Tests fresh and continued refusal retries.

Review details

Tip

Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread actions/setup/js/claude_harness.cjs Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Test Quality Sentinel Report 🧪

PR: #52198 — "Retry cold-start Claude connection refusals as fresh runs"
Repository: github/gh-aw
Analysis: JavaScript test file changes

Summary

Test Quality Score: 85/100 (Excellent)

This PR adds 4 new test functions (2 unit tests + 2 integration tests) to validate cold-start connection-refused detection and harness retry behavior. Tests follow strong behavioral contracts and avoid mocking violations.


Test Additions

Test File: actions/setup/js/claude_harness.test.cjs

  • Lines added: 63 (no deletions)
  • Lines in source: +38 / -2
  • Test inflation ratio: 1.66 ✅ (< 2:1 threshold)

New Test Functions

Unit Tests (2)
Test Name File Purpose Assertions Assessment
detects common connection-refused messages claude_harness.test.cjs:311–314 Regex pattern matching for connection-refused errors 2 expectations ⚠️ Positive-case only: tests only regex matches; missing negative cases
distinguishes initialization output from assistant progress claude_harness.test.cjs:316–319 Parser logic to detect if Claude produced work before failure 2 expectations (negative + positive) Good behavioral contract: tests state distinction
Integration Tests (2)
Test Name File Purpose Setup Assertions Assessment
retries connection-refused...fresh run claude_harness.test.cjs:556–579 Harness retry strategy when connection refused before first response Stub process fails with init + connection refused on attempt 1, succeeds on attempt 2 3: exit status, call count, log message; --continue not used in either call; prompt sent in both High-value contract: verifies fresh-run retry logic and prompt inclusion for initial attempt
continues...after assistant response claude_harness.test.cjs:581–603 Harness retry strategy when connection refused after assistant produced output Stub process produces assistant response on attempt 1, then fails with connection refused, succeeds on attempt 2 2: exit status, call array with --continue in second call High-value contract: verifies session continuation when work exists

Quality Assessment

Behavioral Coverage ✅

  • Design invariants verified: All 4 tests target real user-facing behavior (retry strategy, connection detection)
  • Error/edge cases: 2/4 tests include edge-case verification (state transitions, init vs. assistant output)
  • Mocking policy: ✅ No violations—JavaScript tests use stub subprocesses with actual behavior observation
  • No implementation-detail tests: All assertions measure observable effects

Assertion Quality

  • Count: 7 total assertions across 4 tests (average 1.75/test)
  • Granularity: Integration tests check status codes and call structure; unit tests use direct equality
  • Message quality: Assertions include result.stderr context in first integration test

Structural Compliance ✅

  • No build tag violations: N/A (JavaScript)
  • No mock library hard violations: N/A (JavaScript vitest; stubs are acceptable)
  • Test organization: Clear describe blocks with semantic naming

Scoring Breakdown

Component Value Calculation
Design tests 40/40 4/4 tests verify contracts × 40
Edge-case credit 15/30 2/4 tests handle edge cases × 30
Duplicate penalty 0/20 No duplicated patterns
Inflation penalty 10/10 Ratio 1.66 < 2:1 ✅
Violations penalty 0 None
Total 85/100 ✅ Excellent

Conclusion

Approval recommended. This PR demonstrates strong test discipline:

  • Tests target design invariants (retry policy, state detection)
  • Integration tests verify end-to-end behavior with realistic subprocess scenarios
  • No mocking violations or assertion-quality issues
  • Test inflation is healthy (~1.7× ratio for substantial feature addition)
  • 0% implementation-detail tests; 100% behavioral tests

🧪 Test quality analysis by Test Quality Sentinel · haiku45 · 26.4 AIC · ⌖ 2.75 AIC · ⊞ 7.6K ·
Comment /review to run again

@github-actions github-actions Bot 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.

✅ Test Quality Sentinel: 85/100 (Excellent). All 4 tests verify design invariants with 0% implementation-detail tests. Test inflation ratio 1.66 within threshold. No mocking violations or assertion-quality issues. Approval recommended.

@github-actions github-actions Bot 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.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — three minor issues flagged, no blockers.

📋 Key Themes & Highlights

Key Themes

  • No-op per-line guard in hasClaudeSessionProgress: the !isConnectionRefusedError(line) filter inside .some() can never trigger because a single NDJSON line won't simultaneously match both patterns. The function works correctly today, but the dead guard is misleading.
  • Missing unit-test boundary: the unit suite covers init-only and assistant-present cases but skips the mixed scenario (assistant line followed by a connection-refused line) that the integration test exercises.
  • Implicit state assumption: the cold-start retry branch silently assumes no harness state was mutated during the failed attempt — worth a clarifying comment.

Positive Highlights

  • ✅ Clean separation: isConnectionRefusedError and hasClaudeSessionProgress are small, focused, and independently testable.
  • ✅ Good regression coverage: both cold-start and mid-session refusal paths are covered by integration tests.
  • ✅ The useContinueOnRetry = false reset correctly prevents a misguided --continue on a fresh-run retry.
  • ✅ Logging additions (isConnectionRefusedError=, hasSessionProgress=) make future diagnosis straightforward.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 41 AIC · ⌖ 6.75 AIC · ⊞ 7K
Comment /matt to run again

Comment thread actions/setup/js/claude_harness.cjs Outdated
Comment thread actions/setup/js/claude_harness.test.cjs
Comment thread actions/setup/js/claude_harness.cjs
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skil

…d retries

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please run the pr-finisher skill, verify the minor review notes are addressed or consciously waived, and refresh the branch if needed before handing back to maintainers.

Reviewer follow-up to inspect:

No failed checks were reported in the compact candidate set for this run.
Branch update was requested by sous-chef in run https://github.com/github/gh-aw/actions/runs/31557779439.

Generated by 👨🍳 PR Sous Chef
Comment /souschef to run again

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.6 AIC · ⌖ 5.36 AIC · ⊞ 8.5K ·
Comment /souschef to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please run the pr-finisher skill and hand this PR back to maintainers once the already-addressed review threads are resolved.

Open review threads with follow-up replies detected:

No failed checks were reported in the compact candidate set for this run.
Branch update could not be requested automatically from this environment.
Run context: https://github.com/github/gh-aw/actions/runs/31608510196

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 17.6 AIC · ⌖ 6.5 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please run the pr-finisher skill and hand this PR back to maintainers once the already-addressed review threads are resolved.

Open review threads with follow-up replies detected:...

Re-verified: all four threads are already addressed by commit ad2e34b (sessionHasProgress tracked cumulatively across --continue attempts, no-op per-line guard removed, mid-session refusal regression test present, defensive comment on the fresh-run reset). make fmt produced no changes; claude_harness.test.cjs passes 86/86 (one test timed out only when run under full-suite load — confirmed passing in isolation, and it's a pre-existing test unrelated to this PR's changes). I still have no tool to resolve GitHub review threads in this environment, so a maintainer will need to resolve them and merge.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please run the pr-finisher skill and hand this PR back to maintainers once the remaining already-addressed review threads are resolved.

Open review threads with follow-up replies detected:

No failed checks were reported in the compact candidate set for this run.
Branch update was requested by sous-chef for this run when GitHub allows it.
Run context: https://github.com/github/gh-aw/actions/runs/31611144406

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 13.2 AIC · ⌖ 5.14 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please run the pr-finisher skill and hand this PR back to maintainers once the remaining already-addressed review threads are resolved.

Open review threads with follow-up replies detected:...

No change since my last reply — same automated request. All four threads remain addressed by commit ad2e34b and verified locally. I still have no tool to resolve GitHub review threads in this environment; a maintainer needs to resolve them and merge.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please run the pr-finisher skill and hand this PR back to maintainers once the remaining already-addressed review threads are resolved.

Open review threads with follow-up replies detected:

No failed checks were reported in the compact candidate set for this run.
Branch update was requested by sous-chef for this run when GitHub allows it.
Run context: https://github.com/github/gh-aw/actions/runs/31613667722

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 22 AIC · ⌖ 5.29 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please run the pr-finisher skill and hand this PR back to maintainers once the remaining already-addressed review threads are resolved.

Open review threads with follow-up replies detected:...

Same automated request as before — nothing has changed. All four threads remain addressed by commit ad2e34b and verified locally; I still have no tool to resolve GitHub review threads in this environment, so a maintainer needs to resolve them and merge.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please run the pr-finisher skill and hand this PR back to maintainers once the remaining already-addressed review threads are resolved.

Open review threads with follow-up replies detected:

No failed checks were reported in the compact candidate set for this run.
Branch update was requested by sous-chef for this run when GitHub allows it.
Run context: https://github.com/github/gh-aw/actions/runs/31616336935

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.9 AIC · ⌖ 5.25 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please run the pr-finisher skill and hand this PR back to maintainers once the remaining already-addressed review threads are resolved.

Open review threads with follow-up replies detected:...

Same automated request as before — nothing has changed. All four threads remain addressed by commit ad2e34b and verified locally. I have no tool to resolve GitHub review threads in this environment; a maintainer needs to resolve them and merge.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please inspect the latest branch state, resolve any already-addressed review threads that remain open if tooling allows, refresh the branch if needed, and run the pr-finisher skill before handing this PR back to maintainers.

Open review threads with author follow-up detected:

No failed checks were reported in the compact candidate set for this run.
Branch update was requested automatically for this run when GitHub allows it.

Run context: https://github.com/github/gh-aw/actions/runs/31621521625

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 21.3 AIC · ⌖ 5.52 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please inspect the latest branch state, resolve any already-addressed review threads that remain open if tooling allows, refresh the branch if needed, and run the pr-finisher skill before h...

Branch is already up to date with main. The review thread is now marked resolved, and the code fixes from commit ad2e34b remain unchanged and verified. No further action needed on my end.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please inspect the latest branch state, resolve any already-addressed review threads that remain open if tooling allows, refresh the branch if needed, and run the pr-finisher skill before handing this PR back to maintainers.

Open review threads with author follow-up detected:

No failed checks were reported in the compact candidate set for this run.
Branch update was requested automatically for this run when GitHub allows it.

Run context: https://github.com/github/gh-aw/actions/runs/31624023886

Generated by 👨🍳 PR Sous Chef
Comment /souschef to run again

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 6.39 AIC · ⌖ 6.6 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please inspect the latest branch state, resolve any already-addressed review threads that remain open if tooling allows, refresh the branch if needed, and run the pr-finisher skill before h...

Branch is up to date with main (merge commit 0f785ce already includes latest main). All four review threads remain addressed by commit ad2e34b — verified again: sessionHasProgress is tracked cumulatively across --continue attempts and only reset on a genuinely fresh run, the no-op per-line guard is gone, and the mid-session refusal regression test is present. Ran the full claude_harness.test.cjs suite — 86/86 passing. No code changes needed. I don't have a tool to resolve GitHub review threads in this environment, so a maintainer will need to resolve them and merge.

@pelikhan
pelikhan merged commit cccc09a into main Aug 12, 2026
13 checks passed
@pelikhan
pelikhan deleted the copilot/fix-cli-proxy-connection-issues branch August 12, 2026 18:35
@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: bug
  • Risk: medium
  • Score: 60/100 (impact 30 + urgency 15 + quality 15)
  • Recommended action: fast_track
  • Note: 8 reviews incl 2 APPROVED by github-actions; active discussion (35 comments)

Generated by 🔧 PR Triage Agent · auto · 39.1 AIC · ⌖ 2.59 AIC · ⊞ 7.8K ·

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw-failures] [P1] Fix Claude Code CLI → Anthropic API connection-refused failures (proxy/firewall)

4 participants