Skip to content

No retry on transient TLS errors: "unknown certificate verification error" #43864

Closed as not planned

Description

@Rotaxart

Description

Title: No retry on transient TLS errors: "unknown certificate verification error"

Environment: opencode 1.18.20 (linux-x64), provider zai-coding-plan, endpoint api.z.ai

Problem: When the TCP connection to the provider is reset mid-TLS-handshake (degraded route, ~20% packet loss measured with curl to the same endpoint), Bun surfaces Error: unknown certificate verification error from doStream. None of RETRYABLE_MESSAGE_PATTERNS in packages/opencode/src/session/retry.ts match this message, so opencode aborts the agent run instead of retrying. 45 occurrences in my logs over 2 weeks.

Fix: PR adds TLS handshake/certificate verification patterns to the retryable list — these are transport-level transient failures, same class as econnreset/socket hang up

Plugins

No plugins. Custom provider config only: zai-coding-plan (z.ai endpoint) in ~/.config/opencode/opencode.json

OpenCode version

1.18.20

Steps to reproduce

  1. Configure the zai-coding-plan provider (endpoint https://api.z.ai)
  2. From a network with a degraded route to api.z.ai, run any prompt
  3. When the TCP connection is reset mid-TLS-handshake, the run fails immediately with
    Error: unknown certificate verification error — no retry attempt is shown

Route degradation is verifiable outside opencode:
for i in $(seq 1 15); do curl -sS -o /dev/null -w "%{http_code}\n" --max-time 10 https://api.z.ai/api/coding/paas/v4/models; done
→ ~3/15 requests fail with "Connection timed out", while
openssl s_client -connect api.z.ai:443 verifies the certificate OK every time —
i.e. the cert is valid, the transport is flaky.

Screenshot and/or share link

No response

Operating System

Ubuntu 24.04.3 LTS (Linux 7.0.0-29-generic, x64)

Terminal

kitty / zsh (TUI)

Activity

  1. github-actions commented on Aug 21, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is distinct, please add context explaining how it differs.

  2. MilkyWay008 commented on Aug 21, 2026

    @MilkyWay008

    Since openssl s_client -connect api.z.ai:443 verifies fine every time but the run still dies with unknown certificate verification error, it isn't the cert, it's the handshake getting reset mid-way, and that ~20% packet loss lines up with it. If you're behind a proxy, double check HTTP(S)_PROXY isn't injecting its own CA, a transparent MITM proxy turning a reset into a bogus cert failure is exactly how this presents. Routing api.z.ai through a stabler path (or a VPN) should cut the false positives way down while the retry.ts fix lands.

  3. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions