Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(ui): clarify harness failure details

Call White78d0c261ef36
diff --git a/core/scheduled_tasks.py b/core/scheduled_tasks.py
index d8427a9e2..45a1e0400 100644
--- a/core/scheduled_tasks.py
+++ b/core/scheduled_tasks.py
@@ -113,6 +113,7 @@ from storage.background import (
SWEEP_REASON_ORPHANED,
SWEEP_REASON_QUEUE_HOLD_EXPIRED,
SWEEP_REASON_TRANSPORT_UNAVAILABLE,
+ TASK_LAST_RESULT_STATUS_METADATA_KEY,
SweptRun,
WATCH_HOOK_OUTCOME_CIRCUIT_REPAIR,
WATCH_HOOK_OUTCOME_EVENT,
@@ -1841,6 +1842,7 @@ class ScheduledTaskStore:
exit_code: Optional[int] = None,
records_command_outcome: bool = False,
timed_out: bool = False,
+ result_status: Optional[str] = None,
queued_run: Optional[dict[str, Any]] = None,
expected_uncanceled_run_id: Optional[str] = None,
) -> bool:
@@ -1856,6 +1858,10 @@ class ScheduledTaskStore:
result, and it is what makes ``exit_code`` authoritative in both directions --
see the write below.
+ ``result_status`` is the existing terminal Run verdict when this stamp is a
+ projection from that ledger. It is stored in definition metadata so read
+ surfaces never have to recover cancellation from localized ``error`` text.
+
``expected_uncanceled_run_id`` re-asserts, inside that same transaction, that
the fire being stamped has not been stopped -- see
``upsert_scheduled_task_with_queued_run``. Only meaningful alongside
@@ -1875,6 +1881,18 @@ class ScheduledTaskStore:
expect = self._read_state(task)
task.last_run_at = _utc_now_iso()
task.last_error = error
+ normalized_result_status = str(result_status or "").strip()
+ if normalized_result_status in TERMINAL_RUN_STATUSES:
+ task.metadata = {
+ **(task.metadata if isinstance(task.metadata, dict) else {}),
+ TASK_LAST_RESULT_STATUS_METADATA_KEY: normalized_result_status,
+ }
+ elif (
+ isinstance(task.metadata, dict)
+ and TASK_LAST_RESULT_STATUS_METADATA_KEY in task.metadata
+ ):
+ task.metadata = dict(task.metadata)
+ task.metadata.pop(TASK_LAST_RESULT_STATUS_METADATA_KEY, None)
if records_command_outcome:
# A COMMAND FIRE'S OWN STAMP OWNS THIS COLUMN, ``None`` included. A fire
# that never reached a process -- a working directory that vanished, a
@@ -9125,6 +9143,7 @@ class ScheduledTaskService:
disable_one_shot=retire_one_shot,
exit_code=int(raw_exit_code) if raw_exit_code is not None else None,
records_command_outcome=records_command_outcome,
+ result_status=status,
expected_binding=(
task.session_id,
task.session_key,
diff --git a/storage/background.py b/storage/background.py
index bdc60f885..0f311f35d 100644
--- a/storage/background.py
+++ b/storage/background.py
@@ -962,15 +962,14 @@ def definition_lifecycle_detail(
one consumer — the row — and never a ``GROUP BY``: the filter groups by
state, and the row alone says which of the three endings it was.
- ``timed_out`` is THE ANSWER when the row has one, and the three states are
- distinct on purpose. 124 is the code the runner synthesizes for a limit it
- enforced itself, but it is also an exit status a command is free to return —
- ``timeout 5 ...`` inside a ``--shell`` script returns exactly that — so reading
- the code alone told a user their backup had been cut short by Avibe when it had
- in fact cut itself short. ``False`` therefore SUPPRESSES the old inference rather
- than merely not triggering it; ``None`` means the row never recorded the fact
- (a watch, or a task stamped before this key existed) and keeps the inference,
- which is still the best guess available for those rows.
+ ``timed_out`` is THE ANSWER for scheduled tasks when the row has one. 124 is
+ the code the runner synthesizes for a limit it enforced itself, but it is also
+ an exit status a command is free to return — ``timeout 5 ...`` inside a
+ ``--shell`` script returns exactly that. Inferring a Task timeout from the
+ code therefore mislabels rows written before the explicit fact existed. Watch
+ rows retain their legacy code inference because their waiter contract owns
+ that exit code; ``False`` suppresses it when the scheduler explicitly records
+ that its limit was not reached.
"""
if lifecycle_state != "finished":
@@ -979,7 +978,7 @@ def definition_lifecycle_detail(
return None
if timed_out:
return "timeout"
- if timed_out is None and last_exit_code == _TIMEOUT_EXIT_CODE:
+ if definition_type != "scheduled" and timed_out is None and last_exit_code == _TIMEOUT_EXIT_CODE:
return "timeout"
# 64 is a completion, not a failure: the waiter finished its cycle and decided
# it had nothing worth an Agent turn. Reading it as an ending that "went wrong"
@@ -1249,6 +1248,12 @@ COMMAND_WORKER_REAP_ATTEMPTS_KEY = "reap_attempts"
#: needs those three states apart.
COMMAND_TIMED_OUT_METADATA_KEY = "last_command_timed_out"
+#: The terminal Run status most recently projected onto a scheduled definition.
+#: This reuses the Run ledger's existing status vocabulary; it lets read surfaces
+#: distinguish a user-canceled fire from an arbitrary ``last_error`` without parsing
+#: localized diagnostic text.
+TASK_LAST_RESULT_STATUS_METADATA_KEY = "last_result_status"
+
def command_snapshot_from_definition_row(row: Any) -> Optional[dict[str, Any]]:
"""The ``{"shell", "argv"}`` record of what a scheduled definition row would run.
diff --git a/tests/scenarios/harness_command_task/catalog.yaml b/tests/scenarios/harness_command_task/catalog.yaml
index dc2ec823b..ce49ce585 100644
--- a/tests/scenarios/harness_command_task/catalog.yaml
+++ b/tests/scenarios/harness_command_task/catalog.yaml
@@ -680,3 +680,13 @@ scenarios:
layer: contract
backend: shared
test: tests/test_background_work_banner.py::test_definition_banner_uses_creation_owner_before_execution_target
+ - id: SCT-061
+ name: Harness definition failures lead with translated stable facts and keep raw diagnostics collapsed
+ status: covered
+ kind: failure
+ layer: unit
+ backend: shared
+ test: ui/src/components/workbench/HarnessPage.test.tsx::TaskDetail command task shows a translated failure summary and keeps raw diagnostics collapsed
+ # The shared mapper cases in harnessLifecycle.test.ts cover timeout, nonzero,
+ # and unknown Task/Watch failures, including stderr that looks like another
+ # category. The Watch rendering case proves the same collapsed disclosure.
diff --git a/tests/test_harness_definition_lifecycle.py b/tests/test_harness_definition_lifecycle.py
index 869cf00e5..24a52d9ae 100644
--- a/tests/test_harness_definition_lifecycle.py
+++ b/tests/test_harness_definition_lifecycle.py
@@ -797,6 +797,21 @@ def test_a_forever_watch_retired_by_its_lifetime_says_it_timed_out(store) -> Non
) == "timeout"
+def test_a_legacy_scheduled_task_exit_124_requires_the_explicit_timeout_fact() -> None:
+ """A command may return 124 itself; missing timeout metadata is generic."""
+ assert (
+ definition_lifecycle_detail(
+ lifecycle_state="finished",
+ definition_type="scheduled",
+ last_run_at=NOW,
+ last_exit_code=124,
+ last_error="command returned status 124",
+ timed_out=None,
+ )
+ == "error"
+ )
+
+
def test_re_enabling_a_fired_one_shot_task_does_not_make_it_waiting_again(store) -> None:
"""``enabled`` is not a promise of a future fire.
diff --git a/tests/test_scheduled_tasks.py b/tests/test_scheduled_tasks.py
index f800d0950..536507e59 100644
--- a/tests/test_scheduled_tasks.py
+++ b/tests/test_scheduled_tasks.py
@@ -92,6 +92,7 @@ from storage.background import (
COMMAND_TIMED_OUT_METADATA_KEY,
DefinitionWriteConflict,
SQLiteBackgroundTaskStore,
+ TASK_LAST_RESULT_STATUS_METADATA_KEY,
definition_lifecycle_detail,
)
from storage.models import (
@@ -3057,8 +3058,12 @@ def test_task_definition_projection_follows_the_exact_terminal_cas_winner(
assert task.id not in service.scheduler.jobs
if settlement_winner == "natural_terminal":
assert "interrupt_reason" not in settled["metadata"]
+ assert TASK_LAST_RESULT_STATUS_METADATA_KEY not in (projected.metadata or {})
elif settlement_winner == "user_stop":
assert settled["metadata"]["interrupt_reason"] == SETTLED_BY_STOPPED
+ assert projected.metadata[TASK_LAST_RESULT_STATUS_METADATA_KEY] == "canceled"
+ else:
+ assert projected.metadata[TASK_LAST_RESULT_STATUS_METADATA_KEY] == "failed"
@pytest.mark.parametrize("shutdown_entrypoint", ["stop", "lease_loss"])
diff --git a/ui/src/components/workbench/HarnessPage.test.tsx b/ui/src/components/workbench/HarnessPage.test.tsx
index b94268176..62337971b 100644
--- a/ui/src/components/workbench/HarnessPage.test.tsx
+++ b/ui/src/components/workbench/HarnessPage.test.tsx
@@ -1,6 +1,9 @@
+/* @vitest-environment jsdom */
+
import { createInstance } from 'i18next';
import type { ReactElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
+import { fireEvent, render as renderDom } from '@testing-library/react';
import { I18nextProvider, initReactI18next } from 'react-i18next';
import { MemoryRouter } from 'react-router-dom';
import { describe, expect, it } from 'vitest';
@@ -99,6 +102,7 @@ const watch = (overrides: Partial<HarnessWatch>): HarnessWatch => ({
last_event_at: null,
last_error: null,
last_exit_code: null,
+ metadata: {},
lifecycle_state: 'paused',
lifecycle_detail: null,
next_run_at: null,
@@ -434,6 +438,37 @@ describe('HealthBadge', () => {
expect(html).toContain(`>${i18n.t('harness.health.failing')} 4<`);
expect(html).toContain('text-pink');
});
+
+ it('never exposes raw stderr through the default badge tooltip', () => {
+ const raw = 'database password rejected';
+ const html = render(
+ <HealthBadge
+ row={watch({ health: 'failing', consecutive_failures: 1, recent_failures: 1, last_error: raw })}
+ />,
+ );
+
+ expect(html).toContain(`title="${en.harness.failure.generic}"`);
+ expect(html).not.toContain(raw);
+ });
+
+ it('does not turn a circuit-breaker pause into an ordinary failure tooltip', () => {
+ const html = render(
+ <HealthBadge
+ row={watch({
+ health: 'failing',
+ consecutive_failures: 1,
+ recent_failures: 1,
+ lifecycle_state: 'paused',
+ metadata: { watch_circuit_breaker: { status: 'tripped' } },
+ last_exit_code: 0,
+ last_error: 'localized circuit pause detail',
+ })}
+ />,
+ );
+
+ expect(html).not.toContain(`title="${en.harness.failure.generic}"`);
+ expect(html).not.toContain('localized circuit pause detail');
+ });
});
describe('ProcessingHealthBadge', () => {
@@ -752,6 +787,73 @@ describe('TaskDetail command task', () => {
);
});
+ it('shows a translated failure summary and keeps raw diagnostics collapsed', () => {
+ const raw = 'pg_dump: connection refused';
+ const html = detail(
+ task({
+ shell_command: 'pg_dump app',
+ last_exit_code: 7,
+ last_error: raw,
+ lifecycle_detail: 'error',
+ }),
+ );
+
+ expect(html).toContain(en.harness.failure.generic);
+ expect(html).toContain(`>${en.harness.detail.lastExitCode}<`);
+ expect(html).toContain('>7<');
+ expect(html).toContain(`>${en.harness.detail.technicalDetails}<`);
+ expect(html).toContain(raw);
+ expect(html).toMatch(/<details(?![^>]*\bopen\b)[^>]*>/);
+ expect(html.indexOf(en.harness.failure.generic)).toBeLessThan(html.indexOf(raw));
+ });
+
+ it('uses the generic summary when only an opaque technical error is available', () => {
+ const raw = 'command not found: localized stderr';
+ const html = detail(task({ shell_command: 'missing-tool', last_error: raw }));
+
+ expect(html).toContain(en.harness.failure.generic);
+ expect(html).toContain(`>${en.harness.detail.technicalDetails}<`);
+ expect(html).toContain(raw);
+ expect(html).toMatch(/<details(?![^>]*\bopen\b)[^>]*>/);
+ });
+
+ it('keeps a legacy Task timeout detail generic without the explicit timeout fact', () => {
+ const raw = 'command returned status 124';
+ const html = detail(
+ task({
+ shell_command: 'backup --self-timeout',
+ lifecycle_detail: 'timeout',
+ last_exit_code: 124,
+ last_error: raw,
+ metadata: {},
+ }),
+ );
+
+ expect(html).toContain(en.harness.failure.generic);
+ expect(html).not.toContain(en.harness.failure.timeout);
+ expect(html).toContain(`>${en.harness.detail.technicalDetails}<`);
+ expect(html).toContain(raw);
+ expect(html).toMatch(/<details(?![^>]*\bopen\b)[^>]*>/);
+ });
+
+ it('keeps a canceled Task diagnostic collapsed without calling it a failure', () => {
+ const raw = 'Run canceled by user';
+ const html = detail(
+ task({
+ shell_command: 'make release',
+ health: 'healthy',
+ last_error: raw,
+ metadata: { last_result_status: 'canceled' },
+ }),
+ );
+
+ expect(html).not.toContain(en.harness.failure.generic);
+ expect(html).not.toContain(en.harness.failure.timeout);
+ expect(html).toContain(`>${en.harness.detail.technicalDetails}<`);
+ expect(html).toContain(raw);
+ expect(html).toMatch(/<details(?![^>]*\bopen\b)[^>]*>/);
+ });
+
it('leaves a message task rendering exactly as it does today', () => {
const html = detail(task({ name: 'Nightly digest', prompt: 'Summarize #ops', message: 'Summarize #ops' }));
@@ -838,6 +940,206 @@ describe('WatchDetail runtime', () => {
expect(html).toContain(`>${i18n.t('harness.detail.eventProcessing')}<`);
expect(html).toContain(`>${i18n.t('harness.processingHealth.unknown')}<`);
});
+
+ it('keeps an insufficiently evidenced Watch timeout generic and technical details collapsed', () => {
+ const raw = 'localized-looking stderr must stay technical';
+ const html = render(
+ <WatchDetail
+ watch={watch({
+ lifecycle_state: 'finished',
+ lifecycle_detail: 'timeout',
+ last_exit_code: 124,
+ last_error: raw,
+ })}
+ onToggleEnabled={() => undefined}
+ pending={false}
+ />,
+ );
+
+ expect(html).toContain(en.harness.failure.generic);
+ expect(html).not.toContain(en.harness.failure.timeout);
+ expect(html).toContain(`>${en.harness.detail.lastExitCode}<`);
+ expect(html).toContain('>124<');
+ expect(html).toContain(`>${en.harness.detail.technicalDetails}<`);
+ expect(html).toContain(raw);
+ expect(html).toMatch(/<details(?![^>]*\bopen\b)[^>]*>/);
+ });
+
+ it('keeps configured retry and no-event exits neutral', () => {
+ for (const last_exit_code of [64, 75]) {
+ const html = render(
+ <WatchDetail
+ watch={watch({
+ enabled: true,
+ retry_exit_codes: [75],
+ health: 'healthy',
+ lifecycle_state: 'waiting',
+ lifecycle_detail: null,
+ last_exit_code,
+ })}
+ onToggleEnabled={() => undefined}
+ pending={false}
+ />,
+ );
+ expect(html).toContain(`<span class="font-mono text-[11px] text-muted">${last_exit_code}</span>`);
+ }
+ });
+
+ it('keeps a healthy retry diagnostic without presenting it as a failure', () => {
+ const raw = 'avibe-watch: still waiting';
+ const html = render(
+ <WatchDetail
+ watch={watch({
+ enabled: true,
+ retry_exit_codes: [75],
+ health: 'healthy',
+ lifecycle_state: 'waiting',
+ lifecycle_detail: null,
+ last_exit_code: 75,
+ last_error: raw,
+ })}
+ onToggleEnabled={() => undefined}
+ pending={false}
+ />,
+ );
+
+ expect(html).not.toContain(en.harness.failure.generic);
+ expect(html).toContain(`<span class="font-mono text-[11px] text-muted">75</span>`);
+ expect(html).toContain(`>${en.harness.detail.technicalDetails}<`);
+ expect(html).toContain(raw);
+ expect(html).toMatch(/<details(?![^>]*\bopen\b)[^>]*>/);
+ });
+
+ it('keeps retry history neutral after the user manually pauses a Watch', () => {
+ const raw = 'avibe-watch: still waiting';
+ const html = render(
+ <WatchDetail
+ watch={watch({
+ enabled: false,
+ retry_exit_codes: [75],
+ health: 'failing',
+ lifecycle_state: 'paused',
+ lifecycle_detail: null,
+ retired_at: null,
+ last_exit_code: 75,
+ last_error: raw,
+ })}
+ onToggleEnabled={() => undefined}
+ pending={false}
+ />,
+ );
+
+ expect(html).not.toContain(en.harness.failure.generic);
+ expect(html).toContain('<span class="font-mono text-[11px] text-muted">75</span>');
+ expect(html).toContain(raw);
+ expect(html).toMatch(/<details(?![^>]*\bopen\b)[^>]*>/);
+ });
+
+ it('keeps a terminal missing-cwd retry exit as a failure', () => {
+ const raw = 'working directory is unavailable';
+ const html = render(
+ <WatchDetail
+ watch={watch({
+ enabled: false,
+ retry_exit_codes: [1],
+ health: 'failing',
+ lifecycle_state: 'finished',
+ lifecycle_detail: 'error',
+ retired_at: '2026-08-12T00:00:00Z',
+ last_exit_code: 1,
+ last_error: raw,
+ })}
+ onToggleEnabled={() => undefined}
+ pending={false}
+ />,
+ );
+
+ expect(html).toContain(en.harness.failure.generic);
+ expect(html).toContain('<span class="font-mono text-[11px] text-pink">1</span>');
+ expect(html).toContain(raw);
+ expect(html).toMatch(/<details(?![^>]*\bopen\b)[^>]*>/);
+ });
+
+ it('does not call a Watch lifetime expiry a run timeout', () => {
+ const html = render(
+ <WatchDetail
+ watch={watch({
+ enabled: false,
+ health: 'failing',
+ lifecycle_state: 'finished',
+ lifecycle_detail: 'timeout',
+ last_exit_code: 124,
+ last_error: 'watch lifetime expired before the next cycle',
+ })}
+ onToggleEnabled={() => undefined}
+ pending={false}
+ />,
+ );
+
+ expect(html).toContain(en.harness.failure.generic);
+ expect(html).not.toContain(en.harness.failure.timeout);
+ });
+
+ it('shows a stable circuit-pause summary and keeps the reason technical', () => {
+ const raw = 'Watch paused after rapid event burst';
+ const html = render(
+ <WatchDetail
+ watch={watch({
+ enabled: false,
+ health: 'failing',
+ lifecycle_state: 'paused',
+ lifecycle_detail: null,
+ last_exit_code: 0,
+ last_error: raw,
+ metadata: { watch_circuit_breaker: { status: 'tripped', exit_code: 0 } },
+ })}
+ onToggleEnabled={() => undefined}
+ pending={false}
+ />,
+ );
+
+ expect(html).toContain(en.harness.failure.circuitPaused);
+ expect(html).not.toContain(en.harness.failure.generic);
+ expect(html).not.toContain(en.harness.failure.timeout);
+ expect(html).toContain('text-amber');
+ expect(html).toContain(`>${en.harness.detail.technicalDetails}<`);
+ expect(html).toContain(raw);
+ expect(html).toMatch(/<details(?![^>]*\bopen\b)[^>]*>/);
+ });
+
+ it('resets technical details when selecting another definition', () => {
+ const renderInteractive = (ui: ReactElement) =>
+ renderDom(
+ <I18nextProvider i18n={i18n}>
+ <MemoryRouter>{ui}</MemoryRouter>
+ </I18nextProvider>,
+ );
+ const view = renderInteractive(
+ <TaskDetail
+ task={task({ id: 'task-a', shell_command: 'first', last_error: 'first technical error' })}
+ onToggleEnabled={() => undefined}
+ pending={false}
+ />,
+ );
+ const details = view.container.querySelector('details');
+ expect(details?.open).toBe(false);
+ fireEvent.click(details?.querySelector('summary') as HTMLElement);
+ expect(view.container.querySelector('details')?.open).toBe(true);
+
+ view.rerender(
+ <I18nextProvider i18n={i18n}>
+ <MemoryRouter>
+ <TaskDetail
+ task={task({ id: 'task-b', shell_command: 'second', last_error: 'second technical error' })}
+ onToggleEnabled={() => undefined}
+ pending={false}
+ />
+ </MemoryRouter>
+ </I18nextProvider>,
+ );
+ expect(view.container.querySelector('details')?.open).toBe(false);
+ view.unmount();
+ });
});
describe('RunTriggerChip', () => {
diff --git a/ui/src/components/workbench/HarnessPage.tsx b/ui/src/components/workbench/HarnessPage.tsx
index 452e54847..be127bb80 100644
--- a/ui/src/components/workbench/HarnessPage.tsx
+++ b/ui/src/components/workbench/HarnessPage.tsx
@@ -4,6 +4,7 @@ import {
ArrowLeft,
Activity,
Calendar,
+ ChevronRight,
Eye,
History,
Plus,
@@ -63,7 +64,9 @@ import {
DEFINITION_STATUS_FILTERS,
definitionActiveCount,
definitionChipLabel,
+ definitionExitCodeTone,
definitionHealth,
+ definitionFailureSummaryKey,
definitionProcessingHealth,
definitionRowLine,
definitionRowTitle,
@@ -1034,6 +1037,7 @@ export const HealthBadge: React.FC<{ row: HarnessTask | HarnessWatch }> = ({ row
const { t } = useTranslation();
const health = definitionHealth(row);
if (health !== 'failing' && health !== 'degraded' && health !== 'unknown') return null;
+ const failureSummaryKey = definitionFailureSummaryKey(row);
// No count on ``unknown``: both counters come from the same run history this
// row could not read, so printing one would put a number on nothing.
const count = health === 'unknown' ? 0 : health === 'failing' ? row.consecutive_failures : row.recent_failures;
@@ -1044,7 +1048,7 @@ export const HealthBadge: React.FC<{ row: HarnessTask | HarnessWatch }> = ({ row
'shrink-0 font-mono text-[9px] uppercase',
health === 'failing' ? 'text-pink' : health === 'degraded' ? 'text-amber' : 'text-muted',
)}
- title={row.last_error || undefined}
+ title={failureSummaryKey ? t(failureSummaryKey) : undefined}
>
{t(`harness.health.${health}`)}
{count > 1 ? ` ${count}` : ''}
@@ -1454,26 +1458,19 @@ export const TaskDetail: React.FC<TaskDetailProps> = ({ task, agent, onToggleEna
on the run row: a nightly command task's exit code is the one fact an
operator wants without paging through the runs tab. Not gated on
``last_run_at`` — a stored exit code proves a run happened. */}
+ <FailureDetails row={task} />
{task.last_exit_code != null && (
<DetailField label={t('harness.detail.lastExitCode')}>
<span
- className={clsx('font-mono text-[11px]', task.last_exit_code === 0 ? 'text-muted' : 'text-pink')}
+ className={clsx(
+ 'font-mono text-[11px]',
+ definitionExitCodeTone(task) === 'failure' ? 'text-pink' : 'text-muted',
+ )}
>
{task.last_exit_code}
</span>
</DetailField>
)}
- {/* Its own field, and no longer nested inside ``last_run_at``: a task can
- carry a ``last_error`` with no ``last_run_at`` (a fire that failed before
- it ever ran), and that case rendered nothing at all. ``harness.detail.lastError``
- already existed and was used only by the watch pane. */}
- {task.last_error && (
- <DetailField label={t('harness.detail.lastError')}>
- <pre className="max-h-32 overflow-auto whitespace-pre-wrap rounded-md border border-destructive/40 bg-destructive/[0.06] p-2 font-mono text-[11px] text-destructive">
- {task.last_error}
- </pre>
- </DetailField>
- )}
{task.resume_blocked?.code === 'task_owner_session_unavailable' && (
<DetailField label={t('harness.detail.pauseReason')}>
<span className="text-[12px] text-muted">
@@ -1629,11 +1626,17 @@ export const WatchDetail: React.FC<WatchDetailProps> = ({ watch, agent, onToggle
)}
</DetailField>
)}
- {watch.last_error && (
- <DetailField label={t('harness.detail.lastError')}>
- <div className="rounded-md border border-destructive/40 bg-destructive/[0.06] px-2 py-1 text-[11px] text-destructive">
- {watch.last_error}
- </div>
+ <FailureDetails row={watch} />
+ {watch.last_exit_code != null && (
+ <DetailField label={t('harness.detail.lastExitCode')}>
+ <span
+ className={clsx(
+ 'font-mono text-[11px]',
+ definitionExitCodeTone(watch) === 'failure' ? 'text-pink' : 'text-muted',
+ )}
+ >
+ {watch.last_exit_code}
+ </span>
</DetailField>
)}
{visibleProcessingHealth(watch) && (
@@ -2152,6 +2155,52 @@ const DetailGroup: React.FC<{ label: string; children: React.ReactNode }> = ({ l
</div>
);
+const FailureDetails: React.FC<{
+ row: HarnessTask | HarnessWatch;
+}> = ({ row }) => {
+ const { t } = useTranslation();
+ // The mapper uses structured facts only. A stored error without enough
+ // structure still proves an unclassified failure, so keep the default copy
+ // generic instead of letting raw stderr choose a category.
+ const summaryKey = definitionFailureSummaryKey(row, Boolean(row.last_error));
+ const circuitPaused = summaryKey === 'harness.failure.circuitPaused';
+ const disclosureKey = `${'retry_exit_codes' in row ? 'watch' : 'task'}:${row.id}`;
+ if (!summaryKey && !row.last_error) return null;
+ return (
+ <div className="flex flex-col gap-1.5">
+ {summaryKey && (
+ <>
+ <div className="font-mono text-[10px] font-bold uppercase tracking-[0.12em] text-muted">
+ {t(circuitPaused ? 'harness.detail.pauseReason' : 'harness.detail.failureSummary')}
+ </div>
+ <div
+ className={clsx(
+ 'flex min-w-0 flex-wrap items-center gap-2 text-[12px]',
+ circuitPaused ? 'text-amber' : 'text-pink',
+ )}
+ >
+ <span>{t(summaryKey)}</span>
+ </div>
+ </>
+ )}
+ {row.last_error && (
+ <details
+ key={disclosureKey}
+ className="group min-w-0 rounded-md border border-border bg-surface-3 px-2 py-1.5"
+ >
+ <summary className="flex cursor-pointer list-none items-center gap-1.5 text-[10px] font-medium uppercase tracking-wide text-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-cyan/60">
+ <ChevronRight aria-hidden className="size-3 shrink-0 transition-transform group-open:rotate-90" />
+ {t('harness.detail.technicalDetails')}
+ </summary>
+ <pre className="mt-2 max-h-32 overflow-auto whitespace-pre-wrap break-words border-t border-border pt-2 font-mono text-[11px] text-muted">
+ {row.last_error}
+ </pre>
+ </details>
+ )}
+ </div>
+ );
+};
+
const EmptyState: React.FC<{ i18nKey: string }> = ({ i18nKey }) => {
const { t } = useTranslation();
return (
diff --git a/ui/src/components/workbench/harnessLifecycle.test.ts b/ui/src/components/workbench/harnessLifecycle.test.ts
index b5e00b9f1..e8e7c43f4 100644
--- a/ui/src/components/workbench/harnessLifecycle.test.ts
+++ b/ui/src/components/workbench/harnessLifecycle.test.ts
@@ -13,6 +13,8 @@ import {
definitionStateSince,
definitionStatusCount,
definitionSurvivesToggle,
+ definitionFailureSummaryKey,
+ definitionHasNeutralWatchExit,
formatWallTime,
humanizeCron,
humanizeGap,
@@ -115,6 +117,123 @@ describe('lifecycleLabel', () => {
});
});
+describe('definitionFailureSummaryKey', () => {
+ // SCT-061 final UI contract:
+ // timeout -> translated timeout summary + optional exit code;
+ // nonzero exit -> translated generic failure summary + exit code;
+ // unknown -> translated generic failure summary;
+ // raw technical details -> present but collapsed by default.
+ const cases = [
+ [
+ 'task timeout',
+ { metadata: { last_command_timed_out: true }, last_exit_code: 124, last_error: 'permission denied' },
+ 'harness.failure.timeout',
+ ],
+ [
+ 'legacy task timeout detail without explicit fact',
+ { lifecycle_detail: 'timeout', last_exit_code: 124, last_error: 'command returned status 124' },
+ 'harness.failure.generic',
+ ],
+ [
+ 'watch timeout',
+ { lifecycle_state: 'finished', lifecycle_detail: 'timeout', retry_exit_codes: [], last_exit_code: 124, last_error: 'permission denied' },
+ 'harness.failure.generic',
+ ],
+ [
+ 'task nonzero exit',
+ { last_exit_code: 7, last_error: 'timed out while opening stderr' },
+ 'harness.failure.generic',
+ ],
+ [
+ 'watch nonzero exit',
+ { last_exit_code: 2, last_error: 'timed out while opening stderr' },
+ 'harness.failure.generic',
+ ],
+ ['task unknown failure', { lifecycle_detail: 'error', last_error: null }, 'harness.failure.generic'],
+ ['watch unknown failure', { health: 'failing', last_error: null }, 'harness.failure.generic'],
+ ] as const;
+
+ it.each(cases)('maps %s without classifying stderr prose', (_name, row, expected) => {
+ expect(definitionFailureSummaryKey(row)).toBe(expected);
+ });
+
+ it('does not let stderr wording change the category', () => {
+ const facts = { last_exit_code: 9, lifecycle_detail: 'error' };
+ const classify = (lastError: string) => definitionFailureSummaryKey({ ...facts }, Boolean(lastError));
+ expect(classify('timed out')).toBe(classify('command not found'));
+ });
+
+ it('uses only error presence for an otherwise unknown failure', () => {
+ expect(definitionFailureSummaryKey({ health: 'healthy' }, true)).toBe('harness.failure.generic');
+ expect(definitionFailureSummaryKey({ health: 'healthy' }, false)).toBeNull();
+ });
+
+ it('does not turn technical text into a failure when structured facts say healthy', () => {
+ expect(definitionFailureSummaryKey({ health: 'healthy', last_exit_code: null })).toBeNull();
+ });
+
+ it('keeps structured last-run failure visible after health history ages out', () => {
+ expect(
+ definitionFailureSummaryKey({ health: 'healthy', lifecycle_detail: 'error', last_exit_code: 7 }),
+ ).toBe('harness.failure.generic');
+ expect(
+ definitionFailureSummaryKey({
+ health: 'healthy',
+ lifecycle_detail: 'timeout',
+ metadata: { last_command_timed_out: true },
+ last_exit_code: 124,
+ }),
+ ).toBe('harness.failure.timeout');
+ });
+
+ it('keeps the summary key set translated and in parity', () => {
+ expect(Object.keys(en.harness.failure).sort()).toEqual(['circuitPaused', 'generic', 'timeout']);
+ expect(Object.keys(zh.harness.failure).sort()).toEqual(Object.keys(en.harness.failure).sort());
+ for (const detailKey of ['failureSummary', 'technicalDetails', 'lastExitCode'] as const) {
+ expect(typeof en.harness.detail[detailKey]).toBe('string');
+ expect(typeof zh.harness.detail[detailKey]).toBe('string');
+ }
+ expect(zh.harness.failure.timeout).toBe('最近一次运行已超时。');
+ expect(zh.harness.failure.generic).toBe('最近一次运行失败。');
+ expect(zh.harness.failure.circuitPaused).toBe('此 Watch 因短时间内重复事件而暂停。');
+ });
+
+ it('uses structured pause and cancellation facts without parsing diagnostics', () => {
+ expect(
+ definitionFailureSummaryKey(
+ {
+ lifecycle_state: 'paused',
+ retry_exit_codes: [75],
+ metadata: { watch_circuit_breaker: { status: 'tripped' } },
+ },
+ true,
+ ),
+ ).toBe('harness.failure.circuitPaused');
+ expect(
+ definitionFailureSummaryKey({ metadata: { last_result_status: 'canceled' } }, true),
+ ).toBeNull();
+ expect(
+ definitionFailureSummaryKey({ metadata: { last_result_status: 'failed' } }, true),
+ ).toBe('harness.failure.generic');
+ });
+});
+
+describe('definitionHasNeutralWatchExit', () => {
+ it.each([
+ ['no-event completion', { health: 'healthy', lifecycle_state: 'waiting', lifecycle_detail: null, last_exit_code: 64, retry_exit_codes: [] }, true],
+ ['default retry exit', { health: 'healthy', lifecycle_state: 'waiting', lifecycle_detail: null, last_exit_code: 75, retry_exit_codes: [75] }, true],
+ ['custom retry exit', { health: 'healthy', lifecycle_state: 'waiting', lifecycle_detail: null, last_exit_code: 90, retry_exit_codes: [75, 90] }, true],
+ ['manual pause preserves retry history', { health: 'failing', lifecycle_state: 'paused', lifecycle_detail: null, retired_at: null, last_exit_code: 75, retry_exit_codes: [75] }, true],
+ ['legacy pause without retirement evidence', { health: 'failing', lifecycle_state: 'paused', lifecycle_detail: null, last_exit_code: 75, retry_exit_codes: [75] }, false],
+ ['terminal retry exit', { health: 'failing', lifecycle_state: 'finished', retired_at: '2026-08-12T00:00:00Z', last_exit_code: 1, retry_exit_codes: [1] }, false],
+ ['unconfigured watch exit', { health: 'healthy', lifecycle_state: 'waiting', lifecycle_detail: null, last_exit_code: 9, retry_exit_codes: [75] }, false],
+ ['finished error with no-event code', { health: 'healthy', lifecycle_state: 'finished', lifecycle_detail: 'error', last_exit_code: 64, retry_exit_codes: [] }, false],
+ ['task exit without watch evidence', { last_exit_code: 75 }, false],
+ ] as const)('classifies %s from structured fields', (_name, row, expected) => {
+ expect(definitionHasNeutralWatchExit(row)).toBe(expected);
+ });
+});
+
describe('definitionStatusCount', () => {
const counts = { total: 1180, running: 2, waiting: 22, paused: 0, finished: 1156 };
diff --git a/ui/src/components/workbench/harnessLifecycle.ts b/ui/src/components/workbench/harnessLifecycle.ts
index eab4ab26e..562a342d9 100644
--- a/ui/src/components/workbench/harnessLifecycle.ts
+++ b/ui/src/components/workbench/harnessLifecycle.ts
@@ -322,6 +322,7 @@ export type HarnessDefinitionFacts = {
last_run_at?: string | null;
last_started_at?: string | null;
last_finished_at?: string | null;
+ retired_at?: string | null;
last_error?: string | null;
updated_at?: string | null;
// Derived server-side from the definition's own run history, because
@@ -346,8 +347,103 @@ export type HarnessDefinitionFacts = {
// Decoded server-side (key is ``metadata``, not ``metadata_json``). Holds the
// command-task-only ``on_failure`` policy; see ``taskOnFailure``.
metadata?: Record<string, unknown> | null;
+ retry_exit_codes?: number[] | null;
};
+export type HarnessFailureSummaryKey =
+ | 'harness.failure.timeout'
+ | 'harness.failure.generic'
+ | 'harness.failure.circuitPaused';
+
+export function definitionHasNeutralWatchExit(
+ row: Pick<
+ HarnessDefinitionFacts,
+ 'health' | 'lifecycle_detail' | 'lifecycle_state' | 'last_exit_code' | 'retired_at' | 'retry_exit_codes'
+ >,
+): boolean {
+ if (!Array.isArray(row.retry_exit_codes)) return false;
+ // A terminal pre-cycle failure (for example a missing cwd) can reuse the
+ // configured code, but its projected health must remain visible. A manually
+ // paused Watch preserves its most recent healthy cycle even though disabled
+ // rows project failing health; paused + explicitly unretired is the durable
+ // evidence that separates that history from supervisor retirement.
+ const preservedManualPause = row.lifecycle_state === 'paused' && row.retired_at === null;
+ if (row.health !== 'healthy' && !preservedManualPause) return false;
+ if (row.lifecycle_detail != null && row.lifecycle_detail !== 'normal') return false;
+ const exitCode = row.last_exit_code;
+ return exitCode === 64 || (typeof exitCode === 'number' && row.retry_exit_codes.includes(exitCode));
+}
+
+function definitionIsCircuitPaused(
+ row: Pick<HarnessDefinitionFacts, 'lifecycle_state' | 'metadata'>,
+): boolean {
+ return (
+ row.lifecycle_state === 'paused' &&
+ row.metadata?.watch_circuit_breaker != null &&
+ typeof row.metadata.watch_circuit_breaker === 'object' &&
+ (row.metadata.watch_circuit_breaker as { status?: unknown }).status === 'tripped'
+ );
+}
+
+function definitionLastResultWasCanceled(
+ row: Pick<HarnessDefinitionFacts, 'metadata' | 'retry_exit_codes'>,
+): boolean {
+ return !Array.isArray(row.retry_exit_codes) && row.metadata?.last_result_status === 'canceled';
+}
+
+// The UI can only name a timeout when the scheduler's structured fact or the
+// already-projected lifecycle detail proves it. The remaining structured
+// failure facts collapse to one generic category; last_error is deliberately
+// absent from this mapper and remains technical disclosure content only.
+export function definitionFailureSummaryKey(
+ row: Pick<
+ HarnessDefinitionFacts,
+ | 'health'
+ | 'lifecycle_detail'
+ | 'lifecycle_state'
+ | 'last_exit_code'
+ | 'metadata'
+ | 'retired_at'
+ | 'retry_exit_codes'
+ >,
+ technicalErrorPresent = false,
+): HarnessFailureSummaryKey | null {
+ if (definitionIsCircuitPaused(row)) return 'harness.failure.circuitPaused';
+ if (definitionLastResultWasCanceled(row)) return null;
+ // A lifecycle timeout is insufficient for a Task because legacy rows can carry
+ // exit code 124 from the command itself. Only the scheduler's explicit fact
+ // proves a run timed out; Watch lifetime expiry also remains generic.
+ const timedOut = row.metadata?.last_command_timed_out === true;
+ const exitCode = row.last_exit_code;
+ const successfulWatchExit = definitionHasNeutralWatchExit(row);
+ const lifecycleFailure =
+ row.lifecycle_detail != null && row.lifecycle_detail !== 'normal' && !successfulWatchExit;
+ const failed =
+ timedOut ||
+ (row.health === 'failing' && !successfulWatchExit) ||
+ lifecycleFailure ||
+ (typeof exitCode === 'number' && exitCode !== 0 && !successfulWatchExit);
+ if (!failed && technicalErrorPresent && !successfulWatchExit) return 'harness.failure.generic';
+ if (!failed) return null;
+ return timedOut ? 'harness.failure.timeout' : 'harness.failure.generic';
+}
+
+export function definitionExitCodeTone(
+ row: Pick<
+ HarnessDefinitionFacts,
+ | 'health'
+ | 'lifecycle_detail'
+ | 'lifecycle_state'
+ | 'last_exit_code'
+ | 'metadata'
+ | 'retired_at'
+ | 'retry_exit_codes'
+ >,
+): 'neutral' | 'failure' {
+ if (definitionHasNeutralWatchExit(row)) return 'neutral';
+ return row.last_exit_code != null && row.last_exit_code !== 0 ? 'failure' : 'neutral';
+}
+
// ``failing`` = the newest verdict failed; ``degraded`` = the newest succeeded but
// a failure is still in the window; ``unknown`` = health could not be computed,
// which is deliberately not the same as ``healthy``.
diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsx
index ce0651df2..af145edcc 100644
--- a/ui/src/context/ApiContext.tsx
+++ b/ui/src/context/ApiContext.tsx
@@ -1469,6 +1469,10 @@ export type HarnessWatch = HarnessSessionSummary & HarnessDefinitionState & {
last_event_at: string | null;
last_error: string | null;
last_exit_code: number | null;
+ // Decoded server-side metadata includes durable Watch admission facts such as
+ // the circuit-breaker incident; it is troubleshooting evidence, not a new UI
+ // lifecycle state.
+ metadata: Record<string, unknown> | null;
runtime: HarnessWatchRuntime;
// Whether the waiter process is alive. ``null`` means we have never seen a
// heartbeat for it, which is not the same as having seen it exit — the row
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 1b7c91b6c..bc0f5b856 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -3234,6 +3234,8 @@
"timeoutNone": "No timeout",
"timeoutDefault": "{{duration}} (default)",
"lastExitCode": "Last exit code",
+ "failureSummary": "Failure",
+ "technicalDetails": "Technical details",
"escalation": "On failure → escalation",
"triagePrompt": "Triage prompt",
"cwdFromSession": "Bound session, else runtime default or Avibe state dir",
@@ -3314,6 +3316,11 @@
"error": "Failed",
"unknown": "Unknown"
},
+ "failure": {
+ "timeout": "The last run timed out.",
+ "generic": "The last run failed.",
+ "circuitPaused": "This Watch was paused after repeated events."
+ },
"kind": {
"task": "Scheduled task",
"watch": "Watch"
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 93eb02c91..0ac9a4f9d 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -3234,6 +3234,8 @@
"timeoutNone": "不限时",
"timeoutDefault": "{{duration}}(默认)",
"lastExitCode": "最近退出码",
+ "failureSummary": "失败摘要",
+ "technicalDetails": "技术详情",
"escalation": "失败后 → 交给 Agent",
"triagePrompt": "排查提示词",
"cwdFromSession": "跟随绑定会话,否则运行时默认目录或 Avibe 状态目录",
@@ -3314,6 +3316,11 @@
"error": "出错结束",
"unknown": "未知"
},
+ "failure": {
+ "timeout": "最近一次运行已超时。",
+ "generic": "最近一次运行失败。",
+ "circuitPaused": "此 Watch 因短时间内重复事件而暂停。"
+ },
"kind": {
"task": "定时任务",
"watch": "Watch"