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): show an access error instead of an endless spinner for sessions you cannot open (#6843)

Wolf Mermelsteina3eee467758a
diff --git a/apps/web/src/features/agents-view/components/AgentSessionPane.tsx b/apps/web/src/features/agents-view/components/AgentSessionPane.tsx
index d0a3bc655c..7f70265f98 100644
--- a/apps/web/src/features/agents-view/components/AgentSessionPane.tsx
+++ b/apps/web/src/features/agents-view/components/AgentSessionPane.tsx
@@ -47,6 +47,7 @@ import type { NotificationSource } from '@notifications/notification-source';
import ArrowSquareOut from '@phosphor/arrow-square-out.svg';
import GitBranch from '@phosphor/git-branch.svg';
import ShareIcon from '@phosphor/share.svg';
+import { EmptyStatePanel } from '@ui';
import { createSignal, onCleanup, Show, Suspense } from 'solid-js';
import { ChatSessionInput } from './ChatComposer';
import { SessionModelSelector } from './ModelSelector';
@@ -70,8 +71,15 @@ function SessionContent(props: {
onDeleted: () => void;
notificationSource: NotificationSource;
}) {
- const { loadFailed, loadRetryable, metadata, retryLoad, session, sessionId } =
- useAgentSession();
+ const {
+ accessDenied,
+ loadFailed,
+ loadRetryable,
+ metadata,
+ retryLoad,
+ session,
+ sessionId,
+ } = useAgentSession();
const panel = useSplitPanelOrThrow();
const [shareOpen, setShareOpen] = createSignal(false);
const userId = useUserId();
@@ -226,10 +234,21 @@ function SessionContent(props: {
<Show
when={!loadFailed()}
fallback={
- <LoadErrorPanel
- title="Unable to load this session"
- onRetry={loadRetryable() ? retryLoad : undefined}
- />
+ <Show
+ when={accessDenied()}
+ fallback={
+ <LoadErrorPanel
+ title="Unable to load this session"
+ onRetry={loadRetryable() ? retryLoad : undefined}
+ />
+ }
+ >
+ <EmptyStatePanel
+ centered
+ title="You don't have access to this session"
+ description="Ask a participant to share it with you."
+ />
+ </Show>
}
>
<div class="transcript-host">
diff --git a/apps/web/src/features/block-agent/agent-session-provider.tsx b/apps/web/src/features/block-agent/agent-session-provider.tsx
index 61e0f597e4..e9953ec85a 100644
--- a/apps/web/src/features/block-agent/agent-session-provider.tsx
+++ b/apps/web/src/features/block-agent/agent-session-provider.tsx
@@ -110,7 +110,9 @@ export function AgentSessionProvider(
// A create that failed leaves the block with nothing to load, which
// is the same dead end for the reader as a load that failed.
loadFailed: () => live.loadFailed() || failed(),
- loadRetryable: live.loadFailed,
+ accessDenied: live.accessDenied,
+ // Retrying a 401 gets the same 401.
+ loadRetryable: () => live.loadFailed() && !live.accessDenied(),
retryLoad: live.retry,
turn,
issue: live.issue,
diff --git a/apps/web/src/features/block-agent/component/Block.tsx b/apps/web/src/features/block-agent/component/Block.tsx
index 16971e0a96..94af7d9763 100644
--- a/apps/web/src/features/block-agent/component/Block.tsx
+++ b/apps/web/src/features/block-agent/component/Block.tsx
@@ -48,6 +48,7 @@ function AgentBlockContent(props: {
session,
sessionId,
metadata,
+ accessDenied,
loadFailed,
loadRetryable,
pending,
@@ -73,10 +74,21 @@ function AgentBlockContent(props: {
<Show
when={startupError()}
fallback={
- <LoadErrorPanel
- title="Unable to load this agent session"
- onRetry={loadRetryable() ? retryLoad : undefined}
- />
+ <Show
+ when={accessDenied()}
+ fallback={
+ <LoadErrorPanel
+ title="Unable to load this agent session"
+ onRetry={loadRetryable() ? retryLoad : undefined}
+ />
+ }
+ >
+ <EmptyStatePanel
+ centered
+ title="You don't have access to this agent session"
+ description="Ask a participant to share it with you."
+ />
+ </Show>
}
>
{(error) => (
diff --git a/apps/web/src/features/block-agent/component/session-read-hosts.test.tsx b/apps/web/src/features/block-agent/component/session-read-hosts.test.tsx
index 52a598243e..e7ad262ee2 100644
--- a/apps/web/src/features/block-agent/component/session-read-hosts.test.tsx
+++ b/apps/web/src/features/block-agent/component/session-read-hosts.test.tsx
@@ -39,6 +39,7 @@ vi.mock('../context/AgentSessionContext', () => ({
: undefined,
metadata: () => undefined,
loadFailed: () => mocks.failed(),
+ accessDenied: () => false,
loadRetryable: () => true,
retryLoad: vi.fn(),
pending: () => false,
diff --git a/apps/web/src/features/block-agent/context/AgentSessionContext.tsx b/apps/web/src/features/block-agent/context/AgentSessionContext.tsx
index ffcbfd041d..9042a3a005 100644
--- a/apps/web/src/features/block-agent/context/AgentSessionContext.tsx
+++ b/apps/web/src/features/block-agent/context/AgentSessionContext.tsx
@@ -38,6 +38,8 @@ export type AgentSessionState = {
/** The folded transcript, ordered by turn, live-following the session. */
messages: Accessor<FoldedMessage[]>;
loadFailed: Accessor<boolean>;
+ /** The load failed because the viewer is not a participant (401/403). */
+ accessDenied: Accessor<boolean>;
/**
* Retry can re-run the failed load. False when the create itself failed —
* there is no session to refetch, so offering Retry would do nothing.
diff --git a/apps/web/src/features/block-agent/context/create-agent-session.test.tsx b/apps/web/src/features/block-agent/context/create-agent-session.test.tsx
new file mode 100644
index 0000000000..1a62d624c0
--- /dev/null
+++ b/apps/web/src/features/block-agent/context/create-agent-session.test.tsx
@@ -0,0 +1,104 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * The Solid face of a session whose load fails: the surface must be able to
+ * read `session()` and show its error state instead of leaving the enclosing
+ * `<Suspense>` on its fallback forever.
+ */
+
+import { err, ok } from 'neverthrow';
+import { Show, Suspense } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+const fold = vi.hoisted(() => ({
+ pushSession: vi.fn(),
+ readSession: vi.fn(),
+ closeSession: vi.fn(),
+}));
+const harness = vi.hoisted(() => ({
+ get: vi.fn(),
+ getLog: vi.fn(),
+ control: vi.fn(),
+}));
+
+vi.mock('@core/agent-fold/client', () => fold);
+vi.mock('@service-agent-harness/client', () => ({
+ agentHarnessServiceClient: harness,
+}));
+vi.mock('@queries/agent-session/queue-sync', () => ({
+ subscribeSocketSessionStarted: () => () => {},
+}));
+vi.mock('@queries/agent-session/session-metadata-sync', () => ({
+ subscribeAgentSessionRenamed: () => () => {},
+ subscribeAgentSessionUpdated: () => () => {},
+}));
+
+const { cleanup, render, screen } = await import('@solidjs/testing-library');
+const { AgentSession } = await import('@core/agent-session/AgentSession');
+const { createAgentSession } = await import('./create-agent-session');
+
+const SESSION = '01a0ced3-b839-75ee-bc9b-7b0a11ce0789';
+const bot = { id: 'bot-id', name: 'Agent', handle: 'agent' };
+const session = { id: SESSION, name: 'A session', canEdit: true };
+
+/** Reads the session row the way a pane's title does — outside any error gate. */
+function Pane() {
+ const live = createAgentSession(() => SESSION, { userId: () => 'me' });
+ return (
+ <>
+ <h1>{live.session()?.name ?? 'untitled'}</h1>
+ <Show when={live.loadFailed()}>
+ <p>{live.accessDenied() ? 'no access' : 'load failed'}</p>
+ </Show>
+ </>
+ );
+}
+
+const mount = () =>
+ render(() => (
+ <Suspense fallback={<p>loading</p>}>
+ <Pane />
+ </Suspense>
+ ));
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ for (
+ let leaked = AgentSession.get(SESSION);
+ leaked;
+ leaked = AgentSession.get(SESSION)
+ ) {
+ leaked.release();
+ }
+ fold.pushSession.mockResolvedValue([]);
+ fold.readSession.mockResolvedValue({
+ messages: [],
+ metadata: { turn: 'idle' },
+ });
+ harness.get.mockResolvedValue(ok(session));
+ harness.getLog.mockResolvedValue(ok({ bot, entries: [] }));
+});
+afterEach(cleanup);
+
+describe('createAgentSession', () => {
+ it('shows the fallback while loading and the session once loaded', async () => {
+ mount();
+ expect(screen.getByText('loading')).toBeTruthy();
+ expect(await screen.findByText('A session')).toBeTruthy();
+ });
+
+ it('leaves the fallback and reports a failed load', async () => {
+ harness.getLog.mockResolvedValue(err([{ code: 'SERVER_ERROR' }]));
+ mount();
+ expect(await screen.findByText('load failed')).toBeTruthy();
+ expect(screen.queryByText('loading')).toBeNull();
+ expect(screen.getByText('untitled')).toBeTruthy();
+ });
+
+ it('tells a 401 on the session apart from a generic failure', async () => {
+ harness.get.mockResolvedValue(err([{ code: 'UNAUTHORIZED' }]));
+ mount();
+ expect(await screen.findByText('no access')).toBeTruthy();
+ expect(screen.queryByText('loading')).toBeNull();
+ });
+});
diff --git a/apps/web/src/features/block-agent/context/create-agent-session.ts b/apps/web/src/features/block-agent/context/create-agent-session.ts
index fb9c83dccf..91e1055352 100644
--- a/apps/web/src/features/block-agent/context/create-agent-session.ts
+++ b/apps/web/src/features/block-agent/context/create-agent-session.ts
@@ -10,6 +10,7 @@
import {
AgentSession,
+ AgentSessionAccessDenied,
type IssueResult,
} from '@core/agent-session/AgentSession';
import type { AgentSessionRenamedEvent } from '@queries/agent-session/realtime-protocol';
@@ -50,6 +51,8 @@ export type AgentSessionHandle = {
/** The folded transcript, ordered by turn (prompt before reply). */
messages: Accessor<FoldedMessage[]>;
loadFailed: Accessor<boolean>;
+ /** The load failed because the viewer is not a participant (401/403). */
+ accessDenied: Accessor<boolean>;
/** Re-runs a failed load. */
retry: () => void;
/**
@@ -281,8 +284,17 @@ export function createAgentSession(
);
// A first fetch would suspend; see `openedPending`.
- const session = () =>
- openedPending && resource.state === 'pending' ? undefined : resource.latest;
+ //
+ // Once the load has failed, `resource.latest` rethrows the error on every
+ // read. Nothing above the block catches it, so the throw escapes Solid's
+ // update queue before the enclosing `<Suspense>` swaps its fallback back
+ // out, and the block shows a spinner forever instead of its error panel.
+ // The failure is reported through `loadFailed`; absent is what the row is.
+ const session = () => {
+ if (resource.error !== undefined) return undefined;
+ if (openedPending && resource.state === 'pending') return undefined;
+ return resource.latest;
+ };
return {
session,
@@ -290,6 +302,7 @@ export function createAgentSession(
metadata,
messages: () => list,
loadFailed: () => resource.error !== undefined,
+ accessDenied: () => resource.error instanceof AgentSessionAccessDenied,
retry: () => void refetch(),
issue: (action) => live()?.issue(action, { userId: options.userId() }),
expect: (actionId, action) =>
diff --git a/apps/web/src/lib/core/agent-session/AgentSession.test.ts b/apps/web/src/lib/core/agent-session/AgentSession.test.ts
index 28e7b2527c..0f5235a15c 100644
--- a/apps/web/src/lib/core/agent-session/AgentSession.test.ts
+++ b/apps/web/src/lib/core/agent-session/AgentSession.test.ts
@@ -40,7 +40,11 @@ vi.mock('@queries/agent-session/queue-sync', () => ({
subscribeSocketSessionStarted: socket.subscribeSocketSessionStarted,
}));
-import { AgentSession, AgentSessionReleased } from './AgentSession';
+import {
+ AgentSession,
+ AgentSessionAccessDenied,
+ AgentSessionReleased,
+} from './AgentSession';
import { resetSessionTurns, sessionTurn } from './session-turn';
const SESSION = '01a0abed-279f-724c-9f49-60dbedc79b6e';
@@ -478,6 +482,16 @@ describe('AgentSession', () => {
live.release();
});
+ it('names a 401 on the session or its log as denied access', async () => {
+ harness.get.mockResolvedValueOnce(err([{ code: 'UNAUTHORIZED' }]));
+ const live = AgentSession.acquire(SESSION);
+ await expect(live.load()).rejects.toBeInstanceOf(AgentSessionAccessDenied);
+
+ harness.getLog.mockResolvedValueOnce(err([{ code: 'FORBIDDEN' }]));
+ await expect(live.load()).rejects.toBeInstanceOf(AgentSessionAccessDenied);
+ live.release();
+ });
+
it('re-runs a failed load on the next call only', async () => {
harness.getLog.mockResolvedValueOnce(err([{ code: 'NOT_FOUND' }]));
const live = AgentSession.acquire(SESSION);
diff --git a/apps/web/src/lib/core/agent-session/AgentSession.ts b/apps/web/src/lib/core/agent-session/AgentSession.ts
index 654a13c63a..8948223088 100644
--- a/apps/web/src/lib/core/agent-session/AgentSession.ts
+++ b/apps/web/src/lib/core/agent-session/AgentSession.ts
@@ -64,6 +64,23 @@ export class AgentSessionReleased extends Error {
}
}
+/**
+ * The harness answered 401/403: the viewer is not a participant of this
+ * session. Retrying cannot help, and the surface should say so rather than
+ * report a connectivity problem.
+ */
+export class AgentSessionAccessDenied extends Error {
+ constructor(readonly sessionId: string) {
+ super(`agent session is not accessible to this user: ${sessionId}`);
+ this.name = 'AgentSessionAccessDenied';
+ }
+}
+
+const accessDenied = (errors: { code: string }[]) =>
+ errors.some(
+ (error) => error.code === 'UNAUTHORIZED' || error.code === 'FORBIDDEN'
+ );
+
/**
* Whether this action takes the turn, rather than riding alongside one. ACP
* runs a prompt at a time, so these are the ones the harness queues; mirrors
@@ -352,9 +369,13 @@ export class AgentSession {
agentHarnessServiceClient.getLog(this.id),
]);
if (session.isErr()) {
+ if (accessDenied(session.error)) {
+ throw new AgentSessionAccessDenied(this.id);
+ }
throw new Error(`agent session could not be fetched: ${this.id}`);
}
if (log.isErr()) {
+ if (accessDenied(log.error)) throw new AgentSessionAccessDenied(this.id);
throw new Error(`agent session log could not be fetched: ${this.id}`);
}
if (this.closed) throw new AgentSessionReleased(this.id);