Skip to content
Workbench
Esc
↑↓navigate↵open⌘Jpreview
On this page

Frontend data fetching

Read server state in the web app through TanStack Query, scoped by client, and track backend integration boundaries.

Current behavior

Shipping routes do not import demo records. The root verifies the Better Auth session and its active organization before rendering. The account menu and profile use that identity. Organization memberships are labelled organization access, not clients. The normal directory omits organization-access controls and does not fetch the membership list. When no organization is selected or directory access is denied, the recovery view shows the organization selector. It lists existing memberships and persists the choice through Better Auth; it does not create memberships, change permissions, or select an organization automatically.

The clients page reads the shared GET /clients contract through Effect’s native HttpApiClient on the web server. A successful empty directory, missing actor access, failed request, and absent organization selection have distinct UI states. The Add client action uses the server-derived canCreateClient; submission waits for persisted creation, preserves the name on failure, and refreshes the directory before navigation. Client creation does not provision a Finance space or start an agent.

The provider client root retains the viewer’s private agent page and conversation, with its All to-dos and Apps & Files tabs. Settings use the settings rail and a full-width configuration page, without a conversation panel or mobile Chat button. General reads the persisted client name, kind and optional provider name from the actor-scoped directory. People reads its authorized membership projection independently of firm administration. Linked-client People exposes the narrow client-admin onboarding flow to firm admins, leads and operators. Connections opens the live space-scoped connections directory. Client Rules and memory are hidden from navigation and their route is unavailable for now. Unsupported private execution and other settings content remain explicitly unavailable. The restricted shared-conversation route connects its own files and output-card panels. The owner home and client root expose authorized shared-conversation discovery, including rooms shared without full-space access. The Paper space catalog enables Finance creation as a separate request gated by canManageSpaces, owned by the active organization and explicitly bound to that client. Existing Finance spaces open by persisted type and UUID. Support, Growth and Space Builder remain visibly unavailable with disabled actions. Space pages and task details render persisted task titles, status, descriptions, labels and assignment. Task pages retain their task-specific conversation layout and Details, Messages, Supporting files and Record views; Context, Draft, facts and history show unavailable panels until their persisted projections exist. A task conversation uses its own query key and never falls back to a space-wide chat. They do not invent owner names, industries, activity, attention counts, due dates, agent jobs, evidence, earlier drafts, or request/reply state. The space and All to-dos lists preserve Paper’s flat ruled rows and URL-backed Status, Owner, and Search controls. Both default to the viewer’s open tasks (Ready, In progress, Needs fixing); Owner also offers Everyone and Unassigned. Done and Archived require an explicit status selection. Tab counts show all authorized open tasks across owners, independently of the list filters. Rows show persisted creation dates explicitly as Created; other assignees remain unnamed until an authorized people projection exists. Empty filter results retain the controls and Clear action. Task write controls remain absent until exact write capabilities are supplied. Agent profile settings, memory, conversations, apps and files retain explicit unavailable states.

Each active space supplies its own read capabilities. Client-level aggregate capabilities never widen a space’s permissions. Client-facing-only presentation excludes the Team channel and internal task pages. Conversation-only discovery uses the existing narrow conversation summary and opens a restricted /shared/:conversationId route; it is never cast into a full space or task DTO. See Owner entry for that boundary. A completed task never implies that a client has answered a request.

Queries and isolation

Feature query options stay in features/<feature>/queries.ts. Route loaders start the same queries that components read with useQuery or useSuspenseQuery. Data-dependent panels retain skeletons and errors; no artificial timers delay a response.

TanStack Router links preload their destination routes and loader data when they enter the viewport (defaultPreload: "viewport"). Preloading uses the same Query cache as navigation, with defaultPreloadStaleTime: 0 leaving data freshness to Query.

Space routes also start the active channel’s first conversation history after the room list resolves, before the conversation panel mounts. The panel reads the same cached message query; navigation remains nonblocking, and failures stay in the panel’s existing error state.

getRouter creates one QueryClient per server request and one in the browser. The directory key includes the verified user and active organization as ["actor", userId, organizationId, "directory"]. The root clears cached data when either changes. Organization switching and sign-out use full navigation to discard the previous actor’s browser state. Freshness defaults to 60 seconds. Unsupported feature keys still use client/space identifiers, but cannot cache successful data before their adapters are connected.

Active directory and persisted conversation queries refresh every 10 seconds while the browser is in the foreground and immediately when it returns to the foreground, even while cached data is fresh. This covers changes from another viewer, tab or scheduled agent. Conversation reads include room discovery and capabilities, messages, interactions, files and output cards. Inactive queries do not poll; agent initialization and operation status retain their separate lifecycle. The polling fallback does not provide instantaneous delivery across viewers.

Transient read failures preserve the last successful cache value and unsaved conversation drafts while subsequent refreshes retry. Initial reads still show loading/error states. Explicit access denial replaces cached results, and actor-scope conflicts still clear the old actor’s data through global recovery.

The shared server-only transport forwards method, body, cookies and origin through the API binding (or the configured local API target). Every authenticated domain request also carries the rendered user ID and nullable organization as the shared expected-actor precondition. The web server must not replace that expectation with the current cookie’s actor. The native Better Auth organization switch carries the same rendered precondition. Its existing before hook compares the previous user and nullable active organization against the cached session reused by the native endpoint, before any switch. The target organization may differ, and initial selection from no active organization is allowed. Native ACTOR_SCOPE_CHANGED conflicts use the same whole-page recovery without retrying the switch. The API compares it against the same verified session snapshot used for authorization; it rejects a mismatch with ActorScopeChanged (409) before an operation runs. The expected user header is mandatory; omitting the organization header with a user header explicitly expects no active organization. Effect’s shared contracts own request encoding and response decoding. Client forms reuse exported contract input schemas; the space catalog submits the Finance preset through the shared space contract.

Unsupported reads in features/backend.ts reject with FeatureUnavailableError; they never resolve empty arrays or fixtures. Query does not retry these errors. Start registers a native serialization adapter so unavailable states survive hydration. The router uses the existing ErrorPage as its default error component as well as its root boundary: server rendering resolves failing child matches directly, so the initial document must already contain the correct fallback. Real request failures retain retry behavior; authorization denial is not described as an uninstalled service.

Queries and backend integration points

Boundary Removed behavior Required integration
Client directory Fixture clients, owners, industries, activity and counts Connected shared directory/create contract with verified actor scope
Identity and audience Fixture viewer/firm/owner, account-menu impersonation, as, answered, setup selectors Verified organization/space capabilities and server-filtered audiences
Spaces Fixture proposals and own workflow selector Connected persisted reads and explicit create/bind; no agent or financial-import side effects
Tasks Fixture statuses, owners, drafts, evidence and history Persisted task reads and capability-gated writes; request state comes from conversation interactions
Conversations Scripted posts, setup activity, connected systems and owner replies Persisted Team/Client conversations, deliberate sharing, replies and uploads
Agent Simulated private messages and generated files Organization-scoped personal agent; named personal files remain unavailable
Apps and files Fabricated outputs, charts, runs, files and sharing Persisted outputs/files; app builder is deferred
Settings Fixture rules, people, connections, memory, reach and spend Authorized section-specific reads and mutations

The old fixture adapter and URL view helper are removed. Historical fixture records and obsolete sample-only wrappers are removed. Obsolete fixture-specific metadata is retired. Useful private-agent, task-review, conversation, canvas and settings layouts remain, with generic content slots or unavailable boundaries for unsupported projections.

Client directory contract

GET /clients supplies the authorized directory aggregate: actor context (provider or owner), server-derived canCreateClient, and clients with persisted IDs, names, kinds, spaces, and tasks. Provider clients come from current client_of relationships targeting the active firm, not the viewer’s organization memberships. Owner context returns the acting business and only explicitly readable spaces. Each space’s tasks are independently filtered through task permissions.

The server reads membership, clients, readable spaces, and readable tasks in up to four SELECT queries using one read-only transaction snapshot. Space and task queries cover all visible parents in the directory.

Every client and space includes capabilities.readInternalWork and readClientFacingWork, plus canManageSpaces. Client-level read capabilities summarize returned spaces; they never authorize a space that has different permissions. Treat missing capabilities as unavailable. The optional providerName comes only from authorized returned spaces. The response does not invent industry, owner, last-activity, attention, or reply data. Adapt persisted task status and assignment deliberately; client request/reply state comes from explicit conversation requests and answers, never from task completion.

Each returned space includes canCreateTasks, based on space ownership and the actor’s role. Each returned ClientTask extends the persisted task with canUpdate and canDelete, computed independently from the actor’s role and matching task grants. The server emits these booleans; the shared schema decodes missing fields from an older payload as false, preserving reads during a rolling deployment. Read access and space management never imply task writes. assignee names the task’s owner, with their photo, only for viewers who can read internal work; other viewers see that it is assigned. Mutation endpoints always recheck authorization.

In a space’s To do tab, New task appears only with canCreateTasks. Its dialog persists title, description, workflow status, owner, and an optional due date, with the same controls as the task page; assigning a client asks first here too. The description is the task page’s Markdown editor. Enter in the title, or Command or Control with Enter, creates the task. A dismissed dialog retains its draft, and a failed save retains its entries. A successful creation closes the dialog, refreshes the actor-scoped directory and offers a link to the task.

A task page edits in place. With canUpdate, the title and the description are fields that save when the viewer leaves them; Enter saves the title, Command or Control with Enter saves the description, and Escape puts the saved text back. A blank title is not saved. The description is Markdown in a Tiptap editor that loads only for people who can update the task; text that nobody changed is not rewritten, and Markdown the editor would lose (tables, checklists, images, HTML) is edited as text. Status is a select and Owner a people search, and a choice saves at once. Due date is a calendar with a time, which starts at 5pm: closing it saves the choice, Escape does not, and Clear removes it. A picked time is the viewer’s own, and every viewer sees the moment on their own clock. Owner also takes canCreateTasks in the owning organization, because the server requires it, and assigning a client asks first, because it shares the task. With canDelete, the band’s Task actions menu deletes the task after a confirmation; its conversations, messages and files go with it.

Each edit sends one field with the value it replaces as expected. A draft keeps its text through background refreshes. A conflict shows both values and lets the viewer choose; a failed save keeps the text and offers Retry; a draft whose page goes away is saved, and closing the tab warns first. A saved task updates the cached directory before it reloads.

Every write sends the full rendered actor scope through the shared contract client. A scope-change response invokes page-wide recovery without retrying the write. Visibility is not derived from a stored audience label.

POST /clients accepts only a name and returns the new client with no spaces. See client directory authorization for role, retry, and creation semantics. Finance space creation remains a separate request using the new client’s persisted ID as businessOrganizationId.

Mutations

Client, space, and task mutations await server acknowledgement and invalidate the current actor’s directory. A scope conflict is not a retryable mutation: the root replaces the whole old page with recovery UI, removes stale cache data and reloads the verified root without replaying the form. Background reads use the same recovery, so an old account’s rail and conversation do not remain visible. Validation and request failures preserve entered values. The human conversation UI connects Team room creation and human Send in existing Team and Client rooms to persisted, scope-bound APIs. Client replies require the exact room write capability; they do not imply task or space writes. The shared-conversation UI also connects questions and answers, mentions, read acknowledgement, conversation file upload/download and explicit immutable output-card publication. General app creation, scheduling, connection actions and settings mutations remain separate integrations. Never fall back to fixtures after an API failure.

When a tracked Team agent reaches done or unanswered, the UI immediately invalidates the initiating actor’s directory, shared-conversation discovery/details, and conversation content and capabilities in the affected space. Active readers refetch, updating task lists and details as well as destination Client conversations. Tools commit independently of the final reply, so an unanswered turn still reconciles successful changes. Agent initialization and operation-status queries are excluded from this invalidation to avoid restarting their control loop.

The task model defines the persisted resource hierarchy, workflow statuses, ownership, and separate UI attention states. Space creation, persisted task reads, and task mutations with exact write capabilities are connected. Integration must use persisted UUIDs, preserve the session’s active organization and grant checks, and adapt API resources to each view. A task item’s incrementing version stores current content; it cannot supply TodoDraft.earlier or version-bound approval history.

Existing contracts also include organization relationships, members, invitations, and access grants. Their presence does not imply permission to mutate them. The narrow client-creation workflow does not broaden generic relationship or access-grant management permissions.

Optimistic conversation messages

Team and Client messages use TanStack Query’s pending mutation state to appear immediately with a Sending indicator once attachments finish uploading. Pending rows are scoped to the rendered actor, space, task, and conversation. They remain separate from saved messages so read receipts use confirmed message IDs.

On success, the saved response updates the message cache immediately and refreshes messages and interactions in the background. Message IDs prevent duplicates if a read returns the new message before the save response. Failed sends remove the pending row and retain the composer draft and exact retry ID. Access denial hides the conversation; an actor-scope change clears cached actor data and starts page-wide recovery.

Was this page helpful?