Skip to content

fix(k8s): fail the step when the exec stream dies before a terminal status - #74

Open
KadenZhang3321 wants to merge 2 commits into
mainfrom
fix/exec-stream-fail-closed
Open

KadenZhang3321 wants to merge 2 commits into
mainfrom
fix/exec-stream-fail-closed

Conversation

@KadenZhang3321

Copy link
Copy Markdown
Collaborator

Problem

A step that never ran to completion can be reported green. Observed on the
sglang nightly-4-npu-a3 / run (0) partition (Ascend/sglang run 44082178620):
the Run test step finished in ~6 min, the test process was still loading the
first model's weights (Multi-thread loading shards: 6%) when the step
stopped streaming, execPodStepWithOutput returned
{"metadata":{},"status":"Success"}, and the partition was marked successful —
even though run_suite.py printed none of its completion markers
(End (i/..) / Test Summary / TIMINGS END).

Root cause

For a kubernetes/kubernetes-novolume runner every step is delivered through
k8s.Exec, and the step's result is taken from the single terminal
V1Status frame
the apiserver writes on the exec status channel:
execPodStep / execPodStepWithOutput only ever call
resolve(resp.code || 0) when resp.status === 'Success'.

@kubernetes/client-node v1.x resolves the exec websocket on open and then
installs no close and no post-open error handler
(web-socket-handler.ts#connect). So once the connection is established, the
hook has no independent knowledge of the session's real state. If the exec
stream is torn down mid-run by anything on the path between the runner and the
apiserver — most commonly an idle proxy/edge timeout while a long step sits
quiet (e.g. model-weight loading, which logs a line every several seconds) —
the hook either hangs until the step timeout, or treats a spurious terminal
frame as a genuine success: a silently green step.

This is a latent defect in the exec layer itself; it is independent of which
federation (Karmada) or placement the runner uses. What changed recently is the
exposure: long, quiet nightly suites now run as a single multi-minute
streaming exec across a wider pool, so the quiet window that severs the idle
stream finally lands inside a step.

Fix

Backport the intent of upstream actions#333
(WebSocketHeartbeat) and make the step-exec paths fail closed:

  • Keepalive: a periodic WebSocket ping so a quiet output window no longer
    looks like a dead connection to the proxy/edge on the path to the apiserver.
  • Fail-closed on a severed session: if the socket closes or errors
    before a genuine terminal status arrived, the step is failed, never
    trusted as success.
  • Dead-peer detection: a pong that never arrives past the deadline fails
    the step as well.

execPodStep / execPodStepWithOutput keep every existing exit-code path
intact (Success → 0, Failure/message exit code → parsed code, exec()
rejecting with a non-zero message → parsed code). New tunables:

ACTIONS_RUNNER_HEARTBEAT_PERIOD_MS     (default 5000)
ACTIONS_RUNNER_HEARTBEAT_DEADLINE_MS   (default period*12 + 1000 ≈ 61s)

Relationship to #72 (dependency — read this)

This PR is built on top of #72 (feat/exec-retry) and should be merged
after it. The two are complementary and cover opposite sides of the same exec
channel:

  • fix(k8s): retry kubelet dial failures when executing pod steps #72 retries failures that happen while dialing the kubelet — i.e.
    before the command starts, so re-running is safe.
  • This PR covers a stream that dies after the command started — which
    must never be retried (it would re-execute the step). The guard rejects
    with a deliberately dial-pattern-free message, so retryExecCall /
    isExecDialError classify it as "already ran" and propagate the failure
    instead of retrying.

Because both edit execPodStep / execPodStepWithOutput, the diff against
main also shows #72's changes; the only new commit here is this fix. Once #72
merges, retarget this to main (or it rebases to a single clean commit).

Tests

  • tests/heartbeat-test.ts — ping cadence, deadline only armed after the first
    ping, pong keeps it alive, pong-timeout → failure, stop() clears all timers.
  • tests/exec-pod-step-test.ts / tests/exec-pod-step-with-output-test.ts —
    socket closed/errored before a terminal status → step fails; Success then
    clean close → still resolves (no false failure); a mid-run socket error that
    looks like a dial failure is not retried (exec attempted exactly once).
  • fix(k8s): retry kubelet dial failures when executing pod steps #72's exec-retry-test still passes unchanged.

Cluster-backed suites (prepare-job / run-container-step / e2e) are unaffected on
the success path and run in CI's kind cluster.

resolve https://github.com/opensourceways/ascend-ci-deployment/issues/2638

wyhhai and others added 2 commits November 12, 2026 17:33
…tatus

Stacks on #72 (feat/exec-retry): #72 retries failures that happen while
*dialing* the kubelet, before the command starts. This covers the other half —
a stream that dies *after* the command started — which #72 must not retry.

A step's result is taken from the single terminal V1Status frame the apiserver
writes on the exec status channel, and client-node installs no 'close' or
post-open 'error' handler for the exec socket. When that exec stream is torn
down by an intermediary (an idle proxy/edge timeout while a long step sits
quiet, e.g. loading model weights), the hook cannot tell a real completion from
a severed session: it either hangs until the step timeout, or reports Success
for a command that never finished — a silently green job whose test cases did
not run.

Inside each (already retry-wrapped) exec attempt:
- keep the connection alive with a periodic WebSocket ping, so a quiet output
  window no longer looks dead to whatever sits between the runner and the
  apiserver;
- treat a socket close/error that arrives *before* a genuine terminal status as
  a hard failure, never as success;
- a pong that never arrives past the deadline is likewise a failure.

Guard rejections use a dial-pattern-free message so retryExecCall classifies
them as "already started" and does not re-run the step. execPodStep and
execPodStepWithOutput preserve every existing exit-code path. Tunables:
ACTIONS_RUNNER_HEARTBEAT_PERIOD_MS / ACTIONS_RUNNER_HEARTBEAT_DEADLINE_MS.

Adds WebSocketHeartbeat plus unit tests: heartbeat timing, the fail-closed
path, no-retry on mid-run interruption, and a no-false-failure-on-clean-close
regression.
@opensourceways-bot

Copy link
Copy Markdown

Welcome To opensourceways Community

Hey @KadenZhang3321 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: infratructure ,
and any of the maintainers: @GeorgeCao-hw, @TangJia025, @pkking, @zhongjun2 ,
and any of the committers: @GeorgeCao-hw, @Goalina, @Hourunze1997, @JavaPythonAIForBAT, @KadenZhang3321, @LiYanghang00, @ccijunk, @drizzlezyk, @pkking, @rosecoffe, @tfhddd, @yao-xiaobai, @zhongjun2, @zkhzkhz .

@opensourceways-bot

Copy link
Copy Markdown

CLA Signature Guide

@KadenZhang3321 , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
04914d45 fix(k8s): retry kubelet dial fai... the email used in the commit is an invalid email!
please check all commits.
3eae39bc fix(k8s): fail the step when the... the email used in the commit is an invalid email!
please check all commits.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

@opensourceways-bot

Copy link
Copy Markdown
检查项 状态
敏感信息扫描 ✅
漏洞扫描 ✅
开源license合规扫描 ✅
开发阶段设计文档检查 ❌
流水线链接 点击跳转查看日志

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.

3 participants