Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): stop claiming there are no Sessions while the list is still resolving (#445)

Myriad-Dreamin434f320ee6e9
diff --git a/changelog/unreleased/2026-08-24-chat-empty-state.md b/changelog/unreleased/2026-08-24-chat-empty-state.md
new file mode 100644
index 00000000..2a842492
--- /dev/null
+++ b/changelog/unreleased/2026-08-24-chat-empty-state.md
@@ -0,0 +1,27 @@
+# The chat area stops saying "No Sessions yet" over a list that is about to arrive
+
+- **Date:** 2026-08-24
+- **Type:** fix
+- **Scope:** `web`
+
+[中文版](2026-08-24-chat-empty-state.zh.md)
+
+Two windows where the conversation area claimed there was nothing to show, in front of a list
+that was seconds from appearing. Both are gone.
+
+## An Agent set still being fetched is a list still loading
+
+The Session list cannot be fetched without an Agent set, and the fetch returns early when there
+is none — deliberately leaving the loading flag alone, since nothing was loaded. Nothing else
+covered that window, so after the first successful load it read "loaded". Every Project switch
+clears the Agents and refetches them, which meant a stretch of "loaded, and there is nothing
+here" over an emptied list. Three consumers gated on that flag and all three were wrong for its
+duration, including a redundant lookup for a Session the list had merely not fetched yet.
+
+## A routed Session is not a missing one
+
+The list is paged, so an id in the route that is not among the loaded rows is ordinary — a deep
+link, a Session just created, a row beyond the first page — and it is settled by a direct
+lookup, not by assuming the Session is gone. The auto-select effect already refused to conclude
+anything while that lookup was outstanding; the render concluded it anyway and drew the empty
+state for however long the lookup took. It now waits on exactly what the effect waits on.
diff --git a/changelog/unreleased/2026-08-24-chat-empty-state.zh.md b/changelog/unreleased/2026-08-24-chat-empty-state.zh.md
new file mode 100644
index 00000000..bbb5efd1
--- /dev/null
+++ b/changelog/unreleased/2026-08-24-chat-empty-state.zh.md
@@ -0,0 +1,22 @@
+# 会话区不再对着马上就要出现的列表说"还没有会话"
+
+- **日期:** 2026-08-24
+- **类型:** fix
+- **范围:** `web`
+
+[English](2026-08-24-chat-empty-state.md)
+
+有两处窗口期,会话区会声称没有内容可显示,而列表其实几秒后就到。两处都已修复。
+
+## 智能体集合还在拉取,说明列表仍在加载
+
+没有智能体集合就没法拉会话列表,因此没有时会提前返回——并且刻意不动 loading 标志,因为什么都没加载。
+在此之前没有别的东西覆盖这段窗口,于是首次加载成功之后它就一直读作"已加载"。而每次切换项目都会清空并
+重新拉取智能体,这就出现了一段"已加载,而且这里什么都没有"——盖在一个刚被清空的列表上。有三处消费这个
+标志的地方在这段时间里全是错的,其中一处还会为一个只是尚未拉取的会话发起多余的查找。
+
+## 路由里的会话不等于不存在的会话
+
+列表是分页的,所以路由里的 id 不在已加载的行里是很正常的——深链接、刚创建的会话、第一页之外的行——
+这要靠一次直接查找来判定,而不是假定会话已经没了。自动选中的 effect 本来就拒绝在查找未完成时下结论;
+渲染却照样下了结论,并在整个查找期间画出空状态。现在渲染等待的条件和 effect 完全一致。
diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsx
index 4b1bdcdf..64a2c59c 100644
--- a/packages/web/src/components/layout/sidebar.tsx
+++ b/packages/web/src/components/layout/sidebar.tsx
@@ -1419,9 +1419,16 @@ export function Sidebar({
return (
<>
{empty ? (
- <p className="px-2.5 py-1 text-xs text-gray-400 dark:text-gray-600">
- {S.chat.noSessions}
- </p>
+ loading ? (
+ // The same window the chat pane's skeleton covers: the Agent groups render as
+ // soon as the Agents arrive, but the session pages are still being fetched —
+ // "no Sessions yet" is not the honest answer until they land.
+ <SkeletonList rows={2} />
+ ) : (
+ <p className="px-2.5 py-1 text-xs text-gray-400 dark:text-gray-600">
+ {S.chat.noSessions}
+ </p>
+ )
) : (
// Drag-reorder is offered on the active list under manual sort (folders keep
// chronological order), and never on a search-filtered view.
diff --git a/packages/web/src/features/chat/chat-page.tsx b/packages/web/src/features/chat/chat-page.tsx
index 62a30329..182f74db 100644
--- a/packages/web/src/features/chat/chat-page.tsx
+++ b/packages/web/src/features/chat/chat-page.tsx
@@ -587,9 +587,20 @@ export function ChatPage() {
// below concludes it doesn't exist; only a failed probe releases that redirect.
const probeKey = projectId && routeSessionId ? sessionProbeKey(projectId, routeSessionId) : null;
const [probeFailedKey, setProbeFailedKey] = useState<string | null>(null);
+ /**
+ * The route names a Session we cannot answer for YET: not in the loaded pages, and the
+ * direct lookup that settles it has not failed. Ordinary with a paged list — a deep link,
+ * a Session just created, a row beyond the first page. Shared by the probe effect, the
+ * auto-select effect and the render, so the three cannot disagree about what "pending"
+ * means — their disagreeing is what once painted "no Sessions yet" over a conversation
+ * that was about to appear.
+ */
+ const routeSessionPending = !!routeSessionId && selected === null && probeFailedKey !== probeKey;
useEffect(() => {
if (draft || !projectId || !routeSessionId || !probeKey || sessionsLoading) return;
- if (sessions.some((s) => s.sessionId === routeSessionId)) return;
+ // Settled (row loaded, or the lookup already failed): nothing to probe — and a failed
+ // key must not be re-probed just because the list's identity churned.
+ if (!routeSessionPending) return;
// We deleted this Session ourselves: the row is gone from the list on purpose, so the
// lookup below could only 404 (and the server would record that as an error). Deleting
// the conversation you are looking at is the normal way to discard a Session fork, so
@@ -614,13 +625,17 @@ export function ChatPage() {
return () => {
cancelled = true;
};
+ // `selected` rather than `sessions`: while the routed row stays unloaded, list churn
+ // (status flips, new pages) keeps it null and leaves the in-flight lookup alone —
+ // depending on the array identity cancelled and re-issued it on every user event.
}, [
draft,
projectId,
routeSessionId,
probeKey,
sessionsLoading,
- sessions,
+ routeSessionPending,
+ selected,
addSession,
isSessionDeleted,
]);
@@ -631,12 +646,12 @@ export function ChatPage() {
// (instead of auto-creating one).
useEffect(() => {
if (sessionsLoading || draft) return;
- if (routeSessionId && sessions.some((s) => s.sessionId === routeSessionId)) return;
+ if (selected !== null) return;
// A routed id missing from the paged list isn't gone until the direct lookup fails.
- if (routeSessionId && probeFailedKey !== probeKey) return;
+ if (routeSessionPending) return;
const last = latestConversation(sessions);
navigate(last ? `/chat/${last.sessionId}` : `/chat/${DRAFT_SESSION_ID}`, { replace: true });
- }, [sessionsLoading, draft, routeSessionId, probeKey, probeFailedKey, sessions, navigate]);
+ }, [sessionsLoading, draft, selected, routeSessionPending, sessions, navigate]);
// Sync task_state to the sidebar list badge.
//
@@ -2024,7 +2039,7 @@ export function ChatPage() {
</div>
</>
)
- ) : sessionsLoading ? (
+ ) : sessionsLoading || routeSessionPending ? (
<div className="space-y-3 p-6">
<Skeleton className="h-5 w-1/2" />
</div>
diff --git a/packages/web/src/state/sessions.tsx b/packages/web/src/state/sessions.tsx
index 646713af..047bc47b 100644
--- a/packages/web/src/state/sessions.tsx
+++ b/packages/web/src/state/sessions.tsx
@@ -63,6 +63,12 @@ interface SessionsContextValue {
isLoadedFor: (agentId: string, category: SessionCategory, workspaceGroup?: string) => boolean;
/** Whether the server still holds unfetched Sessions of a category for an Agent (or for one of its Workspace groups) — an unloaded pair answers from the counts. */
hasMoreFor: (agentId: string, category: SessionCategory, workspaceGroup?: string) => boolean;
+ /**
+ * Whether the list is still being assembled — including the window where the Agent set it
+ * is fetched for is itself being refetched (a Project switch clears it). Consumers gate
+ * their "no sessions" empty state on this, so it must not read false while the answer is
+ * merely not known yet.
+ */
loading: boolean;
reload: () => Promise<void>;
/** Fetches a category's first page for each given unloaded Agent and the next page for each loaded one with more (no-op otherwise); `workspaceGroup` pages that group's own stream instead of the Agent's whole one. */
@@ -235,6 +241,10 @@ export function createSessionsStore() {
reload: async () => {
const { projectId, agentIds } = get();
+ // No context to fetch against yet. `loading` is deliberately left alone rather than
+ // cleared: nothing was loaded, so reporting "done" here would be a lie — and one the
+ // empty state renders. The Provider's reset step raised it and a later reload,
+ // once an Agent set exists, is what clears it.
if (!projectId || agentIds.length === 0) return;
const g = ++gen;
set({ loading: true });
@@ -611,6 +621,13 @@ export function SessionsProvider({ children }: { children: ReactNode }) {
pageState: new Map(),
countsByAgent: new Map(),
workspaceCountsByAgent: new Map(),
+ // The pages were just cleared, so the list is loading from this instant — including
+ // the window where the Agent set itself is still being refetched (a Project switch
+ // empties it, which makes reload() below return without fetching or clearing the
+ // flag). Raising it HERE, on fetch-context change, is what keeps an unrelated
+ // reloadAgents() — same agent set, fired after every completed turn — from flapping
+ // the app-wide flag.
+ loading: true,
});
void store.getState().reload();
}, [store, projectId, agentIdsKey]);
@@ -655,21 +672,28 @@ export function SessionsProvider({ children }: { children: ReactNode }) {
[store],
);
- const value = useMemo<SessionsContextValue>(() => {
- const byAgent = new Map<string, SessionInfo[]>();
+ // Keyed on the rows alone: the outer value memo re-runs on every store change (status,
+ // titles, page state), and rebuilding + re-sorting every Agent's bucket for those would be
+ // pure waste.
+ const byAgent = useMemo(() => {
+ const map = new Map<string, SessionInfo[]>();
for (const s of state.sessions) {
- const list = byAgent.get(s.agentId);
+ const list = map.get(s.agentId);
if (list) list.push(s);
- else byAgent.set(s.agentId, [s]);
+ else map.set(s.agentId, [s]);
}
// Encounter order is no longer reliable with paging (appended pages are older, but a
// deep-linked old session is prepended via add): sort each Agent's list newest first
// (same key the server sorts by).
- for (const list of byAgent.values()) {
+ for (const list of map.values()) {
list.sort(
(a, b) => b.createdAt.localeCompare(a.createdAt) || b.sessionId.localeCompare(a.sessionId),
);
}
+ return map;
+ }, [state.sessions]);
+
+ const value = useMemo<SessionsContextValue>(() => {
return {
sessions: state.sessions,
byAgent,
@@ -687,7 +711,7 @@ export function SessionsProvider({ children }: { children: ReactNode }) {
setStatus: state.setStatus,
setTitle: state.setTitle,
};
- }, [state, isLoadedFor, hasMoreFor, isDeleted]);
+ }, [state, byAgent, isLoadedFor, hasMoreFor, isDeleted]);
return <SessionsContext.Provider value={value}>{children}</SessionsContext.Provider>;
}
diff --git a/packages/web/test/sessions-loading.test.ts b/packages/web/test/sessions-loading.test.ts
new file mode 100644
index 00000000..b6076825
--- /dev/null
+++ b/packages/web/test/sessions-loading.test.ts
@@ -0,0 +1,26 @@
+/**
+ * The store's `loading` flag never lies "done" (state/sessions.tsx).
+ *
+ * The flag is what every "no Sessions yet" empty state gates on, so its one hard rule is
+ * that it must not read false while nothing has been fetched. The store is exercised
+ * directly (node, no DOM): the Provider's reset step owns *raising* the flag on a
+ * fetch-context change, which a store test cannot see — what it can pin is that the store
+ * itself never clears the flag without having loaded anything.
+ */
+import { describe, expect, it } from "vitest";
+import { createSessionsStore } from "../src/state/sessions";
+
+describe("sessions store loading", () => {
+ it("starts loading — a fresh store has fetched nothing", () => {
+ expect(createSessionsStore().getState().loading).toBe(true);
+ });
+
+ it("reload() without an Agent set returns without claiming to be done", async () => {
+ const store = createSessionsStore();
+ store.setState({ projectId: "proj", agentIds: [] });
+ await store.getState().reload();
+ // Nothing was fetched, so nothing may report "loaded" — clearing here is what painted
+ // an empty state over a list that was merely not known yet.
+ expect(store.getState().loading).toBe(true);
+ });
+});