fix(claw): state why a turn failed
android / debug (push) Successful in 2m39s
ci / docker (push) Canceled after 0s
android / release (push) Canceled after 1m54s
ci / checks (push) Canceled after 0s
ci / test (push) Canceled after 0s
ci / chart (push) Canceled after 0s
ci / web (push) Canceled after 0s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Canceled after 0s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Canceled after 0s
ci / publish-edge-chart (push) Canceled after 0s

A failed turn reached the client as the bare word "failed": turn_done
carried only the outcome, so the provider's own error — the status line
and the body that name what went wrong — was dropped on the floor. The
session inventory did keep it, as {"Failed": reason}, but the web client
printed that object, and a read-only snapshot (a coding job's key, a
forge thread) hardcoded the label and lost the text entirely.

TurnDone gains a reason, set only on failure and omitted when absent, so
handled and steered frames stay byte-identical and rows recorded before
the field still replay. The stashed transcript carries it too, which is
the path job keys take. The web client renders it under the outcome word
in mono and full-wrap, and the session-info modal reads the inventory's
{"Failed": reason} into a last-failure row instead of showing JSON.

cargo test -p rhema-claw and nuxt typecheck pass; a failed turn renders
its complete reason in the transcript.
This commit is contained in:
vhaudiquet committed 2026-12-02 11:35:04 +01:00
1 parent ec52ae90b2
commit 597c2a98d2
10 files changed
+158 -40

No files matched your search

+15 -2
View File
@@ -86,7 +86,19 @@ export type TurnEvent =
| ({ type: 'consent_request' } & ConsentRequest)
| { type: 'consent_resolved'; id: string; granted: boolean }
| ({ type: 'attachment' } & ClawAttachment)
| { type: 'turn_done'; reply: string | null; outcome: string }
| {
type: 'turn_done'
reply: string | null
outcome: string
/** Why a `failed` turn failed: the handler's own words. null on
* every other outcome, and on rows recorded before the field. */
reason: string | null
}
/** A recorded outcome as the dispatcher serializes it: a bare variant
* name for `Handled` and `Superseded`, `{"Failed": "reason"}` for a
* failure. null when the key never released. */
export type WireOutcome = string | { Failed: string } | null
/** One entry of `GET /v1/sessions` (http.rs `sessions`). */
export interface ClawSession {
@@ -94,7 +106,7 @@ export interface ClawSession {
state: string
revision: number
inbox_depth: number
last_outcome: string | null
last_outcome: WireOutcome
/** Whether the pause gate holds the key: queued work waits, nothing
* dispatches, until resume lifts the hold. */
paused: boolean
@@ -1250,6 +1262,7 @@ function parseTurnEvent(data: string): TurnEvent | null {
type: 'turn_done',
reply: typeof raw.reply === 'string' ? raw.reply : null,
outcome: String(raw.outcome ?? ''),
reason: typeof raw.reason === 'string' ? raw.reason : null,
}
default:
return null
+5 -1
View File
@@ -39,6 +39,9 @@ export interface TurnBlock {
entries: TurnEntry[]
/** Set by `turn_done`: `handled`, `failed`, or whatever the claw reports. */
outcome: string | null
/** Set by `turn_done` on a failure: the handler's own words on why
* the turn broke. null for every other outcome. */
reason: string | null
}
/** One thing the agent asked its human, as the card renders it. */
@@ -230,7 +233,7 @@ export function useTranscript() {
const pendingSent: { text: string; images: number; itemId: number }[] = []
function ensureLive(): TurnBlock {
if (!live.value) live.value = { reply: '', entries: [], outcome: null }
if (!live.value) live.value = { reply: '', entries: [], outcome: null, reason: null }
return live.value
}
@@ -371,6 +374,7 @@ export function useTranscript() {
case 'turn_done': {
const turn = ensureLive()
turn.outcome = event.outcome
turn.reason = event.reason
// The clean end marker wins for the reply: deltas may have been
// dropped (best-effort stream), turn_done carries the final text.
if (event.reply !== null) turn.reply = event.reply