Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(agents): mark failed sessions with a red dot

Wolf Mermelstein2cf68ecdf396
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 6d43cdc82a..a70ced4193 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -615,6 +615,11 @@ On a physical iPhone, WKWebView still synthesises the compatibility `mousedown`/
4. **Strip the instrumentation before committing.**
+### Agent session failure indicators
+
+Use the existing status dot in Home and Agents rows with `bg-failure` when the
+persisted `turnState` is `failed`; open the session to inspect its error.
+
### Agent system events
Agent activity labels share `block-agent/ui/TextShimmer.tsx` and the global
diff --git a/apps/web/src/features/agents-view/components/AgentSessionRow.tsx b/apps/web/src/features/agents-view/components/AgentSessionRow.tsx
index 55509f6180..3514ae1b01 100644
--- a/apps/web/src/features/agents-view/components/AgentSessionRow.tsx
+++ b/apps/web/src/features/agents-view/components/AgentSessionRow.tsx
@@ -16,6 +16,7 @@ export function AgentSessionRow(props: {
trailing?: JSX.Element;
timestamp: string;
unread?: boolean;
+ failed?: boolean;
active?: boolean;
/** When true, hides the leading icon slot to save horizontal space. */
hideLeading?: boolean;
@@ -42,7 +43,9 @@ export function AgentSessionRow(props: {
class="absolute inset-0 rounded-lg outline-none focus-visible:outline-2 focus-visible:outline-accent"
aria-label={props.title}
aria-description={[
- conversationStateLabel(props.state),
+ props.failed
+ ? 'Last turn failed'
+ : conversationStateLabel(props.state),
props.unread ? 'Unread' : undefined,
]
.filter(Boolean)
@@ -69,10 +72,11 @@ export function AgentSessionRow(props: {
);
}
-/** One leading dot combines activity and unread state; read dormant rows are empty. */
+/** One dot combines turn failure, activity, and unread state. */
export function AgentSessionStatusIndicator(props: {
state: ConversationState;
unread?: boolean;
+ failed?: boolean;
}) {
return (
<Show
@@ -80,6 +84,7 @@ export function AgentSessionStatusIndicator(props: {
props.state === 'starting' ||
props.state === 'working' ||
props.state === 'waiting' ||
+ props.failed ||
props.unread
}
>
@@ -87,9 +92,12 @@ export function AgentSessionStatusIndicator(props: {
data-agent-status-indicator
aria-label={props.unread ? 'Unread' : undefined}
class={cn(
- 'size-1.5 rounded-full',
- props.state === 'waiting' ? 'bg-warning' : 'bg-accent',
- (props.state === 'starting' || props.state === 'working') &&
+ 'size-1.5 shrink-0 rounded-full',
+ props.failed && 'bg-failure',
+ !props.failed &&
+ (props.state === 'waiting' ? 'bg-warning' : 'bg-accent'),
+ !props.failed &&
+ (props.state === 'starting' || props.state === 'working') &&
'motion-safe:animate-pulse'
)}
/>
diff --git a/apps/web/src/features/agents-view/core/conversation-state.ts b/apps/web/src/features/agents-view/core/conversation-state.ts
index 034c178ec9..ad1ac50319 100644
--- a/apps/web/src/features/agents-view/core/conversation-state.ts
+++ b/apps/web/src/features/agents-view/core/conversation-state.ts
@@ -16,7 +16,7 @@ export function conversationState(
if (turn === 'blocked') return 'waiting';
if (turn === 'running' || turn === 'stopping') return 'working';
if (turn === 'starting') return 'starting';
- if (turn === 'disconnected') return 'dormant';
+ if (turn === 'disconnected' || turn === 'failed') return 'dormant';
if (!status || STARTING.has(status)) return 'starting';
return 'dormant';
}
diff --git a/apps/web/src/features/agents-view/views/AgentSessionListItem.tsx b/apps/web/src/features/agents-view/views/AgentSessionListItem.tsx
index 19edc7f88d..0166e44459 100644
--- a/apps/web/src/features/agents-view/views/AgentSessionListItem.tsx
+++ b/apps/web/src/features/agents-view/views/AgentSessionListItem.tsx
@@ -40,6 +40,7 @@ export function AgentSessionListItem(props: Props) {
modeForKind(systemBotKind(props.entity.botId) ?? 'agent'));
const state = () =>
conversationState(props.entity.status, props.entity.turnState);
+ const failed = () => props.entity.turnState === 'failed';
const details = (): SessionCodeDetails | undefined => {
if (mode() !== 'code') return undefined;
const pr = parseGithubPrUrl(props.entity.pullRequestUrl ?? '');
@@ -64,11 +65,19 @@ export function AgentSessionListItem(props: Props) {
const hideLeading = () => props.surface === 'agents';
const codeStatusIndicator = () =>
props.surface === 'agents' && mode() === 'code' ? (
- <AgentSessionStatusIndicator state={state()} unread={props.unread} />
+ <AgentSessionStatusIndicator
+ state={state()}
+ unread={props.unread}
+ failed={failed()}
+ />
) : undefined;
const workStatusIndicator = () =>
- props.surface === 'agents' && mode() !== 'code' ? (
- <AgentSessionStatusIndicator state={state()} unread={props.unread} />
+ props.surface === 'agents' && (mode() !== 'code' || !details()) ? (
+ <AgentSessionStatusIndicator
+ state={state()}
+ unread={props.unread}
+ failed={failed()}
+ />
) : undefined;
return (
@@ -77,6 +86,7 @@ export function AgentSessionListItem(props: Props) {
title={props.entity.name || 'Untitled conversation'}
kind={mode()}
state={state()}
+ failed={failed()}
active={props.active}
unread={props.unread}
hideLeading={hideLeading()}
@@ -89,6 +99,7 @@ export function AgentSessionListItem(props: Props) {
<AgentSessionStatusIndicator
state={state()}
unread={props.unread}
+ failed={failed()}
/>
}
>
@@ -106,10 +117,11 @@ export function AgentSessionListItem(props: Props) {
class="size-3.5 shrink-0 text-ink-extra-muted"
/>
</Show>
- <Show when={props.surface === 'home' && props.unread}>
+ <Show when={props.surface === 'home' && (props.unread || failed())}>
<span
- aria-label="Unread"
- class="size-1.5 shrink-0 rounded-full bg-accent"
+ aria-label={props.unread ? 'Unread' : 'Last turn failed'}
+ class="size-1.5 shrink-0 rounded-full"
+ classList={{ 'bg-failure': failed(), 'bg-accent': !failed() }}
/>
</Show>
{workStatusIndicator()}
diff --git a/apps/web/src/features/block-agent/component/AgentComposer.test.tsx b/apps/web/src/features/block-agent/component/AgentComposer.test.tsx
index 2ca638a9aa..1a7740d5e8 100644
--- a/apps/web/src/features/block-agent/component/AgentComposer.test.tsx
+++ b/apps/web/src/features/block-agent/component/AgentComposer.test.tsx
@@ -253,3 +253,16 @@ it('retains the draft if editing access is revoked while applying speed', async
expect(mocks.issue).not.toHaveBeenCalled();
expect(mocks.consumeNotes).not.toHaveBeenCalled();
});
+
+it('allows another prompt after a failed turn', () => {
+ mocks.session = () => ({ canEdit: true });
+ mocks.turn = () => 'failed';
+ render(() => <AgentComposer />);
+
+ expect(mocks.input?.busy).toBe(false);
+ mocks.input?.onSend('Try again', []);
+ expect(mocks.issue).toHaveBeenCalledWith({
+ type: 'prompt',
+ prompt: 'Try again',
+ });
+});
diff --git a/apps/web/src/features/block-agent/component/AgentComposer.tsx b/apps/web/src/features/block-agent/component/AgentComposer.tsx
index 2f974aedc7..e0c79901d0 100644
--- a/apps/web/src/features/block-agent/component/AgentComposer.tsx
+++ b/apps/web/src/features/block-agent/component/AgentComposer.tsx
@@ -136,7 +136,9 @@ export function AgentComposer(props: {
const busy = () => {
const state = turn();
return (
- (state !== 'idle' && state !== 'disconnected' && state !== 'stopping') ||
+ state === 'starting' ||
+ state === 'running' ||
+ state === 'blocked' ||
resuming()
);
};
diff --git a/apps/web/src/features/block-agent/debug/replay/Replay.tsx b/apps/web/src/features/block-agent/debug/replay/Replay.tsx
index 1240bde19e..f8f7288f16 100644
--- a/apps/web/src/features/block-agent/debug/replay/Replay.tsx
+++ b/apps/web/src/features/block-agent/debug/replay/Replay.tsx
@@ -47,7 +47,7 @@ function SessionChrome() {
// already reads as done.
const working = () => {
const state = turn();
- return state !== 'idle' && state !== 'disconnected' && state !== 'stopping';
+ return state === 'starting' || state === 'running' || state === 'blocked';
};
return (
<div class="flex items-center gap-2 border-b border-edge-muted px-4 py-2">
diff --git a/apps/web/src/lib/service-clients/service-agent-fold/generated/types.ts b/apps/web/src/lib/service-clients/service-agent-fold/generated/types.ts
index a7ac38bdc7..f7839e7eb0 100644
--- a/apps/web/src/lib/service-clients/service-agent-fold/generated/types.ts
+++ b/apps/web/src/lib/service-clients/service-agent-fold/generated/types.ts
@@ -1913,6 +1913,8 @@ export type TurnPhase =
export type TurnState =
/** No turn is open. */
| 'idle'
+ /** No turn is open, and the newest agent reply failed. */
+ | 'failed'
/**
* A prompt this client issued is on the wire, unconfirmed, and the agent
* has produced nothing. Only a speculative fold reports this.
diff --git a/crates/folds/agent_fold/AGENTS.md b/crates/folds/agent_fold/AGENTS.md
index 480a139f23..1b407a4440 100644
--- a/crates/folds/agent_fold/AGENTS.md
+++ b/crates/folds/agent_fold/AGENTS.md
@@ -76,6 +76,9 @@ Server-added invocation context is marked by the protocol’s block metadata.
Omit those blocks from user messages, including replay; preserve unmarked text
even when it contains agent-context tags.
+Terminal failures remain `TurnState::Failed` until a new turn starts; the existing
+session projection carries that state to list rows without loading transcripts.
+
## Checks
- `cargo test -p agent_fold`.
diff --git a/crates/folds/agent_fold/src/domain/fold/state.rs b/crates/folds/agent_fold/src/domain/fold/state.rs
index afd362b5e4..8eccc593da 100644
--- a/crates/folds/agent_fold/src/domain/fold/state.rs
+++ b/crates/folds/agent_fold/src/domain/fold/state.rs
@@ -7,7 +7,9 @@ use crate::domain::harness::{HarnessReader, ToolFrame, claude_code};
use agent_client_protocol::schema::v1::SessionId;
use crate::domain::log::{AgentSessionId, AgentSessionLog, Message};
-use crate::domain::model::{Control, FoldedMessage, SessionMetadata, ToolUseId, TurnId, TurnState};
+use crate::domain::model::{
+ Author, Control, FoldedMessage, SessionMetadata, StopReason, ToolUseId, TurnId, TurnState,
+};
use agent_client_protocol::schema::v1::{
CompleteElicitationNotification, CreateElicitationRequest, PromptRequest, RequestId,
RequestPermissionRequest, Response, SessionNotification, SessionUpdate,
@@ -565,7 +567,19 @@ impl FoldState {
.pending_interactions
.retain(|pending| !disconnected && Some(pending.turn()) == live_turn);
let interactions_changed = before != self.metadata.pending_interactions.len();
- let turn = if disconnected {
+ let failed = self.turn.is_none()
+ && self
+ .messages
+ .iter()
+ .rev()
+ .find(|message| matches!(message.author, Author::Agent))
+ .is_some_and(|message| {
+ self.turns_opened.checked_sub(1) == Some(message.id.0)
+ && matches!(message.stop, Some(StopReason::Failed { .. }))
+ });
+ let turn = if failed {
+ TurnState::Failed
+ } else if disconnected {
TurnState::Disconnected
} else {
match &self.turn {
diff --git a/crates/folds/agent_fold/src/domain/model/metadata.rs b/crates/folds/agent_fold/src/domain/model/metadata.rs
index e8524b7a15..84bf13cacf 100644
--- a/crates/folds/agent_fold/src/domain/model/metadata.rs
+++ b/crates/folds/agent_fold/src/domain/model/metadata.rs
@@ -103,6 +103,8 @@ pub enum TurnState {
/// No turn is open.
#[default]
Idle,
+ /// No turn is open, and the newest agent reply failed.
+ Failed,
/// A prompt this client issued is on the wire, unconfirmed, and the agent
/// has produced nothing. Only a speculative fold reports this.
Starting,
diff --git a/crates/folds/agent_fold/src/domain/test/interactions.rs b/crates/folds/agent_fold/src/domain/test/interactions.rs
index 0a3f8e431a..b91cf04c3f 100644
--- a/crates/folds/agent_fold/src/domain/test/interactions.rs
+++ b/crates/folds/agent_fold/src/domain/test/interactions.rs
@@ -296,3 +296,24 @@ fn stopping_the_turn_hides_a_held_tool_call() {
);
assert!(machine.metadata().pending_interactions.is_empty());
}
+
+#[test]
+fn failed_turns_clear_on_the_next_prompt() {
+ let mut machine = FoldMachineImpl::new();
+ prompt(&mut machine, "p");
+ assert!(push(
+ &mut machine,
+ "to_server",
+ json!({"id": "p", "error": {"code": -32603, "message": "Runtime failed"}}),
+ ));
+ assert_eq!(machine.metadata().turn, TurnState::Failed);
+
+ prompt(&mut machine, "next");
+ assert_eq!(machine.metadata().turn, TurnState::Running);
+ push(
+ &mut machine,
+ "to_server",
+ json!({"id": "next", "result": {"stopReason": "cancelled"}}),
+ );
+ assert_eq!(machine.metadata().turn, TurnState::Idle);
+}
diff --git a/crates/folds/agent_fold/src/domain/test/notifications.rs b/crates/folds/agent_fold/src/domain/test/notifications.rs
index b35d57a3e7..9ce0a20804 100644
--- a/crates/folds/agent_fold/src/domain/test/notifications.rs
+++ b/crates/folds/agent_fold/src/domain/test/notifications.rs
@@ -210,3 +210,45 @@ fn execution_context_is_model_only_and_user_authored_suffix_context_remains_visi
assert_eq!(messages.len(), 1);
assert_eq!(messages[0].last_text(), Some(original.to_owned()));
}
+
+#[test]
+fn successful_notification_noop_does_not_restore_an_older_failure() {
+ use crate::domain::model::TurnState;
+
+ let mut machine = LifecycleFold::new();
+ for frame in parse_log(
+ r#"
+{"direction":"to_runtime","content":{"type":"acp","jsonrpc":"2.0","id":"p","method":"session/prompt","params":{"sessionId":"s","prompt":[]}}}
+{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","id":"p","error":{"code":-32603,"message":"Runtime failed"}}}
+"#,
+ ) {
+ let _ = machine.push(frame);
+ }
+ assert_eq!(machine.inner().metadata().turn, TurnState::Failed);
+
+ let request = AgentAction::notification(vec![Notification {
+ id: macro_uuid::generate_uuid_v7(),
+ subject_id: "connection".into(),
+ created_at: "2026-10-21T00:00:00Z".into(),
+ event: NotificationEvent::AppConnected {
+ app: "Calendar".into(),
+ },
+ }])
+ .to_runtime(&SessionId::new("s"), RequestId::Str("event".into()))
+ .unwrap();
+ let _ = machine.push(AgentSessionLog {
+ agent_session_id: test_session(),
+ user_id: None,
+ content: Message::Notification(request),
+ logged_at: None,
+ });
+ for frame in parse_log(
+ r#"
+{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"<noop/>"}}}}}
+{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","id":"event","result":{"stopReason":"end_turn"}}}
+"#,
+ ) {
+ let _ = machine.push(frame);
+ }
+ assert_eq!(machine.inner().metadata().turn, TurnState::Idle);
+}
diff --git a/crates/macro_db_client/AGENTS.md b/crates/macro_db_client/AGENTS.md
index d30825b706..4b1807a9c4 100644
--- a/crates/macro_db_client/AGENTS.md
+++ b/crates/macro_db_client/AGENTS.md
@@ -31,6 +31,11 @@ bridges old-producer writes during rollout; keep that bridge until legacy
review producers have retired. Encode empty legacy item lists as JSON arrays so
the typed notification reader can decode them.
+The `agent_session.turn_state` constraint includes `failed` for terminal turn
+errors; extend it additively before services begin writing new turn states.
+Install widened checks as `NOT VALID` and validate in a separate migration so
+the scan does not retain the replacement migration's exclusive table lock.
+
## Boundaries
- Depends on: `entity_access_db_utils`, `entity_registry_db_utils`,
diff --git a/crates/macro_db_client/migrations/20261028231646_agent_session_failed_turn.sql b/crates/macro_db_client/migrations/20261028231646_agent_session_failed_turn.sql
new file mode 100644
index 0000000000..22a1415fbe
--- /dev/null
+++ b/crates/macro_db_client/migrations/20261028231646_agent_session_failed_turn.sql
@@ -0,0 +1,7 @@
+-- Retain all existing states while allowing failed turns in the list projection.
+SET LOCAL lock_timeout = '5s';
+
+ALTER TABLE agent_session
+ DROP CONSTRAINT agent_session_turn_state_valid,
+ ADD CONSTRAINT agent_session_turn_state_valid
+ CHECK (turn_state IN ('idle', 'starting', 'running', 'stopping', 'blocked', 'disconnected', 'failed')) NOT VALID;
diff --git a/crates/macro_db_client/migrations/20261028234010_validate_agent_session_failed_turn.sql b/crates/macro_db_client/migrations/20261028234010_validate_agent_session_failed_turn.sql
new file mode 100644
index 0000000000..e9a286c33f
--- /dev/null
+++ b/crates/macro_db_client/migrations/20261028234010_validate_agent_session_failed_turn.sql
@@ -0,0 +1,4 @@
+-- Run after the replacement migration releases its exclusive table lock.
+SET LOCAL lock_timeout = '5s';
+
+ALTER TABLE agent_session VALIDATE CONSTRAINT agent_session_turn_state_valid;
diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.md
index 55c55579f4..0dd42b7102 100644
--- a/docs/agent-guide/ai-chat.md
+++ b/docs/agent-guide/ai-chat.md
@@ -1714,6 +1714,13 @@ with `set_pull_request`, then use **Refresh changes**. An unavailable or
oversized PR is explained in the pane; there is no branch or container fallback.
Refresh request failures show a retry banner while keeping the last diff visible.
The pane does not create PRs or generate their descriptions.
+
+### Failed session rows
+
+A failed agent turn shows a small red status dot in Home and Agents, including
+after reloading the list. Open the row to read the existing transcript error.
+Starting another turn clears the failure dot; unread state remains independent.
+
### Live development previews
Coding agents can call the internal **SharePreview** tool with their local HTTP
diff --git a/packages/sdk/generated/agent-fold/index.ts b/packages/sdk/generated/agent-fold/index.ts
index 7769210ea9..95c981e038 100644
--- a/packages/sdk/generated/agent-fold/index.ts
+++ b/packages/sdk/generated/agent-fold/index.ts
@@ -1771,6 +1771,8 @@ export type TurnPhase =
export type TurnState =
/** No turn is open. */
"idle" |
+/** No turn is open, and the newest agent reply failed. */
+"failed" |
/**
* A prompt this client issued is on the wire, unconfirmed, and the agent
* has produced nothing. Only a speculative fold reports this.