Sync / Replicated state
4. What the user sees, and what waits for the server
Local edits appear in Model immediately while pending sync. Two cases require explicit handling:
- Rejected edits: When the server rejects an operation, the replica drops it, replays the remaining queue, and reverts the UI, recording the refusal (
ForbiddenorInvalid) inreplica.status.rejected. - Actions requiring server confirmation: Agent tools or "shared with team" confirmations wait on
mounted.committed(the server-confirmed slice without pending edits):
ts
import { Agent } from 'foldkit-agent'
const TodoAgent = Agent.forApplication(App)
const agent = TodoAgent.make({
messages: TodoAgent.expose(Message, {
CreatedTodo: {
name: 'create_todo',
description: 'Create a shared todo',
completion: Agent.when({
source: mounted.committed,
predicate: (shared, request) => shared.todos.some(todo => todo.id === request.id),
}),
},
}),
})This completes only after the server commits CreatedTodo and skips rejected edits. See what a reader sees while a change is in flight.