ariadne/ariadne/services/hermes_storage_signals.py
codex ca2324ab95
All checks were successful
Tests / Declarative: Post Actions passed: 1251
feat(hermes): reclaim exhausted workspace storage, and stop hung builds
Two real actions, both for failures that interrupted this project while it was
being built, and both backed by code Ariadne already had.

reclaim_workspace_storage closes a gap left open deliberately: 'no space left
on device' was excluded from the transient retry because a rebuild lands on
the same full volume and either fails identically or hides a capacity problem.
Reclaiming first makes the retry meaningful. The reclaim is the existing
scheduled cleanup, with its own deletion budget, so no new capability is
granted - it is only reachable from triage now. Its signature requires both a
storage marker and a workspace hint, because a full disk elsewhere in the
cluster is a different failure that reclaiming Jenkins workspaces would not
address.

Hung-build detection previously filed an issue and left the build running,
holding one of five Jenkins agent slots and starving every other job - the
actual harm. Ariadne now stops it as well, which is reversible: the job can
simply be built again.

The action executors move to their own module. They are the only code in
triage that changes anything outside Ariadne and should be reviewable as one
unit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 20:55:35 -03:00

68 lines
2.5 KiB
Python

"""Recognise a build that failed because Jenkins workspace storage was full.
This is the case deliberately excluded from the transient-infra retry. A
rebuild alone lands on the same full volume, so it either fails identically or
hides a capacity problem. The remediation is to reclaim the stale workspace
artifacts first and only then rebuild, which is a different action rather than
a more permissive retry.
Ariadne already owns that reclaim: `cleanup_jenkins_workspace_storage` deletes
stale workspace PVCs, PVs and orphan Longhorn volumes under its own deletion
budget, and has been running on a schedule. Wiring it to triage gives the
failure a remedy without granting any capability that did not already exist.
"""
from __future__ import annotations
from typing import Any
STORAGE_MARKERS: tuple[str, ...] = (
"no space left on device",
"no space left",
"disk quota exceeded",
"insufficient disk space",
"failed to write: disk full",
)
# A build can mention a full disk while failing for another reason, so the
# marker must appear alongside something that ties it to the workspace.
WORKSPACE_HINTS: tuple[str, ...] = (
"workspace",
"/home/jenkins/agent",
"jenkins-workspace",
"pvc",
)
def has_storage_exhaustion_signature(bundle: dict) -> tuple[bool, str | None]:
"""Report whether the evidence shows workspace storage exhaustion.
Inputs: an evidence bundle from `collect_evidence`. Outputs: (matched,
marker) where marker is the storage phrase that matched, so the audit
trail records why the reclaim was considered justified.
Both a storage marker and a workspace hint must appear, in that region or
the tail. A full disk elsewhere in the cluster is not this failure, and
reclaiming Jenkins workspaces would not address it. Never raises.
"""
try:
jenkins = bundle.get("jenkins") if isinstance(bundle.get("jenkins"), dict) else {}
haystacks = []
regions = jenkins.get("console_failures")
for region in regions if isinstance(regions, list) else []:
if isinstance(region, dict):
haystacks.append(str(region.get("text") or ""))
haystacks.append(str(jenkins.get("console_tail") or ""))
for text in haystacks:
lowered = text.lower()
if not any(hint in lowered for hint in WORKSPACE_HINTS):
continue
for marker in STORAGE_MARKERS:
if marker in lowered:
return True, marker
return False, None
except Exception:
return False, None