Skip to content

Commit 6c42043

Browse files
committed
fix(es-app): quiet shared backend status; sends never lock the composer (es-app#190, anomalyco#186, anomalyco#207/anomalyco#215)
Status: - backend-status store; one fixed slot in the mode switch (every page incl. Front desk): dot after 2 s of persisting failure, peach for real faults, sanitized Diagnostics disclosure. - Background reads report there instead of warning cards; sources without polling retry. - Front desk: non-current sources are compact rows (detail in tooltip/diagnostics); unreadable requests pending at last check stay counted; ignored-failures 403 reported, list kept. - In-flight Send/steer/queue shows in the work-status slot, not rows under the controls. Sends (anomalyco#207/anomalyco#215): - Send carries a client message ID; Send and /input POSTs have a 25 s deadline. - No answer: 'Not confirmed', composer unlocked, draft+images kept. Send is checked by its ID on every refresh/Check: found -> shown sent, draft cleared, no second POST; absent from a reachable session -> explicit 'Send again' with the same ID only. - An unknown input (incl. one restored after reload) is set aside with its request ID when the next message is sent, or immediately on deadline; never blocks; retry stays explicit.
1 parent 7a6174d commit 6c42043

30 files changed

Lines changed: 906 additions & 91 deletions

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,17 @@ export const oc = {
161161
model?: { providerID: string; modelID: string }
162162
images?: readonly { mime: string; url: string; filename?: string }[]
163163
context?: readonly ContextPart[]
164+
/** Client-chosen user message ID, so an unconfirmed send can be found later by GET /message/:id. */
165+
messageID?: string
166+
signal?: AbortSignal
164167
} = {},
165168
) => {
166169
const parts: Record<string, unknown>[] = []
167170
if (text) parts.push({ type: "text", text })
168171
parts.push(...inputImages(opts.images ?? []))
169172
parts.push(...(opts.context ?? []))
170173
// A selected preference is resolved server-side, including its variant.
171-
const body: Record<string, unknown> = { parts, agent: session.agent }
174+
const body: Record<string, unknown> = { parts, agent: session.agent, ...(opts.messageID ? { messageID: opts.messageID } : {}) }
172175
const model =
173176
opts.model ??
174177
(session.preferredModel ? undefined : session.model ? { providerID: session.model.providerID, modelID: session.model.id } : undefined)
@@ -177,6 +180,7 @@ export const oc = {
177180
method: "POST",
178181
headers: { "content-type": "application/json" },
179182
body: JSON.stringify(body),
183+
signal: opts.signal,
180184
})
181185
if (!res.ok) throw await httpError(res)
182186
},

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createEffect, createSignal, onCleanup, onMount } from "solid-js"
2+
import { clearBackend, describeFailure, reportBackend } from "./backend-status"
23

34
export type AttentionRecord = {
45
id: string
@@ -156,9 +157,12 @@ export const createAttention = (project: () => string | undefined, options: { re
156157
})
157158
setScopes(previous => ({ ...previous, [scope ?? ""]: { checked, partial: unavailable.size > 0, truncated: pages.length === 50 } }))
158159
setError("")
160+
clearBackend("Attention ledger")
159161
} catch (cause) {
160162
if (current !== version) return
161-
setError(cause instanceof Error ? cause.message : "Attention ledger unavailable.")
163+
// Source state keeps "unavailable"; its detail stays short and the header carries the status.
164+
setError(`Attention ledger unavailable (${describeFailure(cause)}).`)
165+
reportBackend("Attention ledger", cause)
162166
} finally {
163167
if (current === version) setLoading(false)
164168
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { afterEach, beforeEach, expect, test } from "bun:test"
2+
import { BACKEND_STATUS_DELAY_MS, backendIssues, backendStatus, clearBackend, describeFailure, isTransient, reportBackend, resetBackend } from "./backend-status"
3+
4+
beforeEach(() => resetBackend())
5+
afterEach(() => resetBackend())
6+
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
7+
8+
test("a brief failure never reaches the indicator", async () => {
9+
reportBackend("Sessions", new Error("http://127.0.0.1:4096/session: HTTP 502 {\"error\":\"bad gateway\"}"))
10+
await wait(BACKEND_STATUS_DELAY_MS / 4)
11+
clearBackend("Sessions")
12+
await wait(BACKEND_STATUS_DELAY_MS)
13+
expect(backendStatus()).toBe("")
14+
})
15+
16+
test("persisting load trouble shows one updating state, and recovery clears it", async () => {
17+
reportBackend("Sessions", new Error("HTTP 502"))
18+
reportBackend("Brief checks", new TypeError("Failed to fetch"))
19+
reportBackend("Sessions", new Error("HTTP 502"))
20+
expect(backendStatus()).toBe("")
21+
await wait(BACKEND_STATUS_DELAY_MS + 100)
22+
expect(backendStatus()).toBe("updating")
23+
expect(backendIssues().map((issue) => issue.source)).toEqual(["Sessions", "Brief checks"])
24+
clearBackend("Sessions")
25+
clearBackend("Brief checks")
26+
expect(backendStatus()).toBe("")
27+
})
28+
29+
test("a refused read is a problem, not load", async () => {
30+
reportBackend("Ignored failures", new Error("HTTP 403"))
31+
await wait(BACKEND_STATUS_DELAY_MS + 100)
32+
expect(backendStatus()).toBe("problem")
33+
})
34+
35+
test("details never carry URLs or bodies", () => {
36+
expect(describeFailure(new Error("http://127.0.0.1:3181/oc/session/ses_x/children?directory=/a: HTTP 502 {\"name\":\"x\"}"))).toBe("service unavailable (HTTP 502)")
37+
expect(describeFailure(new TypeError("Failed to fetch"))).toBe("no connection")
38+
expect(describeFailure(new DOMException("signal timed out", "TimeoutError"))).toBe("timed out")
39+
expect(isTransient({ status: 503 })).toBe(true)
40+
expect(isTransient({ status: 403 })).toBe(false)
41+
})
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* One app-wide account of background reads that are failing. Pages keep their
2+
* last-known content and report here instead of rendering their own warning;
3+
* the header shows a single compact indicator once trouble persists, with the
4+
* sanitized detail behind a disclosure. Human-actionable results of a user's
5+
* own action (an unconfirmed send or ignore) stay where the action happened. */
6+
import { createRoot, createSignal } from "solid-js"
7+
8+
export type BackendIssue = {
9+
source: string
10+
detail: string
11+
/** Transient: load or availability (5xx, timeout, offline). Otherwise a real fault worth fixing. */
12+
transient: boolean
13+
since: number
14+
}
15+
16+
/** How long a background failure must persist before the indicator reports it. */
17+
export const BACKEND_STATUS_DELAY_MS = 2000
18+
19+
const store = createRoot(() => {
20+
const [issues, setIssues] = createSignal<Record<string, BackendIssue>>({})
21+
const [shown, setShown] = createSignal<"" | "updating" | "problem">("")
22+
let timer: ReturnType<typeof setTimeout> | undefined
23+
const evaluate = () => {
24+
const current = Object.values(issues())
25+
if (!current.length) {
26+
clearTimeout(timer)
27+
timer = undefined
28+
return setShown("")
29+
}
30+
const kind = current.some((issue) => !issue.transient) ? "problem" : "updating"
31+
const due = Math.min(...current.map((issue) => issue.since)) + BACKEND_STATUS_DELAY_MS - Date.now()
32+
clearTimeout(timer)
33+
if (due <= 0) return setShown(kind)
34+
timer = setTimeout(evaluate, due)
35+
}
36+
return { issues, setIssues, shown, evaluate }
37+
})
38+
39+
export const backendIssues = () => Object.values(store.issues()).sort((a, b) => a.since - b.since)
40+
export const backendStatus = store.shown
41+
42+
export const reportBackend = (source: string, cause: unknown) => {
43+
const detail = describeFailure(cause)
44+
const transient = isTransient(cause)
45+
const previous = store.issues()[source]
46+
if (previous && previous.detail === detail && previous.transient === transient) return
47+
// Agents read the console; keep one sanitized line per change, never raw bodies or URLs.
48+
console.info(`[backend] ${source}: ${detail}`)
49+
store.setIssues((current) => ({ ...current, [source]: { source, detail, transient, since: previous?.since ?? Date.now() } }))
50+
store.evaluate()
51+
}
52+
53+
export const clearBackend = (source: string) => {
54+
if (!store.issues()[source]) return
55+
console.info(`[backend] ${source}: recovered`)
56+
store.setIssues((current) => {
57+
const next = { ...current }
58+
delete next[source]
59+
return next
60+
})
61+
store.evaluate()
62+
}
63+
64+
/** Test seam. */
65+
export const resetBackend = () => {
66+
store.setIssues({})
67+
store.evaluate()
68+
}
69+
70+
const statusOf = (cause: unknown): number | undefined => {
71+
if (cause && typeof cause === "object" && "status" in cause && typeof cause.status === "number") return cause.status
72+
const match = /\bHTTP (\d{3})\b/.exec(String(cause instanceof Error ? cause.message : cause))
73+
return match ? Number(match[1]) : undefined
74+
}
75+
76+
export const isTransient = (cause: unknown) => {
77+
const status = statusOf(cause)
78+
// 501: the server has no such route; that is a missing feature, not load.
79+
if (status !== undefined) return (status >= 500 && status !== 501) || status === 408 || status === 429
80+
// No status: the request never got an answer (offline, refused, timed out, aborted).
81+
return true
82+
}
83+
84+
/** A short human phrase: no URLs, paths, JSON or stack text. */
85+
export const describeFailure = (cause: unknown) => {
86+
const status = statusOf(cause)
87+
if (status === 401 || status === 403) return `not authorized (HTTP ${status})`
88+
if (status === 404 || status === 501) return `not available here (HTTP ${status})`
89+
if (status === 502 || status === 503 || status === 504) return `service unavailable (HTTP ${status})`
90+
if (status !== undefined) return `HTTP ${status}`
91+
const text = String(cause instanceof Error ? `${cause.name} ${cause.message}` : cause)
92+
if (/timeout|timed out/i.test(text)) return "timed out"
93+
if (/abort/i.test(text)) return "cancelled"
94+
return "no connection"
95+
}

‎packages/es-app/src/components/backend-status.css‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createSignal, For, onCleanup, Show } from "solid-js"
2+
import { backendIssues, backendStatus } from "../backend-status"
3+
import { usePulse } from "../pulse"
4+
import "./backend-status.css"
5+
6+
const ago = (since: number) => {
7+
const seconds = Math.max(0, Math.round((Date.now() - since) / 1000))
8+
return seconds < 60 ? `${seconds}s` : `${Math.round(seconds / 60)}m`
9+
}
10+
11+
/** Fixed-size header slot: empty when healthy, a quiet spinner while background reads fail. */
12+
export const BackendStatus = () => {
13+
const [open, setOpen] = createSignal(false)
14+
const tick = usePulse(() => backendStatus() === "updating")
15+
const label = () => backendStatus() === "problem" ? "Some data could not be read" : "Updating — showing last known data"
16+
let root: HTMLSpanElement | undefined
17+
const close = (event: PointerEvent) => { if (root && !root.contains(event.target as Node)) setOpen(false) }
18+
document.addEventListener("pointerdown", close)
19+
onCleanup(() => document.removeEventListener("pointerdown", close))
20+
return (
21+
<span class="backend-status" ref={root} data-state={backendStatus() || "ok"}>
22+
<Show when={backendStatus()}>
23+
<button class="backend-status-button" aria-label={label()} title={label()} aria-expanded={open()}
24+
onClick={() => setOpen(!open())}>
25+
<span class="backend-status-dot" data-on={backendStatus() === "problem" || tick() % 2 ? "true" : undefined} aria-hidden="true" />
26+
</button>
27+
<Show when={open()}>
28+
<div class="backend-status-panel" role="dialog" aria-label="Diagnostics">
29+
<p>{label()}</p>
30+
<ul>
31+
<For each={backendIssues()}>{(issue) =>
32+
<li data-transient={issue.transient ? "true" : "false"}>
33+
<span>{issue.source}</span><span class="dim">{issue.detail} · {ago(issue.since)}</span>
34+
</li>
35+
}</For>
36+
</ul>
37+
</div>
38+
</Show>
39+
</Show>
40+
</span>
41+
)
42+
}

‎packages/es-app/src/components/composer-controls.tsx‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
import { For, Show } from "solid-js"
22
import { Markdown } from "@opencode-ai/session-ui/markdown"
33
import type { Composer } from "../composer"
4+
import type { Session } from "@opencode-ai/sdk/v2"
45
import { ComposerImages } from "./composer-images"
56

6-
export const ComposerResults = (props: { composer: Composer; connected: boolean }) => {
7+
export const ComposerResults = (props: { composer: Composer; connected: boolean; session?: Session }) => {
78
const state = props.composer.state
89
const pending = () => state.receipts.filter((item) => item.state === "pending" && item.source?.type !== "editspace-mail")
910
const queued = () => pending().filter((item) => item.delivery === "queue").length
1011
const steers = () => pending().filter((item) => item.delivery === "steer").length
1112
return (
1213
<div class="composer-results" data-composer-controls>
13-
<Show when={state.normalSubmission?.status !== "accepted" && state.normalSubmission}>
14+
{/* In-flight sends show only in the transcript echo; this row appears for an outcome that
15+
needs the human (unknown), so a routine send never inserts and removes a row here. */}
16+
<Show when={state.normalSubmission?.status === "unknown" && state.normalSubmission}>
1417
{(submission) => (
1518
<section class="normal-submission" aria-label="Message status">
1619
<div class="composer-actions">
1720
<span role="status">
18-
<b>{submission().action === "steer" ? "Send" : "Previous message"}</b> ·{" "}
19-
{submission().status === "sending"
20-
? "Sending…"
21-
: "Outcome unknown — check the conversation before resending"}
21+
<b>Not confirmed</b> · {submission().checking ? "checking…"
22+
: submission().absent ? "the server has no record of it"
23+
: submission().messageID ? "will check again when the server answers" : "check the conversation"}
2224
</span>
23-
<Show when={submission().status !== "sending"}>
24-
<button aria-label="Dismiss send status" onClick={() => props.composer.dismissNormalSubmission()}>
25-
Dismiss
26-
</button>
25+
<Show when={submission().messageID && !submission().absent}>
26+
<button disabled={submission().checking || !props.connected} onClick={() => void props.composer.checkSubmission()}>Check</button>
27+
</Show>
28+
<Show when={submission().absent && props.session}>
29+
{(session) => <button disabled={state.sending || !props.connected} onClick={() => void props.composer.sendAgain(session())}>Send again</button>}
2730
</Show>
31+
<button aria-label="Dismiss send status" onClick={() => props.composer.dismissNormalSubmission()}>
32+
Dismiss
33+
</button>
2834
</div>
2935
<p dir="auto">
3036
{submission().text}
@@ -33,7 +39,8 @@ export const ComposerResults = (props: { composer: Composer; connected: boolean
3339
</section>
3440
)}
3541
</Show>
36-
<Show when={state.admission && !state.admission.fence ? state.admission : undefined}>
42+
{/* A routine admission reports in the work-status slot; this row is for an unknown outcome. */}
43+
<Show when={state.admission && !state.admission.fence && state.admission.status !== "sending" ? state.admission : undefined}>
3744
{(admission) => (
3845
<section class="input-admission" aria-label="Input admission" aria-live="polite">
3946
<b>
@@ -63,11 +70,11 @@ export const ComposerResults = (props: { composer: Composer; connected: boolean
6370
</Show>
6471
<Show when={state.recoveries.length}>
6572
<details class="input-recoveries">
66-
<summary>Set-aside inputs ({state.recoveries.length})</summary>
73+
<summary>Not confirmed ({state.recoveries.length})</summary>
6774
<For each={state.recoveries}>
6875
{(entry) => (
6976
<section aria-label="Set-aside input" data-recovery-id={entry.admission.payload.requestID}>
70-
<b>{entry.admission.payload.delivery} · {state.receipts.find((item) => item.requestID === entry.admission.payload.requestID)?.state ?? "admission unknown"}</b>
77+
<b>{entry.admission.payload.delivery} · {state.receipts.find((item) => item.requestID === entry.admission.payload.requestID)?.state ?? "not confirmed"}</b>
7178
<p dir="auto">{entry.admission.payload.text}</p>
7279
<ComposerImages images={entry.admission.payload.images} />
7380
<p class="dim">Request <bdi>{entry.admission.payload.requestID}</bdi>. Kept locally; not cancelled.</p>

‎packages/es-app/src/components/direct-composer.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ export const DirectComposer = (props: {
3333
? "Session unavailable or another session action is running."
3434
: props.composer.reasonForAction(action)
3535
const empty = () => !props.composer.visibleDraft().text.trim() && !props.composer.visibleDraft().images.length
36+
// An in-flight send reports in the work-status slot; listing it here too would add and
37+
// remove a row under the controls on every send (es-app#186). Buttons keep it as a title.
3638
const reasons = () =>
37-
props.connected ? [...new Set([primary(), ...(menu() ? secondary() : [])].map(reason).filter(Boolean))] : []
39+
props.connected && !state.sending ? [...new Set([primary(), ...(menu() ? secondary() : [])].map(reason).filter(Boolean))] : []
3840
const other = () => state[state.visibleBuffer === "task" ? "aside" : "task"]
3941
// Keep textarea focus (and its selection) when a submit button is pressed.
4042
const keepFocus = (e: PointerEvent) => {

‎packages/es-app/src/components/mode-switch.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createEffect, Show } from "solid-js"
66
import { A, useLocation } from "@solidjs/router"
77
import { Glyph } from "./icons"
88
import { useDeskQueue } from "../desk-queue"
9+
import { BackendStatus } from "./backend-status"
910

1011
export type Mode = "desk" | "agents"
1112
export const modeOf = (pathname: string): Mode => pathname === "/" ? "desk" : "agents"
@@ -39,5 +40,7 @@ export const ModeSwitch = (props: { compact?: boolean }) => {
3940
<A href={href("agents")} class="mode-tab" aria-current={current() === "agents" ? "page" : undefined} title="Agents" aria-label={props.compact ? "Agents" : undefined}>
4041
<Show when={props.compact} fallback="Agents"><Glyph name="graph" /></Show>
4142
</A>
43+
{/* The mode switch is on every page, so it carries the one app-wide background-read status. */}
44+
<BackendStatus />
4245
</nav>
4346
}

‎packages/es-app/src/components/native-header.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export const NativeHeader = (props: ParentProps) => {
2929
)
3030
}
3131

32-
/** `inline` keeps the header in its own pane instead of the native titlebar, for a page embedded beside others. */
32+
/** `inline` keeps the header in its own pane instead of the native titlebar, for a page embedded beside others.
33+
*/
3334
export const AppHeader = (props: ParentProps<{ inline?: boolean }>) => (
3435
<Show when={nativeHeader && !props.inline} fallback={<header class="topbar">{props.children}</header>}>
3536
<Show when={headerTarget()}>

0 commit comments

Comments
 (0)