Installation

Install as Agent Plugin Recommended
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install gke-ai-troubleshooting-jobset-interruption@skills-hub

Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled). Plugin gke-ai-troubleshooting-jobset-interruption v1.0.0 follows the Agent Plugins spec.

Install with the gh extension
gh skills-hub install gke-ai-troubleshooting-jobset-interruption

Don't have the extension? Run gh extension install samueltauil/skills-hub first.

Download and extract to your repository:

.github/skills/gke-ai-troubleshooting-jobset-interruption/

Extract the ZIP to .github/skills/ in your repo. The folder name must match gke-ai-troubleshooting-jobset-interruption for Copilot to auto-discover it.

Skill Files (4)

SKILL.md 11.3 KB
---
name: gke-ai-troubleshooting-jobset-interruption
metadata:
  version: "1.0.1"
  category: Containers
description: >-
  Diagnoses GKE JobSet interruptions, restarts, and preemptions for AI/ML training workloads autonomously.
  Use when troubleshooting JobSet restart loops, spot VM preemptions, node readiness failures, host VM issues, or coordinator worker crashes.
  Don't use for general GKE cluster creation, basic workload deployment, or non-JobSet application issues.
---

# GKE JobSet Interruption Troubleshooting

Use this skill to systematically diagnose and resolve JobSet interruptions,
restarts, and preemptions on GKE clusters hosting large-scale AI/ML workloads.

## Attribution

**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
MUST read [Usage Attribution](references/attribution.md). For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix `gcloud` with
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-ai-troubleshooting-jobset-interruption)"`
and append `agent-skills/1.0 (skill:gke-ai-troubleshooting-jobset-interruption)` to `User-Agent` headers.

## ⚠️ Prerequisites & Sandbox Rules

-   JobSet metrics package must be enabled in `kube-state-metrics` for your
    cluster.
-   Cloud Logging and Cloud Monitoring enabled for the Google Cloud Project.
-   **Autonomous & Sandbox Execution Rule**: If API queries, tools, or commands
    encounter `403 Permission Denied`, authentication errors, or network
    isolation, **do NOT enter authentication or credential troubleshooting
    loops**. Populate the query templates with the acquired variables
    (`{project_id}`, `{cluster_name}`, `{workload_name}`, `{start_time}`,
    `{end_time}`), inspect any locally staged telemetry or mock data files if
    available, and complete the diagnostic workflow and resolution
    recommendations autonomously.

## 🔍 Diagnostic Workflow

### Step 0: Context Acquisition & Time Window Definition

Independently gather context using tools, workspace files, environment details,
or user prompt context:

-   **Project ID** (`{project_id}`)
-   **Cluster Name** (`{cluster_name}`)
-   **Workload Name (JobSet Name)** (`{workload_name}`)
-   **Workload Namespace** (`{namespace}`)
-   **Issue Time** (`{issue_time}`)

If specific variables are not explicitly provided by the user, inspect cluster
resources or logs to determine them, or use the `{variable}` placeholders
provided.

#### Time Handling Rules

1.  **Autonomous Time Window**: If a relative time (e.g., "X minutes ago") or no
    exact timestamp is provided, calculate the query window based on current
    time or available log timestamps.
2.  **Window Calculation**: If a timestamp `{issue_time}` is available (or
    calculated as `T`), set `{start_time}` = `T - 30m` and `{end_time}` = `T +
    30m`.

--------------------------------------------------------------------------------

### Step 1: Identify JobSet Restarts and Attempts [Low Risk]

Verify if the JobSet is experiencing restart loops and determine the frequency
of restarts.

#### Visual Chart / MQL Query - restarts

-   **MQL Query Specification**:

    ```mql
    fetch prometheus_target
    | metric 'prometheus.googleapis.com/kube_jobset_restarts/gauge'
    | filter resource.cluster_name == '{cluster_name}' && metric.jobset_name == '{workload_name}'
    | align next_older(1m)
    | every 1m
    | group_by [metric.jobset_name], [val: max(value)]
    ```

#### PromQL Metric Query - restarts

-   **PromQL Query Specification**:

    ```promql
    kube_jobset_restarts{jobset_name="{workload_name}", cluster="{cluster_name}"}
    ```

-   **Diagnostic Logic**: A non-zero or increasing value for restarts indicates
    that the JobSet is being actively restarted by the controller due to worker
    failure or interruption.

-   **Automation**: Proceed to Step 2 automatically after reporting findings.

--------------------------------------------------------------------------------

### Step 2: Inspect Nodepool Interruptions [Low Risk]

Determine if the JobSet restarts were triggered by physical nodepool-level
events (such as spot preemptions, maintenance, or host terminations).

#### A. Metrics Query (Nodepool Interruption Counts)

##### Visual Chart / MQL Query - interruptions

-   **MQL Query Specification**:

    ```mql
    fetch k8s_node_pool
    | metric 'kubernetes.io/node_pool/interruption_count'
    | filter cluster_name == '{cluster_name}'
    | align next_older(10m)
    | every 10m
    | group_by [metric.interruption_type, metric.interruption_reason, metadata.system.node_pool_name], [val: sum(value)]
    ```

##### PromQL Query - interruptions

-   **PromQL Query Specification**:

    ```promql
    sum by (interruption_type, interruption_reason, node_pool_name, cluster_name) (
      avg_over_time(kubernetes_io:node_pool_interruption_count{cluster_name="{cluster_name}"}[10m])
    )
    ```

#### B. Log Query (Nodepool Life Events)

-   **LQL Log Filter Specification**:

    ```sql
    resource.type="gke_nodepool"
    AND resource.labels.cluster_name="{cluster_name}"
    AND timestamp >= "{start_time}"
    AND timestamp <= "{end_time}"
    ```

-   **Diagnostic Logic**:

    -   **PreemptionEvent**: Spot VMs were preempted, or node was scale-down.
    -   **MaintenanceEvent**: Node pool updated or Google scheduled maintenance.
    -   **TerminationEvent**: Serious host failures. Check `interruption_reason`
        or logs for host issues.
    -   See [Failure Signatures](references/failure_signatures.md) for examples
        of node termination logs and preemption events.

-   **Automation**: Proceed to Step 3 automatically.

--------------------------------------------------------------------------------

### Step 3: Inspect Nodes and Underlying Host VMs [Low Risk]

Correlate node readiness failures with physical host VMs to see if a single
faulty host repeatedly fails coordinator pods.

#### A. Metrics Query (Node Ready Status Check)

##### Visual Chart / MQL Query - node status

-   **MQL Query Specification**:

    ```mql
    fetch k8s_node
    | metric 'kubernetes.io/node/status_condition'
    | filter cluster_name == '{cluster_name}' && metric.condition == 'Ready' && metric.status == 'False'
    | align next_older(1m)
    | every 1m
    | group_by [node_name, metadata.user.gke_nodepool], [val: max(value)]
    ```

##### PromQL Query - node status

-   **PromQL Query Specification**:

    ```promql
    sum by (status, condition, node_pool_name) (
      kubernetes_io:node_status_condition{cluster_name="{cluster_name}", condition="Ready", status="False"}
    )
    ```

#### B. Metrics Query (Node-to-Host Metadata Topology Correlation)

-   **MQL Query Specification**:

    ```mql
    fetch k8s_node
    | metric 'kubernetes.io/node/cpu/total_cores'
    | filter cluster_name == '{cluster_name}'
    | align next_older(1m)
    | every 1m
    | group_by [node_name, metadata.user.gce_topology_host, metadata.user.gke_nodepool], [val: max(value)]
    ```

#### C. Log Query (Node Fault Logs)

-   **LQL Log Filter Specification**:

    ```sql
    resource.type="k8s_node"
    AND resource.labels.cluster_name="{cluster_name}"
    AND (textPayload:"host error" OR textPayload:"kernel panic" OR textPayload:"hardware failure" OR textPayload:"NodeNotReady")
    AND timestamp >= "{start_time}"
    AND timestamp <= "{end_time}"
    ```

-   **Diagnostic Logic**: Identify if specific nodes are unhealthy
    (`Ready=False` or `Unknown`) and correlate them to their GCE physical host
    ID via `metadata.user.gce_topology_host`. Check if the same host is
    repeatedly failing.

-   **Automation**: Proceed to Step 4 automatically.

--------------------------------------------------------------------------------

### Step 4: Inspect Pod and Worker / Container Failures [Low Risk]

Analyze pod status phases and retrieve coordinator worker logs to identify
application-level crashes or network deadlocks.

> **Required Execution Order**: You MUST analyze pod status phases (Section A)
> and unschedulable pod metrics (Section B) to assess overall workload health
> before inspecting specific worker container logs (Section C).

#### A. Metrics Query (Pod Lifecycle Phases)

##### Visual Chart / MQL Query - pod phase

-   **MQL Query Specification**:

    ```mql
    fetch k8s_pod
    | metric 'kubernetes.io/pod/status/phase'
    | filter cluster_name == '{cluster_name}' && pod_name ==~ '{workload_name}.*'
    | align next_older(10m)
    | every 10m
    | group_by [metric.phase], [val: count()]
    ```

##### PromQL Query - pod phase

-   **PromQL Query Specification**:

    ```promql
    sum by (phase) (
      avg_over_time(kube_pod_status_phase{cluster="{cluster_name}", pod=~"{workload_name}.*"}[10m])
    )
    ```

#### B. Metrics Query (Unschedulable Pod Count)

-   **MQL Query Specification**:

    ```mql
    fetch k8s_pod
    | metric 'kubernetes.io/pod/status/unschedulable'
    | filter cluster_name == '{cluster_name}' && pod_name ==~ '{workload_name}.*'
    | align next_older(10m)
    | every 10m
    | group_by [pod_name], [val: max(value)]
    ```

#### C. Log Query (Worker Container Logs)

-   **LQL Log Filter Specification**:

    ```sql
    resource.type="k8s_container"
    AND resource.labels.cluster_name="{cluster_name}"
    AND labels."k8s-pod/jobset_sigs_k8s_io/jobset-name"="{workload_name}"
    AND timestamp >= "{start_time}"
    AND timestamp <= "{end_time}"
    ```

-   **Diagnostic Logic**:

    1.  Check the pod timeline to spot pending or unschedulable pods.
    2.  Use worker container logs to analyze worker 0 in slice 0 (coordinator)
        for NCCL timeouts, collective communication issues, or MegaScale hangs.

-   **Automation**: Proceed to Resolution.

--------------------------------------------------------------------------------

## 🛠️ Resolution Workflow

### Resolution 1: Preemption & Autoscaling Optimizations [Low Risk]

If Step 2 showed high preemption counts on Spot VMs:

-   **Action**: Suggest switching critical long-running training workloads to
    **GKE Reserved/On-Demand VMs** or utilizing **Compact Placement Policies**
    to minimize defragmentation interruptions.
-   **Justification**: Eliminates spot-market preemptions and reduces training
    restarts.

### Resolution 2: Quarantine Faulty Host VMs [High Risk]

If Step 3 identified a specific host ID (`gce-topology-host`) that consistently
fails or triggers restarts across multiple attempts:

-   **Action**: Recommend cordoning/draining the GKE node, deleting the
    underlying GCE VM instance to trigger instance recreation, and opening a
    support ticket with Google Cloud Support specifying the physical host ID.
-   **Justification**: GKE auto-repair will recreate the VM instance on healthy
    physical hardware, preventing infinite restart loops.

--------------------------------------------------------------------------------

## 📋 Copypaste Checklist

-   [ ] Gather context and compute `{start_time}` (`{issue_time} - 30m`) and
    `{end_time}` (`{issue_time} + 30m`) window.
-   [ ] Query JobSet restart attempts.
-   [ ] Check Nodepool interruptions (spot preemptions vs. hardware
    terminations).
-   [ ] Query node-to-host mapping and check node logs for physical host errors.
-   [ ] Inspect pod timeline status and coordinator worker container logs.
-   [ ] Recommend appropriate scheduling strategy (On-demand vs Spot) or host VM
    quarantining.
references/
attribution.md 1.9 KB
# Usage Attribution

**MUST READ**: Before executing any `gcloud`, REST API, or MCP command with
this skill, follow these usage attribution instructions. Tag every command you
execute directly in the terminal so usage can be attributed. The tag identifies
only the skill and its version; it carries no user data.

-   **`gcloud` CLI Commands**: Prefix every `gcloud` invocation, whatever the
    subcommand, with the metrics environment variable. Set it inline on each
    command because shell state may not persist between commands:

    ```bash
    CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-ai-troubleshooting-jobset-interruption)" \
    gcloud <command> [flags]
    ```

    Do not use `gcloud config set` for this: it would persist beyond the current
    task and mislabel unrelated usage.

-   **Direct HTTP, REST, and MCP Requests**: On direct HTTP calls to Google
    Cloud APIs (for example with `curl`) or HTTP requests to a remote MCP
    server, include `agent-skills/1.0 (skill:gke-ai-troubleshooting-jobset-interruption)` in the `User-Agent`
    header. If a `User-Agent` header is already specified, append this string to
    the end of it rather than overwriting existing `User-Agent` data — the
    collection pipeline parses the `agent-skills/<version>` and `skill:<name>`
    tokens, so any rewording breaks attribution:

    ```
    User-Agent: <existing_user_agent> agent-skills/1.0 (skill:gke-ai-troubleshooting-jobset-interruption)
    ```

-   **Constraint for Generated Code**: The tracking prefix is strictly for
    commands you execute directly in the terminal. Do NOT include this tracking
    prefix in generated scripts, Terraform templates, or code provided to the
    user for their own repositories.

-   **User Opt-Out**: If the user asks to disable or remove tracking or
    attribution tags, omit the `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION` variable
    and custom `User-Agent` suffix from all commands.
failure_signatures.md 2.5 KB
# JobSet Interruption Failure Signatures

This document provides authentic, anonymized logs, metrics, and signal patterns
associated with GKE JobSet interruptions, Spot VM preemptions, physical host
hardware failures, and worker application hangs.

--------------------------------------------------------------------------------

## 1. Nodepool Preemption Event (Spot VMs)

When Spot VMs are preempted by GCE, the nodepool logs record a preemption
interruption event.

**Example Cloud Logging (LQL) Match:**

```sql
resource.type="gke_nodepool"
severity=INFO

"PreemptionEvent: Node 'gke-tpu-pool-12345-abcde' in node pool 'tpu-pool' was preempted."
```

--------------------------------------------------------------------------------

## 2. Node / Host Hardware Failure (TerminationEvent)

A physical host error or hardware failure will trigger a TerminationEvent, often
accompanied by a "Host Error" or "kernel panic" payload.

**Example Logs:**

```text
May 20 08:12:15 gke-tpu-pool-12345-abcde kernel: [ 9876.543210] BUG: unable to handle kernel paging request at 0000000000002008
May 20 08:12:16 gke-tpu-pool-12345-abcde systemd[1]: node-problem-detector.service: Main process exited, code=exited, status=1/FAILURE
```

**Cloud Logging Filter Match:**

```sql
resource.type="k8s_node"
severity=ERROR

"TerminationEvent: Node 'gke-tpu-pool-12345-abcde' was terminated due to: Host Error"
```

--------------------------------------------------------------------------------

## 3. Worker NCCL / Collective Communication Timeouts (MegaScale Hang)

When a training run hangs due to network packet drop or worker failure, the
remaining workers will eventually timeout waiting for collective communication.

**Example Log Patterns:**

```text
[rank0]:[2026-05-20 08:14:30,123] torch.distributed.elastic.multiprocessing.api: [ERROR] Child process 12345 died with exit code 1
[rank0]:[2026-05-20 08:14:35,456] NCCL WARN : [Proxy Service] Failed to send, connection reset by peer
[rank0]:[2026-05-20 08:14:40,000] NCCL WARN: Collective collectiveName/1234567890abcde timeout after 1800 seconds
```

--------------------------------------------------------------------------------

## 4. Pod Unschedulable Due to Resource Quota / Placement Constraints

If the GKE autoscaler cannot find sufficient capacity or compact placement
groups for rescheduled JobSet workers, pods will remain `Pending` with
`Unschedulable` status.

**Example Log / PromQL Signal:**

```sql
resource.type="k8s_pod"
severity=WARNING

"0/8 nodes are available: 8 Insufficient tpu, 8 node(s) did not match Topology Spread Constraints."
```
scripts/
validate_queries.sh 3.6 KB
#!/bin/bash
# Validate Cloud Logging LQL queries used in SKILL.md
set -euo pipefail

# Allow PROJECT_ID to be passed as environment variable, fallback to gcloud config
PROJECT_ID=${PROJECT_ID:-$(gcloud config get-value project 2>/dev/null || echo "")}

if [[ -z "${PROJECT_ID}" ]]; then
  echo "⚠️ Warning: PROJECT_ID not set and gcloud config project is empty. Skipping validation."
  exit 0
fi

echo "Using project: ${PROJECT_ID}"

# Step 2: Nodepool Logs Filter
readonly FILTER_1="resource.type=\"gke_nodepool\" AND resource.labels.cluster_name=\"test-cluster\""
echo "Validating Step 2 Nodepool filter..."
gcloud logging read "${FILTER_1}" --limit=1 --project="${PROJECT_ID}" >/dev/null || echo "⚠️ Dry run warning: Filter 1 validation failed or returned error (could be permissions/empty logs)."

# Step 3: Node Logs Filter
readonly FILTER_2="resource.type=\"k8s_node\" AND resource.labels.cluster_name=\"test-cluster\" AND (textPayload:\"host error\" OR textPayload:\"kernel panic\")"
echo "Validating Step 3 Node filter..."
gcloud logging read "${FILTER_2}" --limit=1 --project="${PROJECT_ID}" >/dev/null || echo "⚠️ Dry run warning: Filter 2 validation failed or returned error (could be permissions/empty logs)."

# Step 4: Worker Container Logs Filter
readonly FILTER_3="resource.type=\"k8s_container\" AND resource.labels.cluster_name=\"test-cluster\" AND labels.\"k8s-pod/jobset_sigs_k8s_io/jobset-name\"=\"test-jobset\""
echo "Validating Step 4 Worker Container filter..."
gcloud logging read "${FILTER_3}" --limit=1 --project="${PROJECT_ID}" >/dev/null || echo "⚠️ Dry run warning: Filter 3 validation failed or returned error (could be permissions/empty logs)."

# Step 5: Prometheus PromQL Query Validation (Dry-Run)
echo "Validating GMS for Prometheus PromQL query compilation..."

validate_promql() {
  local name="${1}"
  local query="${2}"
  local response

  response=$(curl -s -w "%{http_code}" -o /dev/null -H "Authorization: Bearer $(gcloud auth print-access-token 2>/dev/null || echo '')" \
    "https://monitoring.googleapis.com/v1/projects/${PROJECT_ID}/location/global/prometheus/api/v1/query?query=${query}" 2>/dev/null || echo "000")

  if [[ "${response}" == "200" ]]; then
    echo "  - ${name} validated successfully (HTTP 200 OK)."
  elif [[ "${response}" == "000" || "${response}" == "401" || "${response}" == "403" ]]; then
    echo "⚠️ Warning: Could not reach GMS query API for ${name} (offline or unauthenticated). Skipping."
  else
    echo "❌ Error: PromQL compilation failed for ${name} with HTTP status ${response}."
    exit 1
  fi
}

# 1. JobSet Restarts PromQL
validate_promql "JobSet Restarts Query" "kube_jobset_restarts%7Bcluster%3D%22test-cluster%22%7D"

# 2. Nodepool Interruption Counts PromQL
validate_promql "Nodepool Interruption Query" "sum%20by%20%28interruption_type%2C%20interruption_reason%2C%20node_pool_name%2C%20cluster_name%29%20%28avg_over_time%28%7B__name__%3D%22kubernetes.io%2Fnode_pool%2Finterruption_count%22%2C%20monitored_resource%3D%22k8s_node_pool%22%2C%20cluster_name%3D%22test-cluster%22%7D%5B10m%5D%29%29"

# 3. Node Ready Status PromQL
validate_promql "Node Ready Status Query" "sum%20by%20%28status%2C%20condition%2C%20node_pool_name%29%20%28%7B__name__%3D%22kubernetes.io%2Fnode%2Fstatus_condition%22%2C%20monitored_resource%3D%22k8s_node%22%2C%20cluster_name%3D%22test-cluster%22%2C%20condition%3D%22Ready%22%2C%20status%3D%22False%22%7D%29"

# 4. Pod Lifecycle Phases PromQL
validate_promql "Pod Lifecycle Query" "sum%20by%20%28phase%29%20%28avg_over_time%28%7B__name__%3D%22kube_pod_status_phase%22%2C%20cluster%3D%22test-cluster%22%2C%20pod%3D~%22test-jobset.*%22%7D%5B10m%5D%29%29"

echo "✅ Validation pass completed."

License (Apache-2.0)

View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/google/skills/blob/main/LICENSE