Skip to content

Commit 1086b31

Browse files
committed
merge: integrate Home permissions/TODO/map (dotfiles#234-236) with anomalyco#232 failed-session retry UI
Resolves session-activity reconnect (todos.reload + reconnected), pinned row (failure dot/Retry + TodoLine). Shared fixture serves the failed-session listing; agent map shares the red failed dot.
2 parents 56dca72 + 00f02db commit 1086b31

28 files changed

Lines changed: 1868 additions & 17 deletions

‎packages/es-app/src/api.ts‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Thin fetch layer. The daemon (:4096) is reached via the /oc proxy, the es
22
* dashboard server (:7777) via /es — both same-origin through vite. */
3-
import type { Agent, GlobalSession, Message, Part, PermissionRequest, QuestionRequest, Session, SessionV1InputImage, Todo } from "@opencode-ai/sdk/v2"
3+
import type { Agent, GlobalSession, Message, Part, PermissionRequest, QuestionRequest, Session, SessionFailure, SessionRetryResult, SessionV1InputImage, Todo } from "@opencode-ai/sdk/v2"
44
import { httpError } from "./api-error"
55

66
export type MessageWithParts = { info: Message; parts: Part[] }
@@ -150,6 +150,36 @@ export const oc = {
150150
if (!res.ok) throw new Error(`abort failed: HTTP ${res.status} ${await res.text()}`)
151151
},
152152

153+
// undefined = this Core predates failure tracking; the feature stays hidden.
154+
failedSessions: async (): Promise<SessionFailure[] | undefined> => {
155+
const res = await fetch("/oc/experimental/session/failed")
156+
if (res.status === 404) return undefined
157+
return json<SessionFailure[]>(res)
158+
},
159+
160+
// "unknown": the request may have reached Core, so the outcome must be re-read, never re-assumed.
161+
retrySession: async (failure: Pick<SessionFailure, "sessionID" | "directory" | "messageID">):
162+
Promise<SessionRetryResult | { outcome: "unknown" | "unavailable" | "rejected"; detail: string }> => {
163+
let res: Response
164+
try {
165+
res = await fetch(`/oc/session/${failure.sessionID}/retry?${q(failure.directory)}`, {
166+
method: "POST",
167+
headers: { "content-type": "application/json" },
168+
body: JSON.stringify({ messageID: failure.messageID }),
169+
})
170+
} catch {
171+
return { outcome: "unknown", detail: "The response was lost" }
172+
}
173+
if (res.ok) {
174+
const value = await res.json().catch(() => undefined)
175+
return value && typeof value.outcome === "string" ? value as SessionRetryResult
176+
: { outcome: "unknown", detail: "Unreadable response" }
177+
}
178+
if (res.status === 404) return { outcome: "unavailable", detail: "Session or retry support not found" }
179+
if (res.status >= 500 || res.status === 408) return { outcome: "unknown", detail: `HTTP ${res.status}` }
180+
return { outcome: "rejected", detail: `HTTP ${res.status}` }
181+
},
182+
153183
// messageID = fork point: the new session copies history strictly before it;
154184
// omitted = fork at tip (full history)
155185
fork: (id: string, directory: string, messageID?: string): Promise<Session> =>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { createSignal, For, Show } from "solid-js"
2+
import { A } from "@solidjs/router"
3+
import type { SessionFailure } from "@opencode-ai/sdk/v2"
4+
import { sessionHref, useDashboard } from "../state"
5+
import { failureLabel, retryLabel, unavailableReason, type RetryResult } from "../session-failures"
6+
7+
const settled = (result: RetryResult | undefined) => result?.outcome === "accepted" || result?.outcome === "running"
8+
9+
/** Per-session Retry with its inline outcome. Renders nothing unless the session is failed. */
10+
export const FailureRetry = (props: { sessionID: string; compact?: boolean }) => {
11+
const { failures, handedOff } = useDashboard()
12+
const failure = () => (handedOff(props.sessionID) ? undefined : failures.failure(props.sessionID))
13+
const state = () => failures.retryState(props.sessionID)
14+
const sending = () => state()?.phase === "sending"
15+
const result = () => { const value = state(); return value?.phase === "done" ? value.result : undefined }
16+
return (
17+
<Show when={failure() || (result() && !settled(result()))}>
18+
<span class="failure-retry" data-compact={props.compact ? "" : undefined}>
19+
<Show when={failure()}>
20+
{(item) => (
21+
<Show when={item().retry === "available"} fallback={
22+
<span class="failure-note" title={item().retry === "out-of-order"
23+
? "Newer steps would sort before the failed one, so a retry could not track its progress."
24+
: "The failed step ran tools; retrying could repeat or hide their effects."}>
25+
Retry unavailable: {unavailableReason(item())}
26+
</span>
27+
}>
28+
<button type="button" class="failure-retry-button" disabled={sending()}
29+
aria-label={`Retry failed turn${props.compact ? "" : `: ${failureLabel(item())}`}`}
30+
onClick={() => void failures.retry(item())}>
31+
{sending() ? "Retrying…" : "Retry"}
32+
</button>
33+
</Show>
34+
)}
35+
</Show>
36+
<Show when={result()}>
37+
{(value) => <span class="failure-note" role="status" data-outcome={value().outcome}>{retryLabel(value())}</span>}
38+
</Show>
39+
</span>
40+
</Show>
41+
)
42+
}
43+
44+
/** Scoped bulk control: retries every retryable failed root in the current sidebar scope. */
45+
export const ResumeAllFailed = () => {
46+
const { scopedFailures, failures, allProjects, sessionRows } = useDashboard()
47+
const [running, setRunning] = createSignal(false)
48+
const [report, setReport] = createSignal<{ failure: SessionFailure; result: RetryResult | undefined }[]>()
49+
const retryable = () => scopedFailures().filter((item) => item.retry === "available")
50+
const title = (id: string) => sessionRows().find((row) => row.id === id)?.title || id
51+
const run = async () => {
52+
if (running()) return
53+
setRunning(true)
54+
setReport(undefined)
55+
try { setReport(await failures.retryAll(retryable())) } finally { setRunning(false) }
56+
}
57+
const summary = () => {
58+
const rows = report() ?? []
59+
const started = rows.filter((row) => settled(row.result)).length
60+
return `${started} of ${rows.length} resumed${rows.length - started ? `; ${rows.length - started} not resumed` : ""}`
61+
}
62+
return (
63+
// An outage shows even with nothing cached: an empty list must not read as "none failed".
64+
<Show when={failures.error() || (failures.supported() && (scopedFailures().length || report()))}>
65+
<section class="failed-section" aria-label="Failed sessions">
66+
<Show when={failures.supported() && scopedFailures().length}>
67+
<div class="failed-heading">
68+
<span class="dot failed" aria-hidden="true" />
69+
<span>{scopedFailures().length} failed{allProjects() ? "" : " in this project"}</span>
70+
<Show when={retryable().length}>
71+
<button type="button" class="failure-retry-button" disabled={running()} onClick={() => void run()}
72+
title="Continue each failed turn from where it stopped; steps that cannot be retried safely are skipped">
73+
{running() ? "Resuming…" : `Resume all failed (${retryable().length})`}
74+
</button>
75+
</Show>
76+
</div>
77+
</Show>
78+
<Show when={report()}>
79+
<div class="failed-report" role="status">
80+
<span>{summary()}</span>
81+
<For each={(report() ?? []).filter((row) => !settled(row.result))}>{(row) => (
82+
<A href={sessionHref(row.failure.sessionID, row.failure.directory)} class="failure-note">
83+
<bdi dir="auto">{title(row.failure.sessionID)}</bdi>: {row.result ? retryLabel(row.result) : "Already retrying"}
84+
</A>
85+
)}</For>
86+
<button type="button" class="failure-dismiss" aria-label="Dismiss resume report" onClick={() => setReport(undefined)}>×</button>
87+
</div>
88+
</Show>
89+
<Show when={failures.error()}><div class="failure-note" role="status">{failures.error()}</div></Show>
90+
</section>
91+
</Show>
92+
)
93+
}

‎packages/es-app/src/components/sidebar.tsx‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { nativeHeader, NativeHeader } from "./native-header"
1212
import { NewSession } from "./new-session"
1313
import { peekAttrs, SessionPeek } from "./session-peek"
1414
import { CloudNav, CloudDiscovery } from "./cloud-sidebar"
15+
import { ResumeAllFailed } from "./session-failure"
16+
import { failureLabel } from "../session-failures"
1517

1618
const BusyDot = () => {
1719
const [visible, setVisible] = createSignal(false)
@@ -29,17 +31,22 @@ const BusyDot = () => {
2931
data-on={enabled() ? String(!!(tick() % 2)) : undefined} />
3032
}
3133

32-
const StatusDot = (props: { state: DotState }) => (
33-
<Show when={props.state === "busy"} fallback={<span class={`dot ${props.state}`} />}>
34+
const StatusDot = (props: { state: DotState; label?: string }) => (
35+
<Show when={props.state === "busy"} fallback={<span class={`dot ${props.state}`}
36+
{...(props.state === "failed" ? { role: "img", "aria-label": props.label ?? "Failed" } : {})} />}>
3437
<BusyDot />
3538
</Show>
3639
)
3740

3841
export default function Sidebar() {
3942
const { state, dotFor, editspace, setEditspace, editspaces, archivedIds, notifications, markViewed,
4043
allProjects, setAllProjects, sessionRows, sessions, pinnedSessions, unpinnedSessions, isPinned, togglePin,
41-
sessionsLoading, sessionsError, setVisibleSessions, cloud } =
44+
sessionsLoading, sessionsError, setVisibleSessions, cloud, failures } =
4245
useDashboard()
46+
const dotText = (s: SessionRow, dot: DotState) => {
47+
const failure = dot === "failed" ? failures.failure(s.id) : undefined
48+
return failure ? `failed: ${failureLabel(failure)}` : dot
49+
}
4350
const observed = new Map<Element, string>()
4451
const visible = new Set<Element>()
4552
let published = new Set<string>()
@@ -172,10 +179,10 @@ export default function Sidebar() {
172179
href={sessionHref(s.id, s.directory)}
173180
activeClass="active"
174181
class="nav-item archived"
175-
title={`${s.title} (${dot()})${allProjects() ? ` · ${s.directory}` : ""}`}
182+
title={`${s.title} (${dotText(s, dot())})${allProjects() ? ` · ${s.directory}` : ""}`}
176183
{...peekAttrs(s)}
177184
>
178-
<StatusDot state={dot()} />
185+
<StatusDot state={dot()} label={dotText(s, dot())} />
179186
<span class="nav-title">{s.title || s.id}</span>
180187
<Show when={allProjects()}><span class="session-project">{s.project}</span></Show>
181188
</A>
@@ -186,9 +193,9 @@ export default function Sidebar() {
186193
href={sessionHref(s.id, s.directory)}
187194
activeClass="active"
188195
class="nav-item"
189-
title={`${s.title} (${dot()})${allProjects() ? ` · ${s.directory}` : ""}`}
196+
title={`${s.title} (${dotText(s, dot())})${allProjects() ? ` · ${s.directory}` : ""}`}
190197
>
191-
<StatusDot state={dot()} />
198+
<StatusDot state={dot()} label={dotText(s, dot())} />
192199
<span class="nav-title">{s.title || s.id}</span>
193200
<Show when={allProjects()}><span class="session-project">{s.project}</span></Show>
194201
</A>
@@ -206,8 +213,8 @@ export default function Sidebar() {
206213
<div class="mini-session" {...peekAttrs(s)}>
207214
<A ref={(el) => observeSession(el, s.id)} href={sessionHref(s.id, s.directory)}
208215
activeClass="active" class="mini-item"
209-
title={`${s.title} (${dot()})${allProjects() ? ` · ${s.project}` : ""}`}>
210-
<StatusDot state={dot()} />
216+
title={`${s.title} (${dotText(s, dot())})${allProjects() ? ` · ${s.project}` : ""}`}>
217+
<StatusDot state={dot()} label={`${s.title || s.id}: ${dotText(s, dot())}`} />
211218
</A>
212219
<button type="button" class="mini-pin" classList={{ pinned: isPinned(s) }}
213220
aria-label={`${isPinned(s) ? "Unpin" : "Pin"} ${s.title || s.id}`}
@@ -306,6 +313,7 @@ export default function Sidebar() {
306313
</For>
307314
</div>
308315
</Show>
316+
<ResumeAllFailed />
309317
<div class="search-box">
310318
<input
311319
class="search-input"

‎packages/es-app/src/composer.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,41 @@ export const getComposer = (sessionID: string, directory: string): Composer => {
144144
return composer
145145
}
146146

147+
/**
148+
* Why a failed-turn Retry must wait: a human send whose admission is unresolved could
149+
* still land, and retrying first would reorder or obscure it. Reads saved state for
150+
* sessions whose composer is not open; unreadable saved state blocks like an unknown send.
151+
*/
152+
export const unresolvedSend = (
153+
sessionID: string,
154+
directory: string,
155+
storage: () => Pick<Storage, "getItem"> | null = () =>
156+
typeof window === "undefined" ? null : composerStorage(navigator.userAgent, window.sessionStorage, () => window.localStorage),
157+
) => {
158+
const live = controllers.get(storageKey(sessionID, directory))
159+
if (live?.restoreError()) return "Saved composer state could not be restored. Check the conversation first."
160+
const saved = live ? undefined : readSubmission(storage, storageKey(sessionID, directory))
161+
if (saved === "unreadable") return "Saved composer state is unreadable. Open the session and check the conversation first."
162+
const submission = live ? live.state.normalSubmission : saved?.normalSubmission
163+
if (live?.state.sending || submission?.status === "sending") return "A message is still being sent."
164+
if (submission?.status === "unknown") return "A previous Send outcome is unknown. Check the conversation first."
165+
if (live ? live.state.admission : saved?.admission) return "An input admission is unresolved. Reconcile it first."
166+
return ""
167+
}
168+
169+
// undefined = nothing saved for this session; "unreadable" = saved state exists or may exist but cannot be read.
170+
const readSubmission = (storage: () => Pick<Storage, "getItem"> | null, key: string) => {
171+
try {
172+
const raw = storage()?.getItem(key)
173+
if (raw == null) return undefined
174+
const value: unknown = JSON.parse(raw)
175+
if (!value || typeof value !== "object") return "unreadable" as const
176+
return value as Partial<Pick<ComposerState, "normalSubmission" | "admission">>
177+
} catch {
178+
return "unreadable" as const
179+
}
180+
}
181+
147182
export const createComposer = (sessionID: string, directory: string, dependencies: ComposerDependencies = {}) => {
148183
const request = dependencies.fetch ?? ((url, init) => fetch(url, init))
149184
const prompt = dependencies.prompt ?? oc.prompt
@@ -1389,6 +1424,7 @@ export const createComposer = (sessionID: string, directory: string, dependencie
13891424
}
13901425
return {
13911426
state,
1427+
restoreError: () => restoreError,
13921428
persistAsync,
13931429
persistForRecovery: () => persistAsync(true),
13941430
// Resolves once saved image refs are restored into the in-memory drafts.

‎packages/es-app/src/index.css‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,3 +2001,16 @@ textarea.vim-normal::selection { background: var(--lavender); color: var(--crust
20012001
}
20022002
.session-panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
20032003
.session-panel-close { display: flex; justify-content: flex-end; }
2004+
2005+
/* failed turn: red, distinct from idle grey and unknown/offline (no dot change) */
2006+
.dot.failed { background: var(--red); }
2007+
.failure-retry { display: inline-flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
2008+
.failure-retry-button { font-size: 12px; padding: 1px 8px; border: 1px solid var(--red); color: var(--red); background: transparent; cursor: pointer; }
2009+
.failure-retry-button:disabled { opacity: 0.6; cursor: default; }
2010+
.failure-note { font-size: 12px; color: var(--subtext0); overflow-wrap: anywhere; white-space: normal; }
2011+
.failed-section { margin: 6px 0; padding: 6px 8px; border-inline-start: 2px solid var(--red); font-size: 12.5px; }
2012+
.failed-heading { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
2013+
.failed-report { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; position: relative; padding-inline-end: 18px; }
2014+
.failure-dismiss { position: absolute; inset-inline-end: 0; top: 0; background: none; border: 0; color: var(--subtext0); cursor: pointer; }
2015+
.home-name .dot.failed { margin-inline-end: 6px; }
2016+
.home-failed { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--red); }

‎packages/es-app/src/pages/home.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { ActivityBriefInput } from "../activity-brief"
88
import { answerDraftKey, attentionPath, blockedReason, createAttention, decisionLabel, deliveryLabel, type AttentionRecord } from "../attention"
99
import { createHomeRequests, requestKey, type HomeRequest } from "../home-requests"
1010
import HomeActivity from "../home-activity"
11+
import { FailureRetry } from "../components/session-failure"
12+
import { failureLabel } from "../session-failures"
1113
import HomeCloudAgents from "../home-cloud-agents"
1214
import type { HomeActivityRow } from "../home-activity-data"
1315
import { HomePermission, type HomeReplyReceipt } from "../components/home-permission"
@@ -31,8 +33,9 @@ const PinnedAgent = (props: { session: SessionRow }) => {
3133
tools: snapshot.value?.turn.active_tools.map(tool => ({ name: tool.name, status: tool.status, sessionID: props.session.id })),
3234
}
3335
}
36+
const failure = () => dashboard.handedOff(props.session.id) ? undefined : dashboard.failures.failure(props.session.id)
3437
return <div class="home-agent">
35-
<div><A class="home-name" href={sessionHref(props.session.id, props.session.directory)}><bdi dir="auto">{props.session.title || props.session.id}</bdi></A><div class="home-muted"><bdi dir="auto">{props.session.project || dashboard.editspace() || "project"}</bdi></div><button onClick={() => dashboard.togglePin(props.session)}>Unpin</button></div>
38+
<div><A class="home-name" href={sessionHref(props.session.id, props.session.directory)}><Show when={failure()}>{item => <span class="dot failed" role="img" aria-label={`Failed: ${failureLabel(item())}`} title={`Failed: ${failureLabel(item())}`} />}</Show><bdi dir="auto">{props.session.title || props.session.id}</bdi></A><Show when={failure()}>{item => <div class="home-failed">{failureLabel(item())} <FailureRetry sessionID={props.session.id} compact /></div>}</Show><div class="home-muted"><bdi dir="auto">{props.session.project || dashboard.editspace() || "project"}</bdi></div><button onClick={() => dashboard.togglePin(props.session)}>Unpin</button></div>
3639
<div><ActivityBriefView input={brief()} /><TodoLine session={props.session} turn={turnOf(work())} /><details><summary>Turn telemetry</summary><div class="home-source">Read-only turn telemetry · generated summary cache</div><CurrentWorkView id={props.session.id} directory={props.session.directory} compact onSnapshot={setWork} /></details></div>
3740
</div>
3841
}

‎packages/es-app/src/pages/session.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import type { FindHit } from "../transcript-find"
4242
import { ToolSize } from "../components/tool-size"
4343
import { ToolRun } from "../components/tool-run"
4444
import { HeaderMenu } from "../components/header-menu"
45+
import { FailureRetry } from "../components/session-failure"
4546
import { completedTurns, messageSegments, planToolRuns, samePlan, sameSegments } from "../transcript-groups"
4647
import { isUserPrompt, promptPosition, promptTarget } from "../transcript-nav"
4748

@@ -476,6 +477,7 @@ function SessionView(props: { sessionID: string; directory: string }) {
476477
<Show when={workState() === "retry"}><WorkSpinner /></Show>
477478
<span>{workState() === "retry" ? "Retrying" : workState() === "waiting" ? "Waiting for your reply" : workState() === "failed" ?
478479
`Session failed — see error ${inlineError() ? "in conversation" : "above"}` : "Reconnecting — activity unavailable"}</span>
480+
<Show when={workState() === "failed"}><FailureRetry sessionID={sessionID} /></Show>
479481
</>}>
480482
<Show when={workState() === "working" || workState() === "retry"}><WorkSpinner /></Show>
481483
<ActivityBriefView input={briefInput()} />

0 commit comments

Comments
 (0)